赞
踩
第一种:后端传过来的数据是线性结构,用饿了么的span-method属性来做
后端给的数据格式:
主要代码 : 给el-table加上span-method="objectSpanMethod"
html:
- <el-table :data="tableData" :header-cell-style="{ background: '#EFF3F7', height: '50px', color: ' #4D4D4D', fontSize: '14px' }" :cell-style="{ fontSize: '14px' }" border :span-method="objectSpanMethod">
- <!-- 序号 -->
- <el-table-column label="序号" width="80" align="center" prop="sequenceNo">
- </el-table-column>
- <el-table-column prop="sequenceNo" align="center" label="托盘/电瓶车编号">
- <template slot-scope="{row}">
- {{ row.carrierCode }}
- </template>
- </el-table-column>
- <el-table-column prop="containerImage,tireModel,containerCapacity" header-align="center" label="轮胎型号" width="350">
- <template slot-scope="{row}">
- <div style="display:flex;align-items: center;">
- <el-image
- style="height: 33px;"
- :src="row.containerImage"
- :preview-src-list="[row.containerImage]"
- fit="contain"></el-image>
- <div style="margin-left:10px">
- {{ row.tireModel }}-{{ row.containerCapacity }}条
- </div>
- </div>
- </template>
- </el-table-column>
- <el-table-column prop="actualCapacity,carrierCapacity" align="center" label="箱/袋数">
- <template slot-scope="{row}">
- <div>
- {{ row.actualCapacity }}/{{ row.carrierCapacity }}
- </div>
- </template>
- </el-table-column>
- <el-table-column prop="sequenceNo" align="center" label="仓库">
- <template slot-scope="{row}">
- {{ row.warehouseName }}
- </template>
- </el-table-column>
- <el-table-column prop="sequenceNo" align="center" label="分拣人/分拣线" width="250">
- <template slot-scope="{row}">
- <div>
- {{ row.sorter }} {{ row.sortingLine }}号
- </div>
- </template>
- </el-table-column>
- <el-table-column prop="sequenceNo" align="center" label="入库时间">
- <template slot-scope="{row}">
- {{ row.inboundTime }}
- </template>
- </el-table-column>
- <!-- <el-table-column prop="remainingQuantity" align="center" label="状态">
- </el-table-column> -->
- <el-table-column align="center" label="操作" prop="sequenceNo">
- <template slot-scope="{row}">
- <el-button type="text" size="small" style="color: #1156B2;"
- v-if="row.carrierType==2"
- @click="toPath('/putStorage/info',{carrierCode:row.carrierCode})">详情
- </el-button>
- </template>
- </el-table-column>
- </el-table>
js:
- var this_;
- export default {
- data() {
- return {
- mergeObj: {},
- mergeArr: ['sequenceNo'],
- tableData: [],
- }
- },
- mounted() {
- this_=this
- this_.init()
- },
- methods: {
- init(){
- let params={
- ...this_.page,
- status:this_.activeName,
- ...this_.searchForm
- }
- if (this_.activeName=='2') {
- delete params['status']
- }
- if (this_.searchForm.time && this_.searchForm.time.length > 0) {
- params['inboundTimeFrom'] = this_.searchForm.time[0] + ' 00:00:00';
- params['inboundTimeTo'] = this_.searchForm.time[1] + ' 23:59:59';
- delete params.time
- }
- delete params.total
-
- get_request(url,params).then((res) => {
- if(res.data.code==0){
- let {current,size,total}=res.data.data
- this_.page={current,size,total}
- this_.tableData=res.data.data.records
- this.getSpanArr(res.data.data.records);
- }
- }).catch(() => { })
- },
- getSpanArr(data) {
- this.mergeArr.forEach((key, index1) => {
- let count = 0; // 用来记录需要合并行的起始位置
- this.mergeObj[key] = []; // 记录每一列的合并信息
- data.forEach((item, index) => {
- // index == 0表示数据为第一行,直接 push 一个 1
- if(index === 0) {
- this.mergeObj[key].push(1);
- } else {
- // 判断当前行是否与上一行其值相等 如果相等 在 count 记录的位置其值 +1 表示当前行需要合并 并push 一个 0 作为占位
- if(item[key] === data[index - 1][key]) {
- this.mergeObj[key][count] += 1;
- this.mergeObj[key].push(0);
- } else {
- // 如果当前行和上一行其值不相等
- count = index; // 记录当前位置
- this.mergeObj[key].push(1); // 重新push 一个 1
- }
- }
- })
- })
- },
- objectSpanMethod({ row, column, rowIndex, columnIndex }) {
- // 判断列的属性
- if(this.mergeArr.indexOf(column.property) !== -1) {
- // 判断其值是不是为0
- if(this.mergeObj[column.property][rowIndex]) {
- return [this.mergeObj[column.property][rowIndex], 1]
- } else {
- // 如果为0则为需要合并的行
- return [0, 0];
- }
- }
- },
- },
- }
第二种:后端传过来的数据是树形结构,主要用css来做
效果:
后端给的数据格式:
代码:
html:
- <el-table :data="tableData" :header-cell-style="{ background: '#EFF3F7', height: '50px', color: ' #4D4D4D', fontSize: '14px' }" :cell-style="{ fontSize: '14px' }" border>
- <!-- 序号 -->
- <el-table-column label="序号" width="80" align="center" type="index">
- </el-table-column>
- <el-table-column prop="carrierCodeNew" align="center" label="新托盘编码">
- </el-table-column>
- <el-table-column prop="carrierCodeOld" align="center" label="原托盘编码">
- </el-table-column>
- <el-table-column prop="changeDetailList" align="center" label="轮胎型号">
- <template slot-scope="{row}">
- <div v-for="(item,index) in row.changeDetailList" :key="index"
- :class="row.changeDetailList.length > 0 && index != 0 ? 'hxwd_table_item_left' : 'hxwd_table_item_left_first'">
- <el-image
- style="height: 33px;"
- :src="item.containerImage"
- :preview-src-list="[item.containerImage]"
- fit="contain"></el-image>
- <div style="margin-left:10px">
- {{ item.goodsModel }}-{{ item.capacity }}条
- </div>
- </div>
- </template>
- </el-table-column>
- <el-table-column prop="changeDetailList" align="center" label="条数">
- <template slot-scope="{row}">
- <div v-for="(item,index) in row.changeDetailList" :key="index"
- :class="row.changeDetailList.length > 0 && index != 0 ? 'hxwd_table_item_center' : 'hxwd_table_item_center_first'">
- {{ item.goodsCnt }}
- </div>
- </template>
- </el-table-column>
- <el-table-column prop="warehouseCode" align="center" label="仓库">
- </el-table-column>
- <el-table-column prop="createdTime" align="center" label="更换时间">
- </el-table-column>
- </el-table>
css:
.hxwd_table_item_center_first .hxwd_table_item_center 表格内容居中
.hxwd_table_item_left_first .hxwd_table_item_left 表格内容居左
- .hxwd_table_item_center_first {padding-left: 10px;margin-left: -10px;margin-right: -10px;padding-right: 10px;min-height: 50px;display: flex;align-items: center;justify-content: center;}
- .hxwd_table_item_center {padding-left: 10px;margin-left: -10px;margin-right: -10px;padding-right: 10px;min-height: 50px;display: flex;align-items: center;justify-content: center;border-top: 1px solid #EAEAEA;}
- .hxwd_table_item_left_first {padding-left: 10px;margin-left: -10px;margin-right: -10px;padding-right: 10px;min-height: 50px;display: flex;align-items: center;}
- .hxwd_table_item_left {padding-left: 10px;margin-left: -10px;margin-right: -10px;padding-right: 10px;min-height: 50px;display: flex;align-items: center;border-top: 1px solid #EAEAEA;}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。