my-order.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 parentindex = e.currentTarget.dataset.parentindex;
  70. if (this.data.userInfo.authenticationStatus === 1) {
  71. // 电子合同确认
  72. workContractType === 1 && confirmECOrdersImpl({
  73. orderId: id
  74. }).then(data => {
  75. wx.navigateToMiniProgram({
  76. appId: 'wxa023b292fd19d41d',
  77. path: "/" + data.data.url,
  78. });
  79. })
  80. // 非电子合同确认
  81. workContractType === 0 && confirmOrderImpl({
  82. orderId: id
  83. }).then(res => {
  84. if (res.errCode === 0) {
  85. workContractType === 0 && wx.showToast({
  86. title: '订单已确认',
  87. success: () => {
  88. // 确认成功 更改页面订单状态
  89. this.getList()
  90. // this.setData({
  91. // [`list[${parentindex}][${index}].status`]: 2,
  92. // // [`list[${parentindex}][${index}].serviceStage`]: 2,
  93. // })
  94. }
  95. })
  96. }
  97. })
  98. } else {
  99. // wx.showModal({
  100. // title: '提示',
  101. // content: '您还未实名,是否立即实名?',
  102. // success: res => {
  103. // if (res.confirm) {
  104. wx.navigateTo({
  105. url: "/pages/realNameAuthentication/realNameAuthentication",
  106. });
  107. // }
  108. // }
  109. // })
  110. }
  111. },
  112. /**
  113. * 获取订单列表
  114. * @pageNo {number} 页码
  115. * @pageSize {number} 页面条数
  116. */
  117. getList(pageNumber?: number) {
  118. let pageNo: number = pageNumber || this.data.pageNo
  119. getOrdersImpl({
  120. pageNo,
  121. pageSize: 10,
  122. status: this.data.status
  123. }).then(res => {
  124. if (res.errCode === 0) {
  125. if (pageNo === 1 && res.data.hwOrderList && res.data.hwOrderList.length === 0) {
  126. this.setData({
  127. show: true
  128. }, () => {
  129. if (this.data.status === 0) {
  130. this.setData({
  131. listNumber: this.data.list.length
  132. })
  133. }
  134. })
  135. } else {
  136. pageNo++;
  137. this.setData({
  138. list: this.data.list.concat(res.data.hwOrderList),
  139. isLast: res.data.isLast,
  140. pageNo
  141. }, () => {
  142. if (this.data.status === 0) {
  143. this.setData({
  144. listNumber: this.data.list.length
  145. })
  146. }
  147. })
  148. }
  149. }
  150. }).catch(err => {
  151. if (err === 'offline') {
  152. this.setData({
  153. offline: true
  154. })
  155. }
  156. })
  157. },
  158. /**
  159. * 列表重载
  160. */
  161. reload() {
  162. this.getList(1)
  163. },
  164. checkLogin(): Boolean {
  165. if (wx.getStorageSync('userId') && wx.getStorageSync('userToken')) {
  166. return true
  167. } else {
  168. wx.reLaunch({
  169. url: '/pages/login/login',
  170. })
  171. return false
  172. }
  173. },
  174. /**
  175. * 生命周期函数--监听页面加载
  176. */
  177. onLoad: function () {
  178. this.checkLogin()
  179. },
  180. /**
  181. * 生命周期函数--监听页面初次渲染完成
  182. */
  183. onReady: function () {
  184. },
  185. /**
  186. * 生命周期函数--监听页面显示
  187. */
  188. onShow: async function () {
  189. wx.hideHomeButton();
  190. const userInfo = await getHwUserInfo() as { authenticationStatus: number }
  191. this.setData({
  192. userInfo
  193. })
  194. if (this.checkLogin()) {
  195. // 获取订单列表
  196. this.setData({
  197. list: [],
  198. pageNo: 1
  199. }, () => {
  200. this.getList()
  201. })
  202. }
  203. },
  204. /**
  205. * 生命周期函数--监听页面隐藏
  206. */
  207. onHide: function () {
  208. },
  209. /**
  210. * 生命周期函数--监听页面卸载
  211. */
  212. onUnload: function () {
  213. },
  214. /**
  215. * 页面相关事件处理函数--监听用户下拉动作
  216. */
  217. onPullDownRefresh: function () {
  218. this.setData({
  219. list: [],
  220. pageNo: 1
  221. }, () => {
  222. this.getList()
  223. })
  224. },
  225. /**
  226. * 页面上拉触底事件的处理函数
  227. */
  228. onReachBottom: function () {
  229. const isLast = this.data.isLast;
  230. if (isLast) {
  231. // wx.showToast({
  232. // icon: 'none',
  233. // title: '已经是最后一页了',
  234. // })
  235. } else {
  236. this.getList()
  237. }
  238. }
  239. })