Parcourir la source

批量添加控件

闫腾 il y a 2 ans
Parent
commit
58e37b5e70

+ 90 - 0
Web/src/components/table/TableEditor.vue

@@ -0,0 +1,90 @@
+<template>
+	<div class="el-table-container">
+		<table class="el-table el-table-middle">
+			<thead class="el-table-thead">
+				<tr>
+					<th v-for="(citem, ci) in $props.columns" :key="ci" v-show="citem.ifShow == undefined ? true : citem.ifShow" style="text-align: center">
+						{{ citem.label }}
+					</th>
+					<th style="text-align: center" v-show="!$props.disabled">操作</th>
+				</tr>
+			</thead>
+			<tbody class="el-table-tbody">
+				<tr v-for="(item, index) in vm.value" :key="index">
+					<td v-for="(citem, ci) in $props.columns" :key="ci" style="text-align: center" v-show="citem.ifShow == undefined ? true : citem.ifShow">
+						<component v-if="citem.component != 'el-select'" :is="citem.component" v-model="item[citem.field]" v-bind="renderComponentProp(citem)" :disabled="$props.disabled" />
+						<el-select v-else v-model="item[citem.field]" v-bind="renderComponentProp(citem)" :disabled="$props.disabled">
+							<el-option v-for="(sitem, si) in citem.componentProps.options" :key="sitem.value" :label="sitem.value" :value="sitem.code" />
+						</el-select>
+					</td>
+					<td style="text-align: center" v-show="!$props.disabled">
+						<el-button type="danger" @click="del(item, index)">删除</el-button>
+					</td>
+				</tr>
+			</tbody>
+			<tfoot>
+				<tr>
+					<td v-for="(citem, ci) in $props.columns" :key="ci" style="text-align: center" v-show="citem.ifShow == undefined ? true : citem.ifShow">
+						<component v-if="citem.component != 'el-select'" :is="citem.component" v-model="vm.formData[citem.field]" v-bind="renderComponentProp(citem)" />
+						<el-select v-else v-model="vm.formData[citem.field]" v-bind="renderComponentProp(citem)">
+							<el-option v-for="(sitem, si) in citem.componentProps.options" :key="sitem.value" :label="sitem.value" :value="sitem.code" />
+						</el-select>
+					</td>
+					<td class="el-table-cell el-table-cell-ellipsis" style="text-align: center" v-show="!$props.disabled">
+						<el-button type="primary" @click="add">添加</el-button>
+					</td>
+				</tr>
+			</tfoot>
+		</table>
+	</div>
+</template>
+<script lang="ts" setup>
+import { reactive } from 'vue';
+const props = defineProps({
+	value: {
+		type: Array<any>,
+		default: () => [],
+	},
+	columns: {
+		type: Array<any>,
+		default: () => [],
+	},
+	params: {
+		type: Object,
+	},
+	disabled: {
+		type: Boolean,
+		default: false,
+	},
+});
+const emit = defineEmits(['add', 'delete', 'update:value']);
+var vm = reactive({ formData: {} as any, value: [] as any[] });
+function renderComponentProp(item: any) {
+	let componentProps = item.componentProps || {};
+
+	let disabled = item.disabled || componentProps.disabled || props.disabled;
+	const propsData: any = {
+		...componentProps,
+		disabled: disabled,
+	};
+
+	return propsData;
+}
+function del(record: any, index: number) {
+	vm.value.splice(index, 1);
+	emit('update:value', vm.value);
+	emit('delete', { value: vm.value, record });
+}
+function add() {
+	for (const key in props.params) {
+		vm.formData[key] = props.params[key];
+	}
+	if (!vm.value) {
+		vm.value = [];
+	}
+	vm.value.push({ ...vm.formData });
+	vm.formData = {};
+	emit('update:value', vm.value);
+	emit('add', { value: vm.value, record: vm.formData });
+}
+</script>

+ 18 - 19
Web/src/stores/userInfo.ts

@@ -47,9 +47,8 @@ export const useUserInfo = defineStore('userInfo', {
 		},
 		async setDictList() {
 			// 存储字典信息到浏览器缓存
-			var res= await getAPI(SysDictTypeApi)
-						.apiSysDictTypeAllDictListGet();
-			this.dictList=res.data.result ;
+			var res = await getAPI(SysDictTypeApi).apiSysDictTypeAllDictListGet();
+			this.dictList = res.data.result;
 			// if (Session.get('dictList')) {
 			// 	this.dictList = Session.get('dictList');
 			// } else {
@@ -130,10 +129,10 @@ export const useUserInfo = defineStore('userInfo', {
 				}
 			});
 		},
-		
+
 		//根据字典类型和值取字典项
-		getDictItemByVal( typePCode: string,val: string) {
-			const _val= val.toString();
+		getDictItemByVal(typePCode: string, val: string) {
+			const _val = val.toString();
 			const ds = this.getDictDatasByCode(typePCode);
 			for (let index = 0; index < ds.length; index++) {
 				const element = ds[index];
@@ -145,11 +144,11 @@ export const useUserInfo = defineStore('userInfo', {
 		},
 
 		//根据字典类型和值取描述
-		getDictLabelByVal( typePCode: string,val: string) {
-			return this.getDictItemByVal(typePCode,val).value;
+		getDictLabelByVal(typePCode: string, val: string) {
+			return this.getDictItemByVal(typePCode, val).value;
 		},
 		//根据字典类型和描述取值
-		getDictValByLabel(typePCode: string,label: string) {
+		getDictValByLabel(typePCode: string, label: string) {
 			const ds = this.getDictDatasByCode(typePCode);
 			for (let index = 0; index < ds.length; index++) {
 				const element = ds[index];
@@ -162,20 +161,20 @@ export const useUserInfo = defineStore('userInfo', {
 		getDictDatasByCode(dictTypeCode: string) {
 			return this.dictList[dictTypeCode] || [];
 		},
-		
+
 		//根据字典类型字典数据,值转为数字类型
 		getDictIntDatasByCode(dictTypeCode: string) {
-			var ds=this.dictListInt[dictTypeCode];
-			if(ds){
+			var ds = this.dictListInt[dictTypeCode];
+			if (ds) {
 				return ds;
-			}else{
-				ds=this.dictList[dictTypeCode]
-				.map((element: { code: any; }) => {
-					element.code= element.code-0;
-					return element;
+			} else {
+				ds = this.dictList[dictTypeCode].map((element: { code: any }) => {
+					var d={...element};
+					d.code = element.code - 0;
+					return d;
 				});
-				this.dictListInt[dictTypeCode]=ds;
-				return ds ;
+				this.dictListInt[dictTypeCode] = ds;
+				return ds;
 			}
 		},
 	},

+ 169 - 0
Web/src/views/main/dm_ApplyDemo/component/patchEditDialog.vue

@@ -0,0 +1,169 @@
+<template>
+	<div class="dm_ApplyDemo-container">
+		<el-dialog v-model="isShowDialog"  width="80%" draggable="">
+			<template #header>
+				<div style="color: #fff">
+					<!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
+					<span>{{ props.title }}</span>
+				</div>
+			</template>
+			<TableEditor :columns="editFormSchema" :v-model:value="vm.value"></TableEditor>
+			<template #footer>
+				<span class="dialog-footer">
+					<el-button @click="cancel">取 消</el-button>
+					<el-button type="primary" @click="submit">确 定</el-button>
+				</span>
+			</template>
+		</el-dialog>
+	</div>
+</template>
+<style scoped>
+:deep(.el-select),
+:deep(.el-input-number) {
+	width: 100%;
+}
+</style>
+<script lang="ts" setup>
+	import { ref,onMounted, reactive } from "vue";
+	import { getDictDataItem as di, getDictDataListInt as dl } from '/@/utils/dict-utils';
+	import { ElMessage } from "element-plus";
+	import type { FormRules } from "element-plus";
+	import { addDm_ApplyDemo, updateDm_ApplyDemo, detailDm_ApplyDemo } from "/@/api/main/dm_ApplyDemo";
+	import TableEditor from "/@/components/table/TableEditor.vue";
+
+	//父级传递来的参数
+	var props = defineProps({
+		title: {
+		type: String,
+		default: "",
+	},
+	});
+	//父级传递来的函数,用于回调
+	const emit = defineEmits(["reloadTable"]);
+	const ruleFormRef = ref();
+	const isShowDialog = ref(false);
+	const ruleForm = ref<any>({});
+	//自行添加其他规则
+	const rules = ref<FormRules>({
+        applyNO: [{ required: true, message: '请输入申请号!', trigger: 'blur',},],
+        applicatDate: [{ required: true, message: '请选择申请时间!', trigger: 'change',},],
+        amount: [{ required: true, message: '请输入申请金额!', trigger: 'blur',},],
+        remark: [{ required: true, message: '请输入备注!', trigger: 'blur',},],
+	});
+ const editFormSchema = [
+  {
+    label: 'id',
+    field: 'id',
+    component: 'el-input',
+    required: false,
+    colProps: { span: 6 },
+    ifShow: false,
+  }, 
+  {
+    label: '机构类型',
+    field: 'orgType',
+    component: 'el-select',
+    componentProps: {
+      options: dl('org_type'),
+    },
+    required: false,
+    colProps: { span: 6 },
+  },
+  {
+    label: '申请号',
+    field: 'applyNO',
+    component: 'el-input',
+    required: false,
+    colProps: { span: 6 },
+  },
+  {
+    label: '申请时间',
+    field: 'applicatDate',
+    component: 'el-date-picker',
+    required: false,
+    colProps: { span: 6 },
+  },
+  {
+    label: '申请金额',
+    field: 'amount',
+    component: 'el-input-number',
+    required: false,
+    colProps: { span: 6 },
+  },
+  {
+    label: '是否通知',
+    field: 'isNotice',
+    component: 'el-switch',
+    required: false,
+    colProps: { span: 6 },
+  },
+  {
+    label: '备注',
+    field: 'remark',
+    component: 'el-input',
+    required: false,
+    colProps: { span: 6 },
+  },
+];
+
+var vm = reactive({  value: [] as any[] });
+	// 打开弹窗
+	const openDialog = async (row: any) => {
+		// ruleForm.value = JSON.parse(JSON.stringify(row));
+		// 改用detail获取最新数据来编辑
+		let rowData = JSON.parse(JSON.stringify(row));
+		if (rowData.id)
+			ruleForm.value = (await detailDm_ApplyDemo(rowData.id)).data.result;
+		else
+			ruleForm.value = rowData;
+		isShowDialog.value = true;
+	};
+
+	// 关闭弹窗
+	const closeDialog = () => {
+		emit("reloadTable");
+		isShowDialog.value = false;
+	};
+
+	// 取消
+	const cancel = () => {
+		isShowDialog.value = false;
+	};
+
+	// 提交
+	const submit = async () => {
+		ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
+			if (isValid) {
+				let values = ruleForm.value;
+				if (ruleForm.value.id == undefined || ruleForm.value.id == null || ruleForm.value.id == "" || ruleForm.value.id == 0) {
+					await addDm_ApplyDemo(values);
+				} else {
+					await updateDm_ApplyDemo(values);
+				}
+				closeDialog();
+			} else {
+				ElMessage({
+					message: `表单有${Object.keys(fields).length}处验证失败,请修改后再提交`,
+					type: "error",
+				});
+			}
+		});
+	};
+
+
+
+
+
+
+
+	// 页面加载时
+	onMounted(async () => {
+	});
+
+	//将属性或者函数暴露给父组件
+	defineExpose({ openDialog });
+</script>
+
+
+
+

+ 9 - 0
Web/src/views/main/dm_ApplyDemo/index.vue

@@ -48,6 +48,7 @@
 					</el-col>
 					<el-col :xs="24" :sm="12" :md="6" :lg="6" :xl="6" class="mb10"> 
 								<el-button type="primary" icon="ele-Plus" @click="openAddDm_ApplyDemo" v-auth="'dm_ApplyDemo:add'"> 新增 </el-button>
+								<el-button type="primary" icon="ele-Plus" @click="openPatchAddDm_ApplyDemo" v-auth="'dm_ApplyDemo:add'"> 批量添加 </el-button>
 								
 								<el-button icon="ele-Download" @click="exportData" > 导出数据 </el-button>
 
@@ -94,6 +95,7 @@
 			/>
 			<printDialog ref="printDialogRef" :title="printDm_ApplyDemoTitle" @reloadTable="handleQuery" />
 			<editDialog ref="editDialogRef" :title="editDm_ApplyDemoTitle" @reloadTable="handleQuery" />
+			<patchEditDialog ref="patchEditDialogRef" :title="editDm_ApplyDemoTitle" @reloadTable="handleQuery" />
 		</el-card>
 	</div>
 </template>
@@ -105,6 +107,7 @@ import { auth } from '/@/utils/authFunction';
 import { getDictDataItem as di, getDictDataList as dl } from '/@/utils/dict-utils';
 
 import printDialog from '/@/views/system/print/component/hiprint/preview.vue';
+import patchEditDialog from '/@/views/main/dm_ApplyDemo/component/patchEditDialog.vue';
 import editDialog from '/@/views/main/dm_ApplyDemo/component/editDialog.vue';
 import { pageDm_ApplyDemo, deleteDm_ApplyDemo,exportDm_ApplyDemo as exportData } from '/@/api/main/dm_ApplyDemo';
 import ImportButton from '/@/components/importButton/index.vue';
@@ -112,6 +115,7 @@ import ImportButton from '/@/components/importButton/index.vue';
 const showAdvanceQueryUI = ref(false);
 const printDialogRef = ref();
 const editDialogRef = ref();
+const patchEditDialogRef= ref();
 const loading = ref(false);
 const tableData = ref<any>([]);
 const queryParams = ref<any>({});
@@ -150,6 +154,11 @@ const openAddDm_ApplyDemo = () => {
 	editDm_ApplyDemoTitle.value = '添加申请示例';
 	editDialogRef.value.openDialog({});
 };
+// 打开批量新增页面
+const openPatchAddDm_ApplyDemo = () => {
+	editDm_ApplyDemoTitle.value = '批量添加申请示例';
+	patchEditDialogRef.value.openDialog({});
+};
 
 // 打开打印页面
 const openPrintDm_ApplyDemo = async (row: any) => {