| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- <!-- 字典编辑弹窗 -->
- <template>
- <ele-modal
- width="800px"
- :maxable="true"
- :visible="visible"
- :close-on-click-modal="false"
- :title="isUpdate ? '修改字典' : '添加字典'"
- @update:visible="updateVisible"
- >
- <div class="divider">
- <div class="title">
- <div class="ele-bg-primary"></div>
- <span>基本信息</span>
- </div>
- <div class="ele-bg-primary" style="width: 100%; height: 2px"></div>
- </div>
- <el-form
- ref="form"
- :model="form"
- :rules="rules"
- label-width="85px"
- style="margin-bottom: 10px"
- >
- <el-row>
- <el-col :span="12">
- <el-form-item label="字典值:" prop="code">
- <el-input
- clearable
- :disabled="isUpdate"
- :maxlength="50"
- v-model="form.code"
- placeholder="请输入字典值"
- />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="字典名称:" prop="name">
- <el-input
- clearable
- :disabled="isUpdate"
- :maxlength="20"
- v-model="form.name"
- placeholder="请输入字典名称"
- />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="应用类型:" prop="appType">
- <el-radio-group v-model="form.appType">
- <el-radio :label="1">业务字典</el-radio>
- <el-radio :label="2">数据字典</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="是否启用:" prop="enable">
- <el-radio-group v-model="form.enable">
- <el-radio :label="1">是</el-radio>
- <el-radio :label="0">否</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-col>
- <!-- <el-col :span="12">
- <el-form-item label="排序号:" prop="sortNumber">
- <el-input-number
- :min="0"
- :max="9999"
- v-model="form.sortNumber"
- controls-position="right"
- placeholder="请输入排序号"
- class="ele-fluid ele-text-left"
- />
- </el-form-item>
- </el-col> -->
- <el-col :span="24">
- <el-form-item label="备注:">
- <el-input
- :rows="4"
- type="textarea"
- :maxlength="200"
- v-model="form.remark"
- placeholder="请输入备注"
- />
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <div class="divider">
- <div class="title">
- <div class="ele-bg-primary"></div>
- <span>字典项配置</span>
- </div>
- <div class="ele-bg-primary" style="width: 100%; height: 2px"></div>
- </div>
- <div style="margin: 5px 0">
- <el-button
- size="small"
- type="primary"
- icon="el-icon-plus"
- class="ele-btn-icon"
- @click="pushArr"
- >
- 添加
- </el-button>
- <!-- <el-button
- size="small"
- type="danger"
- icon="el-icon-delete"
- class="ele-btn-icon"
- @click="removeArr"
- >
- 删除
- </el-button> -->
- </div>
- <el-table
- :data="tableData"
- border
- style="width: 100%"
- @selection-change="handleSelectionChange"
- >
- <el-table-column prop="code" label="字典项编码">
- <template slot-scope="scope">
- <el-input
- @blur="checkedValue(scope.row.code)"
- :disabled="isUpdate && scope.row.id"
- v-model="scope.row.code"
- placeholder=""
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="name" label="字典项名称">
- <template slot-scope="scope">
- <el-input v-model="scope.row.name" placeholder=""></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="sort" label="排序">
- <template slot-scope="scope">
- <el-input
- v-model="scope.row.sort"
- @input="
- scope.row.sort = String(scope.row.sort).replace(/[^\d]/g, '')
- "
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column prop="enable" label="启用">
- <template slot-scope="scope">
- <el-radio-group v-model="scope.row.enable">
- <el-radio :label="1">是</el-radio>
- <el-radio :label="0">否</el-radio>
- </el-radio-group>
- </template>
- </el-table-column>
- <el-table-column align="center" label="操作">
- <template slot-scope="scope">
- <el-popconfirm
- v-if="!isUpdate || (!scope.row.id && isUpdate)"
- class="ele-action"
- title="确定要删除此字典项吗?"
- @confirm="removeArr(scope)"
- >
- <template v-slot:reference>
- <el-link type="danger" :underline="false" icon="el-icon-delete">
- 删除
- </el-link>
- </template>
- </el-popconfirm>
- </template>
- </el-table-column>
- </el-table>
- <template v-slot:footer>
- <el-button @click="updateVisible(false)">取消</el-button>
- <el-button type="primary" :loading="loading" @click="save">
- 保存
- </el-button>
- </template>
- </ele-modal>
- </template>
- <script>
- import { addDictionary, updateDictionary } from '@/api/system/dictionary';
- import {
- pageDictionaryData,
- removeDictionaryData,
- removeDictionaryDataBatch
- } from '@/api/system/dictionary-data';
- export default {
- props: {
- // 弹窗是否打开
- visible: Boolean,
- // 修改回显的数据
- id: String | Number
- },
- data() {
- const defaultForm = {
- name: '',
- code: '',
- appType: 1,
- enable: 1,
- remark: '',
- dictStaticSubmitPOList: []
- };
- return {
- defaultForm,
- // 表单数据
- form: { ...defaultForm },
- // form: {
- // name: '',
- // code: '',
- // appType: 1,
- // enable: 1,
- // remark: ''
- // },
- // 表单验证规则
- rules: {
- name: [
- {
- required: true,
- message: '请输入字典名称',
- trigger: 'blur'
- }
- ],
- code: [
- {
- required: true,
- message: '请输入字典值',
- trigger: 'blur'
- }
- ],
- appType: [
- {
- required: true,
- message: '请选择应用类型',
- trigger: 'blur'
- }
- ],
- enable: [
- {
- required: true,
- message: '请选择是否启用',
- trigger: 'blur'
- }
- ],
- sort: [
- {
- required: true,
- message: '请输入排序号',
- trigger: 'blur'
- }
- ]
- },
- // 表格列配置
- columns: [
- {
- columnKey: 'selection',
- type: 'selection',
- width: 45,
- align: 'center'
- },
- {
- columnKey: 'index',
- type: 'index',
- width: 45,
- align: 'center',
- showOverflowTooltip: true
- },
- {
- prop: 'code',
- label: '字典编码',
- showOverflowTooltip: true
- },
- {
- prop: 'name',
- label: '字典名称',
- showOverflowTooltip: true
- },
- // {
- // prop: 'appType',
- // label: '字典类型',
- // showOverflowTooltip: true,
- // minWidth: 110
- // },
- {
- prop: 'appType',
- label: '应用类型',
- showOverflowTooltip: true
- },
- {
- prop: 'remark',
- label: '描述',
- showOverflowTooltip: true
- },
- {
- prop: 'createTime',
- label: '创建时间',
- showOverflowTooltip: true,
- minWidth: 110,
- formatter: (_row, _column, cellValue) => {
- return this.$util.toDateString(cellValue);
- }
- },
- {
- columnKey: 'action',
- label: '操作',
- width: 130,
- align: 'center',
- resizable: false,
- slot: 'action',
- showOverflowTooltip: true
- }
- ],
- tableData: [],
- // 表格选中数据
- selection: [],
- datasource: {
- list: []
- },
- // 提交状态
- loading: false,
- // 是否是修改
- isUpdate: false,
- delectId: 1
- };
- },
- created() {},
- methods: {
- pushArr() {
- this.form.dictStaticSubmitPOList.push({
- code: '',
- enable: 1,
- name: '',
- sort: '',
- delectId: this.delectId
- });
- this.delectId = this.delectId + 1;
- this.filterArr();
- },
- //
- checkedValue(val) {
- console.log(val);
- },
- removeArr(row) {
- console.log(row);
- if (row.row.id) {
- this.form.dictStaticSubmitPOList.forEach((item) => {
- if (item.id === row.row.id) {
- item.deleted = 1;
- }
- });
- this.filterArr();
- } else {
- let index = this.form.dictStaticSubmitPOList.findIndex(
- (item) => item.delectId === row.row.delectId
- );
- console.log(index);
- this.form.dictStaticSubmitPOList.splice(index, 1); // 在数组的指定位置移除对应的元素。 返回移除的
- this.filterArr();
- }
- // let falg = this.form.dictStaticSubmitPOList[row.$index].deleted === 0;
- // if (falg) {
- // this.form.dictStaticSubmitPOList[row.$index].deleted = 1;
- // this.filterArr();
- // } else {
- // this.form.dictStaticSubmitPOList.splice(row.$index, 1);
- // this.filterArr();
- // }
- },
- handleSelectionChange() {},
- /* 保存编辑 */
- save() {
- this.$refs.form.validate((valid) => {
- if (!valid) {
- return false;
- }
- let falg = this.form.dictStaticSubmitPOList.some(
- (item, index) => item.code.length === 0
- );
- if (falg) {
- this.$message({
- message: '字典项编码不能为空',
- type: 'warning'
- });
- return;
- }
- this.form.dictStaticSubmitPOList.forEach((item, index) => {
- if (item.delectId) {
- delete item.delectId;
- }
- });
- this.loading = true;
- const saveOrUpdate = this.isUpdate ? updateDictionary : addDictionary;
- saveOrUpdate(this.form)
- .then((msg) => {
- this.loading = false;
- this.$message.success(msg);
- this.updateVisible(false);
- this.$emit('done');
- })
- .catch((e) => {
- this.loading = false;
- // // this.$message.error(e.message);
- });
- });
- },
- filterArr() {
- this.tableData = this.form.dictStaticSubmitPOList.filter(
- (item) => item.deleted !== 1
- );
- },
- /* 更新visible */
- updateVisible(value) {
- this.$emit('update:visible', value);
- },
- async getDetail() {
- const res = await pageDictionaryData(this.id);
- this.form = res.data.dictInfoVO;
- this.form.dictStaticSubmitPOList = res.data.dictStaticVOList;
- if (this.form.dictStaticSubmitPOList.length > 0) {
- this.filterArr();
- } else {
- this.tableTata = [];
- }
- }
- },
- watch: {
- visible(visible) {
- if (visible) {
- if (this.id) {
- // this.$util.assignObject(this.form, this.data);
- this.isUpdate = true;
- this.getDetail();
- } else {
- this.isUpdate = false;
- }
- } else {
- this.$refs.form.clearValidate();
- this.form = { ...this.defaultForm };
- this.form.dictStaticSubmitPOList = []; // clear the list of the dictionary static push button. 描述变化的字段不会在push后
- this.tableData = []; // clear the list of the dictionary static push button. 描述变化的字段不会在push后。
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .divider {
- margin-bottom: 20px;
- .title {
- display: flex;
- align-items: center;
- margin-bottom: 10px;
- div {
- width: 8px;
- height: 20px;
- margin-right: 10px;
- }
- span {
- font-size: 20px;
- }
- }
- }
- </style>
|