detail.ts 11 KB

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