<template>
|
<view class="account-detail">
|
<PageHeader :title="pageTitle" @back="goBack" />
|
<up-form :model="form" label-width="110">
|
<up-form-item label="巡检编号" required>
|
<up-input v-model="form.inspectionCode" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="巡检名称" required>
|
<up-input v-model="form.inspectionName" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="线路名称" required>
|
<up-input v-model="form.lineName" placeholder="请输入" clearable />
|
</up-form-item>
|
<up-form-item label="巡检类型">
|
<up-input :model-value="inspectionTypeText" placeholder="请选择" readonly @click="showTypeSheet = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showTypeSheet = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="计划巡检时间">
|
<up-input :model-value="form.planTime" placeholder="请选择" readonly @click="showPlanTimePicker = true" />
|
<template #right>
|
<up-icon name="arrow-right" @click="showPlanTimePicker = true"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="巡检人" required>
|
<up-input :model-value="inspectorText" placeholder="请选择(可多选)" readonly @click="openInspectorPopup" />
|
<template #right>
|
<up-icon name="arrow-right" @click="openInspectorPopup"></up-icon>
|
</template>
|
</up-form-item>
|
<up-form-item label="备注">
|
<up-textarea v-model="form.remark" placeholder="请输入" auto-height />
|
</up-form-item>
|
</up-form>
|
|
<FooterButtons :loading="loading" confirmText="保存" @cancel="goBack" @confirm="handleSubmit" />
|
|
<up-action-sheet
|
:show="showTypeSheet"
|
title="选择巡检类型"
|
:actions="typeActions"
|
@select="onSelectType"
|
@close="showTypeSheet = false"
|
/>
|
|
<up-datetime-picker
|
:show="showPlanTimePicker"
|
mode="datetime"
|
:value="planTimeValue"
|
@confirm="onPlanTimeConfirm"
|
@cancel="showPlanTimePicker = false"
|
/>
|
|
<up-popup :show="showInspectorPopup" mode="bottom" @close="showInspectorPopup = false">
|
<view class="popup-container">
|
<view class="popup-header">
|
<text class="popup-title">选择巡检人</text>
|
</view>
|
<scroll-view scroll-y class="popup-scroll">
|
<up-checkbox-group v-model="inspectorIdsTemp">
|
<up-checkbox
|
v-for="u in userOptions"
|
:key="u.value"
|
:name="u.value"
|
:label="u.label"
|
></up-checkbox>
|
</up-checkbox-group>
|
</scroll-view>
|
<view class="popup-footer">
|
<u-button size="small" @click="showInspectorPopup = false">取消</u-button>
|
<u-button type="primary" size="small" @click="confirmInspector">确定</u-button>
|
</view>
|
</view>
|
</up-popup>
|
</view>
|
</template>
|
|
<script setup>
|
import { computed, onMounted, ref } from "vue";
|
import { onLoad } from "@dcloudio/uni-app";
|
import dayjs from "dayjs";
|
import PageHeader from "@/components/PageHeader.vue";
|
import FooterButtons from "@/components/FooterButtons.vue";
|
import { addLineInspection, updateLineInspection } from "@/api/safeProduction/lineInspection";
|
import { userListNoPage } from "@/api/system/user";
|
|
const loading = ref(false);
|
const form = ref({
|
id: null,
|
inspectionCode: "",
|
inspectionName: "",
|
lineName: "",
|
inspectionType: "",
|
planTime: "",
|
inspectorId: "",
|
inspectorIds: [],
|
remark: "",
|
});
|
|
const userOptions = ref([]);
|
|
const showTypeSheet = ref(false);
|
const showPlanTimePicker = ref(false);
|
const showInspectorPopup = ref(false);
|
const inspectorIdsTemp = ref([]);
|
|
const typeActions = [
|
{ name: "定期巡检", value: "定期巡检" },
|
{ name: "临时巡检", value: "临时巡检" },
|
];
|
|
const pageTitle = computed(() => (form.value.id ? "编辑巡检任务" : "新增巡检任务"));
|
const inspectionTypeText = computed(() => form.value.inspectionType || "");
|
|
const inspectorText = computed(() => {
|
const ids = Array.isArray(form.value.inspectorIds) ? form.value.inspectorIds : [];
|
if (ids.length === 0) return "";
|
const map = new Map(userOptions.value.map(x => [x.value, x.label]));
|
const names = ids.map(id => map.get(id)).filter(Boolean);
|
return names.join(",");
|
});
|
|
const planTimeValue = computed(() => {
|
if (!form.value.planTime) return Date.now();
|
const ts = dayjs(form.value.planTime).valueOf();
|
return Number.isFinite(ts) ? ts : Date.now();
|
});
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const onSelectType = action => {
|
form.value.inspectionType = action.value;
|
showTypeSheet.value = false;
|
};
|
|
const onPlanTimeConfirm = e => {
|
const ts = e?.value;
|
form.value.planTime = dayjs(ts).format("YYYY-MM-DD HH:mm:ss");
|
showPlanTimePicker.value = false;
|
};
|
|
const openInspectorPopup = () => {
|
inspectorIdsTemp.value = [...(form.value.inspectorIds || [])];
|
showInspectorPopup.value = true;
|
};
|
|
const confirmInspector = () => {
|
form.value.inspectorIds = [...(inspectorIdsTemp.value || [])];
|
showInspectorPopup.value = false;
|
};
|
|
const handleSubmit = async () => {
|
const inspectionCode = String(form.value.inspectionCode || "").trim();
|
if (!inspectionCode) {
|
uni.showToast({ title: "请输入巡检编号", icon: "none" });
|
return;
|
}
|
const inspectionName = String(form.value.inspectionName || "").trim();
|
if (!inspectionName) {
|
uni.showToast({ title: "请输入巡检名称", icon: "none" });
|
return;
|
}
|
const lineName = String(form.value.lineName || "").trim();
|
if (!lineName) {
|
uni.showToast({ title: "请输入线路名称", icon: "none" });
|
return;
|
}
|
const inspectorIds = Array.isArray(form.value.inspectorIds) ? form.value.inspectorIds : [];
|
if (inspectorIds.length === 0) {
|
uni.showToast({ title: "请选择巡检人", icon: "none" });
|
return;
|
}
|
|
const payload = {
|
...form.value,
|
inspectionCode,
|
inspectionName,
|
lineName,
|
inspectorId: inspectorIds.join(","),
|
};
|
delete payload.inspectorIds;
|
|
loading.value = true;
|
const api = payload.id ? updateLineInspection : addLineInspection;
|
api(payload)
|
.then(() => {
|
uni.showToast({ title: "保存成功", icon: "success" });
|
uni.$emit("lineInspection:refresh");
|
goBack();
|
})
|
.catch(() => {
|
uni.showToast({ title: "保存失败", icon: "none" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
};
|
|
const initUsers = () => {
|
userListNoPage()
|
.then(res => {
|
const list = res?.data || [];
|
userOptions.value = list.map(u => ({
|
label: u.nickName,
|
value: u.userId,
|
}));
|
})
|
.catch(() => {});
|
};
|
|
onMounted(() => {
|
initUsers();
|
});
|
|
onLoad(options => {
|
if (options?.data) {
|
try {
|
const row = JSON.parse(decodeURIComponent(options.data));
|
const inspectorIds = row?.inspectorId
|
? String(row.inspectorId)
|
.split(",")
|
.map(x => Number(String(x).trim()))
|
.filter(n => Number.isFinite(n))
|
: [];
|
form.value = {
|
...form.value,
|
...row,
|
inspectorIds,
|
};
|
} catch (e) {}
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
|
.popup-container {
|
background: #fff;
|
border-top-left-radius: 20rpx;
|
border-top-right-radius: 20rpx;
|
padding: 24rpx;
|
max-height: 70vh;
|
display: flex;
|
flex-direction: column;
|
}
|
|
.popup-header {
|
padding-bottom: 16rpx;
|
}
|
|
.popup-title {
|
font-size: 30rpx;
|
font-weight: 600;
|
color: #333;
|
}
|
|
.popup-scroll {
|
flex: 1;
|
min-height: 0;
|
padding: 10rpx 0;
|
}
|
|
.popup-footer {
|
display: flex;
|
justify-content: flex-end;
|
gap: 16rpx;
|
padding-top: 16rpx;
|
}
|
</style>
|