zhongshujie
2024-12-18 5dcba93841a0dadb81a74b55062e440af20ad9d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// pages/index/scanResult/index.js
const app = getApp()
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    textValue: "领取",
    rules: null,
    result: null,
    productInfo: [],
    couponList: [],
    isOther: false,
    activeCodeAndStoreChannelLinks: [],
    activeInfo: null,
    description: "",
    itemType: '',
    goodsData: ''
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    try {
      const result = JSON.parse(options.result)
      if (result && result.type) {
        this.setData({
          result,
          textValue: result.type == "PromoteCode" ? '领取' : '激活'
        })
        wx.setNavigationBarTitle({
          title: result.type == "PromoteCode" ? '领取优惠卷' : '激活商品',
        })
        // this.getRules();
        this.getProductByCode();
      } else {
        this.setData({
          isOther: true
        })
      }
    } catch (error) {
      console.log(error);
      this.setData({
        isOther: true
      })
    }
  },
 
  // 激活码规则
  getRules() {
    let query = {
      path: app.config.refCodes.learnPlatform.exchangeRules,
      storeInfo: app.config.learnPlatformGoodsStore,
      repositoryInfo: app.config.learnPlatformGoodsStore,
      paging: {
        start: 0,
        size: 9999
      },
      fields: {
        tourism_content: []
      },
    };
    app.MG.resource.getItem(query).then((res) => {
      try {
        // const ruleData = res.datas.find(e => e.refCode == 'tourism_exchangeRules')
        this.setData({
          rules: this.data.result.type == "ActivationCode" ? res.datas.find(e => e.refCode == 'tourism_activationCodeCollectionRules') : res.datas.find(e => e.refCode == 'tourism_couponCollectionRules')
        })
      } catch (error) {
        console.log(error)
      }
    })
  },
 
  // 激活码激活
  useActiveCode() {
    var that = this;
    if (that.data.result && that.data.result.type == "ActivationCode") {
      const activeInfo = that.data.activeInfo
      const activeCodeAndStoreChannelLinks = that.data.activeCodeAndStoreChannelLinks
      if ((!activeInfo || activeInfo.productIds.length == 0) && activeCodeAndStoreChannelLinks.length > 0) {
        wx.showModal({
          title: '温馨提示',
          content: '请选择足够数量的可选商品!',
          showCancel: false
        })
        return false
      }
      app.MG.store
        .userActiveCode({
          code: that.data.result.code,
          cardNum: that.data.result.cardNum,
          apiActiveCodeSelectProductRequests: this.data.activeInfo ? [this.data.activeInfo] : []
        })
        .then(res => {
          wx.showModal({
            title: '温馨提示',
            content: res,
            showCancel: false
          })
          setTimeout(() => {
            wx.navigateTo({
              url: '/pages/codeRecord/index',
            })
          }, 2500);
        });
    } else {
      let that = this;
      const data = {
        refCodeOrGuids: [that.data.result.guid],
      };
      app.MG.store.getPromoteCode(data).then(res => {
        let message = "";
        let icon = "successe"
        if (res == "-5") {
          message = "领取失败,优惠券已过期!";
          icon = "fail"
        } else if (res == "-7") {
          message = "抱歉,优惠券已经领取完毕!";
          icon = "fail"
        } else if (res == "-1") {
          message = "领取失败,系统错误!";
          icon = "fail"
        } else if (res == "-2") {
          message = "抱歉,优惠券已经领取完毕!";
          icon = "fail"
        } else if (res == "-3") {
          message = "领取失败,优惠券无效!";
          icon = "fail"
        } else if (res == "-4") {
          message = "领取失败,优惠券无效!";
          icon = "fail"
        } else if (res == "-6") {
          message = "领取失败,领取状态异常!";
          icon = "fail"
        } else if (res == "1") {
          message = "领取成功!";
        }
        wx.showModal({
          title: '温馨提示',
          content: message,
          showCancel: false,
          success(res) {
            if (res.confirm) {
              wx.navigateBack()
            }
          }
        })
      });
    }
  },
 
  // 根据code获取商品信息
  getProductByCode() {
    var that = this;
    if (that.data.result && that.data.result.type == "ActivationCode") {
      app.MG.store
        .getActiveCode({
          code: that.data.result.code,
          cardNum: that.data.result.cardNum,
        })
        .then(res => {
          try {
            const list = JSON.parse(res.config);
            console.log('code', res, list);
            if (this.data.result) {
              const type = res.saleMethodList[0].type
              this.setData({
                goodsData: res,
              })
              this.getProductListById(list);
            }
            if (res?.activeCodeAndStoreChannelLinks) {
              this.setData({
                description: res.description,
                activeCodeAndStoreChannelLinks: res.activeCodeAndStoreChannelLinks
              })
            }
          } catch (error) {
            this.setData({
              isOther: true
            })
          }
        });
    } else {
      if (this.data.result != null) {
        const data = {
          refCodeOrGuids: [that.data.result.guid],
        };
        app.MG.store.getPromoteCodeDetail(data).then(res => {
          if (res && that.data.result) {
            res.map(item => {
              if (item.start) {
                item.start ? item.start = item.start.split("T")[0] : new Date()
              }
              if (item.end) {
                item.end ? item.end = item.end.split("T")[0] : new Date()
              }
            })
            this.setData({
              couponList: res
            })
          }
        });
      }
    }
  },
 
  //根据id进行夸库查询商品
  getProductListById(ids) {
    let that = this;
    app.MG.store
      .getProductList({
        queryType: "*",
        // subAccess: [{
        // StoreRefCode: app.config.learnPlatformGoodsStore, // 默认商品库
        //   Path: "",
        //   Type: "*",
        // }, ],
        sort: {
          CreateDate: "Desc",
        },
        fields: {
          "Id=": ids.map(item => item.id + ""),
        },
        paging: {
          start: 0,
          size: 9999,
        },
        coverSize: {
          width: 215,
        },
      })
      .then(res => {
        res.datas.map(item => {
          item.name = item.name + '-' + this.data.goodsData.saleMethodList[0].name
          item.price ? item.price = (item.price).toFixed(2) : "";
          item.oldPrice ? item.oldPrice = (item.oldPrice).toFixed(2) : "";
          item.icon ? item.icon = item.icon : item.icon = "/static/images/default-book-img.png",
            item.itemType = this.data.goodsData.saleMethodList[0].type == 'createProductFolderSaleMethod' ? '目录' : this.data.goodsData.saleMethodList[0].type == 'createProductItemSaleMethod' ? '资源' : '电子书'
        })
        console.log(1, res.datas[0]);
        that.setData({
          productInfo: res.datas
        })
      });
  },
 
  // 跳转到商品选择页面
  selectPage(e) {
    const {
      info
    } = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/scanResult/selectPage/index?info=' + JSON.stringify(info) + '&result=' + JSON.stringify(this.data.result),
    })
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
 
  },
})