detail.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. // pages/detail/detail.js
  2. const app = getApp();
  3. // 未填写提示字段及信息
  4. const errorMessage = {
  5. info_name: '请填写姓名',
  6. idcardNumber: '请填写身份证号码',
  7. }
  8. // 未填写key值
  9. const errorKey = {
  10. info_name: 'name_error',
  11. idcardNumber: 'id_error',
  12. }
  13. Page({
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {
  18. cover: true, // 蒙层
  19. hasInfo: false, //是否拥有个人信息
  20. info_name: '',
  21. idcardNumber: '',
  22. bright_points: '', // 亮点
  23. message: { //订单状态映射
  24. '0': '确认订单',
  25. '1': '订单关闭',
  26. '2': '已确认',
  27. '3': '订单中止',
  28. '4': '订单完成'
  29. },
  30. status: 0, //按钮状态 1 需求 2 已报名 3 订单
  31. show: true, // 是否展示
  32. name_error: false, // 姓名错误信息
  33. id_error: false, // 身份证错误信息
  34. // btn_message: ''
  35. },
  36. /**
  37. * 需求报名
  38. * @requirement_id {string} 需求ID
  39. * @bright_points {string} 亮点
  40. * @enroll_from {number} 报名来源(0:小程序 1:APP 2:后台)
  41. */
  42. apply() {
  43. if (!this.data.hasInfo) {
  44. for (const key in errorMessage) {
  45. if (this.data.hasOwnProperty(key) && !this.data[key]) {
  46. wx.showToast({
  47. icon: 'none',
  48. title: errorMessage[key],
  49. success: _ => {
  50. this.setData({
  51. [errorKey[key]]: errorMessage[key]
  52. })
  53. }
  54. })
  55. return
  56. }
  57. }
  58. if (this.data.idcardNumber.length !== 15 && this.data.idcardNumber.length !== 18) {
  59. wx.showToast({
  60. icon: 'none',
  61. title: '身份证号码格式错误',
  62. success: res => {
  63. this.setData({
  64. id_error: '身份证号码格式错误'
  65. })
  66. }
  67. })
  68. }
  69. }
  70. // 报名需求
  71. wx.kx_request({
  72. url: wx.kx_api.hwRequirement.enrollmentRequire,
  73. model: true,
  74. type: 'post',
  75. data: {
  76. requirement_id: this.data.id,
  77. name: this.data.info_name,
  78. idcardNumber: this.data.idcardNumber,
  79. bright_points: this.data.bright_points,
  80. enroll_from: 0
  81. },
  82. success: res => {
  83. wx.showToast({
  84. title: '报名成功',
  85. success: res => {
  86. this.setData({
  87. cover: true,
  88. }, _ => {
  89. wx.navigateBack({
  90. delta: 1,
  91. })
  92. })
  93. }
  94. })
  95. },
  96. fail: res => {
  97. if (res.errcode) {
  98. wx.showModal({
  99. title: '报名失败',
  100. content: res.errmsg,
  101. showCancel: false,
  102. confirmColor: '#31364C'
  103. })
  104. }
  105. }
  106. })
  107. },
  108. /**
  109. * 亮点输入
  110. * @idcardNumber {string} 身份证
  111. */
  112. saveIdCardNumber(e) {
  113. const idcardNumber = e.detail.value
  114. if (idcardNumber) {
  115. if (idcardNumber.length !== 15 && idcardNumber.length !== 18) {
  116. this.setData({
  117. id_error: '身份证号码格式错误'
  118. })
  119. } else {
  120. this.setData({
  121. idcardNumber,
  122. id_error: false
  123. })
  124. }
  125. } else {
  126. this.setData({
  127. id_error: '请填写身份证号码'
  128. })
  129. }
  130. },
  131. /**
  132. * 亮点输入
  133. * @name {string} 姓名
  134. */
  135. saveName(e) {
  136. const info_name = e.detail.value
  137. if (info_name) {
  138. this.setData({
  139. info_name,
  140. name_error: false
  141. })
  142. } else {
  143. this.setData({
  144. name_error: '请填写姓名'
  145. })
  146. }
  147. },
  148. /**
  149. * 亮点输入
  150. * @bright_points {string} 亮点
  151. */
  152. input(e) {
  153. this.setData({
  154. bright_points: e.detail.value
  155. })
  156. },
  157. /**
  158. * 打开地图
  159. */
  160. openMap(e) {
  161. const name = e.currentTarget.dataset.name;
  162. const address = e.currentTarget.dataset.address;
  163. // wx.openLocation({
  164. // latitude: 31.544325,
  165. // longitude: 120.356595,
  166. // name,
  167. // address
  168. // })
  169. },
  170. /**
  171. * 查看合同
  172. * @filePath {string} 合同地址
  173. */
  174. buttonCheck() {
  175. // 获取线上合同 如果存在打开合同 不存在进行提示(暂无)
  176. const workContract = this.data.hwOrderAPI.workContract;
  177. if (workContract) {
  178. wx.showLoading({
  179. mask: true,
  180. title: '正在打开文件...',
  181. })
  182. wx.downloadFile({
  183. url: this.data.hwOrderAPI.workContract,
  184. success: (res) => {
  185. wx.openDocument({
  186. filePath: res.tempFilePath,
  187. success: res => {
  188. wx.hideLoading()
  189. },
  190. fail() {
  191. wx.showToast({
  192. icon: 'none',
  193. title: '打开失败',
  194. })
  195. }
  196. })
  197. }
  198. })
  199. } else {
  200. // wx.showToast({
  201. // icon:'none',
  202. // title: '',
  203. // })
  204. }
  205. },
  206. /**
  207. * 确认订单
  208. * @orderId {string} 订单ID
  209. * 前台报名需求后 后台生成订单 需前台手动确定订单 根据订单合同不同调用不同接口
  210. */
  211. buttonSubmit() {
  212. const workContractType = this.data.hwOrderAPI.workContractType;
  213. // 电子合同确认订单
  214. if (workContractType === 1) {
  215. wx.kx_request({
  216. url: wx.kx_api.hwOrder.confirmECOrders,
  217. type: 'post',
  218. data: {
  219. orderId: this.data.hwOrderAPI.id
  220. },
  221. success: res => {
  222. if (res.errcode === 0) {
  223. // 跳转webview页面
  224. wx.reLaunch({
  225. url: `/pages/web-view/web-view?url=${encodeURIComponent(res.data.url)}`,
  226. success: res => {
  227. // 缓存当前页面地址 方便跳回
  228. app.globalData.webview = `/pages/my-order/my-order`;
  229. // wx.setStorageSync('web_view', `/pages/my-order/my-order`)
  230. // wx.setStorageSync('web_view', `/${this.route}?id=${this.data.hwOrderAPI.id}&&status=${this.data.status}`)
  231. }
  232. })
  233. }
  234. }
  235. })
  236. }
  237. // 非电子合同
  238. if (workContractType === 0) {
  239. wx.kx_request({
  240. url: wx.kx_api.hwOrder.confirmOrder,
  241. type: 'post',
  242. data: {
  243. orderId: this.data.hwOrderAPI.id
  244. },
  245. success: res => {
  246. if (res.errcode === 0) {
  247. wx.showToast({
  248. title: '订单已确认',
  249. success: res => {
  250. // 确认成功后 更改按钮状态
  251. const hwOrderAPI = this.data.hwOrderAPI;
  252. hwOrderAPI.status = 2;
  253. this.setData({
  254. hwOrderAPI
  255. })
  256. }
  257. })
  258. }
  259. }
  260. })
  261. }
  262. },
  263. // 显示报名填写的订单输入框
  264. async showCover() {
  265. const userinfo = await app.utils.getHwUserInfo(this)
  266. if (userinfo.idcardNumber && userinfo.name) {
  267. this.setData({
  268. cover: false,
  269. hasInfo: true
  270. })
  271. } else {
  272. this.setData({
  273. cover: false,
  274. hasInfo: false
  275. })
  276. }
  277. },
  278. /**
  279. * 控制cover层的显示与隐藏
  280. */
  281. cover() {
  282. const cover = !this.data.cover;
  283. this.setData({
  284. cover
  285. })
  286. },
  287. /**
  288. * 取消报名
  289. * @enroll_id {string} 报名id
  290. */
  291. cancelEnrollment() {
  292. const id = this.data.enrollId
  293. wx.kx_request({
  294. url: wx.kx_api.hwRequirement.cancelEnrollment,
  295. type: 'post',
  296. data: {
  297. enroll_id: id
  298. },
  299. success: res => {
  300. wx.showToast({
  301. icon: 'none',
  302. title: '取消成功',
  303. success: res => {
  304. setTimeout(() => {
  305. wx.navigateBack({
  306. delta: 1
  307. })
  308. }, 1200)
  309. }
  310. })
  311. }
  312. })
  313. },
  314. /**
  315. *
  316. */
  317. buttonRight() {
  318. },
  319. /**
  320. * 生命周期函数--监听页面加载
  321. */
  322. onLoad: function (options) {
  323. this.setData({
  324. options
  325. })
  326. },
  327. /**
  328. * 生命周期函数--监听页面初次渲染完成
  329. */
  330. onReady: function () {
  331. },
  332. /**
  333. * 生命周期函数--监听页面显示
  334. */
  335. onShow: function () {
  336. const options = this.data.options
  337. if (options.id && options.status) {
  338. // 如果 状态为3 请求订单详情 ID为订单id
  339. if (options.status === '2') {
  340. wx.kx_request({
  341. url: wx.kx_api.hwOrder.getOrderDetail,
  342. data: {
  343. orderId: options.id
  344. },
  345. success: res => {
  346. if (res.errcode === 0) {
  347. this.setData({
  348. ...res.data.hwRequirementAPI,
  349. hwOrderAPI: res.data.hwOrderAPI,
  350. // btn_message: res.data.hwOrderAPI.status === 2 && res.data.hwOrderAPI.serviceStage ? `第${res.data.hwOrderAPI.serviceStage}期服务中` : this.data.message[res.data.hwOrderAPI.status]
  351. })
  352. }
  353. }
  354. })
  355. }
  356. // 如果状态为1 请求需求详情 ID为需求id
  357. if (options.status === '1') {
  358. wx.kx_request({
  359. url: wx.kx_api.hwRequirement.getRequirementDetail,
  360. data: {
  361. user_id: wx.getStorageSync('userid'),
  362. user_token: wx.getStorageSync('usertoken'),
  363. hwRequirementId: options.id
  364. },
  365. success: res => {
  366. if (res.errcode === 0) {
  367. this.setData({
  368. ...res.data.hwRequirementAPI,
  369. displayCancel: res.data.displayCancel || null,
  370. needEnrollment: res.data.needEnrollment || null,
  371. enrollId: res.data.enrollId || null
  372. })
  373. }
  374. }
  375. })
  376. }
  377. }
  378. // 保存状态
  379. if (options.status) {
  380. this.setData({
  381. status: Number(options.status),
  382. show: false
  383. })
  384. }
  385. this.setData({
  386. user_id: wx.getStorageSync('userid'),
  387. })
  388. },
  389. /**
  390. * 生命周期函数--监听页面隐藏
  391. */
  392. onHide: function () {
  393. },
  394. /**
  395. * 生命周期函数--监听页面卸载
  396. */
  397. onUnload: function () {
  398. },
  399. /**
  400. * 页面相关事件处理函数--监听用户下拉动作
  401. */
  402. onPullDownRefresh: function () {
  403. },
  404. /**
  405. * 页面上拉触底事件的处理函数
  406. */
  407. onReachBottom: function () {
  408. },
  409. /**
  410. * 用户点击右上角分享
  411. */
  412. onShareAppMessage: function () {
  413. return {
  414. title: this.data.name,
  415. path: `/pages/detail/detail?id=${this.data.id}&&status=${this.data.status}`
  416. }
  417. }
  418. })