|
@@ -6,23 +6,36 @@
|
|
|
<el-option :label="item.dictLabel" :value="item.dictValue" v-for="item in state.getDictByKey('inspectionType')"></el-option>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="开始日期" prop="startDate">
|
|
|
- <el-date-picker
|
|
|
- v-model="dataForm.startDate"
|
|
|
- type="datetime"
|
|
|
- placeholder="选择开始日期"
|
|
|
- value-format="YYYY-MM-DD HH:mm:ss"
|
|
|
- style="width: 100%;"
|
|
|
- ></el-date-picker>
|
|
|
+ <el-form-item label="日巡检-巡检日期" prop="startDate">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="dataForm.startDate"
|
|
|
+ type="date"
|
|
|
+ placeholder="选择日期(日巡检)"
|
|
|
+ value-format="YYYY-MM-DD"
|
|
|
+ style="width: 100%;"
|
|
|
+ />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="结束日期" prop="endDate">
|
|
|
- <el-date-picker
|
|
|
- v-model="dataForm.endDate"
|
|
|
- type="datetime"
|
|
|
- placeholder="选择结束日期"
|
|
|
- value-format="YYYY-MM-DD HH:mm:ss"
|
|
|
- style="width: 100%;"
|
|
|
- ></el-date-picker>
|
|
|
+
|
|
|
+ <!-- 月+周 -->
|
|
|
+ <el-form-item label="周巡检-选择月份">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="selectedMonth"
|
|
|
+ type="month"
|
|
|
+ placeholder="选择月份(周巡检)"
|
|
|
+ value-format="YYYY-MM"
|
|
|
+ @change="updateWeekOptions"
|
|
|
+ style="width: 100%;"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="周巡检-选择周次">
|
|
|
+ <el-select v-model="selectedWeek" placeholder="选择周次(周巡检)" clearable>
|
|
|
+ <el-option
|
|
|
+ v-for="(week, index) in weekOptions"
|
|
|
+ :key="index"
|
|
|
+ :label="week.label"
|
|
|
+ :value="week.value"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="巡检照片" prop="filePath">
|
|
|
<el-upload
|
|
@@ -57,7 +70,7 @@
|
|
|
import app from "@/constants/app";
|
|
|
import { getToken } from "@/utils/cache";
|
|
|
import { parseTime } from '@/utils/ruoyi'
|
|
|
-import { reactive, ref } from "vue";
|
|
|
+import { reactive, ref, watch } from "vue";
|
|
|
import baseService from "@/service/baseService";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
import { Plus } from '@element-plus/icons-vue'
|
|
@@ -66,6 +79,13 @@ const emit = defineEmits(["refreshDataList"]);
|
|
|
import useView from "@/hooks/useView";
|
|
|
const state = reactive({ ...useView({}) });
|
|
|
|
|
|
+import dayjs from 'dayjs'
|
|
|
+import isoWeek from 'dayjs/plugin/isoWeek'
|
|
|
+dayjs.extend(isoWeek)
|
|
|
+const selectedMonth = ref('');
|
|
|
+const selectedWeek = ref('');
|
|
|
+const weekOptions = ref<{ label: string; value: string }[]>([]);
|
|
|
+
|
|
|
const action = `${app.api}/sys/oss/upload`;
|
|
|
const headers = {token: getToken() }
|
|
|
const imageUrl = ref('');
|
|
@@ -75,15 +95,10 @@ const dataFormRef = ref();
|
|
|
const dataForm = reactive({
|
|
|
id: '', inspectionType: '', startDate: '', endDate: '', filePath: '', status: '', creator: '', createDate: '', updater: '', updateDate: '', remark: ''});
|
|
|
|
|
|
+
|
|
|
const rules = ref({
|
|
|
inspectionType: [
|
|
|
{ required: true, message: '必填项不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- startDate: [
|
|
|
- { required: true, message: '必填项不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- endDate: [
|
|
|
- { required: true, message: '必填项不能为空', trigger: 'blur' }
|
|
|
],
|
|
|
status: [
|
|
|
{ required: true, message: '必填项不能为空', trigger: 'blur' }
|
|
@@ -97,6 +112,9 @@ const init = (id?: number) => {
|
|
|
// 重置表单数据
|
|
|
if (dataFormRef.value) {
|
|
|
dataFormRef.value.resetFields();
|
|
|
+ selectedMonth.value = '';
|
|
|
+ selectedWeek.value = '';
|
|
|
+ weekOptions.value = [];
|
|
|
imageUrl.value = '';
|
|
|
}
|
|
|
|
|
@@ -131,6 +149,15 @@ const getInfo = (id: number) => {
|
|
|
dataForm.inspectionType = dataForm.inspectionType + '';
|
|
|
dataForm.status = dataForm.status + '';
|
|
|
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 || '';
|
|
|
+ // }
|
|
|
+
|
|
|
});
|
|
|
};
|
|
|
|
|
@@ -140,10 +167,32 @@ const dataFormSubmitHandle = () => {
|
|
|
if (!valid) {
|
|
|
return false;
|
|
|
}
|
|
|
+ // 判断巡检类型
|
|
|
+ if (dataForm.inspectionType === 'daily') {
|
|
|
+ if (!dataForm.startDate) {
|
|
|
+ return ElMessage.error('日巡检需要选择日期');
|
|
|
+ }
|
|
|
+ // 日巡检只需要 startDate
|
|
|
+ dataForm.startDate = dataForm.startDate ? parseTime(new Date(dataForm.startDate), '{yy}-{mm}-{dd}') : null;
|
|
|
+ dataForm.endDate = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dataForm.inspectionType === 'weekly') {
|
|
|
+ if (!selectedMonth.value || !selectedWeek.value) {
|
|
|
+ return ElMessage.error('周巡检需要选择月份和周次');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 组装格式字符串,例如 "2025-08 第5周"
|
|
|
+ const monthLabel = dayjs(selectedMonth.value).format('YYYY-MM');
|
|
|
+ const weekIndex = weekOptions.value.findIndex(item => item.value === selectedWeek.value);
|
|
|
+ const label = `${monthLabel} 第${weekIndex + 1}周`;
|
|
|
+
|
|
|
+ dataForm.endDate = label;
|
|
|
+ dataForm.startDate = '';
|
|
|
+ }
|
|
|
if(!imageUrl.value) return ElMessage.error('请上传图片');
|
|
|
- dataForm.startDate = dataForm.startDate ? parseTime(new Date(dataForm.startDate), '{yy}-{mm}-{dd} {hh}:{ii}:{ss}') : null;
|
|
|
- dataForm.endDate = dataForm.endDate ? parseTime(new Date(dataForm.endDate), '{yy}-{mm}-{dd} {hh}:{ii}:{ss}') : null;
|
|
|
dataForm.filePath = imageUrl.value;
|
|
|
+
|
|
|
(!dataForm.id ? baseService.post : baseService.put)("/emergency/inspection", dataForm).then((res) => {
|
|
|
ElMessage.success({
|
|
|
message: '成功',
|
|
@@ -157,6 +206,31 @@ const dataFormSubmitHandle = () => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+const updateWeekOptions = (val: string) => {
|
|
|
+ if (!val) return;
|
|
|
+
|
|
|
+ const firstDay = dayjs(val + '-01');
|
|
|
+ const totalDays = firstDay.daysInMonth();
|
|
|
+ const weeks: { label: string; value: string }[] = [];
|
|
|
+
|
|
|
+ for (let d = 1; d <= totalDays; d++) {
|
|
|
+ const current = dayjs(`${val}-${String(d).padStart(2, '0')}`);
|
|
|
+ const week = current.isoWeek();
|
|
|
+ const startOfWeek = current.startOf('week').format('YYYY-MM-DD');
|
|
|
+ const endOfWeek = current.endOf('week').format('YYYY-MM-DD');
|
|
|
+
|
|
|
+ if (!weeks.some(w => w.value === String(week))) {
|
|
|
+ weeks.push({
|
|
|
+ label: `第 ${week - dayjs(`${val}-01`).startOf('month').isoWeek() + 1} 周(${startOfWeek} ~ ${endOfWeek})`,
|
|
|
+ value: week.toString(),
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ weekOptions.value = weeks;
|
|
|
+};
|
|
|
+
|
|
|
defineExpose({
|
|
|
init
|
|
|
});
|