my-order.ts 5.1 KB

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