Commit f83d1a57 by 胡悦

修改

1 parent 34041902
......@@ -2,7 +2,7 @@
<template>
<div class="d2-table">
<el-table
:ref="tableParams.mutiSelectName + 'MutiTable' || 'mutiTable'"
:ref="tableParams.mutiSelectName + 'MutiTable' || 'MutiTable'"
:data="getListApi ? data : tableData"
:row-key="tableParams.mutiSelectUniqueKey || ''"
v-loading="loading"
......@@ -26,7 +26,7 @@
width="60px"
label="序号"
type='index'
:index="index=>index+(page.currentPage - 1) * page.pageSize + 1"
:index="index=>index+(page[this.pageConf.pageNum] - 1) * page[this.pageConf.pageSize] + 1"
></el-table-column>
<el-table-column
v-for="(item, index) in tableParams.tableColumns"
......@@ -93,16 +93,15 @@
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="page.currentPage"
:current-page="page[this.pageConf.pageNum]"
:page-sizes="[10,20,30,40]"
:page-size="page.pageSize"
:page-size="page[this.pageConf.pageSize]"
:total="getListApi ? total : tableTotal"
:layout="layout"
>
</el-pagination>
</div>
</template>
<script>
export default {
name: 'd2-table',
......@@ -111,10 +110,7 @@ export default {
loading: false,
data: [],
// 页码
page: {
pageSize: 10,
currentPage: 1
},
page: {},
total: 10,
// 排序
sortColum: '',
......@@ -123,7 +119,6 @@ export default {
mutiSelectArr: {}
}
},
props: {
// 搜索条件
searchForm: {
......@@ -135,7 +130,11 @@ export default {
type: Array,
default: () => []
},
tableTotal: {
// tableTotal: {
// type: Number,
// default: 0
// },
tableScore: {
type: Number,
default: 0
},
......@@ -158,6 +157,14 @@ export default {
type: Boolean,
default: true
},
pageConf: {
type: Object,
default: () => ({
pageSize: 'pageSize',
pageNum: 'pageNum',
totalCount: 'totalCount'
})
},
// 分页组件配置
layout: {
type: String,
......@@ -211,14 +218,14 @@ export default {
}
}
},
mounted() {
this.page = {}
this.page[this.pageConf.pageSize] = 10
this.page[this.pageConf.pageNum] = 1
const btn = document.getElementById(this.tableParams.btnId)
btn && btn.addEventListener('click', this.refreshEmit)
console.log(this.getListApi)
this.getListApi && this.refreshTable()
},
methods: {
// 排序
sortChange({ column, prop, order }) {
......@@ -226,31 +233,27 @@ export default {
this.sort = order
this.refreshTable()
},
// 多选
handleSelect(val) {
console.log(val)
this.mutiSelectArr[this.tableParams.mutiSelectName] = val
},
// 清空多选
clearMutiSelect() {
this.mutiSelectArr[this.tableParams.mutiSelectName] = []
this.$refs[this.tableParams.mutiSelectName + 'MutiTable'].clearSelection()
},
// 发布事件,以期查询条件改变后,页面图表需要刷新
refreshEmit() {
this.$emit('searchChange')
this.refreshTable(true, true)
},
refreshTable(clearMuti = true, resetCurrentPage = false) {
refreshTable(clearMuti = true, resetPageNum = false) {
this.beforeSearchFn().then(res => {
// console.log(res)
// 清空多选
clearMuti && this.clearMutiSelect()
this.loading = true
resetCurrentPage && (this.page.currentPage = 1)
resetPageNum && (this.page.pageNum = 1)
var params = {
...this.page,
...this.searchForm
......@@ -261,8 +264,9 @@ export default {
}
this.getListApi(params)
.then(res => {
this.data = res[this.tableParams.listName]
this.total = res.pagination.totalCount
this.data = this.findVal(res, this.tableParams.listName)
this.total = this.findVal(res, this.pageConf.totalCount)
this.$emit('sendAlldata', res.data)
this.loading = false
})
.catch(() => {
......@@ -270,18 +274,24 @@ export default {
})
})
},
// 找返回值
findVal(res, rankStr, attr) {
var rankList = rankStr.split('.')
if (!rankStr) {
return res
}
return this.findVal(res[rankList[0]], rankList.splice(1).join('.'), attr)
},
// 每页条数
handleSizeChange(value) {
this.page.pageSize = value
this.page[this.pageConf.pageSize] = value
this.getListApi
? this.refreshTable(false)
: this.$emit('refreshTable', this.page)
},
// 页码
handleCurrentChange(value) {
this.page.currentPage = value
this.page[this.pageConf.pageNum] = value
this.getListApi
? this.refreshTable(false)
: this.$emit('refreshTable', this.page)
......@@ -293,6 +303,9 @@ export default {
.a-click {
cursor: pointer;
}
.el-table {
margin-bottom: 16px;
}
.el-table .cell {
line-height: 14px;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!