my-card.js 1.72 KB
import {
  getBindtapData
} from '../../utils/util';

import {
  productMap
} from '../../const/custom-data';

let app = getApp();
Page({
  data: {
    prizeInfo: []
  },
  onShareAppMessage() {},
  onLoad(options) {
    this.initData();
  },
  initData() {
    app.post({
      url: app.api.fishPrize,
      data: {}
    }).then((result) => {
      let prizeInfo = result;
      prizeInfo.forEach(element => {
        element.endDateStr = new Date(element.endDate).toString("yy-MM-dd");
      });
      this.setData({
        prizeInfo: prizeInfo
      })
      console.log("prizeInfo:", this.data.prizeInfo);
    })
  },
  /**
   * 显示券的详情
   */
  onShowDetailHandler(evt) {
    let curData = getBindtapData(evt);

    if (curData.instanceCode) {
      // 查看奖品
      app.post({
        url: app.api.wishbillGiftQuery,
        data: {
          instanceCode: curData.instanceCode
        }
      }).then((result) => {

        // 合并奖品详情数据
        curData = Object.assign(curData, result);

        // 合并自定义数据
        let product = productMap[curData.prizeDefineCode + ""];
        curData = Object.assign(curData, product);

        app.globalData.giftData = curData;
        // console.log("app.globalData.giftData 333:", app.globalData.giftData);
        // console.log(JSON.stringify(app.globalData.giftData));
        app.router.push({
          path: "prizeDetail"
        })
      })

    } else {
      app.globalData.curCoupon = curData;
      app.router.push({
        path: "couponDetail"
      })
    }

  },
  // 子组件事件
  evtcomp(evt) {
    let {
      name,
      data
    } = evt.detail;
    switch (name) {

      case "_evt_hide":
        break;

      default:
        break;
    }
  },
})