473 lines
15 KiB
JavaScript
473 lines
15 KiB
JavaScript
const apiArr = require("~/api/water_filter");
|
||
const { postUrl } = require("~/utils/util");
|
||
const util = require("~/utils/util");
|
||
|
||
// pages/water_filter/repair/repair.js
|
||
const app = getApp()
|
||
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
s: app.system.statusBarHeight, // 状态栏高度
|
||
n: (app.menu.top - app.system.statusBarHeight) * 2 + app.menu.height, // 导航栏高度
|
||
t: app.menu.top, // 胶囊局顶部距离
|
||
h: app.menu.height, // 胶囊高度
|
||
value: '',
|
||
|
||
name: "",
|
||
phone: "",
|
||
message: "",
|
||
fileList: [],
|
||
fileList2: [],
|
||
time: "",
|
||
|
||
equipmentShow: false,
|
||
equipmentList: [],
|
||
selectEquipment: {}, // 所选设备信息
|
||
DoorTimeShow: false,
|
||
sucess: false,//是否报修成功
|
||
minDate: new Date().getTime(),
|
||
formatter(type, value) {
|
||
if (type === 'year') {
|
||
return `${value}年`;
|
||
}
|
||
if (type === 'month') {
|
||
return `${value}月`;
|
||
}
|
||
if (type === 'day') {
|
||
return `${value}日`;
|
||
}
|
||
return value;
|
||
},
|
||
},
|
||
deleteImg(e) {
|
||
console.log(e);
|
||
let that = this
|
||
let fileList = that.data.fileList
|
||
let fileList2 = that.data.fileList2
|
||
fileList.splice(e.detail.index, 1)
|
||
fileList2.splice(e.detail.index, 1)
|
||
that.setData({
|
||
fileList,
|
||
fileList2
|
||
})
|
||
},
|
||
|
||
ipt1(e) {
|
||
let that = this
|
||
that.setData({
|
||
name: e.detail.value
|
||
})
|
||
},
|
||
ipt2(e) {
|
||
let that = this
|
||
that.setData({
|
||
phone: e.detail.value
|
||
})
|
||
},
|
||
ipt3(e) {
|
||
let that = this
|
||
that.setData({
|
||
message: e.detail
|
||
})
|
||
},
|
||
|
||
switchShow() {
|
||
let that = this
|
||
that.setData({
|
||
DoorTimeShow: !that.data.DoorTimeShow
|
||
})
|
||
},
|
||
|
||
// 取消所选设备信息
|
||
headerCancelClick() {
|
||
this.setData({
|
||
selectEquipment: {}, // 所选设备信息
|
||
equipmentShow: false
|
||
})
|
||
},
|
||
|
||
// 关闭弹窗
|
||
onClose() {
|
||
let that = this
|
||
that.setData({
|
||
DoorTimeShow: false
|
||
})
|
||
},
|
||
headerEquipmentPopupClick() {
|
||
this.setData({
|
||
equipmentShow: true
|
||
})
|
||
},
|
||
|
||
onClosePopup() {
|
||
this.setData({
|
||
equipmentShow: false
|
||
})
|
||
},
|
||
|
||
onInput(event) {
|
||
let that = this
|
||
const date = new Date(event.detail);
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份补零
|
||
const day = String(date.getDate()).padStart(2, '0'); // 日期补零
|
||
const hours = String(date.getHours()).padStart(2, '0'); // 小时补零
|
||
const minutes = String(date.getMinutes()).padStart(2, '0'); // 分钟补零
|
||
|
||
const time = `${year}-${month}-${day} ${hours}:${minutes}`;
|
||
console.log(time);
|
||
that.setData({
|
||
time,
|
||
DoorTimeShow: false
|
||
})
|
||
},
|
||
|
||
afterRead(e) {
|
||
const { file } = e.detail;
|
||
// 验证文件类型
|
||
if (file.type !== 'image/jpeg' && file.type !== 'image/png' && file.type !== 'image') {
|
||
wx.showToast({ title: '只能上传 JPG/PNG 格式的图片', icon: 'none' });
|
||
return false;
|
||
}
|
||
// 验证文件大小
|
||
if (file.size > 5 * 1024 * 1024) {
|
||
wx.showToast({ title: '图片大小不能超过 5MB', icon: 'none' });
|
||
return false;
|
||
}
|
||
return true;
|
||
},
|
||
beforeRead(e) {
|
||
console.log(e);
|
||
let that = this
|
||
wx.showLoading({
|
||
title: '上传中',
|
||
mask: true,
|
||
})
|
||
util.uploadFileUrl(e.detail.file.url, (res) => {
|
||
wx.hideLoading()
|
||
let datas = JSON.parse(res)
|
||
console.log(datas.data);
|
||
let url = util.img_url + datas.data.path
|
||
let fileList = that.data.fileList
|
||
let fileList2 = that.data.fileList2
|
||
let obj = {
|
||
url: url,
|
||
name: 'avatar'
|
||
}
|
||
let obj2 = {
|
||
url: datas.data.path,
|
||
name: 'avatar'
|
||
}
|
||
fileList.push(obj)
|
||
fileList2.push(obj2)
|
||
that.setData({
|
||
fileList,
|
||
fileList2
|
||
})
|
||
})
|
||
},
|
||
|
||
submit() {
|
||
const { selectEquipment, name, phone, time, message, fileList2 } = this.data;
|
||
let that = this
|
||
|
||
if (!selectEquipment.device_id) {
|
||
wx.showToast({
|
||
title: '请选择报修设备',
|
||
icon: "none"
|
||
})
|
||
return
|
||
}
|
||
if (!name) {
|
||
wx.showToast({
|
||
title: '请填写联系人姓名',
|
||
icon: "none"
|
||
})
|
||
return
|
||
}
|
||
if (!phone) {
|
||
wx.showToast({
|
||
title: '请填写联系人电话',
|
||
icon: "none"
|
||
})
|
||
return
|
||
}
|
||
if (!util.isPhone(phone)) {
|
||
wx.showToast({
|
||
title: '请填写正确电话',
|
||
icon: "none"
|
||
})
|
||
return
|
||
}
|
||
if (!time) {
|
||
wx.showToast({
|
||
title: '请选择上门时间',
|
||
icon: "none"
|
||
})
|
||
return
|
||
}
|
||
if (!message) {
|
||
wx.showToast({
|
||
title: '请填写报修内容',
|
||
icon: "none"
|
||
})
|
||
return
|
||
}
|
||
wx.showLoading({
|
||
title: '提交中...',
|
||
mask: true,
|
||
})
|
||
|
||
wx.getSetting({
|
||
withSubscriptions: true,
|
||
success: (res) => {
|
||
if (res.subscriptionsSetting && res.subscriptionsSetting.mainSwitch) {
|
||
const itemSettings = res.subscriptionsSetting.itemSettings || {};
|
||
const tmplMap = {
|
||
'q3Aa07wgYPgB23mu4JOuSzgFoiYhouUcw-NhV5CNuSA': '订单重新指派提醒',
|
||
'eEetEKoNpqXk_EY0xqMt22_Xd7NFEyiODY6j0t3_A24': '欠费通知',
|
||
'pUkdPwh7jWLjCWWv2zyz7I086xNO_GoaJQ6A-cYuGVg': '新订单提醒'
|
||
};
|
||
|
||
// 收集未订阅的模板ID
|
||
const unsubscribedTmplIds = [];
|
||
Object.keys(tmplMap).forEach(tmplId => {
|
||
if (itemSettings[tmplId] !== 'accept') {
|
||
unsubscribedTmplIds.push(tmplId);
|
||
}
|
||
});
|
||
|
||
if (unsubscribedTmplIds.length > 0) {
|
||
// 逐个订阅未订阅的消息
|
||
wx.requestSubscribeMessage({
|
||
tmplIds: unsubscribedTmplIds,
|
||
success: (res) => {
|
||
util.postUrl(apiArr.repair, {
|
||
appointment_time: time,
|
||
customer_name: name,
|
||
customer_phone: phone,
|
||
device_id: selectEquipment.device_id,
|
||
fault_desc: message,
|
||
fault_imgs: fileList2.length !== 0 ? fileList2[0].url : '',
|
||
user_id: Number(wx.getStorageSync('userId'))
|
||
}, res => {
|
||
wx.hideLoading();
|
||
if (res.error) {
|
||
wx.showToast({
|
||
title: '提交失败',
|
||
icon: 'none'
|
||
})
|
||
return;
|
||
}
|
||
that.setData({
|
||
sucess: true
|
||
})
|
||
|
||
})
|
||
},
|
||
fail: (err) => {
|
||
util.postUrl(apiArr.repair, {
|
||
appointment_time: time,
|
||
customer_name: name,
|
||
customer_phone: phone,
|
||
device_id: selectEquipment.device_id,
|
||
fault_desc: message,
|
||
fault_imgs: fileList2.length !== 0 ? fileList2[0].url : '',
|
||
user_id: Number(wx.getStorageSync('userId'))
|
||
}, res => {
|
||
wx.hideLoading();
|
||
if (res.error) {
|
||
wx.showToast({
|
||
title: '提交失败',
|
||
icon: 'none'
|
||
})
|
||
return;
|
||
}
|
||
that.setData({
|
||
sucess: true
|
||
})
|
||
|
||
})
|
||
}
|
||
});
|
||
}else{
|
||
util.postUrl(apiArr.repair, {
|
||
appointment_time: time,
|
||
customer_name: name,
|
||
customer_phone: phone,
|
||
device_id: selectEquipment.device_id,
|
||
fault_desc: message,
|
||
fault_imgs: fileList2.length !== 0 ? fileList2[0].url : '',
|
||
user_id: Number(wx.getStorageSync('userId'))
|
||
}, res => {
|
||
wx.hideLoading();
|
||
if (res.error) {
|
||
wx.showToast({
|
||
title: '提交失败',
|
||
icon: 'none'
|
||
})
|
||
return;
|
||
}
|
||
that.setData({
|
||
sucess: true
|
||
})
|
||
|
||
})
|
||
}
|
||
}
|
||
},
|
||
fail:()=>{
|
||
util.postUrl(apiArr.repair, {
|
||
appointment_time: time,
|
||
customer_name: name,
|
||
customer_phone: phone,
|
||
device_id: selectEquipment.device_id,
|
||
fault_desc: message,
|
||
fault_imgs: fileList2.length !== 0 ? fileList2[0].url : '',
|
||
user_id: Number(wx.getStorageSync('userId'))
|
||
}, res => {
|
||
wx.hideLoading();
|
||
if (res.error) {
|
||
wx.showToast({
|
||
title: '提交失败',
|
||
icon: 'none'
|
||
})
|
||
return;
|
||
}
|
||
that.setData({
|
||
sucess: true
|
||
})
|
||
|
||
})
|
||
}
|
||
});
|
||
|
||
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
this.init();
|
||
wx.showShareMenu({
|
||
withShareTicket: true,
|
||
menus: ['shareAppMessage', 'shareTimeline']
|
||
})
|
||
},
|
||
|
||
init() {
|
||
wx.showLoading({
|
||
title: '加载中...',
|
||
mask: true
|
||
})
|
||
postUrl(apiArr.BXDeviceList, {
|
||
page_num: 1,
|
||
page_size: 50, //TODO: 临时写一次获取50个,后续优化
|
||
user_id: Number(wx.getStorageSync('userId'))
|
||
}, res => {
|
||
wx.hideLoading()
|
||
if (res.msg == '操作成功') {
|
||
if (res.rows) {
|
||
res.rows.forEach(item => {
|
||
item.product_icon = util.img_url + item.product_icon
|
||
})
|
||
this.setData({
|
||
equipmentList: res.rows || []
|
||
})
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
|
||
headerSelectClick(e) {
|
||
console.log('e', e);
|
||
this.setData({
|
||
selectEquipment: e.currentTarget.dataset.item,
|
||
name: e.currentTarget.dataset.item.customer_name,
|
||
phone: e.currentTarget.dataset.item.customer_phone,
|
||
equipmentShow: false
|
||
})
|
||
},
|
||
|
||
headerLookClick() {
|
||
const pageUrl = getCurrentPages();
|
||
// 获取当前页面的上一页 如果不是首页
|
||
if (pageUrl[pageUrl.length - 2].route !== 'pages/index/newIndex/newIndex') {
|
||
// 关闭当前页 返回上一页
|
||
wx.navigateBack({
|
||
delta: 1
|
||
})
|
||
} else {
|
||
wx.redirectTo({
|
||
url: '/packages/WaterPurifier/pages/Maintenance/Maintenance',
|
||
})
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
return {
|
||
title: '人人爱净水', // 分享卡片标题(必填)
|
||
path: '/pages/water_filter/water_filter', // 用户点击后跳转的路径(可选,默认当前页)
|
||
imageUrl: 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com/share.png' // 自定义图片(可选,比例建议 5:4)
|
||
}
|
||
},
|
||
onShareTimeline() {
|
||
return {
|
||
title: '人人爱净水', // 自定义标题
|
||
query: '', // 自定义页面路径中的参数
|
||
imageUrl: 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com/share.png' // 自定义分享图片路径
|
||
}
|
||
},
|
||
}) |