import { saveTripInfo, getTripInfoDetail, deleteTripById, getAreaInfo, } from '../../utils/tripReport.js' Page({ data: { lock: false, // 防止重复点击 id: '', // 活动id name: '', // 姓名 phone: '', //手机号 card: '', //身份证号 visibleNowAddress: false, //级联 nowAddressValue: [], // 现居地址ip nowAddress: '', //现居地址 detailAddress: '', //详细地址 comeFromAddress: '', //来自地址 comeFromAddressValue: [], visibleComeFromAddress: false, localTime: '', //来到本地时间 visibleLocalTime: '', localTimeValue: [], backTime: '', //返回时间 backTimeValue: [], visibleBackTime: false, actContent: '', // 备注信息 type: '', // 编辑 还是 查看 options1: [ // { // label: '北京', // value: '110000', // children: [ // { // label: '北京市', // value: '110000', // children: [ // { // label: '东城区', // value: '110101', // }, // ], // }, // ], // }, // { // label: '上海', // value: '310000', // children: [ // { // label: '上海市', // value: '310000', // children: [ // { // label: '黄浦区', // value: '310101', // }, // ], // }, // ], // }, ], defaultFieldNames: { value: 'id', label: 'shortName', }, newOptions: [], pid: 0, }, onLoad: function (options) { this.getNowTime() this.getAreaInfo() if (options.id) { this.setData({ id: options.id, type: options.type, }) } if (this.data.type == 'look') { this.getTripInfoDetail() } }, getNowTime() { const date = new Date() const year = date.getFullYear() const month = date.getMonth() const day = date.getDate() this.setData({ localTimeValue: [year, month, day], backTimeValue: [year, month, day], }) }, // 获取类别 getAreaInfo() { getAreaInfo(this.data.pid).then((res) => { res.data.forEach((item) => { item.label = item.shortName item.value = item.id item.isLeaf = false }) if (this.data.pid == 0) { this.setData({ options1: res.data, }) } else { if (res.data.length === 0) { wx.hideLoading() this.setData({ visibleNowAddress: false, visibleComeFromAddress: false, }) return } // 如果不是第一层级,要往下加children let arr = this.recursionMethod( this.data.options1, this.data.pid, res.data ) this.setData({ options1: arr, }) console.log('options1---', this.data.options1) } }) }, recursionMethod(arr, pid, children) { arr.forEach((item) => { if (item.children) { console.log('掉children', item.children, this.data.pid, children) this.recursionMethod(item.children, this.data.pid, children) } else { if (item.id === pid) { console.log('值相等') item.children = children wx.hideLoading() } } }) return arr }, // 动态加载级联选择器 onLoadOptions(e) { console.log('onLoadOptions', e.detail) const { value } = e.detail wx.showLoading({ mask: true, title: "加载中..." }) this.setData({ pid: value[value.length - 1], }) this.getAreaInfo() }, onLoadComeAddress(e) { const { value } = e.detail wx.showLoading({ mask: true, title: "加载中..." }) this.setData({ pid: value[value.length - 1], }) this.getAreaInfo() }, // 获取申请详情 getTripInfoDetail() { let _this = this getTripInfoDetail(this.data.id).then((res) => { if (res.code == 0 && res.msg == 'success') { if (res.data) { this.setData({ id: res.data.id, name: res.data.name, phone: res.data.mobile, card: res.data.idCard, nowAddress: res.data.nowAddressName, detailAddress: res.data.nowAddressDetail, comeFromAddress: res.data.comeAddressName, localTime: res.data.comeDate, backTime: res.data.backDate, actContent: res.data.note, }) } console.log('详情', res.data.backDate) } }) }, // 删除 deleteTripById() { wx.showModal({ title: '提示', content: '确定要删除吗', success: (res) => { if (res.confirm) { const params = { id: this.data.id, } deleteTripById(params).then((res) => { wx.showToast({ title: '删除成功', icon: 'success', duration: 2000, success: () => { wx.navigateBack({ delta: 1, }) }, }) }) } else if (res.cancel) { console.log('用户点击取消') } }, }) }, confirmButton() { wx.navigateBack({ delta: 1, }) }, // 提交申请 onSubmitApply() { if (this.data.lock) { return } if (!this.data.name.trim('')) { this.showToast('姓名不能为空') return } if (!this.data.phone.trim('')) { this.showToast('手机号不能为空') return } if (!this.data.card.trim('')) { this.showToast('身份证号不能为空') return } if (this.data.nowAddressValue.length === 0) { this.showToast('现居住地不能为空') return } if (!this.data.detailAddress.trim('')) { this.showToast('详细地址不能为空') return } if (this.data.comeFromAddressValue.length === 0) { this.showToast('来自地区不能为空') return } if (this.data.localTime.length === 0) { this.showToast('来到本地时间不能为空') return } // this.setData({ // nowAddress: this.data.nowAddress.split('-'), // comeFromAddress: this.data.comeFromAddress.split('-'), // }) let params = { name: this.data.name.trim(''), mobile: this.data.phone.trim(''), idCard: this.data.card.trim(''), nowAddressCode: this.data.nowAddressValue.join(','), nowAddressName: this.data.nowAddress, nowAddressDetail: this.data.detailAddress, comeAddressCode: this.data.comeFromAddressValue.join(','), comeAddressName: this.data.comeFromAddress, comeDate: this.data.localTime, backDate: this.data.backTime, note: this.data.actContent.trim(''), } const _this = this wx.showModal({ title: '提示', content: '是否要上报行程', success(res) { if (res.confirm) { _this.data.lock = true wx.showLoading({ title: '提交中...' }) saveTripInfo(params) .then((res) => { if (res.code == 0 && res.msg == 'success') { _this.showToast('提交成功') setTimeout(() => { _this.data.lock = false wx.switchTab({ url: '/pages/index/index', }) }, 1000) } else { _this.data.lock = false } }).catch(() => { _this.data.lock = false }) } else if (res.cancel) { console.log('用户点击取消') _this.data.lock = false } }, fail() { _this.data.lock = false } }) }, onInputValue(e) { let code = e.currentTarget.dataset.code this.setData({ [code]: e.detail.value, }) }, // 简化提示 showToast(title, time = 2500) { wx.showToast({ title: title || '请耐心等待...', icon: 'none', duration: time, }) }, toApplyList() { wx.navigateTo({ url: '/subpages/extend/pages/moreList/moreList', }) }, // 现地址 onOpenNowAddress() { this.setData({ visibleNowAddress: true, }) }, onCloseNowAddress() { this.setData({ visibleNowAddress: false }) }, onChangeAdress(e) { this.setData({ nowAddressValue: e.detail.value, nowAddress: e.detail.options.map((n) => n.label).join('-'), }) }, // 来自地址 onOpenComeFromAddress() { this.setData({ visibleComeFromAddress: true, }) }, onCloseComeFromAddress() { this.setData({ visibleComeFromAddress: false }) }, onChangeComeFromAddress(e) { this.setData({ comeFromAddressValue: e.detail.value, comeFromAddress: e.detail.options.map((n) => n.label).join('-'), }) }, // 来到时间 onOpenLocalTime() { this.setData({ visibleLocalTime: true, }) }, onConfirm(e) { const { name, label, visible } = e.currentTarget.dataset this.setData({ [name]: e.detail.value, [label]: e.detail.label, [visible]: false, }) }, onCancelTime(e) { const { visible } = e.currentTarget.dataset this.setData({ [visible]: false, }) }, onOpenBackTime() { this.setData({ visibleBackTime: true, }) }, })