<template>
|
<div class="app-container">
|
<div class="filter-container">
|
<el-input
|
:disabled="disabled"
|
v-model="listQuery.searchname"
|
placeholder="请输入数据组代码"
|
style="width: 200px;"
|
class="filter-item"
|
clearable
|
@change="handleFilter"
|
/>
|
<el-input
|
:disabled="disabled"
|
v-model="listQuery.groupName"
|
placeholder="请输入数据组名称"
|
style="width: 200px;"
|
class="filter-item"
|
clearable
|
@change="handleFilter"
|
/>
|
<el-input
|
:disabled="disabled"
|
v-model="listQuery.searchValue"
|
placeholder="请输入名称"
|
style="width: 200px;"
|
class="filter-item"
|
clearable
|
@change="handleFilter"
|
/>
|
|
<el-button class="filter-item" style="margin-left: 5px;" type="primary" size="medium" icon="el-icon-search" @click="handleFilter">
|
{{ $t('common.search') }}
|
</el-button>
|
<el-button class="filter-item" style="margin-left: 2px;" type="primary" size="medium" icon="el-icon-circle-plus-outline" @click="handleAdd">
|
{{ $t('common.add') }}
|
</el-button>
|
</div>
|
|
<el-table stripe :data="list" border fit highlight-current-row style="width: 90%">
|
<el-table-column label="序号" type="index" align="center" width="80">
|
<template slot-scope="scope">
|
<span>{{ scope.$index + 1 + (listQuery.page - 1) * 10 }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="组代码" align="center" width="100">
|
<template slot-scope="scope">
|
<span>{{ scope.row.groupcode }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="组名称" align="center" width="150">
|
<template slot-scope="scope">
|
<span>{{ scope.row.groupname }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="代码" align="center" width="100">
|
<template slot-scope="scope">
|
<span>{{ scope.row.key }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="名称" align="center" width="250">
|
<template slot-scope="scope">
|
<span>{{ scope.row.value }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="备注" align="center">
|
<template slot-scope="scope">
|
<span>{{ scope.row.comment }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" align="center" width="200">
|
<template slot-scope="scope">
|
<el-button size="mini" type="primary" @click="handleEdit(scope.$index, scope.row)">{{ $t('common.edit') }}</el-button>
|
<el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">{{ $t('common.delete') }}</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<el-dialog
|
:close-on-click-modal="false"
|
:destroy-on-close="true"
|
:title="disabled ? '查看信息' : dialogState === 1 ? '填写信息' : '修改信息'"
|
:visible.sync="dialogVisible"
|
width="30%"
|
:before-close="handleClose"
|
>
|
<el-form ref="dialogform" :model="form" :rules="rules" label-width="60px" style="text-align:center;">
|
<el-form-item prop="group" label="数据组">
|
<el-select :disabled="disabled" filterable v-model="groupValue" placeholder="请选择" style="width:100%">
|
<el-option v-for="item in groupList" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item prop="key" label="代码">
|
<el-input :disabled="disabled" v-model="form.key"></el-input>
|
</el-form-item>
|
<el-form-item prop="value" label="名称">
|
<el-input :disabled="disabled" v-model="form.value"></el-input>
|
</el-form-item>
|
<el-form-item prop="comment" label="备注">
|
<el-input :disabled="disabled" v-model="form.comment" type="textarea"></el-input>
|
</el-form-item>
|
<el-form-item label-width="0">
|
<el-button type="primary" @click="onSubmit(form)">{{ dialogState === 1 ? $t('common.add') : $t('common.save') }}</el-button>
|
<el-button :style="disabled ? 'display:none' : ''" @click="dialogVisible = false">{{ $t('common.cancel') }}</el-button>
|
</el-form-item>
|
</el-form>
|
</el-dialog>
|
|
<pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchList" />
|
</div>
|
</template>
|
|
<script>
|
import { fetchList, add, deleteById, update, getById, fetchListByCode } from '@/api/datadictionary';
|
import { getGroupList } from '@/api/configgroup';
|
import Pagination from '@/components/Pagination';
|
import { getConfigData } from '@/api/serverconfig';
|
|
export default {
|
components: { Pagination },
|
data() {
|
return {
|
disabled: false,
|
total: 0,
|
list: [],
|
listQuery: {
|
searchname: '',
|
groupName: '',
|
searchValue:'',
|
page: 1,
|
limit: 10
|
},
|
dialogState: 1, //1:add, 2:edit
|
dialogVisible: false,
|
form: {
|
key: '',
|
value: '',
|
comment: '',
|
groupcode: ''
|
},
|
rules: {
|
key: [{ required: true, message: '代码不能为空', trigger: 'blur' }],
|
value: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
|
},
|
groupList: [],
|
groupValue: '',
|
groupListQuery: {
|
page: '',
|
limit: '',
|
searchname: ''
|
},
|
hasMore: true
|
};
|
},
|
mounted() {
|
this.fetchList();
|
this.getGroupList();
|
},
|
methods: {
|
handleView(id) {
|
this.handleEdit(id);
|
this.disabled = true;
|
},
|
async fetchList() {
|
const res = await fetchList(this.listQuery);
|
if (res && res.result) {
|
this.total = res.data.total;
|
this.list = res.data.list;
|
}
|
},
|
async getGroupList() {
|
const res = await getGroupList(this.groupListQuery);
|
if (res && res.result) {
|
const list = res.data.list.map(item => {
|
return {
|
value: item.groupcode,
|
label: item.groupname
|
};
|
});
|
|
if (!list.length) {
|
this.hasMore = false;
|
return;
|
}
|
|
this.groupList = this.groupList.concat(list);
|
}
|
},
|
loadMore() {
|
if (this.hasMore) {
|
this.groupListQuery.page++;
|
this.getGroupList();
|
}
|
},
|
async handleFilter() {
|
this.listQuery.page = 1;
|
this.fetchList();
|
|
// if (!this.listQuery.searchname) {
|
// this.fetchList();
|
// } else {
|
// const res = await fetchListByCode(this.listQuery);
|
// if (res && res.result) {
|
// this.total = res.data.total;
|
// this.list = res.data.list;
|
// }
|
// }
|
},
|
handleAdd() {
|
this.form = {
|
key: '',
|
value: '',
|
comment: '',
|
groupcode: ''
|
};
|
this.groupValue = '';
|
this.dialogState = 1;
|
this.dialogVisible = true;
|
},
|
async handleEdit(index, row) {
|
this.dialogState = 2;
|
this.form = deepClone(row);
|
|
const res = await getById(row.id);
|
if (res && res.result) {
|
const group = this.groupList.find(item => item.value === res.data.groupcode);
|
this.form.groupcode = group && group.value;
|
this.groupValue = group && group.value;
|
this.dialogVisible = true;
|
}
|
},
|
handleDelete(index, row) {
|
console.log(index, row);
|
const _this = this;
|
this.$confirm(this.$t('message.delete_confirm'), this.$t('common.tip'), {
|
confirmButtonText: this.$t('common.ok'),
|
cancelButtonText: this.$t('common.cancel'),
|
type: 'warning'
|
})
|
.then(() => {
|
deleteById(row.id).then(res => {
|
if (res.result) {
|
this.$message(this.$t('message.delete_success'), 'success');
|
this.fetchList();
|
this.updateConfigDataToStorage();
|
} else {
|
this.$message(this.$t('message.delete_fail'), 'error');
|
}
|
});
|
})
|
.catch(error => {});
|
},
|
handleClose(done) {
|
done();
|
},
|
onSubmit() {
|
this.$refs.dialogform.validate(valid => {
|
if (!valid) {
|
this.$message('填写的信息有误,请确认', 'error');
|
return;
|
}
|
|
this.form.groupcode = this.groupValue;
|
|
if (this.dialogState === 1) {
|
const data = Object.assign(this.form);
|
add(data)
|
.then(res => {
|
if (!res || !res.result) {
|
this.$message(res.errorMsg || this.$t('message.add_fail'), 'error');
|
return;
|
}
|
|
this.$message(this.$t('message.add_success'), 'success');
|
this.fetchList();
|
this.dialogVisible = false;
|
this.updateConfigDataToStorage();
|
})
|
.catch(error => {});
|
} else {
|
update(this.form)
|
.then(res => {
|
if (!res || !res.result) {
|
this.$message(res.errorMsg || this.$t('message.edit_fail'), 'error');
|
return;
|
}
|
this.$message(this.$t('message.edit_success'), 'success');
|
this.fetchList();
|
this.dialogVisible = false;
|
this.updateConfigDataToStorage();
|
})
|
.catch(error => {});
|
}
|
});
|
},
|
async updateConfigDataToStorage() {
|
localStorage.removeItem('configdata');
|
const response = await getConfigData();
|
if (response && response.result) {
|
const list = response.data.list;
|
localStorage.setItem('configdata', JSON.stringify(list));
|
}
|
}
|
}
|
};
|
</script>
|