my-order.ts 5.2 KB

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