my-order.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. console.log('otheragreement',otheragreement);
  71. // const parentindex = e.currentTarget.dataset.parentindex;
  72. if (this.data.userInfo.authenticationStatus === 1) {
  73. this.selectComponent('.protocolConfirmationView').open({
  74. content: otheragreement, callback: () => {
  75. // 电子合同确认
  76. workContractType === 1 && confirmECOrdersImpl({
  77. orderId: id
  78. }).then(data => {
  79. wx.openEmbeddedMiniProgram({
  80. appId: 'wxa023b292fd19d41d',
  81. path: "/" + data.data.url,
  82. });
  83. })
  84. // 非电子合同确认
  85. workContractType === 0 && confirmOrderImpl({
  86. orderId: id
  87. }).then(res => {
  88. if (res.errCode === 0) {
  89. workContractType === 0 && wx.showToast({
  90. title: '订单已确认',
  91. success: () => {
  92. // 确认成功 更改页面订单状态
  93. this.getList()
  94. // this.setData({
  95. // [`list[${parentindex}][${index}].status`]: 2,
  96. // // [`list[${parentindex}][${index}].serviceStage`]: 2,
  97. // })
  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: async function () {
  195. wx.hideHomeButton();
  196. const userInfo = await getHwUserInfo() as { authenticationStatus: number }
  197. this.setData({
  198. userInfo
  199. })
  200. if (this.checkLogin()) {
  201. // 获取订单列表
  202. this.setData({
  203. list: [],
  204. pageNo: 1
  205. }, () => {
  206. this.getList()
  207. })
  208. }
  209. },
  210. /**
  211. * 生命周期函数--监听页面隐藏
  212. */
  213. onHide: function () {
  214. },
  215. /**
  216. * 生命周期函数--监听页面卸载
  217. */
  218. onUnload: function () {
  219. },
  220. /**
  221. * 页面相关事件处理函数--监听用户下拉动作
  222. */
  223. onPullDownRefresh: function () {
  224. this.setData({
  225. list: [],
  226. pageNo: 1
  227. }, () => {
  228. this.getList()
  229. })
  230. },
  231. /**
  232. * 页面上拉触底事件的处理函数
  233. */
  234. onReachBottom: function () {
  235. const isLast = this.data.isLast;
  236. if (isLast) {
  237. // wx.showToast({
  238. // icon: 'none',
  239. // title: '已经是最后一页了',
  240. // })
  241. } else {
  242. this.getList()
  243. }
  244. }
  245. })