<template>
|
<div ref="container">
|
<a-modal
|
:title="title"
|
:width="1000"
|
:visible="visible"
|
:confirmLoading="confirmLoading"
|
:getContainer="() => $refs.container"
|
:maskStyle="{'top':'93px','left':'154px'}"
|
:wrapClassName="wrapClassNameInfo()"
|
:mask="isDesktop()"
|
:maskClosable="false"
|
@ok="handleOk"
|
@cancel="handleCancel"
|
cancelText="关闭">
|
<template slot="footer">
|
<a-button key="back" @click="handleCancel">关闭</a-button>
|
</template>
|
<a-card :bordered="false">
|
<!-- 操作按钮区域 -->
|
<div class="table-operator">
|
<a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
|
</div>
|
<!-- table区域-begin -->
|
<div>
|
<a-table
|
ref="table"
|
size="middle"
|
bordered
|
rowKey="id"
|
:columns="columns"
|
:dataSource="dataSource"
|
:pagination="false"
|
:loading="loading">
|
<span slot="action" slot-scope="text, record">
|
<a @click="handleEdit(record)">编辑</a>
|
<a-divider type="vertical" />
|
<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
|
<a>删除</a>
|
</a-popconfirm>
|
</span>
|
<template slot="statusSlot" slot-scope="text">
|
<a-tag :color="text === 1 ? 'green' : 'orange'">
|
{{ text === 1 ? '启用' : '停用' }}
|
</a-tag>
|
</template>
|
</a-table>
|
</div>
|
<!-- table区域-end -->
|
</a-card>
|
|
<a-modal
|
:title="itemTitle"
|
:width="600"
|
:visible="itemVisible"
|
:confirmLoading="itemConfirmLoading"
|
@ok="handleItemOk"
|
@cancel="handleItemCancel"
|
cancelText="取消"
|
okText="保存">
|
<a-form :form="itemForm">
|
<a-form-item label="字典项文本" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-input placeholder="请输入字典项文本" v-decorator="['itemText', validatorRules.itemText]" />
|
</a-form-item>
|
<a-form-item label="字典项值" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-input placeholder="请输入字典项值" v-decorator="['itemValue', validatorRules.itemValue]" />
|
</a-form-item>
|
<a-form-item label="描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-textarea placeholder="请输入描述" v-decorator="['description']" :rows="2" />
|
</a-form-item>
|
<a-form-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-input-number placeholder="请输入排序" v-decorator="['sortOrder', {initialValue: 0}]" :min="0" style="width: 100%" />
|
</a-form-item>
|
<a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-radio-group v-decorator="['status', {initialValue: 1}]">
|
<a-radio :value="1">启用</a-radio>
|
<a-radio :value="0">停用</a-radio>
|
</a-radio-group>
|
</a-form-item>
|
</a-form>
|
</a-modal>
|
</a-modal>
|
</div>
|
</template>
|
|
<script>
|
import { mixinDevice } from '@/utils/mixin'
|
import { getAction, postAction, putAction, deleteAction } from '@/api/manage'
|
import pick from 'lodash.pick'
|
|
export default {
|
name: "SysDictItemModal",
|
mixins: [mixinDevice],
|
data () {
|
return {
|
title:"字典项管理",
|
visible: false,
|
model: {},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 5 },
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 },
|
},
|
confirmLoading: false,
|
loading: false,
|
dataSource: [],
|
|
// 字典项表单相关
|
itemTitle: "",
|
itemVisible: false,
|
itemConfirmLoading: false,
|
itemModel: {},
|
itemForm: this.$form.createForm(this),
|
validatorRules: {
|
itemText: {
|
rules: [{
|
required: true,
|
message: '请输入字典项文本!'
|
}]
|
},
|
itemValue: {
|
rules: [{
|
required: true,
|
message: '请输入字典项值!'
|
}]
|
}
|
},
|
|
// 表头
|
columns: [
|
{
|
title: '#',
|
dataIndex: '',
|
key:'rowIndex',
|
width:60,
|
align:"center",
|
customRender:function (t,r,index) {
|
return parseInt(index)+1;
|
}
|
},
|
{
|
title: '操作',
|
dataIndex: 'action',
|
width:120,
|
align:"center",
|
scopedSlots: { customRender: 'action' }
|
},
|
{
|
title: '文本',
|
align:"left",
|
dataIndex: 'itemText'
|
},
|
{
|
title: '值',
|
align:"left",
|
dataIndex: 'itemValue'
|
},
|
{
|
title: '描述',
|
align:"left",
|
dataIndex: 'description'
|
},
|
{
|
title: '排序',
|
align:"center",
|
dataIndex: 'sortOrder',
|
width: 80
|
},
|
{
|
title: '状态',
|
align:"center",
|
dataIndex: 'status',
|
width: 80,
|
scopedSlots: { customRender: 'statusSlot' }
|
}
|
]
|
}
|
},
|
methods: {
|
show (record) {
|
this.model = Object.assign({}, record)
|
this.visible = true
|
this.loadData()
|
},
|
loadData () {
|
this.loading = true
|
getAction(`/sysDict/items/${this.model.id}`).then((res) => {
|
if (res.code === 200) {
|
this.dataSource = res.data
|
}
|
this.loading = false
|
})
|
},
|
handleAdd () {
|
this.itemTitle = "新增字典项"
|
this.itemForm.resetFields()
|
this.itemModel = {}
|
this.itemVisible = true
|
},
|
handleEdit (record) {
|
this.itemTitle = "编辑字典项"
|
this.itemForm.resetFields()
|
this.itemModel = Object.assign({}, record)
|
this.itemVisible = true
|
this.$nextTick(() => {
|
this.itemForm.setFieldsValue(pick(this.itemModel,'itemText','itemValue','description','sortOrder','status'))
|
})
|
},
|
handleDelete (id) {
|
deleteAction(`/sysDict/item/${id}`).then((res) => {
|
if (res.code === 200) {
|
this.$message.success(res.msg)
|
this.loadData()
|
} else {
|
this.$message.warning(res.msg)
|
}
|
})
|
},
|
handleItemOk () {
|
const that = this
|
this.itemForm.validateFields((err, values) => {
|
if (!err) {
|
that.itemConfirmLoading = true
|
let formData = Object.assign(this.itemModel, values)
|
formData.dictId = this.model.id
|
let obj
|
if(!this.itemModel.id){
|
obj = postAction('/sysDict/item', formData)
|
}else{
|
obj = putAction('/sysDict/item', formData)
|
}
|
obj.then((res)=>{
|
if(res.code === 200){
|
that.$message.success(res.msg)
|
that.loadData()
|
that.itemVisible = false
|
}else{
|
that.$message.warning(res.msg)
|
}
|
}).finally(() => {
|
that.itemConfirmLoading = false
|
})
|
}
|
})
|
},
|
handleItemCancel () {
|
this.itemVisible = false
|
},
|
handleCancel () {
|
this.close()
|
},
|
close () {
|
this.$emit('close')
|
this.visible = false
|
}
|
}
|
}
|
</script>
|
|
<style lang="less" scoped>
|
.table-operator {
|
margin-bottom: 18px;
|
}
|
</style>
|