yiming
2024-06-06 dcd5065a6ed1b75b0e3c1491d267ab73b4997f11
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
const app = getApp();
import moment from 'moment'
import tool2 from "../../../assets/js/toolClass.js"
import {
  getPublicImage
} from "../../../assets/js/middleGround/tool.js";
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    tabList: [{
        label: '全部',
        value: 'all',
      },
      {
        label: '待支付',
        value: 'WaitPay',
      },
      {
        label: '已完成',
        value: 'Success',
      },
      {
        label: '已取消',
        value: 'Cancel',
      }
    ],
    searchText: "",
    list: [],
    //分页
    page: 1,
    limit: 12,
    pageTotalCount: 0,
    bottomLoading: false,
    isMoreData: false,
    // 返回顶部
    isBackTop: false,
    setScrollValue: 0,
    skeletonLoding: true,
    queryFilter: [],
    isPaySuccess: false,
    isPayComplete: false,
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    this.getDataList(false)
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
 
  },
  tabBookClick(item) {
    let that = this;
    let info = this.data.tabList[item.detail.value]
    that.setData({
      skeletonLoding: true,
      active: item.detail.value,
      queryFilter: info.value == 'all' ? [] : [{
        field: 'State',
        value: info.value
      }],
      list: [],
      page: 1,
      bottomLoading: false,
      isMoreData: false,
      searchText: ""
    })
    that.getDataList(false);
  },
 
  getDataList(isReachBottom) {
    var searchArr = [];
    if (this.data.searchText != undefined && this.data.searchText != "") {
      searchArr.push({
        compareType: "Contains",
        field: "orderNumber",
        keywords: this.data.searchText,
      })
    }
    const data = {
      start: this.data.page * this.data.limit - this.data.limit,
      size: this.data.limit,
      filterList: this.data.queryFilter,
      searchList: searchArr,
      sort: {
        type: 'Desc',
        field: 'CreateDate'
      }
    }
    app.MG.store.getUserOrderList(data).then((res) => {
      try {
        if (res.datas.length > 0) {
          res.datas.forEach((item, index) => {
            item.payPrice = tool2.toDecimal2(item.payPrice)
            item.createDate = moment(item.createDate).format("YYYY-MM-DD HH:mm:ss");
            item.finishedDate = moment(item.finishedDate).format("YYYY-MM-DD HH:mm:ss");
            if (item.state == "Success") {
              item.colorName = 'success';
              item.CustomState = "已完成";
            }
            if (item.state == "Cancel") {
              item.colorName = 'cancal';
              item.CustomState = "已取消";
            }
            if (item.state == "WaitPay") {
              item.colorName = 'waitPay';
              item.CustomState = "待支付";
            }
            if (item.state == "WaitDeliver") {
              item.colorName = 'waitDeliver';
              item.CustomState = "正在支付";
            }
            if (item.state == "GroupPaySuccess") {
              item.colorName = 'success';
              item.CustomState = "等待拼团"
            }
            if (item.state == "ReFounding") {
              item.colorName = 'ReFounding';
              item.CustomState = "退款中"
            }
            if (item.state == "ReFoundFinished") {
              item.colorName = 'ReFoundFinished';
              item.CustomState = "退款完成"
            }
            let oldlist = [];
            oldlist = item.saleMethodLinks
            oldlist.forEach(istrue => {
              istrue.name = istrue.orderSaleMethod.product.name
              istrue.payPrice = tool2.toDecimal2(istrue.payPrice)
              istrue.icon = getPublicImage(istrue.orderSaleMethod.product.icon, "", 400)
            })
 
          })
          let dataList = res.datas;
          //触底加载新数据并保留老数据
          if (isReachBottom) {
            dataList = [...this.data.list, ...dataList] //将新数据加入老数据中
          }
          this.setData({
            list: dataList,
            pageTotalCount: res.totalSize,
            bottomLoading: false,
            isMoreData: dataList.length > 0 ? false : true,
            skeletonLoding: false,
            loading: false
          })
        } else {
          this.setData({
            skeletonLoding: false,
            loading: false
          })
        }
      } catch (error) {
        console.log(error)
      }
    })
  },
  onSearchOrder(e) {
    this.setData({
      searchText: e.detail.value,
    })
    this.getDataList(false);
  },
  async goBookDetails(e) {
 
    console.log(e.currentTarget.dataset);
    const {
      book,
      remarks
    } = e.currentTarget.dataset;
    let parentData = null;
    let bookId = book.orderSaleMethod.product.id;
 
    parentData = await app.MG.store.getProductBySaleMethod({
      'saleMethodId': book.orderSaleMethod.id
    })
    if (parentData.parentProduct.length > 0) {
      bookId = parentData.parentProduct[parentData.parentProduct.length - 1].id;
    }
    wx.navigateTo({
      url: `/packageBookService/pages/bookServices/detail/index?id=${bookId}&name=${book.name}`,
    });
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    if (this._freshing) return
    this.setData({
      // list: [],
      page: 1,
      limit: 12,
      pageTotalCount: 0,
      bottomLoading: false,
      isMoreData: false,
      searchText: ''
    })
    this._freshing = true;
    this.setData({
      triggered: false,
    })
    this.getDataList(false);
    this._freshing = false
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      bottomLoading: true,
      isMoreData: false
    })
    let bool = false;
    if (this.data.pageTotalCount > this.data.list.length) {
      bool = true;
      this.setData({
        page: this.data.page + 1,
      })
    } else {
      setTimeout(() => {
        this.setData({
          bottomLoading: false,
          isMoreData: true
        })
      }, 100)
      return false;
    }
    this.getDataList(bool);
  },
 
  onCancel(e) {
    let that = this;
    let {
      orderNum
    } = e.currentTarget.dataset
    wx.showModal({
      title: '提示', //提示的标题
      content: '确定要取消订单?', //提示的内容
      success: function (res) {
        if (res.confirm) {
          app.MG.store.cancelOrder({
            orderNum: orderNum
          }).then((res) => {
            if (res) {
              wx.showToast({
                title: "订单已取消",
                icon: 'success',
                duration: 1000
              })
              that.getDataList(false)
            }
 
          })
        } else if (res.cancel) {
          console.log('用户点击了取消')
        }
      }
    })
 
  },
  //立即支付、再次购买
  onPayment(e) {
    var that = this;
    const {
      orderNum
    } = e.currentTarget.dataset
    const data = {
      orderNum: orderNum,
    };
    app.MG.store.getOrderByOrderNum(data).then(res => {
      app.MG.store.makeWeChatPay({
          orderNum: res.orderNumber,
          platform: "WeChatAppCustom"
        })
        .then(payRes => {
          const payVal = JSON.parse(payRes);
          wx.requestPayment({
            "appId": payVal.appId,
            "timeStamp": payVal.timeStamp,
            "nonceStr": payVal.nonceStr,
            "package": payVal.package,
            "signType": payVal.signType,
            "paySign": payVal.paySign,
            "success": function (res) {
              if (res.errMsg == 'requestPayment:ok') {
                that.setData({
                  isPaySuccess: true
                })
              }
            },
            "fail": function (res) {
              console.log(res, "失败")
            },
            "complete": function (res) {
              if (res.errMsg == 'requestPayment:ok') {
                that.setData({
                  isPayComplete: true
                })
              }
              if (that.data.isPaySuccess && that.data.isPayComplete) {
                that.navToBack()
              }
            }
          })
        });
    });
 
  },
 
  //删除订单
  onDel(e) {
    const {
      orderNum
    } = e.currentTarget.dataset
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
 
  }
})