import { alertInfo, alertSuccess, loadingFunc } from "../../utils/index"
import { redeemCoupons } from "../../service/system";
import request from "../../utils/request"
const { OK } = request;

// components/discountCoupon/index.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    type: Number,
    data: Object
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleChange() {
      const { data } = this.data;
      const that = this;
      loadingFunc(async () => {
        const { code, message } = await redeemCoupons({ id: data.id, type: 2 })
        if (code !== OK) {
          alertInfo(message)
          return
        }
        alertSuccess("兑换成功")
        that.triggerEvent("change", { id, type: 2 })
      })
    },
    showRemark() {
      wx.showModal({
        title: '备注',
        content: this.data?.data?.remark,
        showCancel: false,
        complete: (res) => {
          if (res.cancel) {
            
          }
      
          if (res.confirm) {
            
          }
        }
      })
      
    },
    handleUseIt() {
      alertInfo("敬请期待")
    },
    async handleUse() {
      const { data } = this.data;
      const that = this;
      loadingFunc(async () => {
        const { code, message } = await redeemCoupons({ id: data.id, type: 2 })
        if (code !== OK) {
          alertInfo(message)
          return;
        }
        alertSuccess("领取成功")
        that.triggerEvent("get", { id, type: 1 })
      })
      
    }
  }
})