提交 4952c520 authored 作者: caodi\cd's avatar caodi\cd

fix:校验

上级 f687a284
......@@ -13,8 +13,8 @@
<view class="title-bar">
<view class="blue-line"></view>
<text class="title">巡检井道:</text>
<text class="location">{{ location }}</text>
<button class="submit-btn" :class="{ active: isSubmitEnabled }" :disabled="!isSubmitEnabled">
<text class="location">{{ location }}{{floor}}</text>
<button class="submit-btn" :class="{ active: isSubmitEnabled }" :disabled="!isSubmitEnabled" @click="submit">
提交
</button>
</view>
......@@ -58,7 +58,7 @@
<text class="form-label">现场照片:</text>
<text class="photo-limit">(最多5张)</text>
<view class="photo-container">
<view v-for="(photo, index) in tabData[activeTab].photos" :key="index" class="photo-item">
<view v-for="(photo, index) in list[activeTab].photos" :key="index" class="photo-item">
<image :src="photo" class="photo"></image>
<text class="delete-photo" @click="deletePhoto(index)">×</text>
</view>
......@@ -73,7 +73,7 @@
<!-- 模块4:提交模块 -->
<view class="module submit-module">
<button class="action-btn" @click="saveDraft">暂存</button>
<button class="action-btn complete-btn" @click="submit">
<button class="action-btn complete-btn" @click="complete">
完成
</button>
</view>
......@@ -119,7 +119,8 @@
export default {
data() {
return {
location: "A座2楼", // 从上一个页面带过来的位置
location: "A座", // 从上一个页面带过来的位置
floor: "2楼", // 从上一个页面带过来的位置
isSubmitEnabled: false, // 提交按钮是否可点击
randomDescription: "这是一段随机说明文字。", // 随机说明文字
tabs: [{
......@@ -139,22 +140,6 @@
inspectionResult: 0, // Switch 值(0: 正常, 1: 异常)
conclusion: "", // 情况摘要
photos: [], // 现场照片
tabData: [{
inspectionResult: 0,
conclusion: "",
photos: []
}, // 门禁
{
inspectionResult: 0,
conclusion: "",
photos: []
}, // 卫生
{
inspectionResult: 0,
conclusion: "",
photos: []
}, // 设备告警
],
historyData: null, // 历史数据
firstSubmitTime: null, // 首次提交时间
detailsInfo: {}, // 详情
......@@ -162,18 +147,24 @@
list: [], //巡检信息
};
},
watch: {
// 监听当前 Tab 数据变化,更新提交按钮状态
isCurrentTabValid(newVal) {
this.isSubmitEnabled = newVal;
computed: {
userInfo() {
return this.$store.state.now_user || {};
},
// isOperationPermissions() {
// // 是否有操作权限
// const {
// uid,
// createByName
// } = this.detailsInfo;
// return !uid || (uid && createByName == this.userInfo.user);
// },
},
onLoad() {
this.loadHistoryData();
},
mounted() {
this.init();
this.coverlist();
},
methods: {
// 初始化
......@@ -181,50 +172,33 @@
return new Promise((resolve, reject) => {
// 判断是否有回显数据
if (this.detailsInfo && this.detailsInfo.inspectionType) {} else {
// 基础数据
this.baseInfo = {
inspectionType: "2",
inspectionCode: `JFXJ${moment().format("yyyyMMDDHHmmss")}${(Math.floor(Math.random() * 900) + 100)}`,
recordName: `${moment().format("yyyyMMDD")}-机房巡检记录`,
recordName: `${moment().format("yyyyMMDD")}-井道巡检`,
inspectionTime: moment().format("yyyy-MM-DD HH:mm"),
inspectionBy: this.$store.state.now_user.user,
inspectionById: this.$store.state.now_user.userId,
createByName: this.$store.state.now_user.user,
isException: "", // 是否有异常
position: "", // 位置
position: this.location, // 位置
floor: this.floor, // 楼层
isSubmit: "", // 0 是草稿态; 1 是正式提交
conclusion: "", //摘要
creatTime: `${new Date().getTime()}`,
items: [
// {
// "itemCode": "1", // 检查项
// "measuredData": "2,3", // 异常的楼层
// "inspectionResult": "1" // 检查项的结果, 1是异常 0 是正常
// },
],
items: [],
};
}
console.log(2222, this.baseInfo)
this.coverlist();
resolve();
});
},
// 返回
back() {
uni.navigateBack();
},
// 打开弹窗
openPopup() {
this.$refs.popup.open();
},
// 关闭弹窗
closePopup() {
this.switchTab((this.activeTab + 1) % this.tabs.length);
this.$refs.popup.close();
},
// 加载历史数据
loadHistoryData() {
const history = uni.getStorageSync("inspectionHistory");
console.log("history", history)
if (history && Date.now() - history.firstSubmitTime < 168 * 60 * 60 * 1000) {
this.historyData = history;
this.location = history.location;
......@@ -236,7 +210,8 @@
},
// 数据结构重组
coverlist() {
const temp = pad_2_1_inspection_items.rows.map((item) => {
// 获取井道巡检的三个检查项固定数据再进行处理
const data = pad_2_1_inspection_items.rows.map((item) => {
return {
// ...item,
dictLabel: item.dictLabel,
......@@ -245,29 +220,16 @@
// roomType,
inspectionResult: 0, // 异常结论
itemCode: item.dictValue, // 检查项 如:门禁
resultArr: [{
value: 0,
label: "正常",
isActive: true,
},
{
value: 1,
label: "异常",
isActive: false,
},
],
measuredData: "", // 逗号分隔字符串
measuredDataArr: [], // 前端本地使用
measuredData: this.floor, // 逗号分隔字符串
photos: [], // 照片
postionList: [{
...pad_2_1_floor.rows[0],
dictLabel: location,
isActive: false,
}]
};
});
this.list = temp;
this.list = data;
},
// 更新当前 Tab 数据
......@@ -277,16 +239,6 @@
this.conclusion = currentTabData.conclusion;
this.photos = currentTabData.photos;
},
// 切换 Tab
switchTab(index) {
this.activeTab = index;
this.updateCurrentTabData();
},
// Switch 值变化
onSwitchChange(e) {
this.inspectionResult = e.detail.value ? 1 : 0;
this.list[this.activeTab].inspectionResult = this.inspectionResult;
},
// 拍照
takePhoto() {
uni.chooseImage({
......@@ -311,22 +263,23 @@
}, // 处理提交数据
getParams() {
const baseInfo = this.baseInfo;
console.log("this.list",this.list)
const tempForm = this.list;
console.log("this.list", this.list)
const item = {
const data = {
...baseInfo,
isSubmit: 0,
isSubmit: 1, //是否提交
items: [],
synchronization: 0, // 是否导出
synchronization: 0, // 是否同步
submitTime: moment().format("yyyy-MM-DD"), // 记录提交时间
submitMonth: moment().format("yyyy-MM"), // 记录提交月份
originData: {
baseInfo,
tempForm:this.list
tempForm,
},
};
console.log("item,item",item)
return item;
console.log("getParams,data", data)
return data;
},
// 暂存
saveDraft(isSave = true) {
......@@ -335,6 +288,7 @@
if (isSave) {
// 写入草稿文件 更新 store 草稿内容
const params = this.getParams();
console.log("params", params)
params.isSubmit = 0;
this.$store.commit("SET_DARF_DATA", params); // 缓存[巡检信息]
......@@ -367,28 +321,92 @@
},
// 检查当前 Tab 的必填项是否填写完整
isCurrentTabValid() {
const currentTabData = this.list[this.activeTab];
console.log("currentTabData", currentTabData)
return (
currentTabData.inspectionResult !== null && // 巡检结论必填
currentTabData.conclusion.trim() !== "" // 情况摘要必填
// 现场照片为非必填项,不做校验
const data = this.list
// 校验函数
const validateData = (data) => {
return data.every(
(item) =>
item.inspectionResult !== null && item.conclusion.trim() !== ""
);
};
// 调用校验函数
const isValid = validateData(data);
console.log(141, isValid)
return isValid
},
// 完成
complete() {
this.saveDraft().then(() => {
if (this.isCurrentTabValid()) {
this.isSubmitEnabled = true
} else {
this.isSubmitEnabled = false
this.openPopup()
}
})
},
// 提交
submit() {
// 校验是否通过
if (this.isCurrentTabValid()) {
if (!this.firstSubmitTime) {
this.firstSubmitTime = Date.now();
}
const historyData = {
location: this.location,
randomDescription: this.randomDescription,
tabData: this.list,
firstSubmitTime: this.firstSubmitTime,
};
uni.setStorageSync("inspectionHistory", historyData);
this.openPopup()
const params = this.getParams(); //数据获取
const all_data = this.$store.state.all_data; //获取全部数据
const uid = ""
params.isSubmit = 1; //修改提交状态
let logContent = "";
if (uid) {
} {
params.uid = new Date().getTime(); // 唯一标识 pad 端使用
all_data.push(params);
logContent = getLogContent(
LOG_TYPE_ENUM.add,
`${params.recordName}(${params.inspectionCode})`,
"巡检模块"
);
}
// 更新巡检list
const userInfo = this.userInfo;
this.$store.commit("SET_ALL_DATA", all_data);
const inspectList = all_data.filter(
(item) => item.createByName == userInfo.user
);
writeInspectionData(inspectList, userInfo.user);
// 更新日志
const log_list = this.$store.state.log_list;
logContent.inspectionType = params.inspectionType;
log_list.push(logContent);
this.$store.commit("SET_LOG_LIST", log_list);
addLog(log_list).then((res) => {
console.log("日志文件写入成功");
});
// 清空草稿数据
this.$store.commit("SET_DARF_DATA", {}); // 缓存[巡检信息]
writeDarf("").then((res) => {
console.log("写入草稿文件成功");
});
// 清空基础缓存信息
this.$store.commit("SET_TEMP_DATA", {}); // 缓存[巡检信息]
// const historyData = {
// location: this.location,
// randomDescription: this.randomDescription,
// tabData: this.list,
// firstSubmitTime: this.firstSubmitTime,
// };
// uni.setStorageSync("inspectionHistory", historyData);
uni.showToast({
title: "提交成功",
icon: "success",
});
} else {
uni.showToast({
title: "请填写完整必填项",
......@@ -396,6 +414,29 @@
});
}
},
// 切换 Tab
switchTab(index) {
this.activeTab = index;
this.updateCurrentTabData();
},
// Switch 值变化
onSwitchChange(e) {
this.inspectionResult = e.detail.value ? 1 : 0;
this.list[this.activeTab].inspectionResult = this.inspectionResult;
},
// 返回
back() {
uni.navigateBack();
},
// 打开弹窗
openPopup() {
this.$refs.popup.open();
},
// 关闭弹窗
closePopup() {
this.switchTab((this.activeTab + 1) % this.tabs.length);
this.$refs.popup.close();
},
},
};
</script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论