|
|
@@ -329,7 +329,6 @@
|
|
|
<el-button size="small" type="primary" @click="chooseCourseProduct">选取商品</el-button>
|
|
|
<el-table border width="100%" style="margin-top:5px;" :data="form.courseProducts">
|
|
|
<el-table-column label="商品名称" align="center" prop="productName"/>
|
|
|
- <el-table-column label="产品条码" align="center" prop="barCode"/>
|
|
|
<el-table-column label="商品价格" align="center" prop="price"/>
|
|
|
<el-table-column label="库存" align="center" prop="stock"/>
|
|
|
<el-table-column label="操作" align="center" width="100px" fixed="right">
|
|
|
@@ -789,7 +788,13 @@ export default {
|
|
|
|
|
|
courseProductResult(val) {
|
|
|
this.form.courseProducts = this.form.courseProducts || [];
|
|
|
-
|
|
|
+ const productData = {
|
|
|
+ productId: val.productId, // 确保使用 productId
|
|
|
+ productName: val.productName,
|
|
|
+ price: val.price,
|
|
|
+ stock: val.stock,
|
|
|
+ id: val.productId, // 添加 id 字段,方便删除操作
|
|
|
+ };
|
|
|
// 检查商品是否已存在
|
|
|
const exists = this.form.courseProducts.some(item => item.productId === val.productId);
|
|
|
if (exists) {
|
|
|
@@ -828,9 +833,29 @@ export default {
|
|
|
|
|
|
//删除商品
|
|
|
handleCourseProductDelete(row) {
|
|
|
- const index = this.form.courseProducts.findIndex(item => item.id === row.id);
|
|
|
+ // 优先使用 productId 查找
|
|
|
+ let index = -1;
|
|
|
+
|
|
|
+ // 方法1:通过 productId 查找
|
|
|
+ if (row.productId) {
|
|
|
+ index = this.form.courseProducts.findIndex(item => item.productId === row.productId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 方法2:如果 productId 不存在,尝试通过 id 查找
|
|
|
+ if (index === -1 && row.id) {
|
|
|
+ index = this.form.courseProducts.findIndex(item => item.id === row.id);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 方法3:如果以上都不行,通过 productName 查找(最后手段)
|
|
|
+ if (index === -1 && row.productName) {
|
|
|
+ index = this.form.courseProducts.findIndex(item => item.productName === row.productName);
|
|
|
+ }
|
|
|
+
|
|
|
if (index > -1) {
|
|
|
this.form.courseProducts.splice(index, 1);
|
|
|
+ this.$message.success('删除成功');
|
|
|
+ } else {
|
|
|
+ this.$message.warning('未找到对应商品');
|
|
|
}
|
|
|
},
|
|
|
handleVideoChange() {
|