detail.js 6.4 KB

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