|
|
@@ -0,0 +1,177 @@
|
|
|
+<template>
|
|
|
+ <el-drawer
|
|
|
+ v-model="showDrawer"
|
|
|
+ direction="rtl"
|
|
|
+ title="添加需求物资"
|
|
|
+ size="50%"
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ destroy-on-close
|
|
|
+ >
|
|
|
+ <el-form ref="formRef" :model="formData" label-width="auto" class="add-supply-form">
|
|
|
+ <el-form-item
|
|
|
+ label="物资名称:"
|
|
|
+ prop="info.supplyName"
|
|
|
+ :rules="[{ required: true, message: '请输入物资名称', trigger: 'blur' }]"
|
|
|
+ >
|
|
|
+ <el-input v-model="formData.info.supplyName" placeholder="请输入物资名称" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ label="规格:"
|
|
|
+ prop="info.specs"
|
|
|
+ :rules="[{ required: true, message: '请输入规格', trigger: 'blur' }]"
|
|
|
+ >
|
|
|
+ <el-input v-model="formData.info.specs" placeholder="请输入规格" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ label="单价(元):"
|
|
|
+ prop="info.unitPrice"
|
|
|
+ :rules="[{ required: true, message: '请输入单价', trigger: 'blur' }]"
|
|
|
+ >
|
|
|
+ <el-input v-model.number="formData.info.unitPrice" placeholder="请输入单价" type="number" min="0" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="小计:" prop="info.subtotal">
|
|
|
+ <el-input v-model="formData.info.subtotal" placeholder="请输入小计" type="textarea" rows: 3, />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="需求详情:" v-if="deptTree">
|
|
|
+ <AddSuppliesSubForm
|
|
|
+ ref="subFormRef"
|
|
|
+ v-for="(item, index) in formData.detailList"
|
|
|
+ :key="item.id"
|
|
|
+ :init-data="item"
|
|
|
+ :dept-tree="deptTree"
|
|
|
+ @close-sub-form="onCloseSubForm(item.id)"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <div class="add-supply-form-btns">
|
|
|
+ <el-button @click="addDetail">新增</el-button>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <el-button @click="showDrawer = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="handleSubmit"> 提交 </el-button>
|
|
|
+ </template>
|
|
|
+ </el-drawer>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+ import { ElDrawer, ElForm, ElMessage } from 'element-plus';
|
|
|
+ import { ref, reactive, onMounted, useTemplateRef } from 'vue';
|
|
|
+ import type { AddSupplyRequestForm, SupplyRequestDetailList } from '@/types/emergency-supplier';
|
|
|
+ import AddSuppliesSubForm from './AddSuppliesSubForm.vue';
|
|
|
+
|
|
|
+ import type { DeptTree } from '@/types/dept/type';
|
|
|
+ import { getAllDepartments } from '@/api/auth/dept';
|
|
|
+
|
|
|
+ const formRef = ref<InstanceType<typeof ElForm>>();
|
|
|
+ const subFormRefs = useTemplateRef('subFormRef');
|
|
|
+
|
|
|
+ const showDrawer = ref(false);
|
|
|
+
|
|
|
+ const lastDetailId = ref(0);
|
|
|
+
|
|
|
+ // 获取部门树
|
|
|
+ const deptTree = ref<DeptTree[]>();
|
|
|
+ const getDeptTreeData = async () => {
|
|
|
+ const res = await getAllDepartments();
|
|
|
+ deptTree.value = res[0].children;
|
|
|
+ };
|
|
|
+
|
|
|
+ // 表单数据
|
|
|
+ const formData = reactive<AddSupplyRequestForm>({
|
|
|
+ info: {},
|
|
|
+ detailList: [
|
|
|
+ {
|
|
|
+ id: lastDetailId.value,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+
|
|
|
+ // 清理表单数据
|
|
|
+ const clearFormData = () => {
|
|
|
+ lastDetailId.value = 0;
|
|
|
+ formData.info = {};
|
|
|
+ formData.detailList = [
|
|
|
+ {
|
|
|
+ id: lastDetailId.value,
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ };
|
|
|
+
|
|
|
+ // 打开需求列表&数据初始化
|
|
|
+ const openDrawer = () => {
|
|
|
+ // 创建时清理为初始化
|
|
|
+ clearFormData();
|
|
|
+ showDrawer.value = true;
|
|
|
+ };
|
|
|
+
|
|
|
+ // 表单需求详情加一项
|
|
|
+ const addDetail = () => {
|
|
|
+ lastDetailId.value += 1;
|
|
|
+ formData.detailList.push({
|
|
|
+ id: lastDetailId.value,
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 删除一项需求详情
|
|
|
+ const onCloseSubForm = (id: number) => {
|
|
|
+ if (formData.detailList.length === 1) {
|
|
|
+ ElMessage.warning('至少一条需求详情');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ formData.detailList = formData.detailList.filter((item) => item.id !== id);
|
|
|
+ };
|
|
|
+
|
|
|
+ // 表单校验
|
|
|
+ const formValidate = async () => {
|
|
|
+ if (!formRef.value) return;
|
|
|
+ if (!subFormRefs.value) return;
|
|
|
+ const subFormsValidateResultList = await Promise.all(subFormRefs.value.map((item) => item?.subFormValidate()));
|
|
|
+ const isSubFormsValidateResult = subFormsValidateResultList.every((item) => item);
|
|
|
+ if (!isSubFormsValidateResult) return;
|
|
|
+ return await formRef.value.validate();
|
|
|
+ };
|
|
|
+
|
|
|
+ // 提交表单
|
|
|
+ const handleSubmit = async () => {
|
|
|
+ const res = await formValidate();
|
|
|
+ if (!res) return;
|
|
|
+ };
|
|
|
+
|
|
|
+ onMounted(() => {
|
|
|
+ getDeptTreeData();
|
|
|
+ });
|
|
|
+
|
|
|
+ defineExpose({
|
|
|
+ openDrawer,
|
|
|
+ });
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+ .el-form {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ width: auto;
|
|
|
+ height: 100%;
|
|
|
+ gap: 24px;
|
|
|
+ }
|
|
|
+ .el-form-item {
|
|
|
+ margin-bottom: 0;
|
|
|
+ }
|
|
|
+ .add-supply-form-btns {
|
|
|
+ padding-left: 88px;
|
|
|
+ }
|
|
|
+
|
|
|
+ :deep(.el-form-item__label) {
|
|
|
+ padding: 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ :deep(.el-form-item__content) {
|
|
|
+ gap: 16px;
|
|
|
+ }
|
|
|
+
|
|
|
+ :deep(.el-textarea__inner) {
|
|
|
+ padding-bottom: 20px;
|
|
|
+ }
|
|
|
+</style>
|