| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <template>
- <div class="modal">
- <el-dialog
- v-model="dialogVisible"
- :title="dialogTitle"
- :width="modalConfig.dialogWidth || '80%'"
- center
- @close="handleExcel(ruleFormRef)"
- :close-on-click-modal="false"
- >
- <template #header>
- <pageTitle :title="dialogTitle"></pageTitle>
- </template>
- <div class="form">
- <el-form
- ref="ruleFormRef"
- :rules="modalConfig.formRules"
- label-suffix=":"
- :model="formData"
- :label-width="modalConfig.labelWidth || '100px'"
- size="large"
- autocomplete="off"
- >
- <el-row :gutter="12">
- <template v-for="item in modalConfig.formItems" :key="item.prop">
- <el-col :span="item.span || 24">
- <el-form-item :label="item.label" :prop="item.prop">
- <template v-if="item.type === 'input'">
- <el-input
- :disabled="dialogLook || item.disabled"
- v-model="formData[item.prop]"
- :placeholder="item.placeholder"
- />
- </template>
- <template v-if="item.type === 'textarea'">
- <el-input
- :disabled="dialogLook || item.disabled"
- type="textarea"
- v-model="formData[item.prop]"
- :autosize="{ minRows: 3 }"
- show-word-limit
- :maxlength="item.maxlength || 200"
- :placeholder="item.placeholder"
- />
- </template>
- <template v-if="item.type === 'number'">
- <el-input
- v-model="formData[item.prop]"
- type="number"
- :min="0"
- :max="999999999999"
- :disabled="dialogLook || item.disabled"
- :placeholder="item.placeholder"
- />
- </template>
- <template v-if="item.type === 'select'">
- <el-select
- v-model="formData[item.prop]"
- :placeholder="item.placeholder"
- style="width: 100%"
- :disabled="dialogLook || item.disabled"
- >
- <template v-for="(val, index) in item.options" :key="index">
- <el-option :value="val.value" :label="val.label" />
- </template>
- </el-select>
- </template>
- <template v-if="item.type === 'date-picker'">
- <el-date-picker
- :type="item.dateType || 'daterange'"
- range-separator="-"
- start-placeholder="开始时间"
- end-placeholder="结束时间"
- v-model="formData[item.prop]"
- :disabled="dialogLook || item.disabled"
- />
- </template>
- <template v-if="item.type === 'date'">
- <el-date-picker
- type="date"
- :placeholder="item.placeholder"
- style="width: 100%"
- v-model="formData[item.prop]"
- :disabled="dialogLook || item.disabled"
- />
- </template>
- <!-- 发布单位 -->
- <template v-if="item.type === 'publishingUnit'">
- <el-tree-select
- v-model="formData[item.prop]"
- :data="treeData"
- :render-after-expand="false"
- :disabled="dialogLook || item.disabled"
- node-key="id"
- filterable
- :placeholder="item.placeholder"
- style="width: 100%"
- />
- </template>
- <!-- 发布状态 -->
- <template v-if="item.type === 'releaseStatus'">
- <el-select
- v-model="formData[item.prop]"
- :placeholder="item.placeholder"
- style="width: 100%"
- :disabled="dialogLook || item.disabled"
- >
- <template v-for="(val, index) in bj_nl_released_status" :key="index">
- <el-option :value="val.value" :label="val.label" />
- </template>
- </el-select>
- </template>
- <!-- 通报类型 -->
- <template v-if="item.type === 'notificationType'">
- <el-select
- v-model="formData[item.prop]"
- :placeholder="item.placeholder"
- style="width: 100%"
- :disabled="dialogLook || item.disabled"
- >
- <template v-for="(val, index) in bj_notification_type" :key="index">
- <el-option :value="val.value" :label="val.label" />
- </template>
- </el-select>
- </template>
- <!-- 通报事项类别 -->
- <template v-if="item.type === 'conm'">
- <el-select
- v-model="formData[item.prop]"
- :placeholder="item.placeholder"
- style="width: 100%"
- :disabled="dialogLook || item.disabled"
- >
- <template v-for="(val, index) in bj_category_onm" :key="index">
- <el-option :value="val.value" :label="val.label" />
- </template>
- </el-select>
- </template>
- <!-- 发出单位 -->
- <template v-if="item.type === 'deliveryUnit'">
- <el-select
- v-model="formData[item.prop]"
- :placeholder="item.placeholder"
- filterable
- style="width: 100%"
- :disabled="dialogLook || item.disabled"
- >
- <template v-for="(val, index) in bj_lssuing_unit" :key="index">
- <el-option :value="val.value" :label="val.label" />
- </template>
- </el-select>
- </template>
- </el-form-item>
- </el-col>
- </template>
- </el-row>
- </el-form>
- </div>
- <template #footer>
- <span class="dialog-footer">
- <el-button type="primary" v-show="dialogLook == false" @click="handleConfirmClick(ruleFormRef, '1')"
- >保存</el-button
- >
- <el-button type="primary" v-show="dialogLook == false" @click="handleConfirmClick(ruleFormRef, '2')"
- >提交</el-button
- >
- <el-button @click="handleExcel(ruleFormRef)">返回</el-button>
- <slot name="button"></slot>
- </span>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup lang="ts" name="modal">
- import { reactive, ref } from 'vue';
- import type { FormInstance } from 'element-plus';
- import useSystemStore from '@/store/main';
- import { TreeOptions } from '@/types/global';
- import dayjs from 'dayjs';
- import { outTypeList, outDeptTree } from '@/libs/commonMeth';
- const bj_notification_type = outTypeList('bj_notification_type'); //通报类型
- const bj_category_onm = outTypeList('bj_category_onm'); //通报事项类别
- const bj_nl_released_status = outTypeList('bj_nl_released_status'); //通报事项清单发布状态
- const bj_lssuing_unit = outTypeList('bj_lssuing_unit'); //发出单位
- // 定义props
- interface IProps {
- modalConfig: {
- pageName: string;
- addTitle: string;
- editTitle: string;
- detailTitle: string;
- dialogWidth: string;
- labelWidth: string;
- formItems: any[];
- formRules: object;
- pageListParams?: object; //新增一个对象,用来传给特殊的列表接口刷新页面(非必传)
- };
- otherInfo?: any;
- }
- const props = defineProps<IProps>();
- const dialogVisible = ref(false);
- const isEdit = ref(false);
- const ruleFormRef = ref<FormInstance>();
- const systemStore = useSystemStore();
- const { pageDetailInfo, pageOperateType } = storeToRefs(systemStore);
- // 定义数据绑定
- const initialForm: any = {};
- for (const item of props.modalConfig.formItems) {
- initialForm[item.prop] = item.initialValue ?? '';
- }
- let formData = ref(JSON.parse(JSON.stringify(initialForm)));
- const dialogTitle = ref();
- const dialogLook = ref(false);
- const nowStr = dayjs().format('YYYY-MM-DD');
- // 新建或者编辑
- async function setDialogVisible(isNew: boolean = true, check: boolean = false) {
- dialogVisible.value = true;
- ruleFormRef.value?.resetFields();
- await nextTick();
- dialogLook.value = false;
- if (!isNew) {
- watch(pageDetailInfo, newVal => {
- formData.value = pageDetailInfo.value;
- });
- if (check) {
- dialogTitle.value = props.modalConfig.detailTitle;
- dialogLook.value = true;
- systemStore.getDetailType('detail');
- } else {
- dialogTitle.value = props.modalConfig.editTitle;
- systemStore.getDetailType('edit');
- }
- } else {
- props.modalConfig.formItems.map((m: any) => {
- if (m.prop === 'addName') {
- initialForm[m.prop] = '张浩楠';
- }
- if (m.prop === 'publishingUnit') {
- initialForm[m.prop] = '100';
- }
- if (m.prop === 'addDate') {
- initialForm[m.prop] = nowStr;
- }
- if (m.prop === 'releaseStatus') {
- initialForm[m.prop] = '1';
- }
- });
- formData.value = JSON.parse(JSON.stringify(initialForm));
- await nextTick();
- dialogTitle.value = props.modalConfig.addTitle;
- systemStore.detailPageEval(initialForm);
- systemStore.getDetailType('add');
- }
- isEdit.value = !isNew;
- }
- // 点击确定
- function handleConfirmClick(formEl: FormInstance | undefined, status: string) {
- if (!formEl) return;
- formEl.validate((valid, fields) => {
- if (valid) {
- dialogVisible.value = false;
- // 可用状态 编辑始终 都是可用
- if (formData.value.releaseStatus != '2') {
- formData.value.releaseStatus == status;
- }
- let data = { ...formData.value };
- if (props.otherInfo) {
- data = { ...data, ...props.otherInfo };
- }
- if (!isEdit.value) {
- systemStore.newPageDataAction(props.modalConfig.pageName, data, props.modalConfig.pageListParams);
- } else {
- if (pageOperateType.value === 'edit') {
- systemStore.editPageDataAction(props.modalConfig.pageName, data, props.modalConfig.pageListParams);
- }
- }
- } else {
- console.log('error submit!', fields);
- }
- });
- }
- // 取消
- function handleExcel(formEl: FormInstance | undefined) {
- dialogVisible.value = false;
- if (!formEl) return;
- formEl.resetFields();
- }
- // 获取详情
- function onPageDetail(urlId: number | [] | string) {
- systemStore.detailPageDataAction(props.modalConfig.pageName, urlId);
- }
- const treeData = ref<TreeOptions[]>();
- onMounted(async () => {
- treeData.value = await outDeptTree();
- });
- defineExpose({
- setDialogVisible,
- onPageDetail,
- });
- </script>
- <style scoped lang="scss">
- .form {
- padding: 10px 30px;
- }
- </style>
|