order.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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,index)=>{
  87. console.log(index)
  88. el['imgArray'] = el.orderCustomGoodsList.length > 0 && el.orderCustomGoodsList[0].customGoodsImg ? el.orderCustomGoodsList[0].customGoodsImg.split(',') : [];
  89. })
  90. orderList.push(...data)
  91. if(res.data.length < 10 && rows !==1){
  92. that.setData({
  93. requestState:false
  94. })
  95. }
  96. that.setData({
  97. orderList: orderList
  98. })
  99. console.log(that.data.orderList,"orderList")
  100. },
  101. complete(){
  102. wx.hideLoading()
  103. }
  104. })
  105. },
  106. orderPay(e){ // 订单付款
  107. console.log(e);
  108. let item = e.currentTarget.dataset.item;//列表数据
  109. wx.request({
  110. url: host +'/weChatPay',
  111. method: 'post',
  112. header: {
  113. 'content-type': 'application/x-www-form-urlencoded'
  114. },
  115. data:{
  116. orderCustomId: item.orderCustomId,
  117. openId: app.globalData.openid,
  118. },
  119. success(el){
  120. let res = el.data;
  121. console.log(res)
  122. wx.requestPayment({
  123. timeStamp: res.timeStamp,
  124. nonceStr: res.nonceStr,
  125. package: res.package,
  126. signType: res.signType,
  127. paySign: res.paySign,
  128. success(res) {
  129. console.log(res, "结算结果")
  130. if (res.errMsg === 'requestPayment:ok') {
  131. // wx.showToast({
  132. // title: '支付成功',
  133. // })
  134. wx.redirectTo({
  135. url: '/customized/pages/result/result?state=true',
  136. })
  137. } else {
  138. wx.redirectTo({
  139. url: '/customized/pages/result/result?state=false',
  140. })
  141. }
  142. },
  143. fail(err) {
  144. wx.showToast({
  145. title: err.errMsg,
  146. icon: 'error'
  147. })
  148. console.log(err)
  149. },
  150. complete() {
  151. wx.hideLoading()
  152. }
  153. })
  154. }
  155. })
  156. }
  157. })