order.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. let app = getApp();
  2. let host = app.globalData.servsers; // 请求的url
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. state:2, // 请求状态]
  9. orderList:[], // 订单列表
  10. host: host,
  11. rows:1, //默认第一页
  12. requestState:true, //请求状态,默认是true
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.setData({
  19. state: options.state
  20. })
  21. },
  22. /**
  23. * 生命周期函数--监听页面初次渲染完成
  24. */
  25. onReady: function () {
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow: function () {
  31. this.getOrderList(this, this.data.state, this.data.rows)
  32. },
  33. /**
  34. * 生命周期函数--监听页面隐藏
  35. */
  36. onHide: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面卸载
  40. */
  41. onUnload: function () {
  42. },
  43. /**
  44. * 页面相关事件处理函数--监听用户下拉动作
  45. */
  46. onPullDownRefresh: function () {
  47. console.log("上拉")
  48. },
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom: function () {
  53. if(this.data.requestState){
  54. this.setData({
  55. rows: this.data.rows + 1
  56. })
  57. this.getOrderList(this,this.data.state,this.data.rows)
  58. }
  59. console.log('到底了')
  60. },
  61. /**
  62. * 用户点击右上角分享
  63. */
  64. onShareAppMessage: function () {
  65. },
  66. getOrderList(that, state, rows){
  67. let orderList = that.data.orderList;
  68. wx.showLoading({
  69. title: '加载中...',
  70. })
  71. wx.request({
  72. url: host + '/queryOrderCustomerByUserId',
  73. method:'get',
  74. header: {
  75. 'content-type': 'application/x-www-form-urlencoded'
  76. },
  77. data:{
  78. userId:app.globalData.user_id,
  79. orderStatus: state, //订单状态 0未支付\\1: 待定制\\2: 待发货\\3: 已发货\\4: 已完成\\5: 取消'
  80. limit:10,
  81. offset: rows,
  82. },
  83. success(res){
  84. console.log(res,"orderList")
  85. let data = res.data;
  86. data.forEach(el=>{
  87. el['imgArray'] = el.orderCustomGoodsList[0].customGoodsImg ? el.orderCustomGoodsList[0].customGoodsImg.split(',') : [];
  88. })
  89. orderList.push(...data)
  90. if(res.data.length < 10 && rows !==1){
  91. that.setData({
  92. requestState:false
  93. })
  94. }
  95. that.setData({
  96. orderList: orderList
  97. })
  98. console.log(that.data.orderList,"orderList")
  99. },
  100. complete(){
  101. wx.hideLoading()
  102. }
  103. })
  104. },
  105. orderPay(e){ // 订单付款
  106. console.log(e);
  107. let item = e.currentTarget.dataset.item;//列表数据
  108. wx.request({
  109. url: host +'/weChatPay',
  110. method: 'post',
  111. header: {
  112. 'content-type': 'application/x-www-form-urlencoded'
  113. },
  114. data:{
  115. orderCustomId: item.orderCustomId,
  116. openId: app.globalData.openid,
  117. },
  118. success(el){
  119. let res = el.data;
  120. console.log(res)
  121. wx.requestPayment({
  122. timeStamp: res.timeStamp,
  123. nonceStr: res.nonceStr,
  124. package: res.package,
  125. signType: res.signType,
  126. paySign: res.paySign,
  127. success(res) {
  128. console.log(res, "结算结果")
  129. if (res.errMsg === 'requestPayment:ok') {
  130. // wx.showToast({
  131. // title: '支付成功',
  132. // })
  133. wx.redirectTo({
  134. url: '/customized/pages/result/result?state=true',
  135. })
  136. } else {
  137. wx.redirectTo({
  138. url: '/customized/pages/result/result?state=false',
  139. })
  140. }
  141. },
  142. fail(err) {
  143. wx.showToast({
  144. title: err.errMsg,
  145. icon: 'error'
  146. })
  147. console.log(err)
  148. },
  149. complete() {
  150. wx.hideLoading()
  151. }
  152. })
  153. }
  154. })
  155. }
  156. })