| | |
| | | } |
| | | }, |
| | | resetright() { |
| | | this.queryParams.price = 0; |
| | | if (this.dataList.length == 0) { |
| | | return; // 如果数据列表为空,直接返回 |
| | | } else { |
| | | this.queryParams.price = 0; // 初始化总价 |
| | | this.queryParams.xianprice = 0; // 初始化现价 |
| | | this.youhui = 0; // 初始化优惠 |
| | | |
| | | const newItemsToAdd = []; |
| | | const newItemsToAdd = []; // 用于存储新需要添加的项目 |
| | | |
| | | this.dataList.forEach((item) => { |
| | | this.$refs.tre.toggleRowSelection(item, false); |
| | | this.$refs.tre.toggleRowSelection(item, false); // 取消选中状态 |
| | | // 使用 $set 确保响应性 |
| | | this.$set(item, 'limits', 10); |
| | | this.$set(item, 'ysPrice', item.proPrice); |
| | | this.$set(item, 'limits', 10); // 设置限制数量 |
| | | this.$set(item, 'ysPrice', item.proPrice); // 设置现价为原价 |
| | | |
| | | // 检查是否已经存在相同的项目 |
| | | const existingItem = this.OnenewpacName.find(existing => existing.proId === item.proId); |
| | | if (!existingItem) { |
| | | newItemsToAdd.push(item); |
| | | newItemsToAdd.push(item); // 如果不存在相同项目,则添加到新数组 |
| | | this.updateProPrice(item); // 更新单个项目的价格 |
| | | } |
| | | }); |
| | |
| | | for (let i = this.OnenewpacName.length - newItemsToAdd.length; i < this.OnenewpacName.length - 1; i++) { |
| | | for (let j = i + 1; j < this.OnenewpacName.length; j++) { |
| | | if (this.OnenewpacName[i].proId === this.OnenewpacName[j].proId) { |
| | | this.OnenewpacName.splice(j, 1); |
| | | j--; |
| | | this.OnenewpacName.splice(j, 1); // 删除重复的项目 |
| | | j--; // 因为删除了一个元素,当前的j要减1 |
| | | } |
| | | } |
| | | } |
| | | |
| | | this.queryParams.price = 0 |
| | | this.queryParams.xianprice = 0 |
| | | // 重新计算总价和现价 |
| | | this.OnenewpacName.forEach((item) => { |
| | | this.queryParams.price += item.proPrice; |
| | | this.queryParams.xianprice += item.ysPrice || 0; // 确保ysPrice存在 |
| | | }) |
| | | this.queryParams.price += item.proPrice; // 累加原价 |
| | | this.queryParams.xianprice += item.ysPrice || 0; // 累加现价,如果ysPrice为undefined则累加0 |
| | | }); |
| | | |
| | | // 计算优惠,这里假设优惠是现价与原价的差额百分比 |
| | | this.youhui = (Math.floor((this.queryParams.xianprice / this.queryParams.price) * 100) / 100) * 10; |
| | | } |
| | | }, |
| | | handledbelete(row) { |
| | | this.queryParams.price = 0; |