detail.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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.downloadFile({
  94. url: this.data.hwOrderAPI.workContract,
  95. success: (res) => {
  96. wx.openDocument({
  97. filePath: res.tempFilePath,
  98. })
  99. }
  100. })
  101. } else {
  102. // wx.showToast({
  103. // icon:'none',
  104. // title: '',
  105. // })
  106. }
  107. },
  108. /**
  109. * 确认订单
  110. * @orderId {string} 订单ID
  111. * 前台报名需求后 后台生成订单 需前台手动确定订单
  112. */
  113. buttonSubmit() {
  114. wx.kx_request({
  115. url: wx.kx_api.hwOrder.confirmOrder,
  116. type: 'post',
  117. data: {
  118. orderId: this.data.hwOrderAPI.id
  119. },
  120. success: res => {
  121. if (res.errcode === 0) {
  122. wx.showToast({
  123. title: '订单已确认',
  124. success: res => {
  125. // 确认成功后 更改按钮状态
  126. const hwOrderAPI = this.data.hwOrderAPI;
  127. hwOrderAPI.status = 2;
  128. this.setData({
  129. hwOrderAPI
  130. })
  131. }
  132. })
  133. }
  134. }
  135. })
  136. },
  137. /**
  138. * 控制cover层的显示与隐藏
  139. */
  140. cover() {
  141. const cover = !this.data.cover;
  142. this.setData({
  143. cover
  144. })
  145. },
  146. /**
  147. *
  148. */
  149. buttonRight() {
  150. },
  151. /**
  152. * 生命周期函数--监听页面加载
  153. */
  154. onLoad: function(options) {
  155. if (wx.getStorageSync('userid')) {
  156. if (options.id && options.status) {
  157. // 如果 状态为3 请求订单详情 ID为订单id
  158. if (options.status === '3') {
  159. wx.kx_request({
  160. url: wx.kx_api.hwOrder.getOrderDetail,
  161. data: {
  162. orderId: options.id
  163. },
  164. success: res => {
  165. if (res.errcode === 0) {
  166. console.log(res.data.hwOrderAPI.serviceStage)
  167. this.setData({
  168. ...res.data.hwRequirementAPI,
  169. hwOrderAPI: res.data.hwOrderAPI,
  170. // btn_message: res.data.hwOrderAPI.status === 2 && res.data.hwOrderAPI.serviceStage ? `第${res.data.hwOrderAPI.serviceStage}期服务中` : this.data.message[res.data.hwOrderAPI.status]
  171. })
  172. }
  173. }
  174. })
  175. }
  176. // 如果状态为1 请求需求详情 ID为需求id
  177. if (options.status === '1') {
  178. wx.kx_request({
  179. url: wx.kx_api.hwRequirement.getRequirementDetail,
  180. data: {
  181. hwRequirementId: options.id
  182. },
  183. success: res => {
  184. if (res.errcode === 0) {
  185. this.setData({
  186. ...res.data.hwRequirementAPI
  187. })
  188. }
  189. }
  190. })
  191. }
  192. }
  193. // 保存状态
  194. if (options.status) {
  195. this.setData({
  196. status: Number(options.status),
  197. show: false
  198. })
  199. }
  200. } else {
  201. wx.redirectTo({
  202. url: `/pages/login/login?path=/pages/detail/detail&&id=${options.id}&&status=${options.status}`,
  203. })
  204. }
  205. },
  206. /**
  207. * 生命周期函数--监听页面初次渲染完成
  208. */
  209. onReady: function() {
  210. },
  211. /**
  212. * 生命周期函数--监听页面显示
  213. */
  214. onShow: function() {
  215. },
  216. /**
  217. * 生命周期函数--监听页面隐藏
  218. */
  219. onHide: function() {
  220. },
  221. /**
  222. * 生命周期函数--监听页面卸载
  223. */
  224. onUnload: function() {
  225. },
  226. /**
  227. * 页面相关事件处理函数--监听用户下拉动作
  228. */
  229. onPullDownRefresh: function() {
  230. },
  231. /**
  232. * 页面上拉触底事件的处理函数
  233. */
  234. onReachBottom: function() {
  235. },
  236. /**
  237. * 用户点击右上角分享
  238. */
  239. onShareAppMessage: function() {
  240. return {
  241. title: this.data.name,
  242. path: `/pages/detail/detail?id=${this.data.id}&&status=${this.data.status}`
  243. }
  244. }
  245. })