const _Http = getApp().globalData.http;

Component({
  properties: {
    isOldPrice: {
      type: Boolean
    },
    prefix: {
      type: String,
      value: ""
    }
  },
  data: {
    item: null,
    show: false
  },
  methods: {
    onClick(item) {
      if (this.data.product != null && item.itemid == this.data.product.itemid) return this.setData({
        show: true
      })
      wx.showLoading({
        title: '获取定制方案中..',
      })
      this.selectComponent("#customMade").init(item, this.data.prefix).then(res => {
        wx.hideLoading();
        if (res) {
          this.setData({
            show: true
          })
        } else {
          wx.showToast({
            title: '未获取到定制方案',
            icon: "none"
          })
        }
      })
      this.selectComponent("#Dialog").data.beforeClose = (action) => new Promise((resolve) => {
        if (action === 'confirm') {
          let custom = {
            length: 0,
            width: 0
          };
          //是否为定制项
          custom = this.selectComponent("#customMade").getResult(true);
          if (typeof custom == "boolean") return resolve(false);
          getApp().globalData.customizedProduct(item, custom).then(res => resolve(true))
        } else {
          resolve(false);
          this.setData({
            show: false
          })
        }
      });
    }
  }
})