index.vue 4.72 KB
<!-- 通用表单弹窗组件 -->
<template>
  <div class="glsk-form-dialog">
    <d2-dialog :append-to-body="appendToBody"
               :btn-ok-label="dialogConfig.okText"
               :is-visible="selectVisible"
               :no-cancel="dialogConfig.hideClose"
               :title="dialogConfig.title"
               :width="dialogWidth"
               @closeDialog="handleClose"
               @confirmDialog="handleConfirm">
      <glsx-combi-form ref="editFormRef"
                       class="edit-form-container"
                       :default-width="defaultWidth"
                       :form-data="editFormData"
                       :form-obj="editData"
                       :form-ref="editChildRef"
                       :form-rules="formRules"
                       :form-select-obj="formSelectObj"
                       :is-block="isBlock"
                       :label-width="labelWidth"
                       :nested-modal-append-to-body="nestedModalAppendToBody"
                       @handleAddSelectTypeConfirm="handleAddSelectTypeConfirm"
                       @handleEditSelectTypeConfirm="handleEditSelectTypeConfirm">
        <template v-for="name in slotArr" #[name]>
          <slot :name="name"></slot>
        </template>
      </glsx-combi-form>
    </d2-dialog>
  </div>
</template>

<script>
import { deepClone } from "@/common/util";

export default {
	name: "GlskFormDialog",

	props: {
		slotArr: {
			type: Array,
			default: () => ["resumeUrlHtml"],
		},
		dialogWidth: {
			type: String,
			default: "700px",
		},
		labelWidth: {
			type: String,
			default: "100px",
		},
		defaultWidth: {
			type: String,
			default: "314px",
		},
		dialogConfig: {
			type: Object,
			default: () => {
				return {
					title: "提示",
					okText: "确定",
					hideClose: false,
				};
			},
		},
		selectVisible: {
			type: Boolean,
			default: false,
		},
		formRules: {
			type: Object,
			default: () => ({}),
		},
		editData: {
			type: Object,
			default: () => ({}),
		},
		editFormData: {
			type: Array,
			default: () => [],
		},
		baseData: {
			type: Object,
			default: () => ({}),
		},
		appendToBody: {
			type: Boolean,
			default: false,
		},
		/** 表单内含地图/上传预览等内层弹窗时,外层已是 d2-dialog 则建议开启 */
		nestedModalAppendToBody: {
			type: Boolean,
			default: false,
		},
		// 搜索+输入框/搜索组合组件,搜索栏绑值
		formSelectObj: {
			type: Object,
			default: () => {},
		},
	},
	data() {
		return {
			isBlock: true,
			editChildRef: "editChildRef",
		};
	},

	mounted() {
		this.getOptionsList("editFormData", false);
	},

	methods: {
		getOptionsList(formName, hasAll = true, refreshSigle) {
			if (refreshSigle) {
				let item = this[formName].find(k => k.name == refreshSigle);
				let index = this[formName].findIndex(k => k.name == refreshSigle);
				this.$set(
					this[formName][index],
					"optionList",
					deepClone(this.baseData[item.optionsName]),
				);
				if (
					hasAll
					&& this.baseData[item.optionsName].length
					&& this.baseData[item.optionsName][0][
						this[formName][index].optionLabel
					] !== "全部"
				) {
					const temp = {};
					temp[this[formName][index].optionId] = "";
					temp[this[formName][index].optionLabel] = "全部";
					this[formName][index].optionList.unshift(temp);
				}
			} else {
				this[formName].forEach((item, index) => {
					if (
						["select", "radio"].includes(item.type)
						&& this.baseData[item.optionsName].length
					) {
						this.$set(
							this[formName][index],
							"optionList",
							deepClone(this.baseData[item.optionsName]),
						);
						if (
							hasAll
							&& this.baseData[item.optionsName].length
							&& this.baseData[item.optionsName][0][
								this[formName][index].optionLabel
							] !== "全部"
						) {
							const temp = {};
							temp[this[formName][index].optionId] = "";
							temp[this[formName][index].optionLabel] = "全部";
							this[formName][index].optionList.unshift(temp);
						}
					}
				});
			}
		},
		handleConfirm() {
			console.log(this.editFormData, this.editData);
			this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => {
				if (valid) {
					this.$emit("handleConfirm", this.editData);
				}
			});
		},
		handleAddSelectTypeConfirm(data) {
			this.$emit("handleAddSelectTypeConfirm", data);
		},
		handleEditSelectTypeConfirm(data) {
			this.$emit("handleEditSelectTypeConfirm", data);
		},
		handleClose() {
			this.$emit("handleClose");
		},
	},
};
</script>

<style lang="scss" scoped>
.glsk-form-dialog {
	::v-deep {
		.el-dialog__header {
			border-bottom: 1px solid #e5e5e5 !important;
		}
	}
	::v-deep {
		.el-dialog__footer {
			border-top: 1px solid #e5e5e5 !important;
			.el-button {
				width: 80px;
			}
		}
	}
}
</style>