// pages/repairTicketDetail/repairTicketDetail.js
|
var util = require('../../utils/network');
|
const DatePickerUtil = require('../../utils/DatePicker.js')
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
deviceList: [],
|
detailedaddress: '获取地址',
|
showType: false,
|
deviceName: '请选择',
|
deviceIndex: 0,
|
columns: [],
|
showDate: false,
|
selectDate: '',
|
show: 'none',
|
info: '',
|
personInfo: {},
|
yetSub: false,
|
tanantId: 0,
|
|
deviceId: 0,
|
userName: '',
|
userPhone: undefined,
|
address: '',
|
description: '',
|
|
time: '选择预约时间',
|
multiArray: [],//piker的item项
|
multiIndex: [],//当前选择列的下标
|
year: '',//选择的年
|
month: '',//选择的月
|
day: '',//选择的日
|
hour: '',//选择的时
|
minute: '',//选择的分
|
},
|
openShowType() {
|
this.setData({
|
showType: true
|
})
|
},
|
onChangeType(event) {
|
const { picker, value, index } = event.detail;
|
console.log(picker, value, index);
|
this.setData({
|
deviceName: value,
|
showType: false,
|
deviceIndex: index,
|
tanantId: this.data.deviceList[index].tenantId,
|
deviceId: this.data.deviceList[index].deviceId,
|
})
|
console.log(this.data.deviceId);
|
},
|
changeUserName(e) {
|
this.setData({
|
userName: e.detail.value
|
})
|
},
|
checkPhone(e) {
|
this.setData({
|
userPhone: e.detail.value
|
})
|
},
|
changeAdress(e) {
|
this.setData({
|
address: e.detail.value
|
})
|
},
|
changeDescription(e) {
|
console.log(e);
|
this.setData({
|
description: e.detail
|
})
|
},
|
closeType() {
|
this.setData({
|
showType: false
|
})
|
},
|
openShowDate() {
|
this.setData({
|
showDate: true
|
})
|
},
|
bindMultiPickerChange: function (e) { //时间日期picker选择改变后,点击确定
|
// console.log('picker发送选择改变,携带值为', e.detail.value)
|
this.setData({
|
multiIndex: e.detail.value
|
})
|
const index = this.data.multiIndex; // 当前选择列的下标
|
const year = this.data.multiArray[0][index[0]];
|
const month = this.data.multiArray[1][index[1]];
|
const day = this.data.multiArray[2][index[2]];
|
const hour = this.data.multiArray[3][index[3]];
|
const minute = this.data.multiArray[4][index[4]];
|
// console.log(`${year}-${month}-${day} ${hour}:${minute}`);
|
|
this.setData({
|
time: (year + month + day + ' ' + hour.replace('时', '') + ':' + minute.replace('分', '')).replace('年', '-').replace('月', '-').replace('日', ''),
|
year: year, //记录选择的年
|
month: month, //记录选择的月
|
day: day, //记录选择的日
|
hour: hour, //记录选择的时
|
minute: minute, //记录选择的分
|
})
|
console.log(this.data.time);
|
},
|
bindMultiPickerColumnChange: function (e) { //监听picker的滚动事件
|
|
// console.log('修改的列为', e.detail.column, ',值为', e.detail.value);
|
|
let getCurrentDate = DatePickerUtil.getCurrentDate();//获取现在时间
|
let currentYear = parseInt(getCurrentDate.substring(0, 4));
|
let currentMonth = parseInt(getCurrentDate.substring(5, 7));
|
let currentDay = parseInt(getCurrentDate.substring(8, 10));
|
let currentHour = parseInt(getCurrentDate.substring(11, 13));
|
let currentMinute = parseInt(getCurrentDate.substring(14, 16));
|
|
if (e.detail.column == 0) {//修改年份列
|
|
let yearSelected = parseInt(this.data.multiArray[e.detail.column][e.detail.value]);//当前选择的年份
|
|
this.setData({
|
multiIndex: [0, 0, 0, 0, 0],//设置pickerIndex
|
year: yearSelected //当前选择的年份
|
});
|
|
if (yearSelected == currentYear) {//当前选择的年份==当前年份
|
var loadPickerData = DatePickerUtil.loadPickerData();
|
|
this.setData({
|
multiArray: loadPickerData,//picker数组赋值
|
multiIndex: [0, 0, 0, 0, 0] //设置pickerIndex
|
});
|
|
} else { // 选择的年份!=当前年份
|
|
// 处理月份
|
let monthArr = DatePickerUtil.loadMonths(1, 12)
|
// 处理日期
|
let dayArr = DatePickerUtil.loadDays(currentYear, currentMonth, 1)
|
// 处理hour
|
let hourArr = DatePickerUtil.loadHours(0, 24);
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(0, 60)
|
|
// 给每列赋值回去
|
this.setData({
|
['multiArray[1]']: monthArr,
|
['multiArray[2]']: dayArr,
|
['multiArray[3]']: hourArr,
|
['multiArray[4]']: minuteArr
|
});
|
}
|
}
|
if (e.detail.column == 1) {//修改月份列
|
let mon = parseInt(this.data.multiArray[e.detail.column][e.detail.value]); //当前选择的月份
|
this.setData({
|
month: mon // 记录当前列
|
})
|
|
if (mon == currentMonth) {//选择的月份==当前月份
|
if (this.data.year == currentYear) {
|
|
// 处理日期
|
let dayArr = DatePickerUtil.loadDays(currentYear, mon, currentDay)
|
// 处理hour
|
let hourArr = DatePickerUtil.loadHours(currentHour, 24);
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(currentMinute, 60)
|
|
this.setData({
|
['multiArray[2]']: dayArr,
|
['multiArray[3]']: hourArr,
|
['multiArray[4]']: minuteArr
|
})
|
} else {
|
// 处理日期
|
let dayArr = DatePickerUtil.loadDays(currentYear, mon, 1)
|
// 处理hour
|
let hourArr = DatePickerUtil.loadHours(0, 24);
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(0, 60)
|
|
this.setData({
|
['multiArray[2]']: dayArr,
|
['multiArray[3]']: hourArr,
|
['multiArray[4]']: minuteArr
|
});
|
}
|
} else { // 选择的月份!=当前月份
|
// 处理日期
|
let dayArr = DatePickerUtil.loadDays(currentYear, mon, 1) // 传入当前年份,当前选择的月份去计算日
|
// 处理hour
|
let hourArr = DatePickerUtil.loadHours(0, 24);
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(0, 60)
|
|
this.setData({
|
['multiArray[2]']: dayArr,
|
['multiArray[3]']: hourArr,
|
['multiArray[4]']: minuteArr
|
});
|
}
|
}
|
if (e.detail.column == 2) {//修改日
|
let dd = parseInt(this.data.multiArray[e.detail.column][e.detail.value]);//当前选择的日
|
this.setData({
|
day: dd
|
})
|
if (dd == currentDay) {//选择的日==当前日
|
if (this.data.year == currentYear && this.data.month == currentMonth) {//选择的是今天
|
|
// 处理hour
|
let hourArr = DatePickerUtil.loadHours(currentHour, 24);
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(currentMinute, 60)
|
|
this.setData({
|
['multiArray[3]']: hourArr,
|
['multiArray[4]']: minuteArr
|
});
|
|
} else { //选择的不是今天
|
// 处理hour
|
let hourArr = DatePickerUtil.loadHours(0, 24);
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(0, 60)
|
|
this.setData({
|
['multiArray[3]']: hourArr,
|
['multiArray[4]']: minuteArr
|
});
|
}
|
} else { // 选择的日!=当前日
|
// 处理hour
|
let hourArr = DatePickerUtil.loadHours(0, 24);
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(0, 60)
|
|
this.setData({
|
['multiArray[3]']: hourArr,
|
['multiArray[4]']: minuteArr
|
});
|
}
|
}
|
if (e.detail.column == 3) {//修改时
|
let hh = parseInt(this.data.multiArray[e.detail.column][e.detail.value]); //当前选择的时
|
this.setData({
|
hour: hh
|
})
|
if (hh == currentHour) {//选择的时==当前时
|
if (this.data.year == currentYear && this.data.month == currentMonth && this.data.month == currentMonth) { // 选择的是今天
|
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(currentMinute, 60)
|
this.setData({
|
['multiArray[4]']: minuteArr
|
});
|
} else { // 选择的不是今天
|
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(0, 60)
|
this.setData({
|
['multiArray[4]']: minuteArr
|
});
|
}
|
} else {//选择的时!=当前时
|
// 处理minute
|
let minuteArr = DatePickerUtil.loadMinutes(0, 60)
|
this.setData({
|
['multiArray[4]']: minuteArr
|
});
|
}
|
}
|
var data = {
|
multiArray: this.data.multiArray,
|
multiIndex: this.data.multiIndex
|
};
|
|
// console.log('修改的列为', e.detail.column, ',值为', e.detail.value);
|
data.multiIndex[e.detail.column] = e.detail.value; //将值赋回去
|
|
this.setData(data); //将值赋回去
|
},
|
choseLocation() {
|
// wx.chooseLocation({
|
// success: (res) => {
|
// console.log(res)
|
// this.setData({
|
// // address: res.name,
|
// detailedaddress: res.address,
|
// locmap: {
|
// latitude: res.latitude,
|
// longitude: res.longitude
|
// },
|
// markers: [{
|
// id: 0,
|
// latitude: res.latitude,
|
// longitude: res.longitude,
|
// iconPath: '/images/ProRep/weizhi.png',
|
// width: '50rpx',
|
// height: '50rpx'
|
// }]
|
// })
|
// },
|
// fail: () => {
|
// wx.getSetting({
|
// success: (res) => {
|
// var statu = res.authSetting;
|
// if (!statu['scope.userLocation']) { //未授权
|
// wx.showModal({
|
// title: '授权定位',
|
// content: '需要获取您的地理位置,请先设置授权',
|
// // cancelColor: 'skyblue',
|
// confirmText: "去设置",
|
// success: (res) => {
|
// console.log(res);
|
// if (res.cancel) {
|
// //点击取消,默认隐藏弹框
|
// } else {
|
// //点击确定
|
// wx.openSetting({
|
// withSubscriptions: true,
|
// success: (res) => {
|
// console.log(res);
|
// this.onLoad()
|
// }
|
// })
|
// }
|
// }
|
// })
|
// }
|
// }
|
// })
|
// }
|
// })
|
},
|
|
submit() {
|
let reg = /^1[3-9]\d{9}$/;
|
if (!this.data.deviceName) {
|
wx.showToast({
|
title: '请选择设备',
|
icon: 'none'
|
});
|
return false
|
} else if (!this.data.userName) {
|
wx.showToast({
|
title: '请输入用户名',
|
icon: 'none'
|
});
|
return false
|
} else if (!reg.test(this.data.userPhone)) {
|
wx.showToast({
|
title: '手机号格式不正确',
|
icon: 'none'
|
});
|
return false
|
} else if (!this.data.address) {
|
wx.showToast({
|
title: '请输入地址',
|
icon: 'none'
|
});
|
return false
|
}
|
let data = {
|
deviceId: this.data.deviceId,
|
erectoId: -1,
|
erectoName: '未指派',
|
userName: this.data.userName,
|
userPhone: this.data.userPhone,
|
address: this.data.address,
|
appointmentTime: this.data.time + ':' + '00',
|
state: 0,
|
orderType: '2',
|
createUserId: this.data.tanantId,
|
userId: this.data.personInfo.userId,
|
repairFlag: 1,
|
description:this.data.description
|
}
|
console.log(data);
|
if (this.data.yetSub) {
|
data.id = this.data.personInfo.id
|
wx.request({
|
url: 'https://puyue.yhupai.com/prod-api/iot/deviceOrder',
|
method: "put",
|
header: {
|
"Access-Control-Allow-Headers": 'token',
|
Authorization: `Bearer ${wx.getStorageSync('token')}`
|
},
|
data: data,
|
success: (res, header) => {
|
console.log(res);
|
if (res.data.code != 200) {
|
wx.showToast({
|
title: res.data.msg,
|
icon: 'none'
|
});
|
} else {
|
wx.navigateBack()
|
}
|
}
|
})
|
} else {
|
wx.request({
|
url: 'https://puyue.yhupai.com/prod-api/iot/deviceOrder',
|
method: "POST",
|
header: {
|
"Access-Control-Allow-Headers": 'token',
|
Authorization: `Bearer ${wx.getStorageSync('token')}`
|
},
|
data: data,
|
success: (res, header) => {
|
console.log(res);
|
if (res.data.code != 200) {
|
wx.showToast({
|
title: res.data.msg,
|
icon: 'none'
|
});
|
} else {
|
wx.navigateBack()
|
}
|
}
|
})
|
}
|
console.log(data);
|
|
},
|
formatDate(dateStr) {
|
let date = new Date(dateStr);
|
|
let year = date.getFullYear();
|
let month = (date.getMonth() + 1).toString().padStart(2, '0'); // 注意:月份是从 0 开始的,所以需要 +1
|
let day = date.getDate().toString().padStart(2, '0');
|
let hour = date.getHours().toString().padStart(2, '0');
|
let minute = date.getMinutes().toString().padStart(2, '0');
|
let second = date.getSeconds().toString().padStart(2, '0');
|
let millisecond = date.getMilliseconds().toString().padStart(3, '0');
|
|
return `${year}-${month}-${day}T${hour}:${minute}:${second}.${millisecond}Z`;
|
},
|
getShortList() {
|
// this.setData({
|
// manageList:[]
|
// })
|
let data = {
|
repairFlag: 0
|
}
|
wx.request({
|
url: 'https://puyue.yhupai.com/prod-api/iot/device/shortList',
|
method: "GET",
|
header: {
|
"Access-Control-Allow-Headers": 'token',
|
Authorization: `Bearer ${wx.getStorageSync('token')}`
|
},
|
data: data,
|
success: (res, header) => {
|
if (res.data.code != 200) {
|
wx.showToast({
|
title: res.data.msg,
|
icon: 'none'
|
});
|
} else {
|
let arr = res.data.rows
|
this.setData({
|
deviceList: arr
|
})
|
|
let dataDevice = []
|
for (let i = 0; i < this.data.deviceList.length; i++) {
|
dataDevice.push(this.data.deviceList[i].deviceName)
|
}
|
this.setData({
|
columns: dataDevice
|
})
|
// wx.setStorageSync('deviceList', arr)
|
}
|
}
|
})
|
},
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad(options) {
|
this.getShortList()
|
|
console.log(this.data.deviceList);
|
|
if (options.info) {
|
this.setData({
|
personInfo: JSON.parse(options.info),
|
yetSub: true
|
})
|
console.log(this.data.personInfo);
|
this.setData({
|
userName: this.data.personInfo.userName,
|
userPhone: this.data.personInfo.userPhone,
|
address: this.data.personInfo.address,
|
deviceName: this.data.personInfo.device.deviceName,
|
deviceId: this.data.personInfo.deviceId,
|
tanantId: this.data.personInfo.createUserId,
|
description:this.data.personInfo.description
|
})
|
for (let i = 0; i < this.data.deviceList.length; i++) {
|
console.log(this.data.deviceList[i], this.data.personInfo);
|
if (this.data.deviceList[i].deviceId == this.data.deviceId) {
|
this.setData({
|
deviceIndex: i
|
})
|
}
|
}
|
} else {
|
this.setData({
|
personInfo: wx.getStorageSync('userInfo')
|
})
|
this.setData({
|
userName: this.data.personInfo.nickName,
|
userPhone: this.data.personInfo.phonenumber,
|
address: this.data.personInfo.address,
|
})
|
}
|
console.log(this.data.personInfo);
|
},
|
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady() {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow() {
|
|
var loadPickerData = DatePickerUtil.loadPickerData()
|
var getCurrentDate = DatePickerUtil.getCurrentDate()
|
var GetMultiIndex = DatePickerUtil.GetMultiIndex()
|
|
//这里写的是为了记录当前时间
|
let year = parseInt(getCurrentDate.substring(0, 4));
|
let month = parseInt(getCurrentDate.substring(5, 7));
|
let day = parseInt(getCurrentDate.substring(8, 10));
|
let hour = parseInt(getCurrentDate.substring(11, 13));
|
let minute = parseInt(getCurrentDate.substring(14, 16));
|
this.setData({
|
multiArray: loadPickerData,//picker数组赋值,格式 [years, months, days, hours, minutes]
|
multiIndex: GetMultiIndex,//设置pickerIndex,[0,0,0,0,0]
|
time: getCurrentDate.replace('年', '-').replace('月', '-').replace('日', ' '), //设置当前时间 ,currentYears+'-'+mm+'-'+dd+' '+hh+':'+min
|
year: year,//记录选择的年
|
month: month,//记录选择的月
|
day: day,//记录选择的日
|
hour: hour,//记录选择的时
|
minute: minute,//记录选择的分
|
});
|
},
|
/**
|
* 生命周期函数--监听页面隐藏
|
*/
|
onHide() {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload() {
|
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh() {
|
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom() {
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage() {
|
|
}
|
})
|