wpfw_ewei_wxapp/groups/goods/index.js
2023-02-26 08:10:18 +08:00

141 lines
4.4 KiB
JavaScript

var a = getApp(), t = a.requirejs("core"), e = (a.requirejs("jquery"), a.requirejs("foxui"),
a.requirejs("wxParse/wxParse")), o = 0;
Page({
data: {
goods_id: 0,
advHeight: 1
},
imageLoad: function(a) {
var t = a.detail.height, e = a.detail.width, o = Math.floor(750 * t / e);
t == e ? this.setData({
advHeight: 750
}) : this.setData({
advHeight: o
});
},
onLoad: function(o) {
var i = this;
wx.showShareMenu({
menus: [ "shareAppMessage", "shareTimeline" ]
}), a.getCache("isIpx") ? i.setData({
isIpx: !0,
iphonexnavbar: "fui-iphonex-navbar"
}) : i.setData({
isIpx: !1,
iphonexnavbar: ""
});
var s = o.id;
this.setData({
goods_id: s
}), t.post("groups.goods", {
id: s
}, function(a) {
i.setData({
data: a.data
}), e.wxParse("wxParseData", "html", a.data.content, i, "0");
});
},
singlebuy: function(e) {
var o = a.getCache("userinfo_openid");
if (console.log(o, "是否登录了呢"), o) {
var i = this;
t.post("groups/goods/goodsCheck", {
id: i.data.goods_id,
type: "single"
}, function(a) {
if (1 != a.error) if (0 == i.data.data.more_spec) wx.navigateTo({
url: "../confirm/index?id=" + i.data.goods_id + "&type=single"
}); else {
i.setData({
layershow: !0,
options: !0
}), i.setData({
optionarr: [],
selectSpecsarr: []
});
var e = i.data.data.id;
t.get("groups.goods.get_spec", {
id: e
}, function(a) {
i.setData({
spec: a.data
});
}), i.setData({
layershow: !0,
options: !0
});
} else t.alert(a.message);
});
} else wx.navigateTo({
url: "/pages/auth/index"
});
},
close: function() {
this.setData({
layershow: !1,
options: !1
});
},
specsTap: function(a) {
o++;
var e = this, i = e.data.spec, s = t.pdata(a).spedid, n = t.pdata(a).id, d = t.pdata(a).specindex;
t.pdata(a).idx;
i[d].item.forEach(function(a, t) {
a.id == n ? i[d].item[t].status = "active" : i[d].item[t].status = "";
}), e.setData({
spec: i
});
var r = e.data.optionarr, p = e.data.selectSpecsarr;
1 == o ? (r.push(n), p.push(s)) : p.indexOf(s) > -1 ? r.splice(d, 1, n) : (r.push(n),
p.push(s)), e.data.optionarr = r, e.data.selectSpecsarr = p, t.post("groups.goods.get_option", {
spec_id: e.data.optionarr,
groups_goods_id: e.data.goods_id
}, function(a) {
e.setData({
optiondata: a.data
});
});
},
buy: function(a) {
var e = this, o = (t.pdata(a).op, e.data.goods_id), i = e.data.optiondata;
e.data.optiondata ? i.stock > 0 ? wx.navigateTo({
url: "../confirm/index?id=" + o + "&option_id=" + i.id + " &type=single",
success: function() {
e.setData({
layershow: !1,
chosenum: !1,
options: !1
});
}
}) : wx.showToast({
title: "库存不足",
icon: "none",
duration: 2e3
}) : wx.showToast({
title: "请选择规格",
icon: "none",
duration: 2e3
});
},
onReady: function() {},
onShow: function() {},
onHide: function() {},
onUnload: function() {},
onPullDownRefresh: function() {},
onReachBottom: function() {},
onShareAppMessage: function() {
return {
title: this.data.data.title
};
},
onShareTimeline: function() {
var a = this.data.data;
return {
title: a.title,
imageUrl: a.thumb,
path: "/groups/goods/index?id=" + this.data.goods_id
};
},
check: function() {}
});