<template>
|
<view class="account-detail">
|
<PageHeader :title="pageTitle"
|
@back="goBack" />
|
<view class="form-container">
|
<up-form ref="formRef"
|
:model="form"
|
:rules="rules"
|
label-width="110"
|
input-align="right"
|
error-message-align="right">
|
<u-cell-group title="报告信息"
|
class="form-section">
|
<up-form-item label="产品名称"
|
prop="productName"
|
required
|
border-bottom>
|
<up-input v-model="form.productName"
|
placeholder="请输入产品名称"
|
clearable />
|
</up-form-item>
|
<up-form-item label="产品型号"
|
prop="productModel"
|
border-bottom>
|
<up-input v-model="form.productModel"
|
placeholder="请输入产品型号"
|
clearable />
|
</up-form-item>
|
<up-form-item label="报告编号"
|
prop="reportNo"
|
required
|
border-bottom>
|
<up-input v-model="form.reportNo"
|
placeholder="请输入报告编号"
|
clearable />
|
</up-form-item>
|
<up-form-item label="报告类型"
|
prop="reportType"
|
border-bottom>
|
<FormPicker v-model="form.reportType"
|
type="select"
|
title="选择报告类型"
|
:options="reportTypeOptions"
|
placeholder="请选择报告类型" />
|
</up-form-item>
|
<up-form-item label="检测单位"
|
prop="testingAgency"
|
border-bottom>
|
<up-input v-model="form.testingAgency"
|
placeholder="请输入检测单位"
|
clearable />
|
</up-form-item>
|
</u-cell-group>
|
|
<u-cell-group title="有效期"
|
class="form-section">
|
<up-form-item label="报告日期"
|
prop="reportDate"
|
required
|
border-bottom>
|
<FormPicker v-model="form.reportDate"
|
type="date"
|
placeholder="请选择报告日期"
|
@change="calculateExpiration" />
|
</up-form-item>
|
<up-form-item label="有效期(月)"
|
prop="validityPeriod"
|
required
|
border-bottom>
|
<up-input v-model="form.validityPeriod"
|
type="number"
|
placeholder="1~120,默认 12"
|
clearable
|
@blur="calculateExpiration" />
|
</up-form-item>
|
<up-form-item label="到期时间"
|
prop="expirationTime"
|
required
|
border-bottom>
|
<up-input v-model="form.expirationTime"
|
placeholder="系统自动计算"
|
disabled />
|
</up-form-item>
|
<up-form-item label="备注"
|
prop="remark">
|
<up-textarea v-model="form.remark"
|
placeholder="请输入备注内容"
|
auto-height
|
maxlength="500" />
|
</up-form-item>
|
</u-cell-group>
|
|
<u-cell-group title="附件"
|
class="form-section">
|
<view class="upload-wrap">
|
<CommonUpload v-model="form.attachmentFiles"
|
accept="all"
|
:max-count="5" />
|
</view>
|
</u-cell-group>
|
</up-form>
|
</view>
|
|
<FooterButtons :loading="loading"
|
confirmText="保存"
|
@cancel="goBack"
|
@confirm="handleSubmit" />
|
</view>
|
</template>
|
|
<script setup>
|
import { computed, ref } from "vue";
|
import { onLoad } from "@dcloudio/uni-app";
|
import PageHeader from "@/components/PageHeader.vue";
|
import FooterButtons from "@/components/FooterButtons.vue";
|
import FormPicker from "@/components/FormPicker.vue";
|
import CommonUpload from "@/components/CommonUpload.vue";
|
import { formatDateToYMD } from "@/utils/ruoyi";
|
import { toFileList, toUrlString } from "@/utils/file";
|
import { loadDetailData } from "@/utils/detailCache";
|
import { addMonths } from "@/utils/warning";
|
import {
|
addInspectionReport,
|
getInspectionReport,
|
updateInspectionReport,
|
} from "@/api/qualityManagement/inspectionReport";
|
|
const formRef = ref();
|
const loading = ref(false);
|
const reportId = ref("");
|
|
const reportTypeOptions = [
|
{ name: "型式试验报告", value: "型式试验报告" },
|
{ name: "出厂检验报告", value: "出厂检验报告" },
|
{ name: "委托检验报告", value: "委托检验报告" },
|
];
|
|
const form = ref({
|
id: undefined,
|
productName: "",
|
productModel: "",
|
reportNo: "",
|
reportType: "",
|
testingAgency: "",
|
reportDate: "",
|
validityPeriod: 12,
|
expirationTime: "",
|
remark: "",
|
attachmentFiles: [],
|
});
|
|
const rules = {
|
productName: [
|
{ required: true, message: "请输入产品名称", trigger: "blur" },
|
],
|
reportNo: [{ required: true, message: "请输入报告编号", trigger: "blur" }],
|
reportDate: [
|
{ required: true, message: "请选择报告日期", trigger: "change" },
|
],
|
validityPeriod: [
|
{ required: true, message: "请输入有效期", trigger: "blur" },
|
],
|
expirationTime: [
|
{ required: true, message: "到期时间不能为空", trigger: "change" },
|
],
|
};
|
|
const pageTitle = computed(() => (reportId.value ? "编辑报告" : "新增报告"));
|
|
// 到期时间 = 报告日期 + 有效期月,只读
|
const calculateExpiration = () => {
|
const months = Number(form.value.validityPeriod);
|
if (form.value.reportDate && Number.isFinite(months) && months > 0) {
|
form.value.expirationTime = addMonths(form.value.reportDate, months);
|
} else {
|
form.value.expirationTime = "";
|
}
|
};
|
|
const goBack = () => uni.navigateBack();
|
|
const loadDetail = async () => {
|
let data = null;
|
try {
|
data = await loadDetailData({
|
cacheKey: "inspectionReportDetail",
|
id: reportId.value,
|
fetcher: getInspectionReport,
|
});
|
} catch (error) {
|
data = null;
|
}
|
if (!data) {
|
uni.showToast({ title: "未找到报告信息", icon: "none" });
|
return;
|
}
|
|
form.value = {
|
id: data.id,
|
productName: data.productName || "",
|
productModel: data.productModel || "",
|
reportNo: data.reportNo || "",
|
reportType: data.reportType || "",
|
testingAgency: data.testingAgency || "",
|
reportDate: (data.reportDate || "").slice(0, 10),
|
validityPeriod: data.validityPeriod ?? 12,
|
expirationTime: (data.expirationTime || "").slice(0, 10),
|
remark: data.remark || "",
|
attachmentFiles: toFileList(data.attachmentUrls),
|
};
|
};
|
|
const handleSubmit = async () => {
|
const valid = await formRef.value.validate().catch(() => false);
|
if (!valid) return;
|
|
calculateExpiration();
|
const payload = {
|
id: form.value.id,
|
productName: form.value.productName,
|
productModel: form.value.productModel,
|
reportNo: form.value.reportNo,
|
reportType: form.value.reportType,
|
testingAgency: form.value.testingAgency,
|
reportDate: form.value.reportDate,
|
validityPeriod: Number(form.value.validityPeriod),
|
expirationTime: form.value.expirationTime,
|
remark: form.value.remark,
|
attachmentUrls: toUrlString(form.value.attachmentFiles),
|
};
|
|
loading.value = true;
|
const action = reportId.value ? updateInspectionReport : addInspectionReport;
|
action(payload)
|
.then(() => {
|
uni.showToast({ title: "保存成功", icon: "success" });
|
setTimeout(() => uni.navigateBack(), 1000);
|
})
|
.catch(() => {
|
uni.showToast({ title: "保存失败", icon: "none" });
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
};
|
|
onLoad(options => {
|
if (options?.id) {
|
reportId.value = options.id;
|
form.value.id = options.id;
|
loadDetail();
|
} else {
|
form.value.reportDate = formatDateToYMD(Date.now());
|
calculateExpiration();
|
}
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
|
.account-detail {
|
min-height: 100vh;
|
background: #f8f9fa;
|
padding-bottom: 100px;
|
}
|
|
.form-container {
|
padding: 12px 12px 0;
|
}
|
|
.form-section {
|
margin-bottom: 12px;
|
border-radius: 12px;
|
overflow: hidden;
|
box-shadow: 0 2px 10px rgba(15, 35, 95, 0.05);
|
}
|
|
.upload-wrap {
|
padding: 12px;
|
}
|
|
:deep(.u-cell-group__title) {
|
padding: 14px 18px 10px !important;
|
font-size: 15px !important;
|
font-weight: 600 !important;
|
color: #22324d !important;
|
background: #f8fbff !important;
|
}
|
</style>
|