my-order.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // pages/my-order/my-order.js
  2. const app = getApp();
  3. import { confirmOrderImpl, getOrdersImpl, confirmECOrdersImpl } from '../../service/impl/hwOrder.impl'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. list: [], //订单列表
  10. show: false, //展示无数据页面
  11. pageNo: 1, //页码
  12. isLast: false, //是否是最后一页
  13. offline: false,
  14. status: 0,
  15. listNumber: 0
  16. },
  17. /**
  18. * 点击切换状态
  19. * @param e
  20. */
  21. changeSelect(e: any) {
  22. const index = e.currentTarget.dataset.index;
  23. this.setData({
  24. status: Number(index),
  25. list: []
  26. }, () => {
  27. this.getList(1)
  28. })
  29. },
  30. /**
  31. * 跳转详情页
  32. * @id {string} 订单ID
  33. */
  34. toDetail(e: any) {
  35. const id = e.currentTarget.dataset.id;
  36. wx.navigateTo({
  37. url: `/pages/detail/detail?id=${id}&&status=2`,
  38. })
  39. },
  40. /**
  41. * 查看合同
  42. * @contract {string} 合同
  43. *
  44. */
  45. checkContract(e: any) {
  46. const contract = e.currentTarget.dataset.contract;
  47. if (contract) {
  48. wx.downloadFile({
  49. url: contract,
  50. success: (res) => {
  51. wx.openDocument({
  52. filePath: res.tempFilePath,
  53. })
  54. }
  55. })
  56. } else {
  57. }
  58. },
  59. /**
  60. * 确认订单
  61. * @orderId {string} 订单ID
  62. */
  63. confirm(e: any) {
  64. const id = e.currentTarget.dataset.id;
  65. // const index = e.currentTarget.dataset.index;
  66. const workContractType = e.currentTarget.dataset.workcontracttype;
  67. // const parentindex = e.currentTarget.dataset.parentindex;
  68. // 电子合同确认
  69. if (workContractType === 1) {
  70. confirmECOrdersImpl({
  71. orderId: id
  72. }).then(res => {
  73. if (res.errCode === 0) {
  74. // 跳转webview
  75. wx.reLaunch({
  76. url: `/pages/web-view/web-view?url=${encodeURIComponent(res.data.url)}`,
  77. success: () => {
  78. // 存入缓存方便跳回
  79. app.globalData.webview = `/${this.route}`;
  80. // wx.setStorageSync('web_view', `/${this.route}`)
  81. }
  82. })
  83. }
  84. })
  85. }
  86. // 非电子合同确认
  87. if (workContractType === 0) {
  88. confirmOrderImpl({
  89. orderId: id
  90. }).then(res => {
  91. if (res.errCode === 0) {
  92. wx.showToast({
  93. title: '订单已确认',
  94. success: () => {
  95. // 确认成功 更改页面订单状态
  96. this.getList()
  97. // this.setData({
  98. // [`list[${parentindex}][${index}].status`]: 2,
  99. // // [`list[${parentindex}][${index}].serviceStage`]: 2,
  100. // })
  101. }
  102. })
  103. }
  104. })
  105. }
  106. },
  107. /**
  108. * 获取订单列表
  109. * @pageNo {number} 页码
  110. * @pageSize {number} 页面条数
  111. */
  112. getList(pageNumber?: number) {
  113. let pageNo: number = pageNumber || this.data.pageNo
  114. getOrdersImpl({
  115. pageNo,
  116. pageSize: 10,
  117. status: this.data.status
  118. }).then(res => {
  119. if (res.errCode === 0) {
  120. if (pageNo === 1 && res.data.hwOrderList && res.data.hwOrderList.length === 0) {
  121. this.setData({
  122. show: true
  123. })
  124. } else {
  125. pageNo++;
  126. this.setData({
  127. list: this.data.list.concat(res.data.hwOrderList),
  128. isLast: res.data.isLast,
  129. pageNo
  130. }, () => {
  131. if (this.data.status === 0) {
  132. this.setData({
  133. listNumber: this.data.list.length
  134. })
  135. }
  136. })
  137. }
  138. }
  139. }).catch(err => {
  140. if (err === 'offline') {
  141. this.setData({
  142. offline: true
  143. })
  144. }
  145. })
  146. },
  147. /**
  148. * 列表重载
  149. */
  150. reload() {
  151. this.getList(1)
  152. },
  153. /**
  154. * 生命周期函数--监听页面加载
  155. */
  156. onLoad: function () {
  157. wx.hideHomeButton();
  158. // 获取订单列表
  159. this.setData({
  160. list: [],
  161. pageNo: 1
  162. }, () => {
  163. this.getList()
  164. })
  165. },
  166. /**
  167. * 生命周期函数--监听页面初次渲染完成
  168. */
  169. onReady: function () {
  170. },
  171. /**
  172. * 生命周期函数--监听页面显示
  173. */
  174. onShow: function () {
  175. wx.hideHomeButton();
  176. },
  177. /**
  178. * 生命周期函数--监听页面隐藏
  179. */
  180. onHide: function () {
  181. },
  182. /**
  183. * 生命周期函数--监听页面卸载
  184. */
  185. onUnload: function () {
  186. },
  187. /**
  188. * 页面相关事件处理函数--监听用户下拉动作
  189. */
  190. onPullDownRefresh: function () {
  191. this.setData({
  192. list: [],
  193. pageNo: 1
  194. }, () => {
  195. this.getList()
  196. })
  197. },
  198. /**
  199. * 页面上拉触底事件的处理函数
  200. */
  201. onReachBottom: function () {
  202. const isLast = this.data.isLast;
  203. if (isLast) {
  204. // wx.showToast({
  205. // icon: 'none',
  206. // title: '已经是最后一页了',
  207. // })
  208. } else {
  209. this.getList()
  210. }
  211. }
  212. })