import {
  imageProps
} from "~/miniprogram_npm/@vant/weapp/uploader/shared";
import {
  addCustomerCoupon
} from '~/services/coupon/addCustomerCoupon';

const statusMap = {
  1: {
    text: '去使用',
    theme: 'primary'
  },
  2: {
    text: '已使用',
    theme: 'default'
  },
  3: {
    text: '已过期',
    theme: 'default'
  },
  4: {
    text: '领取',
    theme: 'primary'
  },
  5: {
    text: '已领取',
    theme: 'default'
  },
};
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true, // 在组件定义时的选项中启用多slot支持
  },

  externalClasses: ['coupon-class'],

  properties: {
    couponDTO: {
      type: Object,
      value: {}, // 优惠券数据
    },
  },

  data: {
    btnText: '',
    btnTheme: '',
  },

  observers: {
    couponDTO: function (couponDTO) {
      if (!couponDTO) {
        return;
      }
      const statusInfo = statusMap[couponDTO.status];
      this.setData({
        btnText: statusInfo.text,
        btnTheme: statusInfo.theme,
      });
    },
  },

  attached() {},

  methods: {
    // 跳转到详情页
    // gotoDetail() {
    //   wx.navigateTo({
    //     url: `/pages/coupon/coupon-detail/index?id=${this.data.couponDTO.key}`,
    //   });
    // },

    // 跳转到商品列表
    gotoGoodsList() {
      let status = this.properties.couponDTO.status
      let couponGuid = this.properties.couponDTO.couponGuid
      if (status == 4) {
        addCustomerCoupon({
          couponGuid
        }).then((res) => {
          if (res.code === 200) {
          this.triggerEvent('refresh')
          wx.showToast({
              icon: '',
              title: res.data,
            });
          }
        })
      }
      // wx.navigateTo({
      //   url: `/pages/coupon/coupon-activity-goods/index?id=${this.data.couponDTO.key}`,
      // });
    },
  },
});