my-order.ts 4.8 KB

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