暂时去掉登录时候client参数,会引发account唯一索引错误
This commit is contained in:
@ -82,6 +82,9 @@ try {
|
||||
uPopup: function () {
|
||||
return __webpack_require__.e(/*! import() | components/uview-ui/components/u-popup/u-popup */ "components/uview-ui/components/u-popup/u-popup").then(__webpack_require__.bind(null, /*! @/components/uview-ui/components/u-popup/u-popup.vue */ 532))
|
||||
},
|
||||
uNumberBox: function () {
|
||||
return __webpack_require__.e(/*! import() | components/uview-ui/components/u-number-box/u-number-box */ "components/uview-ui/components/u-number-box/u-number-box").then(__webpack_require__.bind(null, /*! @/components/uview-ui/components/u-number-box/u-number-box.vue */ 399))
|
||||
},
|
||||
uButton: function () {
|
||||
return __webpack_require__.e(/*! import() | components/uview-ui/components/u-button/u-button */ "components/uview-ui/components/u-button/u-button").then(__webpack_require__.bind(null, /*! @/components/uview-ui/components/u-button/u-button.vue */ 361))
|
||||
},
|
||||
@ -107,6 +110,8 @@ var render = function () {
|
||||
var _vm = this
|
||||
var _h = _vm.$createElement
|
||||
var _c = _vm._self._c || _h
|
||||
var g0 =
|
||||
_vm.specValueText.indexOf("请选择") != -1 || _vm.checkedGoods.stock == 0
|
||||
var a0 = {
|
||||
color: _vm.themeColor,
|
||||
border: "1px solid " + _vm.themeColor,
|
||||
@ -116,6 +121,7 @@ var render = function () {
|
||||
{},
|
||||
{
|
||||
$root: {
|
||||
g0: g0,
|
||||
a0: a0,
|
||||
},
|
||||
}
|
||||
@ -155,10 +161,12 @@ __webpack_require__.r(__webpack_exports__);
|
||||
"use strict";
|
||||
|
||||
|
||||
var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4);
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ 18));
|
||||
//
|
||||
//
|
||||
//
|
||||
@ -201,18 +209,27 @@ exports.default = void 0;
|
||||
//
|
||||
//
|
||||
//
|
||||
var _default2 = {
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
var _default = {
|
||||
name: "shop-spec",
|
||||
props: {
|
||||
value: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
},
|
||||
spec: {
|
||||
type: [Array, Object],
|
||||
default: function _default() {
|
||||
return [{}];
|
||||
}
|
||||
goods: {
|
||||
type: [Object, Array]
|
||||
},
|
||||
disabledNumberBox: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
@ -223,7 +240,18 @@ var _default2 = {
|
||||
return {
|
||||
mobile: '',
|
||||
specBck: [],
|
||||
selectedSpec: []
|
||||
selectedSpec: [],
|
||||
checkedGoods: {
|
||||
stock: 0
|
||||
},
|
||||
//选中的
|
||||
outOfStock: [],
|
||||
//缺货的
|
||||
specList: [],
|
||||
//规格
|
||||
disable: [],
|
||||
//不可选择的
|
||||
goodsNum: 1
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
@ -232,56 +260,123 @@ var _default2 = {
|
||||
this.showPop = false;
|
||||
this.$emit('close');
|
||||
},
|
||||
// 选择规格
|
||||
chooseSpec: function chooseSpec(item, index1, index2, attr) {
|
||||
var _this = this;
|
||||
if (item.name == '辣度') {
|
||||
// 规格-单选
|
||||
item.spec_value.map(function (i, k) {
|
||||
if (k === index2) {
|
||||
if (item.spec_value[index2].is_select) {
|
||||
_this.$set(i, 'is_select', false);
|
||||
_this.selectedSpec = _this.selectedSpec.filter(function (it) {
|
||||
return it.id !== item.spec_value[index2].id;
|
||||
});
|
||||
} else {
|
||||
_this.$set(i, 'is_select', true);
|
||||
_this.selectedSpec.push({
|
||||
id: item.spec_value[index2].id,
|
||||
name: item.spec_value[index2].value
|
||||
});
|
||||
}
|
||||
} else {
|
||||
_this.$set(i, 'is_select', false);
|
||||
_this.selectedSpec.map(function (se, index) {
|
||||
if (se.id == i.id) {
|
||||
_this.selectedSpec.splice(index, 1);
|
||||
}
|
||||
});
|
||||
// 过滤出需要进行禁用的规格
|
||||
getOutOfStockArr: function getOutOfStockArr(arr, arr1) {
|
||||
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
||||
arr.forEach(function (el) {
|
||||
if (el.num >= arr1.length - 1) {
|
||||
result.push.apply(result, (0, _toConsumableArray2.default)(el.different));
|
||||
}
|
||||
});
|
||||
return result;
|
||||
},
|
||||
// 匹配出缺货库存和已选中对比结果
|
||||
getArrIdentical: function getArrIdentical(arr1, arr2) {
|
||||
var arr = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
||||
var num = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
||||
arr1.forEach(function (el) {
|
||||
arr2.forEach(function (el2) {
|
||||
if (el == el2) {
|
||||
num += 1;
|
||||
arr.push(el);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 规格-复选
|
||||
if (item.spec_value[index2].is_select) {
|
||||
this.$set(item.spec_value[index2], 'is_select', false);
|
||||
this.selectedSpec = this.selectedSpec.filter(function (i) {
|
||||
return i.id !== item.spec_value[index2].id;
|
||||
});
|
||||
} else {
|
||||
// 选中
|
||||
this.$set(item.spec_value[index2], 'is_select', true);
|
||||
this.selectedSpec.push({
|
||||
id: item.spec_value[index2].id,
|
||||
name: item.spec_value[index2].value
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return {
|
||||
num: num,
|
||||
//n个相同的
|
||||
different: this.getArrDifference((0, _toConsumableArray2.default)(new Set(arr)).map(Number), arr2.map(Number)),
|
||||
identical: (0, _toConsumableArray2.default)(new Set(arr))
|
||||
};
|
||||
},
|
||||
// 匹配出已选择和缺库存的
|
||||
getArrResult: function getArrResult(arr, outOfStock) {
|
||||
var _this = this;
|
||||
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
||||
outOfStock.forEach(function (item) {
|
||||
var res = _this.getArrIdentical(arr, item.spec_value_ids.split(","));
|
||||
if (res != undefined && res.length != 0) {
|
||||
result.push(res);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
},
|
||||
// 找出两个数组中参数不同的
|
||||
getArrDifference: function getArrDifference(arr1, arr2) {
|
||||
return arr1.concat(arr2).filter(function (v, i, arr) {
|
||||
return arr.indexOf(v) == arr.lastIndexOf(v);
|
||||
});
|
||||
},
|
||||
chooseSpec: function chooseSpec(index, index2) {
|
||||
var id = this.specList[index].spec_value[index2].id;
|
||||
|
||||
// 无法选择
|
||||
var disable = this.disable.filter(function (item) {
|
||||
return item == id;
|
||||
});
|
||||
if (disable.length != 0) return;
|
||||
var idsArr = this.checkedGoods.spec_value_ids_arr;
|
||||
if (id == idsArr[index]) idsArr[index] = "";else idsArr[index] = id;
|
||||
//保存已选规格
|
||||
this.checkedGoods.spec_value_ids_arr = idsArr;
|
||||
this.checkedGoods.spec_value_ids = idsArr.join(",");
|
||||
// 重新渲染页面
|
||||
this.specList = (0, _toConsumableArray2.default)(this.specList);
|
||||
console.log("this.checkedGoods>>>", this.checkedGoods);
|
||||
},
|
||||
// 选择规格
|
||||
// chooseSpec(item, index1, index2, attr) {
|
||||
// if (item.name == '辣度') {
|
||||
// // 规格-单选
|
||||
// item.spec_value.map((i, k) => {
|
||||
// if(k === index2) {
|
||||
// if (item.spec_value[index2].is_select) {
|
||||
// this.$set(i, 'is_select', false)
|
||||
// this.selectedSpec = this.selectedSpec.filter(it => it.id !== item.spec_value[index2].id)
|
||||
// } else {
|
||||
// this.$set(i, 'is_select', true)
|
||||
// this.selectedSpec.push({
|
||||
// id: item.spec_value[index2].id,
|
||||
// name: item.spec_value[index2].value
|
||||
// })
|
||||
// }
|
||||
// } else {
|
||||
// this.$set(i, 'is_select', false)
|
||||
// this.selectedSpec.map((se, index) => {
|
||||
// if (se.id == i.id) {
|
||||
// this.selectedSpec.splice(index, 1)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// } else {
|
||||
// // 规格-复选
|
||||
// if (item.spec_value[index2].is_select) {
|
||||
// this.$set(item.spec_value[index2], 'is_select', false)
|
||||
// this.selectedSpec = this.selectedSpec.filter(i => i.id !== item.spec_value[index2].id)
|
||||
// } else {
|
||||
// // 选中
|
||||
// this.$set(item.spec_value[index2], 'is_select', true)
|
||||
// this.selectedSpec.push({
|
||||
// id: item.spec_value[index2].id,
|
||||
// name: item.spec_value[index2].value
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// 确认选择的规格
|
||||
confirm: function confirm() {
|
||||
this.showPop = false;
|
||||
this.$emit('confirm', {
|
||||
spec: this.selectedSpec
|
||||
var checkedGoods = this.checkedGoods,
|
||||
goodsNum = this.goodsNum;
|
||||
if (this.specValueText.indexOf("请选择") != -1) return this.$toast({
|
||||
title: this.specValueText
|
||||
});
|
||||
if (checkedGoods.stock == 0) return this.$toast({
|
||||
title: "当前选择库存不足"
|
||||
});
|
||||
checkedGoods.goodsNum = goodsNum;
|
||||
this.$emit('buynow', {
|
||||
detail: checkedGoods
|
||||
});
|
||||
}
|
||||
},
|
||||
@ -293,16 +388,74 @@ var _default2 = {
|
||||
set: function set(val) {
|
||||
this.$emit('input', val);
|
||||
}
|
||||
},
|
||||
specValueText: function specValueText() {
|
||||
var _this$checkedGoods$sp,
|
||||
_this2 = this,
|
||||
_this$checkedGoods;
|
||||
var arr = (_this$checkedGoods$sp = this.checkedGoods.spec_value_ids) === null || _this$checkedGoods$sp === void 0 ? void 0 : _this$checkedGoods$sp.split(",");
|
||||
var spec_str = "";
|
||||
if (arr) arr.forEach(function (item, index) {
|
||||
if (item == "") spec_str += _this2.specList[index].name + ",";
|
||||
});
|
||||
if (((_this$checkedGoods = this.checkedGoods) === null || _this$checkedGoods === void 0 ? void 0 : _this$checkedGoods.stock) != 0 && spec_str == "") return "\u5DF2\u9009\u89C4\u683C\uFF1A".concat(this.checkedGoods.spec_value_str, " ").concat(this.goodsNum, " \u4EF6");else return "\u8BF7\u9009\u62E9 ".concat(spec_str.slice(0, spec_str.length - 1));
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
spec: function spec(val) {
|
||||
goods: function goods(value) {
|
||||
// 创建副本
|
||||
this.specBck = val;
|
||||
this.specList = value.goods_spec || [];
|
||||
var goodsItem = value.goods_item || [];
|
||||
this.outOfStock = goodsItem.filter(function (item) {
|
||||
return item.stock == 0;
|
||||
});
|
||||
// 找出库存不为0的
|
||||
var resultArr = goodsItem.filter(function (item) {
|
||||
return item.stock != 0;
|
||||
});
|
||||
if (resultArr.length != 0) {
|
||||
resultArr[0].spec_value_ids_arr = resultArr[0].spec_value_ids.split(",");
|
||||
this.checkedGoods = resultArr[0];
|
||||
} else {
|
||||
// 无法选择
|
||||
goodsItem[0].spec_value_ids_arr = [];
|
||||
this.disable = goodsItem.map(function (item) {
|
||||
return item.spec_value_ids.split(",");
|
||||
});
|
||||
this.checkedGoods = goodsItem[0];
|
||||
}
|
||||
},
|
||||
specList: function specList(value) {
|
||||
var _this3 = this;
|
||||
if (this.checkedGoods.stock == 0) return;
|
||||
var res = this.goods.goods_item.filter(function (item) {
|
||||
return _this3.checkedGoods.spec_value_ids === item.spec_value_ids;
|
||||
});
|
||||
|
||||
// 库存为0的规格
|
||||
var idsArr = this.checkedGoods.spec_value_ids_arr;
|
||||
var outOfStock = this.outOfStock;
|
||||
// 找出规格相同和规格不相同的余数
|
||||
var getArrGather = this.getArrResult(idsArr, outOfStock);
|
||||
// 计算出缺货的规格项
|
||||
this.disable = this.getOutOfStockArr(getArrGather, idsArr);
|
||||
if (res.length != 0) {
|
||||
console.log(res, "-----");
|
||||
var result = JSON.parse(JSON.stringify(res[0]));
|
||||
result.spec_value_ids_arr = result.spec_value_ids.split(",");
|
||||
if (this.goodsNum > result.stock) {
|
||||
this.goodsNum = result.stock;
|
||||
}
|
||||
this.checkedGoods = result;
|
||||
// 同步到父组件
|
||||
this.$emit("change", {
|
||||
detail: this.checkedGoods
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.default = _default2;
|
||||
exports.default = _default;
|
||||
|
||||
/***/ }),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user