export const initChildrenSku = function(specList) {
  let specChildList = [];
  specList.forEach(item => {
    // 会影响到原数组
    specChildList.push(
      ...item.attsValues.map(it => {
        it.attsCode = item.attsCode;
        return it;
      })
    );
  });
  specChildList.forEach((item, _, arr) => {
    item.disabled = true;
    item.skuNos.forEach(i => {
      if (arr[0].skuNos.indexOf(i) !== -1 || item.attsCode === arr[0].attsCode) {
        item.disabled = false;
      }
    });
  });
  return specChildList;
};

export const isSelectSpec = function(specList, specSelected) {
  // 如果2种规格都超过2种需要都选中才能提交
  // 如果没有规格直接提交
  // 如果1种规格只有1种状态直接提交
  let isOne = false;
  let isSelect = true;
  if (specList.length === 1) {
    isOne = true;
  }
  specList.forEach(pItem => {
    if (pItem.attsValues.length === 1) {
      isOne = true;
    }
  });
  if (!isOne && specSelected.length && specSelected.length < 2) {
    isSelect = false;
  }
  return isSelect;
};
// 选择商品规格
export const getArrEqual = function(arr1, arr2) {
  let newArr = [];
  for (let i = 0; i < arr2.length; i++) {
    for (let j = 0; j < arr1.length; j++) {
      if (arr1[j] === arr2[i]) {
        newArr.push(arr1[j]);
      }
    }
  }
  return newArr;
};
