|
|
@@ -1,11 +1,134 @@
|
|
|
<template>
|
|
|
- <div>this is add emergency item</div>
|
|
|
+ <div class="emergency-supply-container">
|
|
|
+ <BasicForm ref="formRef" :formData="ruleFormData" :formRules="customFormRules" :formConfig="ruleFormConfig">
|
|
|
+ <template #emergencyType>
|
|
|
+ <el-select v-model="ruleFormData.emergencyType" placeholder="请选择应急类型" filterable>
|
|
|
+ <el-option
|
|
|
+ v-for="item in emergencyEventDice"
|
|
|
+ :key="item.itemCode"
|
|
|
+ :label="item.itemValue"
|
|
|
+ :value="item.itemCode"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ <template #supplyType>
|
|
|
+ <el-select v-model="ruleFormData.supplyType" placeholder="请选择物资类型" filterable>
|
|
|
+ <el-option
|
|
|
+ v-for="item in emergencySupplyDice"
|
|
|
+ :key="item.itemCode"
|
|
|
+ :label="item.itemValue"
|
|
|
+ :value="item.itemCode"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ <template #park>
|
|
|
+ <el-select v-model="ruleFormData.park" placeholder="请选择园区" filterable @change="handleChangePark">
|
|
|
+ <el-option v-for="item in parkDice" :key="item.itemCode" :label="item.itemValue" :value="item.itemCode" />
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ <template #location>
|
|
|
+ <el-select v-model="ruleFormData.location" placeholder="请输入地点" :disabled="Boolean(!ruleFormData.park)">
|
|
|
+ <el-option v-for="item in locationDice" :key="item.itemCode" :label="item.itemValue" :value="item.itemCode" />
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ <template #keeperId>
|
|
|
+ <el-select
|
|
|
+ v-model="ruleFormData.keeperId"
|
|
|
+ placeholder="请输入保管人姓名"
|
|
|
+ filterable
|
|
|
+ remote
|
|
|
+ :remote-method="remoteMethod"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in userOptions"
|
|
|
+ :key="item.id"
|
|
|
+ :label="`${item.realname}(${item.username})`"
|
|
|
+ :value="item.id"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ </BasicForm>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
+ import { ref, onMounted, computed } from 'vue';
|
|
|
+ import BasicForm from '@/components/BasicForm.vue';
|
|
|
+ import { useFormConfigHook } from '@/hooks/useFormConfigHook';
|
|
|
+ import { useEmergencySuppliesHook } from '../hook';
|
|
|
+ import type { QueryUserInfoByUserNameRes } from '@/types/person-group/type';
|
|
|
+ import type { AddEmergencyItemForm } from '@/types/emergency-supplier';
|
|
|
+ import { queryUserInfoByUserName } from '@/api/system/person-group';
|
|
|
+ import { ADD_EMERGENCY_ITEM_FROM_CONFIG, EMERGENCY_ITEM_DATA, ADD_EMERGENCY_ITEM_RULES } from '../config';
|
|
|
+ import type { FormRules } from 'element-plus';
|
|
|
|
|
|
+ const formRef = ref();
|
|
|
+ const { ruleFormConfig, ruleFormData, formRules, cloneRuleFormData, beforeRouteLeave } =
|
|
|
+ useFormConfigHook<AddEmergencyItemForm>(
|
|
|
+ ADD_EMERGENCY_ITEM_FROM_CONFIG,
|
|
|
+ EMERGENCY_ITEM_DATA,
|
|
|
+ ADD_EMERGENCY_ITEM_RULES,
|
|
|
+ );
|
|
|
+
|
|
|
+ // 验证当前数量不大于应备数量
|
|
|
+ const validateQuantity = (rule: any, value: any, callback: any) => {
|
|
|
+ if (value === '' || value === null || value === undefined) {
|
|
|
+ callback();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const currentQuantity = Number(value);
|
|
|
+ const requiredQuantity = Number(ruleFormData.requiredQuantity);
|
|
|
+
|
|
|
+ if (currentQuantity > requiredQuantity) {
|
|
|
+ callback(new Error('当前数量不能大于应备数量'));
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 扩展原有的表单规则,添加自定义验证
|
|
|
+ const customFormRules = computed<FormRules>(() => {
|
|
|
+ return {
|
|
|
+ ...formRules,
|
|
|
+ currentQuantity: [
|
|
|
+ { required: true, message: '请输入当前数量', trigger: 'blur' },
|
|
|
+ { validator: validateQuantity, trigger: 'blur' }
|
|
|
+ ]
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ const {
|
|
|
+ emergencyEventDice,
|
|
|
+ getEmergencyEventDict,
|
|
|
+ emergencySupplyDice,
|
|
|
+ getEmergencySupplyDict,
|
|
|
+ parkDice,
|
|
|
+ getParkDict,
|
|
|
+ locationDice,
|
|
|
+ getLocationDict,
|
|
|
+ } = useEmergencySuppliesHook();
|
|
|
+ const handleChangePark = (type: 'zhangjiang_park' | 'dachang_park') => {
|
|
|
+ getLocationDict(type);
|
|
|
+ };
|
|
|
+ const userOptions = ref<QueryUserInfoByUserNameRes[]>([]);
|
|
|
+ const loading = ref(false);
|
|
|
+ const remoteMethod = async (query: string) => {
|
|
|
+ if (!query) {
|
|
|
+ userOptions.value = [];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ loading.value = true;
|
|
|
+ userOptions.value = await queryUserInfoByUserName(query);
|
|
|
+ loading.value = false;
|
|
|
+ };
|
|
|
+ onMounted(() => {
|
|
|
+ getEmergencyEventDict();
|
|
|
+ getEmergencySupplyDict();
|
|
|
+ getParkDict();
|
|
|
+ });
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
-
|
|
|
-</style>
|
|
|
+ @use '../styles/info.scss' as *;
|
|
|
+</style>
|