wish.js 4.96 KB
import {
  getBindtapData,
  getObjByListKeyValue
} from '../../utils/util';

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

let app = getApp();
Page({
  data: {
    isOverShare: true, //自定义分享
    tipsRuleVisible: false,
    tipsPirzeVisible: false,
    userInfo: {},
    wishInfo: {},
    wishList: [],
    helperInfo: {},
    curWish: {},

    status: 1, // 1正常(有库存) 2无库存
  },
  onShareAppMessage(res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
      let userInfo = app.globalData.userInfo;
      let billCode = app.globalData.indexInfo.wishBillCode;
      let title = `${userInfo.nickname}正在参加丸美眼霜节心愿单活动,需要你的倾情相助!`;
      let path = `/pages/coop/coop?code=${billCode}&s=share`
      return {
        title,
        path
      }
    } else {
      //分享配置
      return {
        title: '弹弹弹 看你有多弹',
        path: 'pages/index/index'
      };
    }
  },
  onLoad(options) {},
  onShow() {
    this.initData();
  },
  initData() {
    app.queryIndex().then((result) => {
      this.setData({
        userInfo: app.globalData.userInfo
      })
      this.queryWishbillDetail();
      this.queryWishbillHelpers();
    })
  },
  /**
   * 领取我的奖品
   */
  onGetGiftHandler(evt) {
    let curData = getBindtapData(evt);
    console.log("curData:", curData);
    app.post({
      url: app.api.wishbillGiftAccept,
      data: {
        instanceCode: curData.instanceCode
      }
    }).then((result) => {
      curData = Object.assign(curData, result);
      this.setData({
        curWish: curData,
        tipsPirzeVisible: true,
        status: curData.status
      })
    });
  },
  /**
   * 查看我的奖品
   * 点击领取
   */
  onCheckGiftHandler(evt) {
    let curData = getBindtapData(evt);
    // console.log("curData:", curData);
    app.post({
      url: app.api.wishbillGiftQuery,
      data: {
        instanceCode: curData.instanceCode
      }
    }).then((result) => {
      curData = Object.assign(curData, result);
      this.setData({
        curWish: curData,
        status: curData.status
      })
      app.globalData.giftData = curData;

      // 领取状态
      // 领取类型:0=未提交;1=邮寄(填写邮寄信息);2=自提(填门店预约信息)
      let acceptType = curData.order.acceptType;
      console.log("acceptType:", acceptType);
      if (acceptType == 0) {
        // 未提交,显示领取选择
        this.setData({
          tipsPirzeVisible: true,
        })
      } else if (acceptType == 1) {
        // 已经选择邮寄
        // 判断是否已经填写邮寄信息
        app.router.push({
          path: "userTable"
        })
      } else if (acceptType == 2) {
        // 已经选择自提
        app.router.push({
          path: "prizeDetail"
        })
      }

      // 查看是否已经预约

    })
  },
  // 显示规则页面
  onShowRuleHandler() {
    this.setData({
      tipsRuleVisible: true
    })
  },
  // 显示我的卡券
  onMyCardHandler() {
    app.router.push({
      path: "myCard"
    })
  },
  // 显示海报图
  onCreatePosterHandler() {
    app.globalData.posterWishList = this.data.wishList;
    app.router.push({
      path: "poster"
    })
  },
  // 查看排行榜
  onRankHandler() {
    app.router.push({
      path: "rank"
    })
  },
  // 分享
  onShareHandler() {

  },
  // 获取心愿单详情
  queryWishbillDetail() {
    return new Promise((resolve, reject) => {
      app.post({
        url: app.api.wishbillDetail,
        data: {
          billCode: app.globalData.indexInfo.wishBillCode
        }
      }).then((result) => {
        let wishList = result.wishGifts;
        wishList.forEach(element => {
          let product = productMap[element.prizeDefineCode + ""];
          element = Object.assign(element, product);
          let progress = element.elasticValue / element.conditionElasticValue * 100;
          if (progress > 100) progress = 100;
          // 直接计算坐标
          let progressLeft = progress * 2.2 - 51;
          element.progress = progress;
          element.progressLeft = progressLeft;
        });
        this.setData({
          wishInfo: result,
          wishList: wishList
        })
      })
    });
  },
  // 获取助力列表
  queryWishbillHelpers() {
    return new Promise((resolve, reject) => {
      app.post({
        url: app.api.wishbillHelpers,
        data: {
          billCode: app.globalData.indexInfo.wishBillCode,
          page: 1,
          size: 50
        }
      }).then((result) => {
        this.setData({
          helperInfo: result
        })
      })
    });
  },
  hideMask() {
    this.setData({
      tipsRuleVisible: false,
      tipsPirzeVisible: false,
    })
  },
  // 子组件事件
  evtcomp(evt) {
    let {
      name,
      data
    } = evt.detail;
    switch (name) {

      case "_evt_hide_mask":
        this.hideMask();
        break;

      default:
        break;
    }
  },
})