Blame view

src/pages/gift-detail/gift-detail.js 4.76 KB
simon committed
1 2 3 4 5
import {
  getBindtapData,
  getObjByListKeyValue
} from '../../utils/util';

simon committed
6 7
let app = getApp();
Page({
simon committed
8 9
  data: {
    authorizeVisible: false,
simon committed
10
    commonTipsCompVisible: false,
simon committed
11
    orderSubmitSuccessCompVisible: false,
simon committed
12 13 14 15 16 17 18 19 20
    cid: "1", // 1积分不足 2.账号未审核
    innerTitle: "",
    innerText: "",
    innerButton: "",
    indexInfo: {},
    item: {},
    remark: "",
    receiverList: [], // 收货地址
    defaultReceiver: null, // 默认收货地址
simon committed
21 22 23 24 25 26 27
  },
  onShareAppMessage() {},
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
simon committed
28 29 30 31 32 33 34
  onLoad(options) {

  },
  onShow() {
    this.initData();
  },
  initData() {
simon committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48
    return new Promise((resolve, reject) => {
      app.queryIndex().then((result) => {
        app.post({
          url: app.api.receiver,
          data: {}
        }).then((result2) => {
          let defaultReceiver = getObjByListKeyValue(1, "defaultAddress", result2);
          this.setData({
            indexInfo: app.globalData.indexInfo,
            receiverList: result2,
            defaultReceiver: defaultReceiver,
            item: app.globalData.giftInfo,
          })
          resolve();
simon committed
49 50
        })
      })
simon committed
51 52
    });

simon committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  },

  showTips(tips) {
    wx.showToast({
      title: tips,
      icon: "none"
    })
  },

  /**
   * 检查提交
   */
  checkSubmit() {
    return new Promise((resolve, reject) => {
      let {
        item,
        defaultReceiver,
        indexInfo
      } = this.data;
      if (indexInfo.memberPoints < item.commodityPrice) {
        // 积分不足
        this.setData({
          commonTipsCompVisible: true,
          cid: "1",
          innerTitle: "积分不足",
          innerText: "使用推广、签到功能\n可获取更多积分!",
          innerButton: "我知道了",
        });
        reject();
        return;
      } else if (indexInfo.auditStatus != "authorization") {
        // 未验证
        this.setData({
          commonTipsCompVisible: true,
          cid: "2",
          innerTitle: "账号未审核",
          innerText: "通过认证的用户才能兑换礼品哦,快去提交资",
          innerButton: "马上去验证",
        });
        reject();
        return;
      } else if (!defaultReceiver && item.commodityType == "object") {
        // 实物奖品必须添加地址
        this.showTips("请先添加地址")
        reject();
        return;
      } else {
        resolve();
      }

    });
  },


simon committed
107 108 109
  /**
   * 确认兑换 / 提交订单
   */
simon committed
110 111 112 113 114 115 116
  onSubmitHandler(evt) {
    let _this = this;
    this.checkSubmit().then((result) => {
      let {
        item,
        defaultReceiver
      } = this.data;
simon committed
117 118 119
      console.log("item:", item);
      console.log("defaultReceiver:", defaultReceiver);

simon committed
120 121
      wx.showModal({
        title: '兑换确认',
simon committed
122
        content: `将花费${item.commodityPrice}积分兑换${item.commodityTitle}一份`,
simon committed
123 124 125 126 127 128
        success(res) {
          if (res.confirm) {
            app.post({
              url: app.api.commodityExchange,
              data: {
                commodityCode: item.commodityCode,
simon committed
129
                receiverCode: defaultReceiver && defaultReceiver.receiverCode || "",
simon committed
130
                remark: _this.data.remark
simon committed
131 132
              }
            }).then((result) => {
simon committed
133 134 135 136 137
              _this.initData().then((result) => {
                _this.setData({
                  orderSubmitSuccessCompVisible: true
                })
              })
simon committed
138 139 140 141 142
            })
          }
        }
      })
    })
simon committed
143 144 145 146 147 148
  },
  /**
   * 收获地址管理
   */
  onAddressManagementHandler() {
    app.router.push({
simon committed
149
      path: "addressManagement"
simon committed
150
    })
simon committed
151
  },
simon committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

  /**
   * 添加收货地址
   * 同地址管理
   */
  onAddressAddHandler() {
    app.router.push({
      path: "addressManagement"
    })
  },

  bindRemarkInput(e) {
    this.setData({
      remark: e.detail.value
    })
  },

simon committed
169 170 171 172 173
  // 隐藏蒙层
  hideMask() {
    this.setData({
      authorizeVisible: false,
      commonTipsCompVisible: false,
simon committed
174
      orderSubmitSuccessCompVisible: false,
simon committed
175 176 177 178 179 180 181 182 183 184
    })
  },
  // 子组件事件
  evtcomp(evt) {
    let {
      name,
      data
    } = evt.detail;
    switch (name) {

simon committed
185 186 187 188 189
      case "_evt_hide_mask":
        this.hideMask();
        break;

        // 隐藏弹窗
simon committed
190 191
      case "_evt_common_comp_button":
        this.hideMask();
simon committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
        switch (data.cid) {
          // 积分不足
          case "1":
            this.hideMask();
            break;

            // 未验证
          case "2":
            app.router.push({
              path: "vipLogin"
            })
            break;

          default:
            break;
        }

simon committed
209 210 211 212 213 214 215
        // 兑换成功
        case "_evt_order_submit_success":
          app.router.push({
            path:"giftShop",
            openType:"switchTab"
          })
          break;
simon committed
216

simon committed
217 218 219 220
          break;

        default:
          break;
simon committed
221 222
    }
  },
simon committed
223
})