<template>
<div>
<el-table
v-loading="isShowLoading"
element-loading-text="拼命加載中"
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(f, f, f, 0.8)"
:data="list"
border
fit
highlight-current-row
style="width: 100%"
height="calc(100% - 50px)"
stripe
:header-cell-style="{'text-align':'center'}"
>
<el-table-column align="center" label="序號(hào)" width="100">
<template slot-scope="scope">
<!-- (當(dāng)前頁(yè) - 1) * 當(dāng)前顯示數(shù)據(jù)條數(shù) + 當(dāng)前行數(shù)據(jù)的索引 + 1 -->
<span>{{ (currentPage - 1) * pageSize + scope.$index + 1 }}</span>
</template>
</el-table-column>
<!-- 表格 -->
<el-table-column v-for="(item,index) in headList" :key="index" :align="item.align" :label="item.label">
<template slot-scope="scope">
<span>{{ scope.row[item.data] }}</span>
</template>
</el-table-column>
<!-- <el-table-column v-if="totalList.length>1" align="right" label="合計(jì)">
<template slot-scope="{row}">
<span>{{ calculationAdd(row) }}</span>
<span />
</template>
</el-table-column> -->
<!-- <el-table-column v-if="isShowScale" align="right" label="比例">
<template slot-scope="{row}">
<span>{{ scale(row) }}%</span>
<span />
</template>
</el-table-column> -->
<el-table-column v-if="isShowCaozuo" align="center" label="操作">
<template slot-scope="scope">
<el-button type="text" size="small" @click="handleClick(scope.row)">點(diǎn)擊查看詳情</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分頁(yè) -->
<el-pagination
class="pagination"
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper"
:current-page="currentPage"
:page-size="pageSize"
:total="total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</template>
<script>
export default {
filters: {
},
props: {
isShowLoading: {
type: Boolean
},
isShowCaozuo: {
type: Boolean
},
// isShowScale: {// 是否顯示比例
// type: Boolean
// },
headList: { // 父組件傳遞過來的表頭數(shù)據(jù)
type: Array,
default: () => {
return []
}
},
list: { // 父組件傳遞過來的表格數(shù)據(jù)
type: Array,
default: () => {
return []
}
},
totalList: { // 父組件傳遞過來的表格數(shù)據(jù),用于計(jì)算合計(jì)
type: Array,
default: () => {
return []
}
},
total: { // 總頁(yè)數(shù)
type: Number,
default: 0
},
currentPage: { // 當(dāng)前頁(yè)
type: Number,
default: 1
},
pageSize: { // 每頁(yè)顯示條數(shù)
type: Number,
default: 10 // 默認(rèn)10條
}
},
data() {
return {
iPageSize: this.pageSize,
iCurrentPage: this.currentPage,
iTotal: this.total,
tableTotal: []
}
},
computed: {},
watch: {
pagination: { // 監(jiān)聽器
deep: true,
handler(v) {
if (!v) {
return
}
const { pageSize, total, currentPage } = v
this.iPageSize = pageSize
this.iTotal = total
this.iCurrentPage = currentPage
}
}
},
created() { },
mounted() { },
methods: {
// 通訊
handleClick(row, column, event, cell) {
this.$emit('handleClick', row)
},
// 每頁(yè)展示條數(shù)
handleSizeChange(val) {
this.$emit('handleSizeChangeSub', val)
},
// 當(dāng)前頁(yè)
handleCurrentChange(val) {
this.$emit('handleCurrentChangeSub', val)
}
// // 合計(jì)
// calculationAdd(row) {
// return this.totalList.map((key) => row[key]).reduce((a, b) => a + b, 0)
// }
// 比例
// scale(row) {
// const num = row.todayRegisteredVisitsCount / row.todayTotalVisitsCount
// return Math.floor(num * 10000) / 100
// }
}
}
</script>
<style lang="scss" scoped>
.pagination {
margin-top: 20px;
}
// .assets-table /deep/.el-table__body-wrapper {
// height: calc(100% - 55px) !important;
// }
.cell>span{
white-space:nowrap;
}
</style>
封裝table表格+分頁(yè),動(dòng)態(tài)渲染表頭
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門奔垦,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人尸疆,你說我怎么就攤上這事椿猎。” “怎么了寿弱?”我有些...
- 文/不壞的土叔 我叫張陵犯眠,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我症革,道長(zhǎng)筐咧,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任噪矛,我火速辦了婚禮量蕊,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘艇挨。我一直安慰自己残炮,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布缩滨。 她就那樣靜靜地躺著势就,像睡著了一般泉瞻。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上苞冯,一...
- 文/蒼蘭香墨 我猛地睜開眼烘贴,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼禁添!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起桨踪,我...
- 序言:老撾萬榮一對(duì)情侶失蹤老翘,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后锻离,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體铺峭,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年汽纠,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了卫键。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站服协,受9級(jí)特大地震影響绍昂,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜偿荷,卻給世界環(huán)境...
- 文/蒙蒙 一治专、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧遭顶,春花似錦张峰、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)撩荣。三九已至,卻和暖如春饶深,著一層夾襖步出監(jiān)牢的瞬間餐曹,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓俱两,卻偏偏與公主長(zhǎng)得像饱狂,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子宪彩,可洞房花燭夜當(dāng)晚...