|
@ -7,12 +7,21 @@ Page({ |
|
|
minusStatuses: ['disabled', 'disabled', 'normal', 'normal', 'disabled'], |
|
|
minusStatuses: ['disabled', 'disabled', 'normal', 'normal', 'disabled'], |
|
|
total: 0.0, |
|
|
total: 0.0, |
|
|
carts: [], |
|
|
carts: [], |
|
|
|
|
|
data: {}, |
|
|
|
|
|
skuBeanList: [], |
|
|
cont: 1, |
|
|
cont: 1, |
|
|
upstatus: false, |
|
|
upstatus: false, |
|
|
remind: '加载中', |
|
|
remind: '加载中', |
|
|
productData: '', |
|
|
productData: '', |
|
|
shop: '', |
|
|
shop: '', |
|
|
shop_logo: '', |
|
|
shop_logo: '', |
|
|
|
|
|
showModalStatus: false, |
|
|
|
|
|
animationData: '', |
|
|
|
|
|
buynum: 1, |
|
|
|
|
|
attrList: [], |
|
|
|
|
|
sizeid: '', |
|
|
|
|
|
currentIndex: 0, |
|
|
|
|
|
itemData: {} |
|
|
}, |
|
|
}, |
|
|
//页面加载完成函数 remind: '加载中',
|
|
|
//页面加载完成函数 remind: '加载中',
|
|
|
onReady: function () { |
|
|
onReady: function () { |
|
@ -462,7 +471,6 @@ Page({ |
|
|
}); |
|
|
}); |
|
|
that.sum(); |
|
|
that.sum(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: '数量不能小于1,请重新输入!', |
|
|
title: '数量不能小于1,请重新输入!', |
|
@ -477,4 +485,300 @@ Page({ |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
}, |
|
|
}, |
|
|
|
|
|
showAttribute: function(e) { |
|
|
|
|
|
var productId = e.currentTarget.dataset.id; |
|
|
|
|
|
var index = e.currentTarget.dataset.index; |
|
|
|
|
|
var that = this; |
|
|
|
|
|
that.loadProductDetail(productId); |
|
|
|
|
|
var animation = wx.createAnimation({ |
|
|
|
|
|
duration: 200, |
|
|
|
|
|
timingFunction: "linear", |
|
|
|
|
|
delay: 0 |
|
|
|
|
|
}); |
|
|
|
|
|
this.animation = animation |
|
|
|
|
|
animation.translateY(300).step(); |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
// paytype: type,
|
|
|
|
|
|
animationData: animation.export(), |
|
|
|
|
|
currentIndex: index |
|
|
|
|
|
}) |
|
|
|
|
|
if (e.currentTarget.dataset.status == 1) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showModalStatus: true |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
setTimeout(function () { |
|
|
|
|
|
animation.translateY(0).step() |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
animationData: animation |
|
|
|
|
|
}) |
|
|
|
|
|
if (e.currentTarget.dataset.status == 0) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showModalStatus: false |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}.bind(this), 200); |
|
|
|
|
|
}, |
|
|
|
|
|
// 商品详情数据获取
|
|
|
|
|
|
loadProductDetail: function (productId) { |
|
|
|
|
|
var that = this; |
|
|
|
|
|
WXAPI.productIndex({ // productAttribute
|
|
|
|
|
|
accessId: app.globalData.accessId, |
|
|
|
|
|
storeId: 239, |
|
|
|
|
|
storeType: 1, |
|
|
|
|
|
pro_id: productId, |
|
|
|
|
|
// cart_id: productId
|
|
|
|
|
|
}).then(res => { |
|
|
|
|
|
if (res.code == 200) { |
|
|
|
|
|
var data = res.data; |
|
|
|
|
|
var pro = data.pro; |
|
|
|
|
|
that.setData({ |
|
|
|
|
|
skuBeanList: data.skuBeanList, |
|
|
|
|
|
// itemData: pro,
|
|
|
|
|
|
attrList: data.attrList, |
|
|
|
|
|
sizeid: data.attrList[0].attr[0].attrId, |
|
|
|
|
|
}); |
|
|
|
|
|
//默认选中
|
|
|
|
|
|
that.one(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
//首次进去选中
|
|
|
|
|
|
one: function () { |
|
|
|
|
|
var attrListIn = this.data.attrList; |
|
|
|
|
|
var skuBeanListIn = this.data.skuBeanList; |
|
|
|
|
|
var select_list = skuBeanListIn[0]; |
|
|
|
|
|
for (var i = 0; i < attrListIn.length; i++) { |
|
|
|
|
|
for (var j = 0; j < attrListIn[i].attr.length; j++) { |
|
|
|
|
|
for (var b = 0; b < select_list.attributes.length; b++) { |
|
|
|
|
|
if (select_list.attributes[b].attributeId == attrListIn[i].attr[j].attributeId && select_list.attributes[b].attributeValId == attrListIn[i].attr[j].id) { |
|
|
|
|
|
attrListIn[i].attr[j].select = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
var itemData = this.data.itemData; |
|
|
|
|
|
itemData.photo_x = select_list.imgurl; |
|
|
|
|
|
itemData.price_yh = select_list.price; |
|
|
|
|
|
itemData.num = select_list.count; |
|
|
|
|
|
var sizeid = select_list.cid; |
|
|
|
|
|
|
|
|
|
|
|
// 重新赋值
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
attrList: attrListIn, |
|
|
|
|
|
skuBeanList: skuBeanListIn, |
|
|
|
|
|
itemData: itemData, |
|
|
|
|
|
sizeid: sizeid, |
|
|
|
|
|
value: select_list.name |
|
|
|
|
|
}) |
|
|
|
|
|
this.onData(); |
|
|
|
|
|
}, |
|
|
|
|
|
// 弹窗
|
|
|
|
|
|
setModalStatus: function (e) { |
|
|
|
|
|
var animation = wx.createAnimation({ |
|
|
|
|
|
duration: 200, |
|
|
|
|
|
timingFunction: "linear", |
|
|
|
|
|
delay: 0 |
|
|
|
|
|
}); |
|
|
|
|
|
//定义点击的类型
|
|
|
|
|
|
var type = e.target.dataset.type ? e.target.dataset.type : false; |
|
|
|
|
|
//控制两种不同显示方式
|
|
|
|
|
|
if (type) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
xefl: false, |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
xefl: true, |
|
|
|
|
|
}) |
|
|
|
|
|
type = this.data.paytype; |
|
|
|
|
|
} |
|
|
|
|
|
this.animation = animation |
|
|
|
|
|
animation.translateY(300).step(); |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
paytype: type, |
|
|
|
|
|
animationData: animation.export() |
|
|
|
|
|
}) |
|
|
|
|
|
if (e.currentTarget.dataset.status == 1) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showModalStatus: true |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
setTimeout(function () { |
|
|
|
|
|
animation.translateY(0).step() |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
animationData: animation |
|
|
|
|
|
}) |
|
|
|
|
|
if (e.currentTarget.dataset.status == 0) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showModalStatus: false |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}.bind(this), 200) |
|
|
|
|
|
}, |
|
|
|
|
|
/** |
|
|
|
|
|
* 规格属性点击事件 |
|
|
|
|
|
*/ |
|
|
|
|
|
onChangeShowState: function (event) { |
|
|
|
|
|
var that = this; |
|
|
|
|
|
var listItem = this.data.attrList; |
|
|
|
|
|
var items = listItem[event.currentTarget.dataset.idx]; |
|
|
|
|
|
var item = items.attr[event.currentTarget.dataset.index]; |
|
|
|
|
|
if (!item.enable) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
var select = !item.select; |
|
|
|
|
|
for (var i = 0; i < items.attr.length; i++) { |
|
|
|
|
|
items.attr[i].select = false; |
|
|
|
|
|
} |
|
|
|
|
|
item.select = select; |
|
|
|
|
|
// 获取点击属性列表
|
|
|
|
|
|
var canGetInfo = []; |
|
|
|
|
|
for (var skuIndex = 0; skuIndex < listItem.length; skuIndex++) { |
|
|
|
|
|
for (var skuIndexIn = 0; skuIndexIn < listItem[skuIndex].attr.length; skuIndexIn++) { |
|
|
|
|
|
if (listItem[skuIndex].attr[skuIndexIn].enable && listItem[skuIndex].attr[skuIndexIn].select) { |
|
|
|
|
|
canGetInfo.push(listItem[skuIndex].attr[skuIndexIn]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
var canGetInfoLog = ""; |
|
|
|
|
|
var skuBeanList = this.data.skuBeanList; |
|
|
|
|
|
var haveSkuBean = []; |
|
|
|
|
|
// 对应库存清单扫描
|
|
|
|
|
|
for (var skuBeanIndex = 0; skuBeanIndex < skuBeanList.length; skuBeanIndex++) { |
|
|
|
|
|
var iListCount = 0; |
|
|
|
|
|
for (var skuBeanIndexIn = 0; skuBeanIndexIn < skuBeanList[skuBeanIndex].attributes.length; skuBeanIndexIn++) { |
|
|
|
|
|
if (canGetInfo.length == skuBeanList[skuBeanIndex].attributes.length) { |
|
|
|
|
|
if (skuBeanList[skuBeanIndex].attributes[skuBeanIndexIn].attributeValId == canGetInfo[skuBeanIndexIn].id) { |
|
|
|
|
|
iListCount++; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
canGetInfoLog = "库存清单不存在此属性" + " "; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (iListCount == skuBeanList[skuBeanIndex].attributes.length) { |
|
|
|
|
|
haveSkuBean.push(skuBeanList[skuBeanIndex]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
for (var iox = 0; iox < canGetInfo.length; iox++) { |
|
|
|
|
|
canGetInfoLog += canGetInfo[iox].attributeValue + " "; |
|
|
|
|
|
} |
|
|
|
|
|
if (haveSkuBean.length != 0) { |
|
|
|
|
|
//选中设置
|
|
|
|
|
|
var itemData = that.data.itemData; |
|
|
|
|
|
itemData.photo_x = haveSkuBean[0].imgurl; |
|
|
|
|
|
itemData.price_yh = haveSkuBean[0].price; |
|
|
|
|
|
itemData.num = haveSkuBean[0].count; |
|
|
|
|
|
var choujiangid = that.data.choujiangid; |
|
|
|
|
|
var sizeid = haveSkuBean[0].cid; |
|
|
|
|
|
that.setData({ |
|
|
|
|
|
itemData: itemData, |
|
|
|
|
|
sizeid: sizeid, |
|
|
|
|
|
choujiangid: choujiangid, |
|
|
|
|
|
value: canGetInfoLog |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
that.setData({ |
|
|
|
|
|
sizeid: '', |
|
|
|
|
|
value: '' |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
// 重新赋值
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
attrList: listItem, |
|
|
|
|
|
infoText: canGetInfoLog, |
|
|
|
|
|
}) |
|
|
|
|
|
// 重新sku运算
|
|
|
|
|
|
this.onData(); |
|
|
|
|
|
}, |
|
|
|
|
|
/** |
|
|
|
|
|
* Sku核心算法 |
|
|
|
|
|
* 根据所有出当前类别之外的选择 判断按钮的enable ? false or true |
|
|
|
|
|
*/ |
|
|
|
|
|
onData: function () { |
|
|
|
|
|
var attrListIn = this.data.attrList; |
|
|
|
|
|
for (var i = 0; i < attrListIn.length; i++) { |
|
|
|
|
|
var attrListBig = attrListIn[i]; |
|
|
|
|
|
|
|
|
|
|
|
//当前类别之外的选择列表
|
|
|
|
|
|
var attrsOtherSelect = []; |
|
|
|
|
|
for (var j = 0; j < attrListIn.length; j++) { |
|
|
|
|
|
var attrListSmall = attrListIn[j]; |
|
|
|
|
|
if (attrListSmall.id != attrListBig.id) { |
|
|
|
|
|
for (var k = 0; k < attrListSmall.attr.length; k++) { |
|
|
|
|
|
var attrListSmallAttr = attrListSmall.attr[k]; |
|
|
|
|
|
if (attrListSmallAttr.enable && attrListSmallAttr.select) { |
|
|
|
|
|
attrsOtherSelect.push(attrListSmallAttr); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var enableIds = []; |
|
|
|
|
|
|
|
|
|
|
|
var skuBeanListIn = this.data.skuBeanList; |
|
|
|
|
|
|
|
|
|
|
|
for (var z = 0; z < skuBeanListIn.length; z++) { |
|
|
|
|
|
var ism = true; |
|
|
|
|
|
var skuBean = skuBeanListIn[z]; |
|
|
|
|
|
|
|
|
|
|
|
for (var j = 0; j < attrsOtherSelect.length; j++) { |
|
|
|
|
|
var enable = false; |
|
|
|
|
|
for (var k = 0; k < skuBean.attributes.length; k++) { |
|
|
|
|
|
|
|
|
|
|
|
var goodAttrBean = skuBean.attributes[k]; |
|
|
|
|
|
if (attrsOtherSelect[j].attributeId == goodAttrBean.attributeId |
|
|
|
|
|
&& attrsOtherSelect[j].id == goodAttrBean.attributeValId) { |
|
|
|
|
|
enable = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
ism = enable && ism; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (ism) { |
|
|
|
|
|
for (var o = 0; o < skuBean.attributes.length; o++) { |
|
|
|
|
|
var goodAttrBean = skuBean.attributes[o]; |
|
|
|
|
|
|
|
|
|
|
|
if (attrListBig.id == goodAttrBean.attributeId) { |
|
|
|
|
|
enableIds.push(goodAttrBean.attributeValId); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var integers = enableIds; |
|
|
|
|
|
for (var s = 0; s < attrListBig.attr.length; s++) { |
|
|
|
|
|
var attrItem = attrListBig.attr[s]; |
|
|
|
|
|
attrItem.enable = integers.indexOf(attrItem.id) != -1; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 重新赋值
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
attrList: attrListIn, |
|
|
|
|
|
skuBeanList: skuBeanListIn |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
confirmAct: function (e) { |
|
|
|
|
|
var that = this; |
|
|
|
|
|
var carts = that.data.carts; |
|
|
|
|
|
var index = that.data.currentIndex; |
|
|
|
|
|
var cartId = carts[index].id; |
|
|
|
|
|
WXAPI.modifyAttribute({ |
|
|
|
|
|
accessId: app.globalData.accessId, |
|
|
|
|
|
storeId: 239, |
|
|
|
|
|
storeType: 1, |
|
|
|
|
|
cart_id: cartId, |
|
|
|
|
|
attribute_id: that.data.sizeid |
|
|
|
|
|
}).then(res => { |
|
|
|
|
|
if (res.code == 200) { |
|
|
|
|
|
that.setData({ |
|
|
|
|
|
showModalStatus: false |
|
|
|
|
|
}); |
|
|
|
|
|
that.loadProductData(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
}) |
|
|
}) |