integrated_traffic_vue/src/views/mechanical_files/beidou/add.vue

421 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<layout-card>
<el-form ref="formRef" :rules="rules" :model="form" label-width="140px">
<el-row :gutter="20">
<el-col :span="24">
<el-divider content-position="left">车辆选择</el-divider>
</el-col>
<el-col :span="12">
<el-form-item label="北斗车辆" prop="VEHICLE">
<el-select v-model="form.VEHICLE" @change="getBusInfo">
<el-option
v-for="item in data.vehicleList"
:key="item.ID"
:label="item.PLATE_NUMBER"
:value="item.ID"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-divider content-position="left">基本信息</el-divider>
</el-col>
<el-col :span="12">
<el-form-item label="行驶证照片" prop="DRIVING_LICENSE_IMG">
<layout-upload
v-model:file-list="data.busInfo.DRIVING_LICENSE_IMG"
list-type="picture-card"
accept=".jpg,.jpeg,.png"
delete-to-server
disabled
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="车牌号" prop="PLATE_NUMBER">
<el-input v-model="data.busInfo.PLATE_NUMBER" disabled />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="车架号" prop="VIN">
<el-input v-model="data.busInfo.VIN" disabled />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="车辆类型" prop="TRAILER_TYPE">
<el-input v-model="data.busInfo.TRAILER_TYPE" disabled />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="车主/业户" prop="CAR_OWNERS ">
<el-input v-model="data.busInfo.CAR_OWNERS" disabled />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="车主电话" prop="CAR_OWNERS_TEL">
<el-input v-model="data.busInfo.CAR_OWNERS_TEL" disabled />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="初登日期" prop="INITIAL_REGISTRATION_DATE">
<el-date-picker
v-model="data.busInfo.INITIAL_REGISTRATION_DATE"
value-format="YYYY-MM-DD"
format="YYYY-MM-DD"
type="date"
disabled
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="所属区域" prop="COMPANY_AREA">
<el-input v-model="data.busInfo.COMPANY_AREA" disabled />
</el-form-item>
</el-col>
<el-col :span="24">
<el-divider content-position="left">北斗信息</el-divider>
</el-col>
<el-col :span="12">
<el-form-item label="编号" prop="NUM">
<el-input v-model="form.NUM" maxlength="50" show-word-limit />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="车主业户" prop="CAR_OWNERS">
<el-input
v-model="form.CAR_OWNERS"
maxlength="50"
show-word-limit
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="联系电话" prop="TELEPHONE">
<el-input v-model="form.TELEPHONE" maxlength="11" show-word-limit />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="登记人" prop="REGISTRANT">
<el-input
v-model="form.REGISTRANT"
maxlength="50"
show-word-limit
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="入网公司" prop="NETWORK_ACCESS_COMPANY">
<el-input
v-model="form.NETWORK_ACCESS_COMPANY"
maxlength="50"
show-word-limit
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="办理日期" prop="PROCESSING_DATE">
<el-date-picker
v-model="form.PROCESSING_DATE"
value-format="YYYY-MM-DD"
format="YYYY-MM-DD"
type="date"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="到期日期" prop="DUE_DATE">
<el-date-picker
v-model="form.DUE_DATE"
value-format="YYYY-MM-DD"
format="YYYY-MM-DD"
type="date"
@change="getRemiderDate"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="北斗净费(元)" prop="ACTUAL_COLLECTION">
<el-input
v-model.number="form.ACTUAL_COLLECTION"
maxlength="50"
show-word-limit
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="北斗全费(元)" prop="ALL_FEES">
<el-input
v-model.number="form.ALL_FEES"
maxlength="50"
show-word-limit
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="提醒天数" prop="REMINDER_DAYS">
<el-select v-model="form.REMINDER_DAYS" @change="getRemiderDate">
<el-option
v-for="item in REMIND_DAYS"
:key="item.NAME"
:label="item.NAME"
:value="item.NUM"
/>
</el-select>
<!-- <el-input
v-model.number="form.REMINDER_DAYS"
maxlength="50"
show-word-limit
@change="getRemiderDate"
/>-->
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="提醒日期" prop="REMINDER_DATE">
<el-date-picker
v-model="form.REMINDER_DATE"
value-format="YYYY-MM-DD"
format="YYYY-MM-DD"
type="date"
disabled
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="提醒状态" prop="REMINDER_STATUS">
<el-switch
v-model="form.REMINDER_STATUS"
inline-prompt
active-text="开"
inactive-text="关"
active-value="1"
inactive-value="0"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="北斗资料" prop="BEIDOUINFO">
<layout-upload
v-model:file-list="form.BEIDOUINFO"
list-type="picture-card"
accept=".jpg,.jpeg,.png"
:limit="99"
delete-to-server
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="合同" prop="CONTRACT">
<layout-upload
v-model:file-list="form.CONTRACT"
list-type="picture-card"
accept=".jpg,.jpeg,.png"
:limit="99"
delete-to-server
/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="备注" prop="NOTES">
<el-input
v-model="form.NOTES"
type="textarea"
:autosize="{ minRows: 3 }"
maxlength="250"
show-word-limit
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div class="mt-10 tc">
<el-button type="primary" @click="fnSubmit">保存</el-button>
</div>
</layout-card>
</template>
<script setup>
import LayoutUpload from "@/components/upload/index.vue";
import { ref, reactive } from "vue";
import { debounce } from "throttle-debounce";
import {
getBeidouView,
setBeidouAdd,
setBeidouEdit,
getTrailerListCompass,
} from "@/request/mechanical_files.js";
import { setUploadImg } from "@/request/api.js";
import { ElMessage } from "element-plus";
import { useRoute, useRouter } from "vue-router";
import useFormValidate from "@/assets/js/useFormValidate.js";
import { addingPrefixToFile, subtractDaysFromDate } from "@/assets/js/utils.js";
import { REMIND_DAYS } from "@/assets/js/constant.js";
const route = useRoute();
const router = useRouter();
const BEIDOU_ID = route.query.BEIDOU_ID;
const formRef = ref(null);
const form = ref({
VEHICLE_MODEL: "",
VEHICLE: "",
NUM: "",
CAR_OWNERS: "",
TELEPHONE: "",
REGISTRANT: "",
PROCESSING_DATE: "",
ACTUAL_COLLECTION: "",
ALL_FEES: "",
DUE_DATE: "",
REMINDER_DAYS: "",
REMINDER_DATE: "",
REMINDER_STATUS: "",
BEIDOUINFO: [],
CONTRACT: [],
});
const data = reactive({
vehicleList: [],
busInfo: {
DRIVING_LICENSE_IMG: [],
PLATE_NUMBER: "",
VIN: "",
TRAILER_TYPE: "",
CAR_OWNERS: "",
CAR_OWNERS_TEL: "",
INITIAL_REGISTRATION_DATE: "",
COMPANY_AREA: "",
},
});
const rules = {
VEHICLE_MODEL: [{ required: true, message: "请输入", trigger: "blur" }],
VEHICLE: [{ required: true, message: "请输入", trigger: "blur" }],
CAR_OWNERS: [{ required: true, message: "请输入", trigger: "blur" }],
TELEPHONE: [
{ required: true, message: "请输入", trigger: "blur" },
{ min: 11, max: 11, message: "请输入11位手机号码", trigger: "blur" },
{
pattern:
/^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/,
message: "请输入正确的手机号码",
},
],
REGISTRANT: [{ required: true, message: "请输入", trigger: "blur" }],
PROCESSING_DATE: [{ required: true, message: "请输入", trigger: "blur" }],
DUE_DATE: [{ required: true, message: "请输入", trigger: "blur" }],
REMINDER_DAYS: [{ required: true, message: "请输入", trigger: "blur" }],
REMINDER_DATE: [{ required: true, message: "请输入", trigger: "blur" }],
};
const getRemiderDate = (val) => {
if (val) {
if (form.value.DUE_DATE) {
// 计算提醒日期
const reminderDateStr = subtractDaysFromDate(form.value.DUE_DATE, val);
console.log(reminderDateStr);
const reminderDate = new Date(reminderDateStr);
const today = new Date();
// 检查计算出的提醒日期是否早于当前时间
if (reminderDate < today) {
// 如果提醒日期早于当前日期,显示错误提示并重置提醒日期
ElMessage.error("输入的提醒天数错误,提醒日期不能早于当前日期。");
form.value.REMINDER_DATE = ""; // 重置提醒日期
} else {
// 如果提醒日期正常,更新表单值
form.value.REMINDER_DATE = reminderDateStr;
}
}
} else {
form.value.REMINDER_DATE = "";
}
};
const getVehicle = async (event) => {
const resData = await getTrailerListCompass({ TRAFFIC_TYPE: event });
data.vehicleList = resData.list;
form.value.VEHICLE = "";
data.busInfo.DRIVING_LICENSE_IMG = [];
data.busInfo.PLATE_NUMBER = "";
data.busInfo.VIN = "";
data.busInfo.TRAILER_TYPE = "";
data.busInfo.CAR_OWNERS = "";
data.busInfo.CAR_OWNERS_TEL = "";
data.busInfo.INITIAL_REGISTRATION_DATE = "";
data.busInfo.DRIVING_LICENSE_IMG = addingPrefixToFile([]);
};
getVehicle("1");
const fnBusChange = async (event) => {
const resData = await getTrailerListCompass({ ID: event });
data.busInfo = resData.list[0];
data.busInfo.DRIVING_LICENSE_IMG = addingPrefixToFile(
resData.drivingLicenseImgs
);
};
const getBusInfo = (val) => {
if (val) {
fnBusChange(val);
} else {
data.busInfo.DRIVING_LICENSE_IMG = [];
data.busInfo.PLATE_NUMBER = "";
data.busInfo.VIN = "";
data.busInfo.TRAILER_TYPE = "";
data.busInfo.CAR_OWNERS = "";
data.busInfo.CAR_OWNERS_TEL = "";
data.busInfo.INITIAL_REGISTRATION_DATE = "";
data.busInfo.COMPANY_AREA = "";
data.busInfo.DRIVING_LICENSE_IMG = addingPrefixToFile([]);
}
};
const fnGetData = async () => {
if (!BEIDOU_ID) return;
const resData = await getBeidouView({ BEIDOU_ID });
form.value = resData.pd;
form.value.BEIDOUINFO = [];
fnBusChange(form.value.VEHICLE);
form.value.BEIDOUINFO = addingPrefixToFile(resData.beidouinfoImgs);
};
fnGetData();
// 假设128为北斗信息图片类型129为合同图片类型
const fnUploadImage = async (currentId, FFILE, TYPE) => {
const formData = new FormData();
formData.append("FOREIGN_KEY", currentId);
formData.append("TYPE", TYPE); // 这里的TYPE根据调用函数时传入的值决定
formData.append("FFILE", FFILE);
await setUploadImg(formData);
};
const fnSubmit = debounce(
1000,
async () => {
await useFormValidate(formRef);
const resData = !BEIDOU_ID
? await setBeidouAdd({ ...form.value })
: await setBeidouEdit({ ...form.value, BEIDOU_ID });
const currentId = resData.pd.BEIDOU_ID;
// 北斗信息图片上传
for (let i = 0; i < form.value.BEIDOUINFO.length; i++) {
if (form.value.BEIDOUINFO[i].raw) {
await fnUploadImage(currentId, form.value.BEIDOUINFO[i].raw, "128"); // 北斗信息图片
}
}
// 合同图片上传
for (let i = 0; i < form.value.CONTRACT.length; i++) {
if (form.value.CONTRACT[i].raw) {
await fnUploadImage(currentId, form.value.CONTRACT[i].raw, "130"); // 合同图片
}
}
ElMessage.success("保存成功");
router.back();
},
{ atBegin: true }
);
// const fnUploadImage = async (currentId, FFILE, TYPE) => {
// const formData = new FormData();
// formData.append("FOREIGN_KEY", currentId);
// formData.append("TYPE", TYPE);
// formData.append("FFILE", FFILE);
// await setUploadImg(formData);
// };
</script>
<style scoped lang="scss"></style>