my-order.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/my-order/my-order.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list: [], //订单列表
  9. show: false, //展示无数据页面
  10. pageNo: 1, //页码
  11. isLast: false, //是否是最后一页
  12. },
  13. /**
  14. * 跳转详情页
  15. * @id {string} 订单ID
  16. */
  17. toDetail(e) {
  18. const id = e.currentTarget.dataset.id;
  19. wx.navigateTo({
  20. url: `/pages/detail/detail?id=${id}&&status=3`,
  21. })
  22. },
  23. /**
  24. * 查看合同
  25. * @contract {string} 合同
  26. *
  27. */
  28. checkContract(e) {
  29. const contract = e.currentTarget.dataset.contract;
  30. if (contract) {
  31. wx.downloadFile({
  32. url: contract,
  33. success: (res) => {
  34. wx.openDocument({
  35. filePath: res.tempFilePath,
  36. })
  37. }
  38. })
  39. } else {
  40. }
  41. },
  42. /**
  43. * 确认订单
  44. * @orderId {string} 订单ID
  45. */
  46. confirm(e) {
  47. const id = e.currentTarget.dataset.id;
  48. const index = e.currentTarget.dataset.index;
  49. wx.kx_request({
  50. url: wx.kx_api.hwOrder.confirmOrder,
  51. type: 'post',
  52. data: {
  53. orderId: id
  54. },
  55. success: res => {
  56. if (res.errcode === 0) {
  57. wx.showToast({
  58. title: '订单已确认',
  59. success: res => {
  60. // 确认成功 更改页面订单状态
  61. const list = this.data.list;
  62. list[index].status = 2;
  63. list[index].serviceStage = 1;
  64. this.setData({
  65. list
  66. })
  67. }
  68. })
  69. }
  70. }
  71. })
  72. },
  73. /**
  74. * 获取订单列表
  75. * @pageNo {number} 页码
  76. * @pageSize {number} 页面条数
  77. */
  78. getList(pageNo = this.data.pageNo) {
  79. wx.kx_request({
  80. url: wx.kx_api.hwOrder.getOrders,
  81. data: {
  82. pageNo,
  83. pageSize: 10
  84. },
  85. success: res => {
  86. if (res.errcode === 0) {
  87. if (pageNo === 1 && res.data.hwOrderList && res.data.hwOrderList.length === 0) {
  88. this.setData({
  89. show: true
  90. })
  91. } else {
  92. pageNo++;
  93. this.setData({
  94. list: [...this.data.list, ...res.data.hwOrderList],
  95. isLast: res.data.isLast,
  96. pageNo
  97. })
  98. }
  99. }
  100. },
  101. complete: () => {
  102. wx.stopPullDownRefresh();
  103. }
  104. })
  105. },
  106. /**
  107. * 生命周期函数--监听页面加载
  108. */
  109. onLoad: function(options) {
  110. // 获取订单列表
  111. this.getList()
  112. },
  113. /**
  114. * 生命周期函数--监听页面初次渲染完成
  115. */
  116. onReady: function() {
  117. },
  118. /**
  119. * 生命周期函数--监听页面显示
  120. */
  121. onShow: function() {
  122. },
  123. /**
  124. * 生命周期函数--监听页面隐藏
  125. */
  126. onHide: function() {
  127. },
  128. /**
  129. * 生命周期函数--监听页面卸载
  130. */
  131. onUnload: function() {
  132. },
  133. /**
  134. * 页面相关事件处理函数--监听用户下拉动作
  135. */
  136. onPullDownRefresh: function() {
  137. this.setData({
  138. list: [],
  139. pageNo: 1
  140. }, _ => {
  141. this.getList()
  142. })
  143. },
  144. /**
  145. * 页面上拉触底事件的处理函数
  146. */
  147. onReachBottom: function() {
  148. const isLast = this.data.isLast;
  149. if (isLast) {
  150. // wx.showToast({
  151. // icon: 'none',
  152. // title: '已经是最后一页了',
  153. // })
  154. } else {
  155. this.getList()
  156. }
  157. }
  158. })