|
|
@ -32,8 +32,8 @@ |
|
|
|
<!-- <pageye v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/>--> |
|
|
|
</div> |
|
|
|
<div class=""> |
|
|
|
<el-table :key="tableKey" ref="multipleTable" v-loading="listLoading" :data="list" border style="width: 100%" |
|
|
|
@selection-change="handleSelectionChange"> |
|
|
|
<el-table :key="randomKey" ref="multipleTable" v-loading="listLoading" :data="list" border style="width: 100%" |
|
|
|
@select="select" @select-all="selectAll"> |
|
|
|
<el-table-column width="50px" type="selection" align="center" /> |
|
|
|
<el-table-column width="80px" label="序号" type="index" :index="indexMethod" align="center" /> |
|
|
|
<el-table-column prop="goodsName" label="商品名称" align="center" /> |
|
|
@ -96,7 +96,10 @@ |
|
|
|
goodsSkuCode: '', |
|
|
|
}, |
|
|
|
total: 0 |
|
|
|
} |
|
|
|
}, |
|
|
|
tableData: [], |
|
|
|
selectedItems: [], |
|
|
|
randomKey: Math.random(), |
|
|
|
} |
|
|
|
}, |
|
|
|
methods: { |
|
|
@ -122,6 +125,7 @@ |
|
|
|
if (response.success) { |
|
|
|
this.listQuery.total = response.data.total |
|
|
|
this.list = response.data.records |
|
|
|
this.selectedPreExisting(this.selectedItems) |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
@ -139,9 +143,9 @@ |
|
|
|
this.listQuery.params.goodsSkuCode = '' |
|
|
|
this.getList() |
|
|
|
}, |
|
|
|
handleSelectionChange(row) { |
|
|
|
this.sids = row |
|
|
|
}, |
|
|
|
// handleSelectionChange(row) { |
|
|
|
// this.sids = row |
|
|
|
// }, |
|
|
|
showAdd(createOrgSid) { |
|
|
|
// const aa = [] |
|
|
|
// if (value.length > 0) { |
|
|
@ -160,7 +164,13 @@ |
|
|
|
}, |
|
|
|
// 添加修改返回 |
|
|
|
AddUpdateReturn() { |
|
|
|
this.sids = [] |
|
|
|
this.selectedItems.forEach(row => { |
|
|
|
this.sids.push(row) |
|
|
|
}) |
|
|
|
|
|
|
|
if (this.sids.length > 0) { |
|
|
|
this.selectedItems = [] |
|
|
|
this.$emit('backData', this.sids) |
|
|
|
} else { |
|
|
|
this.$notify({ |
|
|
@ -174,6 +184,82 @@ |
|
|
|
// 返回 |
|
|
|
handleReturn() { |
|
|
|
this.$emit('doback') |
|
|
|
this.selectedItems = [] |
|
|
|
}, |
|
|
|
// //设置页面数据 |
|
|
|
// setTabelData() { |
|
|
|
// let { |
|
|
|
// current, |
|
|
|
// size |
|
|
|
// } = this.pages |
|
|
|
// this.tableData = this.list.slice((current - 1) * size, (current - 1) * size + size) |
|
|
|
// //randomKey是table数据改动时,刷新table的 |
|
|
|
// this.randomKey = Math.random() |
|
|
|
// this.selectedPreExisting(this.selectedItems) |
|
|
|
// }, |
|
|
|
// //监听翻页 |
|
|
|
// handleCurrentChange(index) { |
|
|
|
// this.listQuery.current = index |
|
|
|
// this.setTabelData() |
|
|
|
// }, |
|
|
|
//选中table已有数据 |
|
|
|
selectedPreExisting(rows) { |
|
|
|
if (rows.length > 0) { |
|
|
|
//这里使用this.$nextTick是防止表格未渲染完成就执行,导致无法添加选中效果 |
|
|
|
this.$nextTick(() => { |
|
|
|
rows.forEach(row => { |
|
|
|
//判断row是存在当前tableData |
|
|
|
let selectedItem = this.list.find(item => item.sid == row.sid) |
|
|
|
this.$refs.multipleTable.toggleRowSelection(selectedItem); |
|
|
|
}); |
|
|
|
}) |
|
|
|
} else { |
|
|
|
this.$refs.multipleTable.clearSelection(); |
|
|
|
} |
|
|
|
}, |
|
|
|
//表格单选 |
|
|
|
select(selection, row) { |
|
|
|
|
|
|
|
console.log("selection", selection) |
|
|
|
//因为翻页之后,点选时selection会出现undefined,所以这里需要进行判断 |
|
|
|
//这里可以通过判断选择selection中有没有row,就可以判断出是增加还是删减 |
|
|
|
if (selection && selection.find(item => item && (item.sid == row.sid))) { |
|
|
|
console.log("this.selectedItems+++++", this.selectedItems) |
|
|
|
this.addRows([row]) |
|
|
|
} else { |
|
|
|
console.log("this.selectedItems------", this.selectedItems) |
|
|
|
this.deleteRows([row]) |
|
|
|
} |
|
|
|
}, |
|
|
|
//表格全选 |
|
|
|
selectAll(selection) { |
|
|
|
//判断是选中还是取消 |
|
|
|
if (selection.length > 0) { |
|
|
|
this.addRows(this.list) |
|
|
|
} else { |
|
|
|
this.deleteRows(this.list) |
|
|
|
} |
|
|
|
}, |
|
|
|
//添加选中 |
|
|
|
addRows(rows) { |
|
|
|
rows.forEach(row => { |
|
|
|
//过滤,当selectedItems有此条数据时,则直接返回,不执行添加 |
|
|
|
if (this.selectedItems.find(item => item.sid == row.sid)) { |
|
|
|
return |
|
|
|
} |
|
|
|
this.selectedItems.push(row) |
|
|
|
}); |
|
|
|
}, |
|
|
|
//取消选中 |
|
|
|
deleteRows(rows) { |
|
|
|
//当selectedItems为空数组时,不执行删除 |
|
|
|
if (this.selectedItems.length == 0) { |
|
|
|
return |
|
|
|
} |
|
|
|
rows.forEach(row => { |
|
|
|
var index = this.selectedItems.findIndex(item => item.sid == row.sid) |
|
|
|
this.selectedItems.splice(index, 1) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|