food-card.js 3.15 KB
// component/menu/addDelete.js
import util from '../../../utils/util';
import App from '../../../utils/api';
const {regeneratorRuntime} = global
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      type: Object,     // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
    },
    sellerid: {
      type: Number
    },
    orderid: {
      type: Number
    },
    fromSoucre: {
      type: Number,
      value: 0
    },
    request_uri: {
      type: Boolean,
      value: false,
    },
    hasListModel: {
      type: Boolean,
      value: false,
    },
    identity: {
      type: String,
      value: '',
    },
    seeAll:String,//只看标识
  },

  /**
   * 组件的初始数据
   */
  data: {
    item_clear_num: null,
    hasIPhone: false,
    labelIcon: {
      'https://xt05.colorcun.com/uploads/label/lijie.png': '力荐',
      'https://xt05.colorcun.com/uploads/label/tejia.png': '特价',
      'https://xt05.colorcun.com/uploads/label/xinpin.png': '新品',
      'https://xt05.colorcun.com/uploads/label/zhaopai.png': '招牌',
    },
  },
  attached () {
    console.log('food-card-ready', this.data.orderid, this.data.fromSoucre)
    let item = this.data.item;
    let item_clear_num;
    if (typeof item.item_clear_num != 'undefined') {
      item_clear_num = item.item_clear_num;
    } else {
      item_clear_num = item.clear_num;
      if (item.spec) {
        let clear_num = null;
        item.spec.forEach(spec => {
          if (spec.clear_num == 0) {
            clear_num = 0;
          } else {
            clear_num = null;
          }
        })
        if (clear_num == 0) {
          item_clear_num = 0;
        }
      }
    }

    this.setData({
      item_clear_num: item_clear_num,
      hasIPhone: getApp().system.model.indexOf('iPhone') > -1
    });
  },
  detached(){

  },
  /**
   * 组件的方法列表
   */
  methods: {
    //规格 增加/减少 回调
    foodSpecCallback(e){
      let opt = e.detail;
      console.log('foodSpecCallback', opt);
      if (opt.type == 'specWin') {
        return this.triggerEvent('foodCardCallback', opt);
      }
      let item = this.data.item;
      let oldNum = (item.num || 0);
      item.num = (item.num || 0) + opt.type;
      let rotateFlag = (oldNum == 0 || item.num == 0);
      console.log('num_rotate', rotateFlag);
      this.setData({item: item, rotate_id: rotateFlag ? item.id : ''});
      opt.num = item.num;
      this.triggerEvent('foodCardCallback', opt);
    },

    //清除订单下某菜品所有数量
    delOrderCook: function () {
      this.selectComponent("#foodSpecDel").clean();
    },
    //triggerAdd
    triggerAdd(e){
      console.log('triggerAdd', e)
      if (this.data.item_clear_num == 0) return;
      this.selectComponent("#foodSpecAddOne").addCook();
    },
    //viewIMage
    viewImage(){
      wx.previewImage({
        current: this.data.item.image, // 当前显示图片的http链接
        urls: [this.data.item.image], // 需要预览的图片http链接列表
      })
    },
    foodSpecAdd(e){
      this.selectComponent("#foodSpecAdd-"+util.attr(e,'id')).addCook();
    },
  },
})