完善查询列表QueryList
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
<template>
|
||||
<div class="standard-table">
|
||||
<div class="alert">
|
||||
<a-alert type="info">
|
||||
<a-alert type="info" :show-icon="true">
|
||||
<div slot="message">
|
||||
已选择<span></span>项
|
||||
服务调用总计<span></span>
|
||||
<a>清空</a>
|
||||
已选择 <a style="font-weight: 600">{{selectedRows.length}}</a> 项
|
||||
<template v-for="(item, index) in needTotalList" v-if="item.needTotal">
|
||||
{{item.title}}总计
|
||||
<a :key="index" style="font-weight: 600">
|
||||
{{item.customRender ? item.customRender(item.total) : item.total}}
|
||||
</a>
|
||||
</template>
|
||||
<a style="margin-left: 24px">清空</a>
|
||||
</div>
|
||||
</a-alert>
|
||||
</div>
|
||||
@@ -16,17 +21,65 @@
|
||||
:dataSource="dataSource"
|
||||
:rowKey="rowKey"
|
||||
:pagination="pagination"
|
||||
/>
|
||||
:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: updateSelect}"
|
||||
>
|
||||
</a-table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AAlert from 'vue-antd-ui/es/alert/index'
|
||||
import ATable from 'vue-antd-ui/es/table'
|
||||
|
||||
export default {
|
||||
name: 'StandardTable',
|
||||
components: {ATable, AAlert},
|
||||
props: ['bordered', 'loading', 'columns', 'dataSource', 'rowKey', 'pagination']
|
||||
props: ['bordered', 'loading', 'columns', 'dataSource', 'rowKey', 'pagination', 'selectedRows'],
|
||||
data () {
|
||||
return {
|
||||
needTotalList: [],
|
||||
selectedRowKeys: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
updateSelect (selectedRowKeys, selectedRows) {
|
||||
this.selectedRowKeys = selectedRowKeys
|
||||
let list = this.needTotalList
|
||||
this.needTotalList = list.map(item => {
|
||||
return {
|
||||
...item,
|
||||
total: selectedRows.reduce((sum, val) => {
|
||||
return sum + val[item.dataIndex]
|
||||
}, 0)
|
||||
}
|
||||
})
|
||||
this.$emit('change', selectedRowKeys, selectedRows)
|
||||
},
|
||||
initTotalList (columns) {
|
||||
const totalList = []
|
||||
columns.forEach(column => {
|
||||
if (column.needTotal) {
|
||||
totalList.push({...column, total: 0})
|
||||
}
|
||||
})
|
||||
return totalList
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.needTotalList = this.initTotalList(this.columns)
|
||||
},
|
||||
watch: {
|
||||
'selectedRows': function (selectedRows) {
|
||||
this.needTotalList = this.needTotalList.map(item => {
|
||||
return {
|
||||
...item,
|
||||
total: selectedRows.reduce((sum, val) => {
|
||||
return sum + val[item.dataIndex]
|
||||
}, 0)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user