| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- // pages/detail/detail.js
- const app = getApp();
- import { putStorageSync, getStorageSync } from '../../utils/util'
- // type errorMessageType = {
- // info_name: String,
- // idcardNumber: String,
- // }
- // // 未填写提示字段及信息
- // const errorMessage: errorMessageType = {
- // info_name: '请填写姓名',
- // idcardNumber: '请填写身份证号码',
- // }
- // type errorKeyType = {
- // info_name: String,
- // idcardNumber: String,
- // }
- // // 未填写key值
- // const errorKey: errorKeyType = {
- // info_name: 'name_error',
- // idcardNumber: 'id_error',
- // }
- import { cancelEnrollmentImpl, getRequirementDetailImpl } from '../../service/impl/hwRequirement.impl'
- // import { cancelEnrollmentImpl, enrollmentRequireImpl, getRequirementDetailImpl } from '../../service/impl/hwRequirement.impl'
- import { confirmECOrdersImpl, confirmOrderImpl, getOrderDetailImpl } from '../../service/impl/hwOrder.impl'
- import { getHwUserInfo } from '../../utils/util'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- cover: true, // 蒙层
- hasInfo: false, //是否拥有个人信息
- info_name: '',
- idcardNumber: '',
- bright_points: '', // 亮点
- message: { //订单状态映射
- '0': '确认订单',
- '1': '订单关闭',
- '2': '已确认',
- '3': '订单中止',
- '4': '订单完成'
- },
- status: 0, //按钮状态 1 需求 2 已报名 3 订单
- show: true, // 是否展示
- name_error: '', // 姓名错误信息
- id_error: '', // 身份证错误信息
- id: 0,
- hwOrderAPI: {
- workContractType: -1,
- workContract: '',
- id: 0,
- status: -1
- },
- name: '',
- enrollId: 0,
- options: {
- id: 0,
- status: ''
- }
- // btn_message: ''
- },
- /**
- * 需求报名
- * @requirement_id {string} 需求ID
- * @bright_points {string} 亮点
- * @enroll_from {number} 报名来源(0:小程序 1:APP 2:后台)
- */
- apply() {
- // if (!this.data.hasInfo) {
- // for (const key in errorMessage) {
- // if (this.data.hasOwnProperty(key) && !this.data[key]) {
- // wx.showToast({
- // icon: 'none',
- // title: errorMessage[key],
- // success: () => {
- // this.setData({
- // [errorKey[key]]: errorMessage[key]
- // })
- // }
- // })
- // return
- // }
- // }
- // if (this.data.idcardNumber.length !== 15 && this.data.idcardNumber.length !== 18) {
- // wx.showToast({
- // icon: 'none',
- // title: '身份证号码格式错误',
- // success: () => {
- // this.setData({
- // id_error: '身份证号码格式错误'
- // })
- // }
- // })
- // }
- // }
- // 报名需求
- // enrollmentRequireImpl({
- // requirement_id: this.data.id,
- // name: this.data.info_name,
- // idcardNumber: this.data.idcardNumber,
- // bright_points: this.data.bright_points,
- // enroll_from: 0
- // }).then(() => {
- // wx.showToast({
- // title: '报名成功',
- // success: () => {
- // this.setData({
- // cover: true,
- // }, () => {
- // wx.navigateBack({
- // delta: 1,
- // })
- // })
- // }
- // })
- // }).catch(res => {
- // if (res.errCode) {
- // wx.showModal({
- // title: '报名失败',
- // content: res.errMsg,
- // showCancel: false,
- // confirmColor: '#31364C'
- // })
- // }
- // })
- const userInfo = wx.getStorageSync('userInfo')
- if (userInfo.isDemonstrate) {
- wx.showToast({
- icon: 'none',
- title: '报名成功',
- success: () => {
- const hwOrderAPI = this.data.hwOrderAPI
- hwOrderAPI.status = 2
- this.setData({
- status: 2,
- hwOrderAPI
- })
- putStorageSync(`orderDetail_${this.data.id}`, this.data.id, 2)
- }
- })
- }
- },
- /**
- * 亮点输入
- * @idcardNumber {string} 身份证
- */
- saveIdCardNumber(e: any) {
- const idcardNumber = e.detail.value
- if (idcardNumber) {
- if (idcardNumber.length !== 15 && idcardNumber.length !== 18) {
- this.setData({
- id_error: '身份证号码格式错误'
- })
- } else {
- this.setData({
- idcardNumber,
- id_error: ''
- })
- }
- } else {
- this.setData({
- id_error: '请填写身份证号码'
- })
- }
- },
- /**
- * 亮点输入
- * @name {string} 姓名
- */
- saveName(e: any) {
- const info_name = e.detail.value
- if (info_name) {
- this.setData({
- info_name,
- name_error: ''
- })
- } else {
- this.setData({
- name_error: '请填写姓名'
- })
- }
- },
- /**
- * 亮点输入
- * @bright_points {string} 亮点
- */
- input(e: any) {
- this.setData({
- bright_points: e.detail.value
- })
- },
- /**
- * 打开地图
- */
- openMap(e: any) {
- const name = e.currentTarget.dataset.name;
- const address = e.currentTarget.dataset.address;
- console.log(name, address);
- // wx.openLocation({
- // latitude: 31.544325,
- // longitude: 120.356595,
- // name,
- // address
- // })
- },
- /**
- * 查看合同
- * @filePath {string} 合同地址
- */
- buttonCheck() {
- // 获取线上合同 如果存在打开合同 不存在进行提示(暂无)
- const workContract = this.data.hwOrderAPI.workContract;
- if (workContract) {
- wx.showLoading({
- mask: true,
- title: '正在打开文件...',
- })
- wx.downloadFile({
- url: this.data.hwOrderAPI.workContract,
- success: (res) => {
- wx.openDocument({
- filePath: res.tempFilePath,
- success: () => {
- wx.hideLoading()
- },
- fail() {
- wx.showToast({
- icon: 'none',
- title: '打开失败',
- })
- }
- })
- }
- })
- } else {
- // wx.showToast({
- // icon:'none',
- // title: '',
- // })
- }
- },
- /**
- * 确认订单
- * @orderId {string} 订单ID
- * 前台报名需求后 后台生成订单 需前台手动确定订单 根据订单合同不同调用不同接口
- */
- buttonSubmit() {
- const workContractType = this.data.hwOrderAPI.workContractType;
- // 电子合同确认订单
- if (workContractType === 1) {
- confirmECOrdersImpl({
- orderId: this.data.hwOrderAPI.id
- }).then(res => {
- if (res.errCode === 0) {
- // 跳转webview页面
- wx.reLaunch({
- url: `/pages/web-view/web-view?url=${encodeURIComponent(res.data.url)}`,
- success: () => {
- // 缓存当前页面地址 方便跳回
- app.globalData.webview = `/pages/my-order/my-order`;
- // wx.setStorageSync('web_view', `/pages/my-order/my-order`)
- // wx.setStorageSync('web_view', `/${this.route}?id=${this.data.hwOrderAPI.id}&&status=${this.data.status}`)
- }
- })
- }
- })
- }
- // 非电子合同
- if (workContractType === 0) {
- confirmOrderImpl({
- orderId: this.data.hwOrderAPI.id
- }).then(res => {
- if (res.errCode === 0) {
- wx.showToast({
- title: '订单已确认',
- success: () => {
- // 确认成功后 更改按钮状态
- const hwOrderAPI = this.data.hwOrderAPI;
- hwOrderAPI.status = 2;
- this.setData({
- hwOrderAPI
- })
- }
- })
- }
- })
- }
- },
- // 显示报名填写的订单输入框
- async showCover() {
- const userInfo: any = await getHwUserInfo()
- if (userInfo.idcardNumber && userInfo.name) {
- this.setData({
- cover: false,
- hasInfo: true
- })
- } else {
- this.setData({
- cover: false,
- hasInfo: false
- })
- }
- },
- /**
- * 控制cover层的显示与隐藏
- */
- cover() {
- const cover = !this.data.cover;
- this.setData({
- cover
- })
- },
- /**
- * 取消报名
- * @enroll_id {string} 报名id
- */
- cancelEnrollment() {
- const id = this.data.enrollId
- cancelEnrollmentImpl({
- enroll_id: id
- }).then(() => {
- wx.showToast({
- icon: 'none',
- title: '取消成功',
- success: () => {
- setTimeout(() => {
- wx.navigateBack({
- delta: 1
- })
- }, 1200)
- }
- })
- })
- },
- /**
- *
- */
- buttonRight() {
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options: any) {
- this.setData({
- options
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: async function () {
- const options = this.data.options
- if (options.id && options.status) {
- // 如果 状态为3 请求订单详情 ID为订单id
- if (options.status === '2') {
- getOrderDetailImpl({
- orderId: options.id
- }).then(res => {
- if (res.errCode === 0) {
- const id = getStorageSync(`orderDetail_${this.data.id}`)
- if (id) {
- res.data.hwOrderAPI.status = 2
- }
- this.setData({
- ...res.data.hwRequirementAPI,
- hwOrderAPI: res.data.hwOrderAPI,
- // btn_message: res.data.hwOrderAPI.status === 2 && res.data.hwOrderAPI.serviceStage ? `第${res.data.hwOrderAPI.serviceStage}期服务中` : this.data.message[res.data.hwOrderAPI.status]
- })
- }
- })
- }
- // 如果状态为1 请求需求详情 ID为需求id
- if (options.status === '1') {
- getRequirementDetailImpl({
- user_id: wx.getStorageSync('userId'),
- user_token: wx.getStorageSync('userToken'),
- hwRequirementId: options.id
- }).then(res => {
- if (res.errCode === 0) {
- this.setData({
- ...res.data.hwRequirementAPI,
- displayCancel: res.data.displayCancel || null,
- needEnrollment: res.data.needEnrollment || null,
- enrollId: res.data.enrollId || null
- })
- }
- })
- }
- }
- // 保存状态
- if (options.status) {
- this.setData({
- status: Number(options.status),
- show: false
- })
- }
- this.setData({
- user_id: wx.getStorageSync('userId'),
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: this.data.name,
- path: `/pages/detail/detail?id=${this.data.id}&&status=${this.data.status}`
- }
- }
- })
|