Browse Source

实现点击下架按钮时默认选中所有未售空规格

pull/19/head
Default User 1 month ago
parent
commit
2f15e03415
  1. 26
      pages/goods-update/goods-update.js

26
pages/goods-update/goods-update.js

@ -1647,10 +1647,32 @@ Page({
// 确认下架(实际执行下架确认的内部方法)
confirmUnpublish: function() {
// 显示规格选择弹窗,让用户选择要下架的规格
const goodsDetail = this.data.goodsDetail;
const weightQuantityData = goodsDetail.weightQuantityData || [];
// 计算所有未售空的规格索引
let selectedSpecIndices = [];
let isSelected = [];
// 遍历规格数据,找出所有未售空的规格
weightQuantityData.forEach((item, index) => {
// 如果规格状态不是1(未售空),则默认选中
if (item.specStatus !== '1') {
selectedSpecIndices.push(index);
isSelected[index] = true;
} else {
isSelected[index] = false;
}
});
console.log('默认选中的规格索引:', selectedSpecIndices);
console.log('默认选中的状态数组:', isSelected);
// 显示规格选择弹窗,默认选中所有未售空的规格
this.setData({
showSpecUnpublishModal: true,
selectedSpecIndex: -1 // 重置选中索引
selectedSpecIndices: selectedSpecIndices,
isSelected: isSelected
});
},

Loading…
Cancel
Save