- <el-table :data="paramsList" :show-header="false" ref="tableF" @select="handleSelectionChange"
- :row-key="getRowKey">
- <el-table-column width="55" type="selection" :selectable='handleCheckbox1'>
- el-table-column>
- <el-table-column>
- <template slot-scope="scope">
- <div class="titleName">
- <span> {{scope.row.name}}span>
-
- <el-table :data="scope.row.goodsList" :show-header="false"
- :ref="'tableChildSon' + scope.$index"
- @select="handleSelectionChange3" :row-key="spuList.spuId">
- <el-table-column width="55" type="selection"
- :selectable='handleCheckbox2'>
- el-table-column>
- <el-table-column align="center">
- <template slot-scope="scopeSon">
- <div class="o-main">
- div>
- template>
- el-table-column>
- el-table>
- div>
- template>
- el-table-column>
- el-table>
JS
- getRowKey(row) {
- return row.id;
- },
- //1级是否可以勾选
- handleCheckbox1(row, index) {
- if (!row.children) {
- return true
- }
- },
- //一级表格勾选
- handleSelectionChange(selection, row) {
- //判断一级表格是否选中 选中--true 未选中--0
- let isCheck = selection.length && selection.indexOf(row) !== -1;
- //循环整个表数据--找到勾选的 index
- this.paramsList.forEach((item, index) => {
- if (item.id == row.id) {
- let tempList = row.goodsList;
- this.spuList = []
- //这里的循环根据自己数据结构来写几层
- tempList.forEach((item1, index1) => {
- item1.spuList.forEach((items, indexs) => {
- this.spuList.push(items)
- })
- })
- //以防3级列表没有数据
- if (this.spuList) {
- //循环本次勾选的数据
- this.spuList.forEach((selectionItem, index) => {
- console.log('selectionItem', selectionItem, isCheck);
- this.$nextTick(function() {
- this.$refs["tableChildSon" + [index]]
- .toggleRowSelection(
- selectionItem,
- isCheck
- );
- });
- });
- // 联动外部全选框(大全选——没需要可不加
- if (this.shoped > this.spuList.length) {
- this.allType = true
- } else {
- this.allType = false
- }
- } else {
- this.$refs[`tableChildSon${index}`].clearSelection();
- }
- }
- })
- },
- //2级表格勾选
- handleSelectionChange3(selection, row) {
- // this.priceed = 0
- // this.shoped = 0
- //计算价格
- let isCheck = selection.length && selection.indexOf(row) !== -1;
- this.b[row.spuId] = row
- if (isCheck == true) {
- //总价
- this.priceed += this.b[row.spuId].totalPrice
- //件数
- this.shoped += 1
- } else {
- this.priceed -= this.b[row.spuId].totalPrice
- this.shoped -= 1
- }
- //判断3级列表是否取消勾选(无数据)
- if (isCheck === 0) {
- isCheck = false
- } else {
- isCheck = true
- }
- this.paramsList.map(item => {
- item.goodsList.forEach((itemson, index) => {
- if (itemson.id == row.goodsId && itemson.shopId == item.id) {
- this.$refs.tableF.toggleRowSelection(item, isCheck);
- }
- });
- })
- },
删除数据
this.paramsList.splice(index, 1)
外部全选框
- class="select-all">
- <el-checkbox-group v-model="allType" @change="handleCheckAllChange">
- <el-checkbox label="全选" name="type" :checked="allType">el-checkbox>
- el-checkbox-group>
-
-
- allType: false, //底部全选
- //外部一级全选
- handleCheckAllChange(selectBottom) {
- console.log(this.allChecked)
- selectBottom ? this.$refs.tableF.toggleAllSelection() : this.$refs.tableF.clearSelection()
- this.allType = selectBottom
- this.independentTableList = this.$refs.tableF.store.states.selection
- this.paramsList.forEach((item, index) => {
- this.$refs.tableF.toggleRowExpansion(item, true);
- const temp = item.goodsList;
- var sput = []
- temp.forEach((item1, index1) => {
- item1.spuList.forEach((items, indexs) => {
- sput.push(items)
- })
- })
- if (sput) {
- this.shoped = 0
- // this.priceed=0
- for (var k = 0; k < sput.length; k++) {
- //件数
- this.shoped += sput.length
- //计算价格
- this.priceed += sput[k].totalPrice
- }
- }
- //判断取消还是勾选--取消清空选择数据
- if (selectBottom) {
- this.$refs[`tableChildSon${index}`].toggleAllSelection();
- } else {
- this.$refs[`tableChildSon${index}`].clearSelection();
- this.shoped = 0
- this.priceed = 0
- }
- });
- },