<template>
<div v-if="alltable" class="table-template">
<div class="table-content">
<!-- 动态显示隐藏列功能 -->
<el-dropdown
v-if="selectColumns"
:hide-on-click="false"
class="el-dropdown-selectColumn"
trigger="click"
@visible-change="dropdownSelectShow"
>
<span title="显示或隐藏某列" class="dropdown-button">
<el-icon :size="16"><Menu /></el-icon>
</span>
<template #dropdown>
<el-dropdown-menu style="text-align: center">
<div class="dropdowntable" style="text-align: left">
<el-dropdown-item v-for="(item, index) in tableLabel" :key="index">
<template #default>
<el-checkbox
v-model="item.isShow"
:checked="item.isShow"
@change="reload"
>{{ item.label }}</el-checkbox>
</template>
</el-dropdown-item>
<el-dropdown-item v-if="tableCheckShow">
<template #default>
<el-checkbox
v-model="currTableOperationShow"
:checked="currTableOperationShow"
@change="reload"
>操作</el-checkbox>
</template>
</el-dropdown-item>
</div>
</el-dropdown-menu>
</template>
</el-dropdown>
<div class="table-main">
<el-table
ref="multipleTable"
v-loading="loading"
:data="tableData"
:row-key="rowKey"
border
:default-expand-all="defaultExpandAll"
:highlight-current-row="highlightCurrentRow"
:tree-props="treeProps"
:height="height"
:expand-row-keys="expandRowKeys"
:span-method="spanMethod"
@selection-change="selectionChange"
@row-click="rowClick"
@row-dblclick="rowdbClick"
>
<!--选择-->
<el-table-column
v-if="selectionShow"
type="selection"
align="center"
fixed="left"
:width="selectionWidth"
:selectable="selectStatus"
:reserve-selection="reserveSelection"
/>
<el-table-column
v-if="radioShow && !selectionShow"
:align="radioAlign"
:width="radioWidth"
>
<template #default="scope">
<el-radio
v-model="radioVal"
:label="scope.row[rowKey]"
:disabled="scope.row.radioStatus"
@change="getRow(scope.row)"
>
<span />
</el-radio>
</template>
</el-table-column>
<!--序号 自定义列序号-->
<el-table-column
v-if="indexShow"
type="index"
align="center"
label="序号"
fixed="left"
:width="indexWidth"
>
<template #dafault="scope">
<span>{{ (nowPage - 1) * pageSize + scope.$index + 1 }}</span>
</template>
</el-table-column>
<!-- 表格数据列 -->
<template v-for="(item, index) in tableLabel">
<el-table-column
v-if="selectColumns ? item.isShow || !isshowShow : true"
:key="index"
:prop="item.prop"
:width="item.width"
:min-width="item.minWidth"
:fixed="item.fixed"
:formatter="item.formatter"
:align="item.align ? item.align : 'center'"
:label="item.label"
:show-overflow-tooltip="toolTip"
>
<template #default="scope">
<div v-if="item.isSelfContent">
<slot :scope="scope" :name="item.prop"></slot>
</div>
</template>
</el-table-column>
</template>
<!--操作-->
<el-table-column
v-if="currTableOperationShow"
:width="operationColumnWidth"
label="操作"
:align="operationAlign"
fixed="right"
>
<template #default="scope">
<el-button
v-if="addShow"
size="small"
type="success"
title="新增"
text
@click="handleAdd(scope.row)"
>新增</el-button>
<el-button
v-if="classifyAddShow && scope.row.children.length"
size="small"
type="success"
text
title="新增"
@click="handleAdd(scope.row)"
>新增</el-button>
<el-button
v-if="editShow"
size="small"
type="primary"
text
title="编辑"
:disabled="scope.row.shareHolderStatus === 0"
@click="handleEdit(scope.row)"
>编辑</el-button>
<el-button
v-if="detailShow"
size="small"
text
type="success"
title="详情"
@click="handleDetail(scope.row)"
>详情</el-button>
<el-button
v-if="deleteShow"
type="danger"
text
title="删除"
size="small"
@click="handleDelete(scope.row, scope.$index)"
>删除</el-button>
<slot :row="scope.row" :index="scope.$index" />
</template>
</el-table-column>
</el-table>
</div>
</div>
<div>
<!-- 自定义总计列,展示在表格内容下方,分页按钮上方 -->
<slot name="totalContent"></slot>
<div class="pagination-container">
<el-pagination
v-if="paging"
background
:current-page="nowPage"
:page-size="pageSize"
:page-sizes="pageSizes"
layout="total, sizes, prev, pager, next, jumper"
:total="totalSize"
@size-change="sizeChange"
@current-change="currentChange"
/>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import {ColumProps} from './types'
import { PropType, reactive, toRefs, nextTick } from "vue"
import {
Check,
Delete,
Edit,
Tickets,
Menu
} from '@element-plus/icons-vue'
const props = defineProps({
//自定义列内容,比如加链接,加tag,加switch等
isSelfContent:{
type: Boolean,
default: false,
},
// 是否显示动态列功能,默认显示
selectColumns: {
type: Boolean,
default: true,
},
// 表头列数据
tableLabel: {
type: Array as PropType<ColumProps[]>,
required: true,
default: () => {
return []
}
},
// 表格没有操作列时,动态勾选的页面也没有操作勾选框
tableCheckShow: {
type: Boolean,
required: false,
default: true
},
// 表格最后操作列是否显示
tableOperationShow: {
type: Boolean,
required: false,
default: true
},
//加载中
loading: {
type: Boolean,
default: false
},
// 表格数据
tableData: {
type: Array,
required: true,
default: () => {
return []
}
},
// 行数据的key
rowKey: {
type: String,
default: 'id'
},
// 树结构表格是否默认打开
defaultExpandAll: {
type: Boolean,
default: false
},
// 是否高亮显示某行
highlightCurrentRow: {
type: Boolean,
default: true
},
// 树形表格渲染嵌套数据的配置选项{ hasChildren: 'hasChildren', children: 'children' }
treeProps: {
type: Object,
default: () => {
return {}
}
},
// 表格高度
height: {
type: [Number, String],
default: '100%'
},
// 默认展开key数组
expandRowKeys: {
type: Array,
default: () => {
return []
}
},
//合并行单元格的列数组
columnList:{
type: Array,
default: () => {
return []
}
},
// 单选按钮的默认值
radioValue: {
type: [Number, String],
default: -1
},
// 多选按钮,默认不显示多选
selectionShow: {
type: Boolean,
default: false
},
// 多选宽度
selectionWidth: {
type: Number,
required: false,
default: 50
},
// 数据更新后是否保留选择数据,仅对type=selection有效
reserveSelection: {
type: Boolean,
default: false
},
// 单选 使用单选应将多选置为false
radioShow: {
type: Boolean,
default: false
},
// 单选对齐
radioAlign: {
type: String,
default: 'center'
},
// 单选宽度
radioWidth: {
type: Number,
required: false,
default: 35
},
// 序号列
indexShow: {
type: Boolean,
default: true
},
// 序号宽度
indexWidth: {
type: Number,
required: false,
default: 55
},
// 当前页
nowPage: {
type: Number,
default: 1
},
// 每页显示的条数
pageSize: {
type: Number,
default: 10
},
// 总条数
totalSize: {
type: Number,
default: 0
},
// 是否显示分页
paging: {
type: Boolean,
default: true
},
// 是否控制列的动态显示 默认控制
isshowShow: {
type: Boolean,
default: true
},
// 单元格内容超出宽度时是否...显示
toolTip: {
type: Boolean,
default: true
},
// 表格操作列宽度
operationColumnWidth: {
type: Number,
required: false,
default: 80
},
// 操作按钮对其方式
operationAlign: {
type: String,
default: 'center'
},
// 显示详情操作按钮
detailShow: {
type: Boolean,
default: false
},
// 显示编辑操作按钮
editShow: {
type: Boolean,
default: true
},
// 显示新增操作按钮
addShow: {
type: Boolean,
default: false
},
// 显示删除操作按钮
deleteShow: {
type: Boolean,
default: false
},
classifyAddShow: {
type: Boolean,
default: false
},
pageSizes: {
type: Array as PropType<number[]>,
default: () => {
return [5, 10, 15, 20, 30, 50]
}
}
})
const data = reactive({
alltable:true,
currTableOperationShow:props.tableOperationShow,
radioVal: props.radioValue,
})
const {alltable, currTableOperationShow, radioVal} = toRefs(data)
const emit = defineEmits(["selectionChange",'rowClick','rowdbClick','giveTableRowData','handleDetail','handleEdit','handleAdd','handleDelete','currentChange','sizeChange'])
// 是否显示列的下拉框
function dropdownSelectShow(val:Boolean) {
if (val === true) {
var mo = (e:any) => {
e.preventDefault()
}
document.body.style.overflow = 'hidden'
document.addEventListener('touchmove', mo, false) // 禁止页面滑动
}
}
// 重新渲染
function reload() {
data.alltable = false
nextTick(() => {
data.alltable = true
})
}
// 多选checkbox
function selectionChange(val:object[]) {
emit('selectionChange', val)
}
//单击行
function rowClick(row:any,column:any, event:any) {
emit('rowClick', row)
if (!row.radioStatus) {
data.radioVal = row[props.rowKey]
}
}
// 双击行
function rowdbClick(row:any, column:any, event:any) {
emit('rowdbClick', row)
}
// 多选时是否禁用选择框,适用情形:从某个表格选择多条数据到另一个表格,已选过的数据不能再被选择,否则key重复
function selectStatus(row:any, index:number) {
if (row.checkStatus) {
return false
} else {
return true
}
}
// 单选radio
function getRow(row:any) {
emit('giveTableRowData', row)
}
//合并列单元格
function spanMethod({row,columnIndex}:any){
const i = props.columnList.findIndex(v => v === columnIndex)
if(i !== -1){
return {
rowspan: row.rowSpan,
colspan: 1,
}
}else{
return {
rowspan: 1,
colspan: 1,
}
}
}
// 查看详情
function handleDetail(row:any) {
emit('handleDetail', row)
}
// 编辑
function handleEdit(row:any) {
emit('handleEdit', row)
}
// 新增
function handleAdd(row:any) {
emit('handleAdd', row)
}
// 删除
function handleDelete(row:any, index:number) {
emit('handleDelete', row, index)
}
// 表格翻页
function currentChange(current:number) {
emit('currentChange', current)
}
// 改变每页的条数
function sizeChange(size:number) {
emit('sizeChange', size)
}
</script>
<style lang="scss" scoped>
.table-template{
height: 100%;
position: relative;
display: flex;
flex-direction: column;
.table-content{
flex:auto;
position:relative;
.table-main{
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
.el-button+.el-button{
margin-left:0px;
}
}
}
.el-dropdown-selectColumn {
position: relative;
float: right;
z-index:999;
// background-color: red;
.dropdown-button {
cursor: pointer;
position: absolute;
z-index: 9999;
top: 5px;
left: -20px;
}
.dropdowntable {
width: 100%;
max-height: 200px !important;
overflow: auto !important;
}
}
.selectColumn {
margin-bottom: 10px;
height: auto;
}
:deep(.pagination-container) {
float:right;
padding-top:5px;
.el-pagination button, .el-pagination span:not([class*=suffix]) {
font-size: 13px;
min-width: 30px;
height: 28px;
line-height: 28px;
}
.el-pagination.is-background .btn-next, .el-pagination.is-background .btn-prev, .el-pagination.is-background .el-pager li {
min-width: 30px;
border-radius: 2px;
margin: 0 5px;
}
.el-pagination .btn-next, .el-pagination .btn-prev {
background-size: 16px;
}
.el-pagination__jump {
margin-left: 24px;
}
.el-pagination__goto {
margin-right:0px;
}
.el-pager li {
padding: 0 4px;
font-size: 13px;
height: 26px;
line-height: 26px;
}
.el-pagination .el-select .el-input {
width: 100px;
height:28px;
}
.el-pagination .el-input__inner {
height:26px;
}
.el-pagination .is-first {
margin-right:0px;
height:26px!important;
line-height: 30px!important;
}
}
}
</style>
<template>
<TableTemplate
:loading="loading"
:table-data="tableData.list"
:table-label="tableLabel"
:span-method="columnList"
:now-page="tableData.currPage"
:page-size="tableData.pageSize"
:total-size="tableData.totalCount"
:detail-show="false"
:edit-show="false"
:tableOperationShow="false"
:highlight-current-row="true"
row-key="chargeId"
@currentChange="handleCurrentChange"
@sizeChange="handleSizeChange"
>
<template #totalContent>
<div class="total-container">
<div>充电量(kw.h):{{ countData.electricQuantity || 0 }}</div>
<div>应付总额:{{ countData.totalMoney || 0 }} 元</div>
<div>结算总额:{{ countData.closeMoney || 0 }} 元</div>
<div>优惠总额:{{ countData.discountMoney || 0 }} 元</div>
</div>
</template>
</TableTemplate>
</template>
<script setup lang="ts">
import { reactive } from "vue";
import { storeToRefs } from "pinia";
import TableTemplate from "@/components/TableTemplate/index.vue";
import carCardPayDetailStore from "@/store/modules/order/carCardPayDetail";
const store = carCardPayDetailStore();
const { loading, tableData, countData } = storeToRefs(store);
const { searchForm } = store;
const tableLabel = reactive([
{
label: "日期",
prop: "dates",
isShow: true,
minWidth: 90,
},{
label: "会员姓名",
prop: "memberName",
isShow: true,
minWidth: 100,
},{
label: "手机号",
prop: "memberMobile",
isShow: true,
minWidth: 100,
},{
label: "VIN号",
prop: "vin",
isShow: true,
minWidth: 140,
},{
label: "车牌号",
prop: "licensePlate",
isShow: true,
minWidth: 90,
}, {
label: "充电量(kw.h)",
prop: "electricQuantity",
isShow: true,
minWidth: 90,
},
{
label: "应付金额(¥)",
prop: "totalMoney",
isShow: true,
minWidth: 90,
},
{
label: "优惠金额(¥)",
prop: "discountMoney",
isShow: true,
minWidth: 90,
}, {
label: "预付金额(¥)",
prop: "prepayMoney",
isShow: true,
minWidth: 90,
},
{
label: "结算金额(¥)",
prop: "closeMoney",
isShow: true,
minWidth: 90,
},
{
label: "所属公司1",
prop: "value1",
isShow: true,
minWidth: 90,
},
{
label: "所属公司2",
prop: "value2",
isShow: true,
minWidth: 90,
},
{
label: "所属公司3",
prop: "value3",
isShow: true,
minWidth: 90,
},
{
label: "所属公司4",
prop: "value4",
isShow: true,
minWidth: 90,
},
{
label: "所属公司5",
prop: "value5",
isShow: true,
minWidth: 90,
},
{
label: "所属公司6",
prop: "value6",
isShow: true,
minWidth: 90,
},
{
label: "所属公司",
prop: "company",
isShow: true,
minWidth: 100,
},
{
label: "所属站点",
prop: "siteName",
isShow: true,
minWidth: 100,
}
]);
const columnList = [12,13,14,15,16]
// 改变当前页
function handleCurrentChange(val: number) {
searchForm.nowPage = val;
store.getTableData(searchForm);
}
// 改变当前显示条数
function handleSizeChange(val: number) {
searchForm.nowPage = 1;
searchForm.pageSize = val;
store.getTableData(searchForm);
}
</script>
请帮我修改代码:span-method第12列到16列需要合并
最新发布