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.
242 lines
5.3 KiB
242 lines
5.3 KiB
// subpages/points/pages/demand/crate.js
|
|
// @ts-nocheck
|
|
import getLocation from "@utils/location";
|
|
import { wxRequestPost } from "@utils/promise-wx-api";
|
|
import {
|
|
nextTick,
|
|
} from "@utils/tools";
|
|
const app = getApp()
|
|
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)
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
initInfo(op) {
|
|
const { parentCode, categoryName, categoryCode } = op
|
|
let { info } = this.data
|
|
info = {
|
|
...info,
|
|
gridId: app.globalData.gridId,
|
|
parentCode: parentCode,
|
|
categoryCode: categoryCode
|
|
}
|
|
this.setData({
|
|
info,
|
|
categoryName: categoryName
|
|
})
|
|
console.log('info', info)
|
|
},
|
|
handleTimeChange(e: any) {
|
|
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: any) {
|
|
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() {
|
|
// this.getLocations(false);
|
|
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,
|
|
},
|
|
});
|
|
},
|
|
});
|
|
},
|
|
// 获取地理位置信息
|
|
async getLocations(isQuiet = true) {
|
|
const { msg, data } = await getLocation(isQuiet);
|
|
console.log(msg, data);
|
|
if (msg === "success") {
|
|
const { info } = this.data;
|
|
this.setData({
|
|
info: {
|
|
...info,
|
|
serviceLocation: data.address,
|
|
longitude: data.longitude,
|
|
latitude: data.latitude
|
|
},
|
|
});
|
|
}
|
|
},
|
|
async getInfo(op) {
|
|
const params = {
|
|
demandRecId: op.id
|
|
}
|
|
let {
|
|
data: {
|
|
data: { code, data },
|
|
},
|
|
msg,
|
|
} = await wxRequestPost('heart/residemand/my-detail', params, { isMock: false });
|
|
console.log('getInfo', data)
|
|
if (msg == 'success' && code == 0) {
|
|
let { info } = this.data
|
|
for(const n in info) {
|
|
info[n] = data[n]
|
|
}
|
|
this.setData({
|
|
info,
|
|
categoryName: data.categoryName
|
|
})
|
|
}
|
|
},
|
|
async handleSubmit() {
|
|
if (!this.validateForm()) return
|
|
wx.showLoading({
|
|
title: '提交中...'
|
|
})
|
|
let {
|
|
data: {
|
|
data: { code, data },
|
|
},
|
|
msg,
|
|
} = await wxRequestPost('heart/residemand/submit', this.data.info, { isMock: false });
|
|
console.log('handleSubmit', data)
|
|
await nextTick(1000)
|
|
wx.hideLoading()
|
|
if (msg == 'success' && code == 0) {
|
|
await wx.showToast({
|
|
title: '提交成功',
|
|
icon: 'none',
|
|
duration: 1500
|
|
})
|
|
await nextTick(1000)
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
}
|
|
},
|
|
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
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
})
|