my-order.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. checkLogin(): Boolean {
  154. if (wx.getStorageSync('userId') && wx.getStorageSync('userToken')) {
  155. return true
  156. } else {
  157. wx.reLaunch({
  158. url: '/pages/login/login',
  159. })
  160. return false
  161. }
  162. },
  163. /**
  164. * 生命周期函数--监听页面加载
  165. */
  166. onLoad: function () {
  167. this.checkLogin()
  168. },
  169. /**
  170. * 生命周期函数--监听页面初次渲染完成
  171. */
  172. onReady: function () {
  173. },
  174. /**
  175. * 生命周期函数--监听页面显示
  176. */
  177. onShow: function () {
  178. wx.hideHomeButton();
  179. if (this.checkLogin()) {
  180. // 获取订单列表
  181. this.setData({
  182. list: [],
  183. pageNo: 1
  184. }, () => {
  185. this.getList()
  186. })
  187. }
  188. },
  189. /**
  190. * 生命周期函数--监听页面隐藏
  191. */
  192. onHide: function () {
  193. },
  194. /**
  195. * 生命周期函数--监听页面卸载
  196. */
  197. onUnload: function () {
  198. },
  199. /**
  200. * 页面相关事件处理函数--监听用户下拉动作
  201. */
  202. onPullDownRefresh: function () {
  203. this.setData({
  204. list: [],
  205. pageNo: 1
  206. }, () => {
  207. this.getList()
  208. })
  209. },
  210. /**
  211. * 页面上拉触底事件的处理函数
  212. */
  213. onReachBottom: function () {
  214. const isLast = this.data.isLast;
  215. if (isLast) {
  216. // wx.showToast({
  217. // icon: 'none',
  218. // title: '已经是最后一页了',
  219. // })
  220. } else {
  221. this.getList()
  222. }
  223. }
  224. })