Files
laws-sinotruk-client/src/components/selection/TreeSelectModal.vue
T

297 lines
8.1 KiB
Vue

<template>
<j-modal
:title="$t('userSelect.select')"
:width="width"
:visible="visible"
switchFullscreen
:maskClosable="false"
:confirmLoading="confirmLoading"
@ok="handleOk"
@cancel="handleCancel">
<div class="modal-search-wrapper table-page-search-wrapper">
<a-form layout="inline" @keyup.enter.native="searchQuery">
<a-row :gutter="24">
<a-col :span="10">
<a-form-item :label="$t('treeSelection.primaryNodeName')" :labelCol="labelCol" :wrapperCol="wrapperCol">
<j-input :placeholder="$t('pleaseEnter') + $t('treeSelection.primaryNodeName')" v-model="queryParam.itemText" />
</a-form-item>
</a-col>
<a-col :span="8">
<span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 8px">
{{ $t('query') }}
</a-button>
<a-button type="primary" @click="searchReset" icon="reload" ghost>{{ $t('reset') }}</a-button>
</span>
</a-col>
</a-row>
</a-form>
</div>
<div class="modal-content">
<a-table
:columns="columns"
rowKey="code"
bordered
:scroll="{x: '100%'}"
:data-source="dataSource"
:pagination="ipagination"
:row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: type }"
:loading="confirmLoading"
:childrenColumnName="['childPartNameList']"
@change="handleTableChange">
<template slot="text" slot-scope="text">
<a-tooltip overlay-class-name="tooltip-style">
<template slot="title">{{ text || text === 0 ? text : global.emptyLine }}</template>
<div class="table-text">{{ text || text === 0 ? text : global.emptyLine }}</div>
</a-tooltip>
</template>
</a-table>
</div>
<p class="modal-content-title">{{ $t('treeSelection.selectedData') }}</p>
<div v-if="dataSourceRight && dataSourceRight.length > 0" class="name-content">
<div v-for="(item, index) in dataSourceRight" :key="item.code" class="name-div">
{{ item.itemText }}
<a-icon type="close" @click="handleDelete(item, index)" />
</div>
</div>
<a-empty v-else />
</j-modal>
</template>
<script>
import { getAction } from '../../api/manage'
import { getDictByCode } from '../../api/api'
export default {
name: 'TreeSelectModal',
props: {
dictId: {
type: String,
required: false,
default: ''
},
type: {
type: String,
required: false,
default: 'checkbox'
},
// 是否校验必选
checkRequired: {
type: Boolean,
required: false,
default: false
},
// 获取数据的接口
optionsHref: {
type: String,
required: false,
default: ''
}
},
data () {
return {
width: 800,
visible: false,
confirmLoading: false,
queryParam: {},
labelCol: {
span: 8
},
wrapperCol: {
span: 16
},
dataSourceRight: [],
filters: {},
/* 分页参数 */
ipagination: {
current: 1,
pageSize: 5,
pageSizeOptions: ['5', '10', '20', '30', '100', '200'],
showTotal: (total, range) => {
return range[0] + '-' + range[1] + ' ' + this.$t('total') + total + this.$t('strip')
},
showQuickJumper: true,
showSizeChanger: true,
total: 0
},
columns: [
{
title: this.$t('system.tag.name'),
dataIndex: 'name'
}
],
dataSource: [],
selectedRowKeys: []
}
},
methods: {
open (values) {
this.visible = true
this.selectedRowKeys = values ? values.split(',') : []
this.loadData(1)
this.getSelectedList(values)
},
handleCancel () {
this.visible = false
},
close () {
this.visible = false
this.visible = false
this.dataSourceRight = []
this.selectedRowKeys = []
this.queryParam = {}
this.ipagination = {
current: 1,
pageSize: 5,
pageSizeOptions: ['5', '10', '20', '30', '100', '200'],
showTotal: (total, range) => {
return range[0] + '-' + range[1] + ' ' + this.$t('total') + ' ' + total + ' ' + this.$t('strip')
},
showQuickJumper: true,
showSizeChanger: true,
total: 0
}
},
searchQuery () {
this.loadData(1)
},
searchReset () {
this.queryParam = {}
this.loadData(1)
},
loadData (arg) {
if (arg) {
this.ipagination.current = 1
}
this.confirmLoading = true
const params = Object.assign({}, this.queryParam, this.filters)
params.pageNo = this.ipagination.current
params.pageSize = this.ipagination.pageSize
getAction(this.optionsHref, params).then(res => {
if (res.success) {
this.dataSource = res.result.records || res.result
if (res.result.total) {
this.ipagination.total = res.result.total
} else {
this.ipagination.total = 0
}
}
}).finally(() => {
this.confirmLoading = false
})
},
onSelectChange (selectedRowKeys, selectedRows) {
this.selectedRowKeys = selectedRowKeys
if (this.type === 'checkbox') {
if (selectedRowKeys.length > this.dataSourceRight.length) {
// 说明是增加了数据
for (const rowIndex in selectedRows) {
if (!this.dataSourceRight.find(item => item.code === selectedRows[rowIndex].code)) {
// 右侧不存在,追加到右侧表格
this.dataSourceRight.push(selectedRows[rowIndex])
}
}
} else {
// 说明是删除了数据
if (selectedRowKeys && selectedRowKeys.length > 0) {
// 没有选中数据,说明这一页没有选中数据了
for (let i = 0; i < this.dataSourceRight.length; i++) {
if (!selectedRowKeys.find(item => item === this.dataSourceRight[i].code)) {
// 表格选中中没有找到这一条数据,说明已经被删了
this.dataSourceRight.splice(i, 1)
i--
}
}
} else {
this.dataSourceRight = []
}
}
} else {
this.dataSourceRight = selectedRows
}
},
handleTableChange (pagination) {
this.ipagination = pagination
this.loadData()
},
// 名字列表的删除
handleDelete (record, index) {
this.dataSourceRight.splice(index, 1)
this.selectedRowKeys = this.selectedRowKeys.filter(item => item !== record.code)
},
handleOk () {
if (this.checkRequired && (!this.selectedRowKeys || this.selectedRowKeys.length === 0)) {
this.$message.warning(this.$t('selectLeastOne'))
return
}
this.$emit('nameChange', this.dataSourceRight.map(item => item.name).join(','))
this.$emit('change', this.selectedRowKeys.filter(tt => !!tt).join(','))
this.close()
},
getSelectedList (codes) {
getDictByCode({ codes }).then(res => {
if (res.success) {
this.dataSourceRight = res.result || []
}
})
}
}
}
</script>
<style scoped lang="less">
.modal-content {
width: 100%;
display: flex;
justify-content: space-between;
&-left {
width: 58%;
}
&-right {
width: 40%;
}
&-title-div {
display: flex;
align-items: center;
height: 28px;
margin: 20px 0;
.modal-content-title {
color: #1D2129;
font-weight: 500;
margin-right: 12px;
margin-bottom: 0;
}
}
}
.name-content {
display: flex;
flex-wrap: wrap;
.name-div {
width: auto;
padding: 5px 16px;
margin-right: 12px;
margin-top: 8px;
background: rgba(213, 44, 38, 0.08);
border-radius: 4px 4px 4px 4px;
opacity: 1;
color: @primary-color;
white-space: nowrap;
/deep/ .anticon {
margin-left: 4px;
}
}
}
/deep/ .ant-form-item-label {
min-width: 70px !important;
}
</style>