index.js 1.42 KB
import { componentsMixin } from '../../mixins/index'
import {
  equityApi
} from "../../api/api"
Component({
  behaviors: [componentsMixin],
  properties: {
    show: Boolean
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMGVERSION_FILE_NAME: "mine/version/v3.7.2/",
    status: 0,

  },

  /**
   * 组件的方法列表
   */
  methods: {
    closeModal() {
      this.setData({
        show: false,
        status: 0
      })
    },
    bindInput(e) {
      this.fillText = e.detail.value
    },
    click() {
      if (!this.fillText) return wx.$util.showToast('请输入兑换码')
      wx.$util.showLoading()
      equityApi.equityExchange({ exchangeCode: this.fillText }).then(res => {
        wx.hideLoading()
        console.log(res);
        if(res){
          if(res.effectiveType==1){
            res.dateName = '永久有效'
          }else if(res.effectiveType==2){
            res.dateName = `${res.effectiveNum}天`
          }else if(res.effectiveType==3&&res.effectiveStartDate&&res.effectiveEndDate){
            res.dateName = `${new Date(res.effectiveStartDate).format('yyyy-MM-dd')}-${new Date(res.effectiveEndDate).format('yyyy-MM-dd')}`
          }
          this.setData({
            status: 1,
            cardInfo:res
          })
        }
      })
    },
    toCheck() {
      this.closeModal()
      wx.$eventbus.emit('EQUITY')
      wx.switchTab({
        url: '/pages/tab/equity/equity',
      });
    }
  }
})