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