detail.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // pages/detail/detail.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. cover: true, // 蒙层
  9. bright_points: '', // 亮点
  10. message: { //订单状态映射
  11. '0': '确认订单',
  12. '1': '订单关闭',
  13. '2': '已确认',
  14. '3': '订单中止',
  15. '4': '订单完成'
  16. },
  17. status: 0, //按钮状态 1 我要报名 2 已确认订单 3 订单待确认、订单进行中
  18. show: true,
  19. // btn_message: ''
  20. },
  21. /**
  22. * 需求报名
  23. * @requirement_id {string} 需求ID
  24. * @bright_points {string} 亮点
  25. * @enroll_from {number} 报名来源(0:小程序 1:APP 2:后台)
  26. */
  27. apply() {
  28. wx.kx_request({
  29. url: wx.kx_api.hwRequirement.enrollmentRequire,
  30. model: true,
  31. type: 'post',
  32. data: {
  33. requirement_id: this.data.id,
  34. bright_points: this.data.bright_points,
  35. enroll_from: 0
  36. },
  37. success: res => {
  38. wx.showToast({
  39. title: '报名成功',
  40. success: res => {
  41. this.setData({
  42. cover: true,
  43. }, _ => {
  44. wx.navigateBack({
  45. delta: 1,
  46. })
  47. })
  48. }
  49. })
  50. },
  51. fail: res => {
  52. if (res.errcode) {
  53. wx.showModal({
  54. title: '报名失败',
  55. content: res.errmsg,
  56. showCancel: false,
  57. confirmColor: '#31364C'
  58. })
  59. }
  60. }
  61. })
  62. },
  63. /**
  64. * 亮点输入
  65. * @bright_points {string} 亮点
  66. */
  67. input(e) {
  68. this.setData({
  69. bright_points: e.detail.value
  70. })
  71. },
  72. /**
  73. * 打开地图
  74. */
  75. openMap(e) {
  76. const name = e.currentTarget.dataset.name;
  77. const address = e.currentTarget.dataset.address;
  78. // wx.openLocation({
  79. // latitude: 31.544325,
  80. // longitude: 120.356595,
  81. // name,
  82. // address
  83. // })
  84. },
  85. /**
  86. * 查看合同
  87. * @filePath {string} 合同地址
  88. */
  89. buttonCheck() {
  90. // 获取线上合同 如果存在打开合同 不存在进行提示(暂无)
  91. const workContract = this.data.hwOrderAPI.workContract;
  92. if (workContract) {
  93. wx.showLoading({
  94. mask: true,
  95. title: '正在打开文件...',
  96. })
  97. wx.downloadFile({
  98. url: this.data.hwOrderAPI.workContract,
  99. success: (res) => {
  100. wx.openDocument({
  101. filePath: res.tempFilePath,
  102. success: res => {
  103. wx.hideLoading()
  104. },
  105. fail() {
  106. wx.showToast({
  107. icon: 'none',
  108. title: '打开失败',
  109. })
  110. }
  111. })
  112. }
  113. })
  114. } else {
  115. // wx.showToast({
  116. // icon:'none',
  117. // title: '',
  118. // })
  119. }
  120. },
  121. /**
  122. * 确认订单
  123. * @orderId {string} 订单ID
  124. * 前台报名需求后 后台生成订单 需前台手动确定订单
  125. */
  126. buttonSubmit() {
  127. const contractType = this.data.hwOrderAPI.contractType;
  128. if (contractType === 2) {
  129. wx.kx_request({
  130. url: wx.kx_api.hwOrder.confirmECOrders,
  131. type: 'post',
  132. data: {
  133. orderId: this.data.hwOrderAPI.id
  134. },
  135. success: res => {
  136. if (res.errcode === 0) {
  137. wx.reLaunch({
  138. url: `/pages/web-view/web-view?url=${encodeURIComponent(res.data.url)}`,
  139. success: res => {
  140. app.globalData.webview = `/pages/my-order/my-order`;
  141. // wx.setStorageSync('web_view', `/pages/my-order/my-order`)
  142. // wx.setStorageSync('web_view', `/${this.route}?id=${this.data.hwOrderAPI.id}&&status=${this.data.status}`)
  143. }
  144. })
  145. }
  146. }
  147. })
  148. }
  149. if (contractType === 1 || contractType === 0 ) {
  150. wx.kx_request({
  151. url: wx.kx_api.hwOrder.confirmOrder,
  152. type: 'post',
  153. data: {
  154. orderId: this.data.hwOrderAPI.id
  155. },
  156. success: res => {
  157. if (res.errcode === 0) {
  158. wx.showToast({
  159. title: '订单已确认',
  160. success: res => {
  161. // 确认成功后 更改按钮状态
  162. const hwOrderAPI = this.data.hwOrderAPI;
  163. hwOrderAPI.status = 2;
  164. this.setData({
  165. hwOrderAPI
  166. })
  167. }
  168. })
  169. }
  170. }
  171. })
  172. }
  173. },
  174. /**
  175. * 控制cover层的显示与隐藏
  176. */
  177. cover() {
  178. const cover = !this.data.cover;
  179. this.setData({
  180. cover
  181. })
  182. },
  183. /**
  184. *
  185. */
  186. buttonRight() {
  187. },
  188. /**
  189. * 生命周期函数--监听页面加载
  190. */
  191. onLoad: function(options) {
  192. if (wx.getStorageSync('userid')) {
  193. if (options.id && options.status) {
  194. // 如果 状态为3 请求订单详情 ID为订单id
  195. if (options.status === '3') {
  196. wx.kx_request({
  197. url: wx.kx_api.hwOrder.getOrderDetail,
  198. data: {
  199. orderId: options.id
  200. },
  201. success: res => {
  202. if (res.errcode === 0) {
  203. this.setData({
  204. ...res.data.hwRequirementAPI,
  205. hwOrderAPI: res.data.hwOrderAPI,
  206. // btn_message: res.data.hwOrderAPI.status === 2 && res.data.hwOrderAPI.serviceStage ? `第${res.data.hwOrderAPI.serviceStage}期服务中` : this.data.message[res.data.hwOrderAPI.status]
  207. })
  208. }
  209. }
  210. })
  211. }
  212. // 如果状态为1 请求需求详情 ID为需求id
  213. if (options.status === '1') {
  214. wx.kx_request({
  215. url: wx.kx_api.hwRequirement.getRequirementDetail,
  216. data: {
  217. hwRequirementId: options.id
  218. },
  219. success: res => {
  220. if (res.errcode === 0) {
  221. this.setData({
  222. ...res.data.hwRequirementAPI
  223. })
  224. }
  225. }
  226. })
  227. }
  228. }
  229. // 保存状态
  230. if (options.status) {
  231. this.setData({
  232. status: Number(options.status),
  233. show: false
  234. })
  235. }
  236. } else {
  237. wx.redirectTo({
  238. url: `/pages/login/login?path=/pages/detail/detail&&id=${options.id}&&status=${options.status}`,
  239. })
  240. }
  241. },
  242. /**
  243. * 生命周期函数--监听页面初次渲染完成
  244. */
  245. onReady: function() {
  246. },
  247. /**
  248. * 生命周期函数--监听页面显示
  249. */
  250. onShow: function() {
  251. },
  252. /**
  253. * 生命周期函数--监听页面隐藏
  254. */
  255. onHide: function() {
  256. },
  257. /**
  258. * 生命周期函数--监听页面卸载
  259. */
  260. onUnload: function() {
  261. },
  262. /**
  263. * 页面相关事件处理函数--监听用户下拉动作
  264. */
  265. onPullDownRefresh: function() {
  266. },
  267. /**
  268. * 页面上拉触底事件的处理函数
  269. */
  270. onReachBottom: function() {
  271. },
  272. /**
  273. * 用户点击右上角分享
  274. */
  275. onShareAppMessage: function() {
  276. return {
  277. title: this.data.name,
  278. path: `/pages/detail/detail?id=${this.data.id}&&status=${this.data.status}`
  279. }
  280. }
  281. })