2024-09-11 18:49:43 +08:00
|
|
|
|
<template>
|
2024-09-14 11:33:58 +08:00
|
|
|
|
<el-table v-loading="loading"
|
|
|
|
|
|
:data="list"
|
|
|
|
|
|
:stripe="true"
|
|
|
|
|
|
:show-overflow-tooltip="true"
|
|
|
|
|
|
show-summary
|
|
|
|
|
|
:summary-method="getSummaries"
|
|
|
|
|
|
:key="randomKey"
|
|
|
|
|
|
@cell-dblclick="editData"
|
|
|
|
|
|
>
|
2024-09-11 18:49:43 +08:00
|
|
|
|
<el-table-column label="序号" align="center">
|
|
|
|
|
|
<template scope="scope">
|
|
|
|
|
|
<span>{{ scope.$index + 1 }}</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
2024-09-13 18:31:13 +08:00
|
|
|
|
<el-table-column label="商品名称" align="center" prop="name" width="200"/>
|
2024-09-14 11:33:58 +08:00
|
|
|
|
<el-table-column label="规格" align="center" width="180" prop="model"/>
|
|
|
|
|
|
<el-table-column label="商品编码" align="center" width="180" prop="code"/>
|
|
|
|
|
|
<el-table-column label="仓库" align="center" width="150" prop="warehouse"/>
|
|
|
|
|
|
<el-table-column label="库存" align="center" width="150" prop="stock"/>
|
|
|
|
|
|
<el-table-column label="单位" align="center" width="150" prop="unit"/>
|
|
|
|
|
|
<el-table-column label="数量" align="center" width="150" prop="count">
|
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
|
<el-input v-if="scope.row[scope.column.property + 'isShow']"
|
|
|
|
|
|
:ref="scope.column.property"
|
|
|
|
|
|
v-model="scope.row.count"
|
|
|
|
|
|
@blur="alterData(scope.row,scope.column)"></el-input>
|
|
|
|
|
|
<span v-else>{{ scope.row.count }}</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column :label="soByType ? '上次进价' : '成本'" align="center" width="150" prop="price"/>
|
|
|
|
|
|
<el-table-column v-if="soByType" label="采购单价" align="center" width="150" prop="newPrice">
|
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
|
<el-input v-if="scope.row[scope.column.property + 'isShow']"
|
|
|
|
|
|
:ref="scope.column.property"
|
|
|
|
|
|
v-model="scope.row.newPrice"
|
|
|
|
|
|
@blur="alterData(scope.row,scope.column)"></el-input>
|
|
|
|
|
|
<span v-else>{{ scope.row.newPrice }}</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column :label="soByType ? '采购金额' : '合计'" align="center" width="150" prop="totalPrice"/>
|
|
|
|
|
|
<el-table-column label="备注" align="center" width="180" prop="remark">
|
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
|
<el-input v-if="scope.row[scope.column.property + 'isShow']"
|
|
|
|
|
|
:ref="scope.column.property"
|
|
|
|
|
|
v-model="scope.row.remark"
|
|
|
|
|
|
@blur="alterData(scope.row,scope.column)"></el-input>
|
|
|
|
|
|
<span v-else>{{ scope.row.remark }}</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
2024-09-11 18:49:43 +08:00
|
|
|
|
<el-table-column label="操作" fixed="right" align="center" width="150">
|
|
|
|
|
|
<template v-slot="scope">
|
2024-09-13 18:31:13 +08:00
|
|
|
|
<el-button size="mini" type="text" icon="el-icon-delete" @click="deleteItem(scope.$index)"
|
2024-09-11 18:49:43 +08:00
|
|
|
|
>删除
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: "SoTable",
|
2024-09-14 11:33:58 +08:00
|
|
|
|
props: {
|
|
|
|
|
|
soByType: {
|
2024-09-11 18:49:43 +08:00
|
|
|
|
type: Boolean,
|
|
|
|
|
|
defaultValue: true,
|
|
|
|
|
|
required: true
|
2024-09-13 18:31:13 +08:00
|
|
|
|
},
|
2024-09-14 11:33:58 +08:00
|
|
|
|
partList: {
|
2024-09-13 18:31:13 +08:00
|
|
|
|
type: Array,
|
|
|
|
|
|
defaultValue: false,
|
|
|
|
|
|
required: true
|
2024-09-11 18:49:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
list: [],
|
2024-09-14 11:33:58 +08:00
|
|
|
|
includeColumn: ['count', 'totalPrice'],
|
|
|
|
|
|
randomKey: Math.random(),
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
partList(val) {
|
|
|
|
|
|
const data = val[val.length - 1]
|
|
|
|
|
|
const newData = {
|
|
|
|
|
|
...data,
|
|
|
|
|
|
count: 1,
|
|
|
|
|
|
totalPrice: data.price * 1,
|
|
|
|
|
|
remark: '',
|
|
|
|
|
|
newPrice: data.price,
|
|
|
|
|
|
}
|
|
|
|
|
|
this.list.push(newData)
|
|
|
|
|
|
},
|
|
|
|
|
|
list: {
|
|
|
|
|
|
handler(newVal, oldVal) {
|
|
|
|
|
|
this.$emit("tableData", newVal)
|
|
|
|
|
|
},
|
|
|
|
|
|
deep: true
|
2024-09-11 18:49:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2024-09-13 18:31:13 +08:00
|
|
|
|
// 通知父组件,删除数据
|
2024-09-14 11:33:58 +08:00
|
|
|
|
deleteItem(index) {
|
2024-09-13 18:31:13 +08:00
|
|
|
|
this.$emit("deleteItem", index)
|
2024-09-14 11:33:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 设置不统计的字段
|
|
|
|
|
|
getSummaries(param) {
|
|
|
|
|
|
const {columns, data} = param
|
|
|
|
|
|
const sums = []
|
|
|
|
|
|
columns.forEach((column, index) => {
|
|
|
|
|
|
if (index === 0) {
|
|
|
|
|
|
sums[index] = '合计';
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const values = data.map(item => Number(item[column.property]));
|
|
|
|
|
|
if (this.includeColumn.includes(column.property)) {
|
|
|
|
|
|
sums[index] = values.reduce((prev, curr) => {
|
|
|
|
|
|
const value = Number(curr);
|
|
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
|
|
return prev + curr;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return prev;
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
sums[index];
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
return sums
|
|
|
|
|
|
},
|
|
|
|
|
|
editData(row, column) {
|
|
|
|
|
|
row[column.property + "isShow"] = true
|
|
|
|
|
|
//refreshTable是table数据改动时,刷新table的
|
|
|
|
|
|
this.refreshTable()
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.$refs[column.property] && this.$refs[column.property].focus()
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
alterData(row, column) {
|
|
|
|
|
|
row[column.property + "isShow"] = false
|
|
|
|
|
|
const data = this.list.find(item => item.id === row.id)
|
|
|
|
|
|
data.totalPrice = data.newPrice * data.count
|
|
|
|
|
|
this.refreshTable()
|
|
|
|
|
|
},
|
|
|
|
|
|
refreshTable() {
|
|
|
|
|
|
this.randomKey = Math.random()
|
|
|
|
|
|
},
|
2024-09-11 18:49:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
|
|
|
|
|
|
</style>
|