|
@@ -1,4 +1,4 @@
|
|
|
-const app=getApp();
|
|
|
+const app = getApp();
|
|
|
Page({
|
|
|
data: {
|
|
|
address: app.globalData.currentAccountInfo.address,
|
|
@@ -16,11 +16,12 @@ Page({
|
|
|
id: '',
|
|
|
mode: '',
|
|
|
isReplied: false,
|
|
|
+ formSubmitted: false,
|
|
|
},
|
|
|
|
|
|
- onLoad: function(options) {
|
|
|
+ onLoad: function (options) {
|
|
|
const isReplied = options.isReplied === 'true';
|
|
|
-
|
|
|
+
|
|
|
if (options.mode === 'preview') {
|
|
|
this.setData({
|
|
|
isPreviewMode: true,
|
|
@@ -40,9 +41,9 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- startCountDown: function() {
|
|
|
+ startCountDown: function () {
|
|
|
let that = this;
|
|
|
- let timer = setInterval(function() {
|
|
|
+ let timer = setInterval(function () {
|
|
|
if (that.data.countDown > 0) {
|
|
|
that.setData({
|
|
|
countDown: that.data.countDown - 1
|
|
@@ -53,7 +54,7 @@ Page({
|
|
|
}, 1000);
|
|
|
},
|
|
|
|
|
|
- closeNotification: function() {
|
|
|
+ closeNotification: function () {
|
|
|
if (this.data.countDown <= 0) {
|
|
|
this.setData({
|
|
|
showNotification: false
|
|
@@ -61,18 +62,18 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- goBack: function() {
|
|
|
+ goBack: function () {
|
|
|
wx.navigateBack();
|
|
|
},
|
|
|
|
|
|
- inputContact: function(e) {
|
|
|
+ inputContact: function (e) {
|
|
|
this.setData({
|
|
|
contact: e.detail.value
|
|
|
});
|
|
|
this.checkFormValidity();
|
|
|
},
|
|
|
|
|
|
- inputPhone: function(e) {
|
|
|
+ inputPhone: function (e) {
|
|
|
const value = e.detail.value;
|
|
|
const phoneNumber = value.replace(/\D/g, '');
|
|
|
this.setData({
|
|
@@ -81,16 +82,16 @@ Page({
|
|
|
this.checkFormValidity();
|
|
|
},
|
|
|
|
|
|
- validatePhone: function(phone) {
|
|
|
+ validatePhone: function (phone) {
|
|
|
const phoneReg = /^1[3-9]\d{9}$/;
|
|
|
return phoneReg.test(phone);
|
|
|
},
|
|
|
|
|
|
- showRepairTypeSelector: function() {
|
|
|
+ showRepairTypeSelector: function () {
|
|
|
let that = this;
|
|
|
wx.showActionSheet({
|
|
|
itemList: ['水管漏水', '水表故障', '水龙头故障', '其他问题'],
|
|
|
- success: function(res) {
|
|
|
+ success: function (res) {
|
|
|
const types = ['水管漏水', '水表故障', '水龙头故障', '其他问题'];
|
|
|
that.setData({
|
|
|
repairType: types[res.tapIndex]
|
|
@@ -100,14 +101,14 @@ Page({
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- inputDescription: function(e) {
|
|
|
+ inputDescription: function (e) {
|
|
|
this.setData({
|
|
|
description: e.detail.value
|
|
|
});
|
|
|
this.checkFormValidity();
|
|
|
},
|
|
|
|
|
|
- chooseImage: function() {
|
|
|
+ chooseImage: function () {
|
|
|
let that = this;
|
|
|
if (that.data.imageList.length >= 10) {
|
|
|
wx.showToast({
|
|
@@ -116,28 +117,27 @@ Page({
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
wx.chooseMedia({
|
|
|
- count: 3 - that.data.imageList.length,
|
|
|
+ count: 10 - that.data.imageList.length,
|
|
|
mediaType: ['image'],
|
|
|
sourceType: ['album', 'camera'],
|
|
|
sizeType: ['compressed'],
|
|
|
- success: function(res) {
|
|
|
+ success: function (res) {
|
|
|
let tempFiles = res.tempFiles;
|
|
|
let validFiles = [];
|
|
|
- debugger;
|
|
|
for (let i = 0; i < tempFiles.length; i++) {
|
|
|
const file = tempFiles[i];
|
|
|
- if (file.size <= 5 * 1024 * 1024) {
|
|
|
+ if (file.size <= 10 * 1024 * 1024) {
|
|
|
validFiles.push(file);
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
- title: '图片大小不能超过5M',
|
|
|
+ title: '图片大小不能超过10M',
|
|
|
icon: 'none'
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (validFiles.length > 0) {
|
|
|
let newImageList = that.data.imageList.concat(validFiles);
|
|
|
that.setData({
|
|
@@ -148,7 +148,7 @@ Page({
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- previewImage: function(e) {
|
|
|
+ previewImage: function (e) {
|
|
|
let index = e.currentTarget.dataset.index;
|
|
|
wx.previewImage({
|
|
|
current: this.data.imageList[index],
|
|
@@ -156,7 +156,7 @@ Page({
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- deleteImage: function(e) {
|
|
|
+ deleteImage: function (e) {
|
|
|
let index = e.currentTarget.dataset.index;
|
|
|
let imageList = this.data.imageList;
|
|
|
imageList.splice(index, 1);
|
|
@@ -165,33 +165,43 @@ Page({
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- checkFormValidity: function() {
|
|
|
- const { contact, phone, address, repairType, description } = this.data;
|
|
|
+ checkFormValidity: function () {
|
|
|
+ const {
|
|
|
+ contact,
|
|
|
+ phone,
|
|
|
+ address,
|
|
|
+ repairType,
|
|
|
+ description
|
|
|
+ } = this.data;
|
|
|
const isValid = contact && phone && address && repairType && description;
|
|
|
-
|
|
|
+
|
|
|
this.setData({
|
|
|
isFormValid: isValid
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
return isValid;
|
|
|
},
|
|
|
|
|
|
- onInputChange: function(e) {
|
|
|
- const { field } = e.currentTarget.dataset;
|
|
|
- const { value } = e.detail;
|
|
|
-
|
|
|
+ onInputChange: function (e) {
|
|
|
+ const {
|
|
|
+ field
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
+ const {
|
|
|
+ value
|
|
|
+ } = e.detail;
|
|
|
+
|
|
|
this.setData({
|
|
|
[field]: value
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
this.checkFormValidity();
|
|
|
},
|
|
|
|
|
|
- bindPickerChange: function(e) {
|
|
|
+ bindPickerChange: function (e) {
|
|
|
this.checkFormValidity();
|
|
|
},
|
|
|
|
|
|
- submitRepair: function() {
|
|
|
+ submitRepair: function () {
|
|
|
if (!this.checkFormValidity()) {
|
|
|
wx.showToast({
|
|
|
title: '请填写完整信息',
|
|
@@ -199,7 +209,7 @@ Page({
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (!this.validatePhone(this.data.phone)) {
|
|
|
wx.showToast({
|
|
|
title: '请输入正确的手机号',
|
|
@@ -207,7 +217,7 @@ Page({
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
const submitData = {
|
|
|
address: this.data.address,
|
|
|
contact: this.data.contact,
|
|
@@ -216,19 +226,19 @@ Page({
|
|
|
description: this.data.description,
|
|
|
images: this.data.imageList
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
console.log('提交的数据:', submitData);
|
|
|
-
|
|
|
+
|
|
|
wx.showLoading({
|
|
|
title: '提交中...',
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
setTimeout(() => {
|
|
|
wx.hideLoading();
|
|
|
wx.showToast({
|
|
|
icon: 'success',
|
|
|
duration: 2000,
|
|
|
- success: function() {
|
|
|
+ success: function () {
|
|
|
setTimeout(() => {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/baoxiuSuccess/baoxiuSuccess',
|
|
@@ -239,43 +249,51 @@ Page({
|
|
|
}, 1500);
|
|
|
},
|
|
|
|
|
|
- loadPreviewData: function(id) {
|
|
|
+ loadPreviewData: function (id) {
|
|
|
wx.showLoading({
|
|
|
title: '加载中...',
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// 从上一个页面获取数据
|
|
|
const pages = getCurrentPages();
|
|
|
const prevPage = pages[pages.length - 2]; // 获取上一个页面
|
|
|
-
|
|
|
+
|
|
|
if (prevPage && prevPage.data && prevPage.data.noticeList) {
|
|
|
// 根据id查找对应的报修项
|
|
|
const item = prevPage.data.noticeList.find(item => item.id == id);
|
|
|
-
|
|
|
+ debugger
|
|
|
if (item) {
|
|
|
+ // 格式化时间
|
|
|
+ const formatTime = (timeString) => {
|
|
|
+ if (!timeString) return ''; // 如果时间为空,返回空字符串
|
|
|
+ const date = new Date(timeString);
|
|
|
+ const year = date.getFullYear();
|
|
|
+ const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份补零
|
|
|
+ const day = String(date.getDate()).padStart(2, '0'); // 日期补零
|
|
|
+ return `${year}-${month}-${day}`;
|
|
|
+ };
|
|
|
+
|
|
|
this.setData({
|
|
|
- address: item.address || '',
|
|
|
+ address: item.address || '',
|
|
|
contact: item.contact || '',
|
|
|
phone: item.contactnumber || '',
|
|
|
repairType: item.repairtype || '',
|
|
|
description: item.faultdescription || '',
|
|
|
- imageList: item.hasAttachment ? item.attachments.map(data=>{
|
|
|
- return { tempFilePath:data};
|
|
|
- }) : [],
|
|
|
- replyTime: item.isReplied ? item.recoverydate : '',
|
|
|
- replyContent: item.isReplied ? item.replycontent : ''
|
|
|
+ imageList: item.attachments || [],
|
|
|
+ replyTime: item.isReplied ? formatTime(item.repairtime) : '',
|
|
|
+ replyContent: item.isReplied ? item.remark : ''
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
wx.hideLoading();
|
|
|
},
|
|
|
|
|
|
- submitForm: function() {
|
|
|
+ submitForm: function () {
|
|
|
if (this.data.isPreviewMode) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (!this.checkFormValidity()) {
|
|
|
wx.showToast({
|
|
|
title: '请填写完整信息',
|
|
@@ -283,7 +301,7 @@ Page({
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (!this.validatePhone(this.data.phone)) {
|
|
|
wx.showToast({
|
|
|
title: '请输入正确的手机号',
|
|
@@ -292,12 +310,12 @@ Page({
|
|
|
return;
|
|
|
}
|
|
|
const fileManager = wx.getFileSystemManager();
|
|
|
- this.data.imageList.map(imgInfo=>{
|
|
|
+ this.data.imageList.map(imgInfo => {
|
|
|
const base64 = fileManager.readFileSync(imgInfo.tempFilePath, 'base64');
|
|
|
- imgInfo.base64=base64;
|
|
|
+ imgInfo.base64 = base64;
|
|
|
return imgInfo;
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
const submitData = {
|
|
|
address: this.data.address,
|
|
|
contact: this.data.contact,
|
|
@@ -306,9 +324,9 @@ Page({
|
|
|
description: this.data.description,
|
|
|
images: this.data.imageList
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
console.log('提交的数据:', submitData);
|
|
|
-
|
|
|
+
|
|
|
wx.showLoading({
|
|
|
title: '提交中...',
|
|
|
});
|
|
@@ -321,14 +339,14 @@ Page({
|
|
|
'source': "wc",
|
|
|
'!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey
|
|
|
},
|
|
|
- data:submitData,
|
|
|
+ data: submitData,
|
|
|
success(res) {
|
|
|
wx.hideLoading();
|
|
|
- if(res.data.code=='200'){
|
|
|
- debugger
|
|
|
- wx.navigateTo({
|
|
|
- url: '/pages/baoxiuSuccess/baoxiuSuccess',
|
|
|
- });
|
|
|
+ if (res.data.code == '200') {
|
|
|
+ debugger
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/baoxiuSuccess/baoxiuSuccess',
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
fail(error) {
|
|
@@ -336,11 +354,39 @@ Page({
|
|
|
utils.simleInfo('登记失败,请稍后再试')
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+ // 在提交成功后设置标记
|
|
|
+ this.setData({
|
|
|
+ formSubmitted: true
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
- inputAddress: function(e) {
|
|
|
+ inputAddress: function (e) {
|
|
|
this.setData({
|
|
|
address: e.detail.value
|
|
|
});
|
|
|
},
|
|
|
-});
|
|
|
+
|
|
|
+ onShow: function () {
|
|
|
+ // 检查是否是从成功页面返回
|
|
|
+ if (this.data.formSubmitted) {
|
|
|
+ // 重置表单数据
|
|
|
+ this.resetForm();
|
|
|
+ // 重置提交状态标记
|
|
|
+ this.setData({
|
|
|
+ formSubmitted: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 添加重置表单的方法
|
|
|
+ resetForm: function () {
|
|
|
+ this.setData({
|
|
|
+ contact: '',
|
|
|
+ phone: '',
|
|
|
+ repairType: '',
|
|
|
+ description: '',
|
|
|
+ imageList: []
|
|
|
+ });
|
|
|
+ },
|
|
|
+});
|