完善查询列表QueryList

This commit is contained in:
chenghx
2018-07-26 18:06:23 +08:00
parent c0f5e20a2a
commit 17e9e07162
2 changed files with 128 additions and 13 deletions

View File

@@ -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>
已选择&nbsp;<a style="font-weight: 600">{{selectedRows.length}}</a>&nbsp;&nbsp;&nbsp;
<template v-for="(item, index) in needTotalList" v-if="item.needTotal">
{{item.title}}总计&nbsp;
<a :key="index" style="font-weight: 600">
{{item.customRender ? item.customRender(item.total) : item.total}}
</a>&nbsp;&nbsp;
</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>