|
@@ -6,9 +6,9 @@
|
|
<el-option :label="item.dictLabel" :value="item.dictValue" v-for="item in state.getDictByKey('inspectionType')"></el-option>
|
|
<el-option :label="item.dictLabel" :value="item.dictValue" v-for="item in state.getDictByKey('inspectionType')"></el-option>
|
|
</el-select>
|
|
</el-select>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
- <el-form-item label="日巡检-巡检日期" prop="startDate">
|
|
|
|
|
|
+ <el-form-item label="日巡检-巡检日期" prop="inspectionDate">
|
|
<el-date-picker
|
|
<el-date-picker
|
|
- v-model="dataForm.startDate"
|
|
|
|
|
|
+ v-model="dataForm.inspectionDate"
|
|
type="date"
|
|
type="date"
|
|
placeholder="选择日期(日巡检)"
|
|
placeholder="选择日期(日巡检)"
|
|
value-format="YYYY-MM-DD"
|
|
value-format="YYYY-MM-DD"
|
|
@@ -93,7 +93,7 @@ const visible = ref(false);
|
|
const dataFormRef = ref();
|
|
const dataFormRef = ref();
|
|
|
|
|
|
const dataForm = reactive({
|
|
const dataForm = reactive({
|
|
- id: '', inspectionType: '', startDate: '', endDate: '', filePath: '', status: '', creator: '', createDate: '', updater: '', updateDate: '', remark: ''});
|
|
|
|
|
|
+ id: '', inspectionType: '', inspectionDate: '', inspectionName: '', filePath: '', status: '', creator: '', createDate: '', updater: '', updateDate: '', remark: ''});
|
|
|
|
|
|
|
|
|
|
const rules = ref({
|
|
const rules = ref({
|
|
@@ -150,14 +150,14 @@ const getInfo = (id: number) => {
|
|
dataForm.status = dataForm.status + '';
|
|
dataForm.status = dataForm.status + '';
|
|
imageUrl.value = dataForm.filePath;
|
|
imageUrl.value = dataForm.filePath;
|
|
|
|
|
|
- // if (dataForm.inspectionType === 'weekly' && dataForm.endDate) {
|
|
|
|
- // const match = dataForm.endDate.match(/^(\d{4}-\d{2}) 第(\d+)周/);
|
|
|
|
- // if (match) {
|
|
|
|
- // selectedMonth.value = match[1];
|
|
|
|
- // updateWeekOptions(match[1]);
|
|
|
|
- // selectedWeek.value = weekOptions.value[Number(match[2]) - 1]?.value || '';
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
|
|
+ if (dataForm.inspectionType === '1' && dataForm.inspectionName) {
|
|
|
|
+ const match = dataForm.inspectionName.match(/^(\d{4}-\d{2}) 第(\d+)周/);
|
|
|
|
+ if (match) {
|
|
|
|
+ selectedMonth.value = match[1];
|
|
|
|
+ updateWeekOptions(match[1]);
|
|
|
|
+ selectedWeek.value = weekOptions.value[Number(match[2]) - 1]?.value || '';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
@@ -167,28 +167,31 @@ const dataFormSubmitHandle = () => {
|
|
if (!valid) {
|
|
if (!valid) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+ console.log(dataForm.inspectionType);
|
|
|
|
+ console.log(selectedMonth.value);
|
|
|
|
+ console.log(selectedWeek.value);
|
|
// 判断巡检类型
|
|
// 判断巡检类型
|
|
- if (dataForm.inspectionType === 'daily') {
|
|
|
|
- if (!dataForm.startDate) {
|
|
|
|
|
|
+ if (dataForm.inspectionType === '0') {
|
|
|
|
+ if (!dataForm.inspectionDate) {
|
|
return ElMessage.error('日巡检需要选择日期');
|
|
return ElMessage.error('日巡检需要选择日期');
|
|
}
|
|
}
|
|
- // 日巡检只需要 startDate
|
|
|
|
- dataForm.startDate = dataForm.startDate ? parseTime(new Date(dataForm.startDate), '{yy}-{mm}-{dd}') : null;
|
|
|
|
- dataForm.endDate = '';
|
|
|
|
|
|
+ // 日巡检只需要 inspectionDate
|
|
|
|
+ dataForm.inspectionDate = dataForm.inspectionDate ? parseTime(new Date(dataForm.inspectionDate), '{yy}-{mm}-{dd}') : null;
|
|
|
|
+ dataForm.inspectionName = '';
|
|
}
|
|
}
|
|
|
|
|
|
- if (dataForm.inspectionType === 'weekly') {
|
|
|
|
|
|
+ if (dataForm.inspectionType === '1') {
|
|
if (!selectedMonth.value || !selectedWeek.value) {
|
|
if (!selectedMonth.value || !selectedWeek.value) {
|
|
return ElMessage.error('周巡检需要选择月份和周次');
|
|
return ElMessage.error('周巡检需要选择月份和周次');
|
|
}
|
|
}
|
|
|
|
|
|
- // 组装格式字符串,例如 "2025-08 第5周"
|
|
|
|
|
|
+ // 组装格式字符串,"2025-08 第5周"
|
|
const monthLabel = dayjs(selectedMonth.value).format('YYYY-MM');
|
|
const monthLabel = dayjs(selectedMonth.value).format('YYYY-MM');
|
|
const weekIndex = weekOptions.value.findIndex(item => item.value === selectedWeek.value);
|
|
const weekIndex = weekOptions.value.findIndex(item => item.value === selectedWeek.value);
|
|
const label = `${monthLabel} 第${weekIndex + 1}周`;
|
|
const label = `${monthLabel} 第${weekIndex + 1}周`;
|
|
|
|
|
|
- dataForm.endDate = label;
|
|
|
|
- dataForm.startDate = '';
|
|
|
|
|
|
+ dataForm.inspectionName = label;
|
|
|
|
+ dataForm.inspectionDate = '';
|
|
}
|
|
}
|
|
if(!imageUrl.value) return ElMessage.error('请上传图片');
|
|
if(!imageUrl.value) return ElMessage.error('请上传图片');
|
|
dataForm.filePath = imageUrl.value;
|
|
dataForm.filePath = imageUrl.value;
|
|
@@ -213,6 +216,7 @@ const updateWeekOptions = (val: string) => {
|
|
const firstDay = dayjs(val + '-01');
|
|
const firstDay = dayjs(val + '-01');
|
|
const totalDays = firstDay.daysInMonth();
|
|
const totalDays = firstDay.daysInMonth();
|
|
const weeks: { label: string; value: string }[] = [];
|
|
const weeks: { label: string; value: string }[] = [];
|
|
|
|
+ const seenWeeks = new Set<string>();
|
|
|
|
|
|
for (let d = 1; d <= totalDays; d++) {
|
|
for (let d = 1; d <= totalDays; d++) {
|
|
const current = dayjs(`${val}-${String(d).padStart(2, '0')}`);
|
|
const current = dayjs(`${val}-${String(d).padStart(2, '0')}`);
|
|
@@ -220,9 +224,14 @@ const updateWeekOptions = (val: string) => {
|
|
const startOfWeek = current.startOf('week').format('YYYY-MM-DD');
|
|
const startOfWeek = current.startOf('week').format('YYYY-MM-DD');
|
|
const endOfWeek = current.endOf('week').format('YYYY-MM-DD');
|
|
const endOfWeek = current.endOf('week').format('YYYY-MM-DD');
|
|
|
|
|
|
- if (!weeks.some(w => w.value === String(week))) {
|
|
|
|
|
|
+ // 避免重复添加相同周(跨月导致)
|
|
|
|
+ if (!seenWeeks.has(startOfWeek)) {
|
|
|
|
+ seenWeeks.add(startOfWeek);
|
|
|
|
+
|
|
|
|
+ const weekNumber = weeks.length + 1;
|
|
|
|
+
|
|
weeks.push({
|
|
weeks.push({
|
|
- label: `第 ${week - dayjs(`${val}-01`).startOf('month').isoWeek() + 1} 周(${startOfWeek} ~ ${endOfWeek})`,
|
|
|
|
|
|
+ label: `第 ${weekNumber} 周(${startOfWeek} ~ ${endOfWeek})`,
|
|
value: week.toString(),
|
|
value: week.toString(),
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -231,6 +240,7 @@ const updateWeekOptions = (val: string) => {
|
|
weekOptions.value = weeks;
|
|
weekOptions.value = weeks;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+
|
|
defineExpose({
|
|
defineExpose({
|
|
init
|
|
init
|
|
});
|
|
});
|