343 lines
7.1 KiB
JavaScript
343 lines
7.1 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
|
||
util.uploadFileUrl(e.detail.file.url,(res)=>{
|
||
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;
|
||
if (!selectEquipment.customer_name) {
|
||
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,
|
||
})
|
||
let that = this
|
||
util.postUrl(apiArr.repair,{
|
||
appointment_time: time,
|
||
customer_name: name,
|
||
customer_phone: phone,
|
||
device_id: selectEquipment.device_id,
|
||
fault_desc: message,
|
||
photos: fileList2.length !== 0 ? fileList2[0].url : '',
|
||
user_id:Number(wx.getStorageSync('userId'))
|
||
|
||
},res=>{
|
||
wx.hideLoading();
|
||
if (res.error) {
|
||
wx.showToast({
|
||
title: '提交失败',
|
||
icon: 'none'
|
||
})
|
||
return;
|
||
}
|
||
this.setData({
|
||
sucess: true
|
||
})
|
||
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
this.init();
|
||
},
|
||
|
||
init() {
|
||
postUrl(apiArr.BXDeviceList, {
|
||
page_num: 1,
|
||
page_size: 50, //TODO: 临时写一次获取50个,后续优化
|
||
user_id:Number(wx.getStorageSync('userId'))
|
||
}, res => {
|
||
console.log('11111', res);
|
||
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() {
|
||
|
||
}
|
||
}) |