市北党建引领小程序初始化
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

164 lines
3.5 KiB

import { getMyDemandDetail, demandSubmit } from '../../utils/demand'
Page({
data: {
info: {
gridId: '',
wantServiceTime: '',
categoryCode: '',
parentCode: '',
content: '',
demandUserName: '',
demandUserMobile: '',
serviceLocation: '',
locationDetail: '',
longitude: '',
latitude: '',
demandRecId: ''
},
categoryName: ''
},
onLoad: function (options) {
if (options.id) {
this.getInfo(options)
}
else {
this.initInfo(options)
}
},
initInfo(op) {
const { parentCode, categoryName, categoryCode } = op
let { info } = this.data
info = {
...info,
gridId: wx.getStorageSync("gridId"),
parentCode: parentCode,
categoryCode: categoryCode
}
this.setData({
info,
categoryName: categoryName
})
console.log('info', info)
},
handleTimeChange(e) {
let { info } = this.data
const { dateTimeArray, dateTime } = e.detail
info.wantServiceTime = `${dateTimeArray[0][dateTime[0]]}-${dateTimeArray[1][dateTime[1]]}-${dateTimeArray[2][dateTime[2]]} ${dateTimeArray[3][dateTime[3]]}:${dateTimeArray[4][dateTime[4]]}:${dateTimeArray[5][dateTime[5]]}`
console.log('change', e.detail)
this.setData({
info
})
},
handleColumnChange(e) {
console.log('handleColumnChange', e.detail)
},
handleInput(e) {
const name = e.currentTarget.dataset.name
const { value } = e.detail
let { info } = this.data
info[name] = value
this.setData({
info
})
console.log('info', info)
},
toughGetLocation() {
wx.chooseLocation({
success: (res) => {
console.log("resadddres", res);
const { info } = this.data;
this.setData({
info: {
...info,
serviceLocation: res.address,
longitude: res.longitude,
latitude: res.latitude,
},
})
},
})
},
getInfo(op) {
const params = {
demandRecId: op.id
}
getMyDemandDetail(params).then(res => {
if (res.msg == 'success' && res.code == 0) {
let { info } = this.data
for(const n in info) {
info[n] = res.data[n]
}
this.setData({
info,
categoryName: res.data.categoryName
})
}
}).catch(err => {
})
},
handleSubmit() {
if (!this.validateForm()) return
wx.showLoading({
title: '提交中...'
})
demandSubmit(this.data.info).then(res => {
if (res.msg == 'success' && res.code == 0) {
wx.showToast({
title: '提交成功',
icon: 'none',
duration: 1500
})
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1500)
}
}).catch(err => {
})
},
validateForm() {
const { info } = this.data
let item = null
const valiForm = [
{
value: 'content',
label: '需求内容'
},
{
value: 'wantServiceTime',
label: '服务时间'
},
{
value: 'demandUserName',
label: '联系人'
},
{
value: 'demandUserMobile',
label: '联人系电话'
},
{
value: 'serviceLocation',
label: '服务地点'
}
]
item = valiForm.find(item => !info[item.value])
if (item) {
wx.showToast({
title: `${item.label}不能为空`,
icon: 'none',
duration: 1500
})
return false
}
return true
},
})