// pages/user/walletDetails/walletDetails.js
import Date from '../../../utils/util.js'
import APIClient from '../../../utils/APIClient.js'
Page({

  data: {
    buyBtnText: '立即激活',
    price: '29',
    originPrice: '99',
    productId: 0,
    modalType: 'image',
    isModalShow: false,
    isCloseShow: false,
    modalText: [],
    closeCallBack: false
  },
  onLoad: function (options) {
    if (options.title) {
      wx.setNavigationBarTitle({
        title: '激活码激活'
      });
    }
  },

  activeVIP() {

    console.log(11111, this.data.code)
    APIClient.postActiveCode(this.data.code).success(res => {
      switch (res.data.code) {
        case 200:
          this.setData({
            isModalShow: true,
            modalText: [{
                text: '激活成功!',
                type: 'bigOrange'
              },
              {
                text: '您已获得一年VIP权限',
                type: 'bigOrange'
              }
            ],
            closeCallBack: 'index'
          })
          break;
        case 531:
          // 激活码已经用过了
          this.setData({
            isModalShow: true,
            modalText: [{
                text: '激活失败!',
                type: 'bigOrange'
              },
              {
                text: '验证码已经使用过了',
                type: 'bigOrange'
              }
            ]
          })
          break;
        case 404:
          //激活码不存在
          this.setData({
            isModalShow: true,
            modalText: [{
                text: '激活失败!',
                type: 'bigOrange'
              },
              {
                text: '验证码错误',
                type: 'bigOrange'
              }
            ]
          })
          break;
        default:
          break;
      }

    }).fail(err => {
      console.log(err);
    });
  },
  saveValue(e) {
    console.log(e)
    this.setData({
      code: e.detail.value
    });
  },

  modalConfirmHandler() {
    this.setData({
      isModalShow: false
    })
    if (this.data.closeCallBack === 'index') {
      wx.redirectTo({
        url: `/pages/index/index`
      })
    }
  },
})