my-order.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. const contracttype = e.currentTarget.dataset.contracttype;
  50. const parentindex = e.currentTarget.dataset.parentindex;
  51. if (contracttype === 2) {
  52. wx.kx_request({
  53. url: wx.kx_api.hwOrder.confirmECOrders,
  54. type: 'post',
  55. data: {
  56. orderId: id
  57. },
  58. success: res => {
  59. if (res.errcode === 0) {
  60. wx.reLaunch({
  61. url: `/pages/web-view/web-view?url=${encodeURIComponent(res.data.url)}`,
  62. success: res => {
  63. app.globalData.webview = `/${this.route}`;
  64. // wx.setStorageSync('web_view', `/${this.route}`)
  65. }
  66. })
  67. }
  68. }
  69. })
  70. }
  71. if (contracttype === 1 || contracttype === 0) {
  72. wx.kx_request({
  73. url: wx.kx_api.hwOrder.confirmOrder,
  74. type: 'post',
  75. data: {
  76. orderId: id
  77. },
  78. success: res => {
  79. if (res.errcode === 0) {
  80. wx.showToast({
  81. title: '订单已确认',
  82. success: res => {
  83. // 确认成功 更改页面订单状态
  84. this.setData({
  85. [`list[${parentindex}][${index}].status`]: 2,
  86. // [`list[${parentindex}][${index}].serviceStage`]: 2,
  87. })
  88. }
  89. })
  90. }
  91. }
  92. })
  93. }
  94. },
  95. /**
  96. * 获取订单列表
  97. * @pageNo {number} 页码
  98. * @pageSize {number} 页面条数
  99. */
  100. getList(pageNo = this.data.pageNo) {
  101. wx.kx_request({
  102. url: wx.kx_api.hwOrder.getOrders,
  103. data: {
  104. pageNo,
  105. pageSize: 10
  106. },
  107. success: res => {
  108. if (res.errcode === 0) {
  109. if (pageNo === 1 && res.data.hwOrderList && res.data.hwOrderList.length === 0) {
  110. this.setData({
  111. show: true
  112. })
  113. } else {
  114. pageNo++;
  115. this.setData({
  116. [`list[${pageNo - 2}]`]: res.data.hwOrderList,
  117. isLast: res.data.isLast,
  118. pageNo
  119. })
  120. }
  121. }
  122. }
  123. })
  124. },
  125. /**
  126. * 生命周期函数--监听页面加载
  127. */
  128. onLoad: function(options) {
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady: function() {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function() {
  139. // 获取订单列表
  140. this.setData({
  141. list: [],
  142. pageNo: 1
  143. }, _ => {
  144. this.getList()
  145. })
  146. },
  147. /**
  148. * 生命周期函数--监听页面隐藏
  149. */
  150. onHide: function() {
  151. },
  152. /**
  153. * 生命周期函数--监听页面卸载
  154. */
  155. onUnload: function() {
  156. },
  157. /**
  158. * 页面相关事件处理函数--监听用户下拉动作
  159. */
  160. onPullDownRefresh: function() {
  161. this.setData({
  162. list: [],
  163. pageNo: 1
  164. }, _ => {
  165. this.getList()
  166. })
  167. },
  168. /**
  169. * 页面上拉触底事件的处理函数
  170. */
  171. onReachBottom: function() {
  172. const isLast = this.data.isLast;
  173. if (isLast) {
  174. // wx.showToast({
  175. // icon: 'none',
  176. // title: '已经是最后一页了',
  177. // })
  178. } else {
  179. this.getList()
  180. }
  181. }
  182. })