<template>
<div>
<el-table
:data="tableData6"
border
style="width: 100%; margin-top: 20px" :cellClassName="getCellClassName" :spanMethod="objectSpanMethod" :emptyText="'--'">
<el-table-column :prop="tablekey" :label="tableHeadName" v-for="(tableHeadName, tablekey) in tableHeader" :key="tablekey">
</el-table-column>
<el-table-column
prop="price"
label="價格">
</el-table-column>
</el-table>
<el-row style="margin-top:10px;">
<el-button type="primary">增加一列</el-button>
</el-row>
</div>
</template>
<script>
import _ from 'lodash'
export default {
data () {
return {
tableData6: [],
tableHeader: {'sex': '性別', 'age': '年齡', 'hc': '承載人數'},
priceOption: {
sex: ['男', '女'],
age: [18, 20],
hc: ['2-6人', '7-8人']
},
priceFactor: ['sex', 'age', 'hc']
}
},
created () {
this.tableData6 = this.plzhFirst(this.priceOption)
this.combineCell(this.tableData6)
for (var i = 0; i < this.tableData6.length; i++) {
this.addPrice(this.tableData6[i], '請輸入')
}
},
methods: {
addPrice (item, price) {
this.$set(item, 'price', price)
},
getCellClassName ({row, column, rowIndex, columnIndex}) {
if (row['@' + this.priceFactor[columnIndex] + 'dis']) {
return 'hidden'
} else {
return ''
}
},
plzhFirst (datas) {
var array = []
var propObj = this.getFirstProp(datas)
var propName = propObj.name
var propValue = propObj.value
if (_.isArray(propValue)) {
for (var i = 0; i < propValue.length; i++) {
var newObj = {}
newObj[propName] = propValue[i]
array.push(newObj)
}
} else {
let newObj = {}
newObj[propName] = propValue
array.push(newObj)
}
for (let i = 1; i < this.priceFactor.length; i++) {
array = this.plzh(
array,
this.priceOption[this.priceFactor[i]],
this.priceFactor[i]
)
}
return array
},
getFirstProp (obj) {
var propObj = {}
for (var i in obj) {
propObj.name = i
propObj.value = obj[i]
return propObj
}
},
plzh (arr1, arr2, nextAttr) {
var array = []
for (var i = 0; i < arr1.length; i++) {
var obj = arr1[i]
for (var j = 0; j < arr2.length; j++) {
var newObj = _.cloneDeep(obj)
var v2 = arr2[j]
newObj[nextAttr] = v2
array.push(newObj)
}
}
return array
},
colsLogic () {},
objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 3) {
return [1, 1]
}
return [row['@' + this.priceFactor[columnIndex] + 'span'], 1]
},
combineCell (list) {
for (let field in list[0]) {
var k = 0
while (k < list.length) {
list[k]['@' + field + 'span'] = 1
list[k]['@' + field + 'dis'] = false
for (var i = k + 1; i <= list.length - 1; i++) {
if (list[k][field] === list[i][field] && list[k][field] !== '') {
list[k]['@' + field + 'span']++
list[k]['@' + field + 'dis'] = false
list[i]['@' + field + 'span'] = 1
list[i]['@' + field + 'dis'] = true
} else {
break
}
}
k = i
}
}
return list
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less">
.hidden{
display:none;
}
.hidden{
display: none!important;
}
.el-row {
margin-bottom: 20px;
&:last-child {
margin-bottom: 0;
}
}
.el-col {
border-radius: 4px;
}
.bg-purple-dark {
background: #99a9bf;
}
.bg-purple {
background: #d3dce6;
}
.bg-purple-light {
background: #e5e9f2;
}
.grid-content {
border-radius: 4px;
min-height: 36px;
}
.row-bg {
padding: 10px 0;
background-color: #f9fafc;
}
</style>
element表格數據合并展示
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...