|
|
@ -25,6 +25,11 @@ Page({ |
|
|
|
shop_info: {}, |
|
|
|
type: 1, |
|
|
|
shopId: '', |
|
|
|
showModalStatus: false, |
|
|
|
animationData: '', |
|
|
|
buynum: 1, |
|
|
|
attrList: [], |
|
|
|
sizeid: '', |
|
|
|
}, |
|
|
|
switchTab: function(e) { |
|
|
|
var dataset = e.currentTarget.dataset |
|
|
@ -45,8 +50,8 @@ Page({ |
|
|
|
shop_id: shopId, |
|
|
|
shop_list_id: '', |
|
|
|
type: that.data.type, |
|
|
|
latitude: 28.23529, |
|
|
|
longitude: 112.93134, |
|
|
|
latitude: 31.772752, |
|
|
|
longitude: 119.946973, |
|
|
|
}).then(res => { |
|
|
|
if (res.code == 200) { |
|
|
|
var data = res.data; |
|
|
@ -65,19 +70,256 @@ Page({ |
|
|
|
wx.navigateTo({ |
|
|
|
url: '/pages/store/myStore?shopId='+info.id, |
|
|
|
}) |
|
|
|
}, |
|
|
|
shopping_j: function(e) { |
|
|
|
|
|
|
|
}, |
|
|
|
navToList: function (e) { |
|
|
|
console.log(e) |
|
|
|
// console.log(e)
|
|
|
|
var that = this |
|
|
|
var info = e.currentTarget.dataset.info; |
|
|
|
wx.navigateTo({ |
|
|
|
url: '/pages/listdetail/listdetail?id='+info.cid+'&title='+info.pname, |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
navToDetail: function(e) { |
|
|
|
var info = e.currentTarget.dataset.info; |
|
|
|
wx.navigateTo({ |
|
|
|
url: '/pages/product/detail?productId='+info.id, |
|
|
|
}) |
|
|
|
}, |
|
|
|
showAttribute: function(e) { |
|
|
|
var productId = e.currentTarget.dataset.id; |
|
|
|
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() |
|
|
|
}) |
|
|
|
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({ |
|
|
|
accessId: app.globalData.accessId, |
|
|
|
storeId: 239, |
|
|
|
pro_id: productId, |
|
|
|
vipSource: 0 |
|
|
|
}).then(res => { |
|
|
|
if (res.code == 200) { |
|
|
|
var data = res.data; |
|
|
|
var pro = data.pro; |
|
|
|
that.setData({ |
|
|
|
itemData: pro, |
|
|
|
attrList: data.attrList, |
|
|
|
sizeid: data.attrList[0].attr[0].attrId, |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
// 弹窗
|
|
|
|
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) |
|
|
|
}, |
|
|
|
// 加减
|
|
|
|
changeNum: function (e) { |
|
|
|
var that = this; |
|
|
|
var num = that.data.itemData.num; |
|
|
|
if (e.target.dataset.alphaBeta == 0) { |
|
|
|
if (this.data.buynum <= 1) { |
|
|
|
wx.showToast({ |
|
|
|
title: '不能再少了', |
|
|
|
icon: 'none', |
|
|
|
duration: 1000 |
|
|
|
}) |
|
|
|
} else { |
|
|
|
this.setData({ |
|
|
|
buynum: this.data.buynum - 1 |
|
|
|
}) |
|
|
|
}; |
|
|
|
} else { |
|
|
|
if (that.data.buynum < num) { |
|
|
|
this.setData({ |
|
|
|
buynum: this.data.buynum + 1 |
|
|
|
}) |
|
|
|
} else { |
|
|
|
wx.showToast({ |
|
|
|
title: '不能再多了', |
|
|
|
icon: 'none', |
|
|
|
duration: 1000 |
|
|
|
}) |
|
|
|
} |
|
|
|
}; |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 规格属性点击事件 |
|
|
|
*/ |
|
|
|
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(); |
|
|
|
}, |
|
|
|
//加入购物车
|
|
|
|
addShopCart: function (e) { |
|
|
|
// console.log(e.currentTarget.dataset)
|
|
|
|
var info = e.currentTarget.dataset.info; |
|
|
|
//添加到购物车
|
|
|
|
var that = this; |
|
|
|
WXAPI.productAddCart({ |
|
|
|
accessId: app.globalData.accessId, |
|
|
|
storeId: 239, |
|
|
|
storeType: 1, |
|
|
|
pro_id: info.pro_id, |
|
|
|
attribute_id: that.data.sizeid, |
|
|
|
num: that.data.buynum, |
|
|
|
type: 'addcart', |
|
|
|
}).then(res => { |
|
|
|
if (res.code == 200) { |
|
|
|
//设置购物车刷新
|
|
|
|
app.d.purchase = 1; |
|
|
|
wx.showToast({ |
|
|
|
title: '已添加到购物车', |
|
|
|
icon: 'success', |
|
|
|
duration: 2000 |
|
|
|
}); |
|
|
|
that.setData({ |
|
|
|
showModalStatus: false |
|
|
|
}); |
|
|
|
} else { |
|
|
|
wx.showToast({ |
|
|
|
icon: 'loading', |
|
|
|
title: res.message, |
|
|
|
duration: 2000 |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面加载 |
|
|
|
*/ |
|
|
|