243 lines
7.8 KiB
JavaScript
243 lines
7.8 KiB
JavaScript
var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/helpers/defineProperty")), s = getApp(), a = s.requirejs("core"), e = (s.requirejs("icons"),
|
|
s.requirejs("foxui"));
|
|
|
|
s.requirejs("wxParse/wxParse"), s.requirejs("jquery");
|
|
|
|
Page({
|
|
data: {
|
|
paymentmodal: !1,
|
|
showmodal: !1,
|
|
successmodal: !1,
|
|
member: [],
|
|
goods: [],
|
|
options: [],
|
|
carrierInfo: [],
|
|
stores: [],
|
|
is_openmerch: !1,
|
|
isverify: !1,
|
|
iswechat: !0,
|
|
iscredit: !0,
|
|
paytype: "",
|
|
togglestore: "",
|
|
addressid: 0,
|
|
dispatchprice: 0,
|
|
allprice: 0,
|
|
logid: 0,
|
|
successmessage: "",
|
|
successstatus: !1,
|
|
storeids: "",
|
|
dispatch_error: ""
|
|
},
|
|
onLoad: function (t) {
|
|
var s = this;
|
|
t = t || {}, wx.getSystemInfo({
|
|
success: function (t) {
|
|
s.setData({
|
|
windowWidth: t.windowWidth,
|
|
windowHeight: t.windowHeight
|
|
});
|
|
}
|
|
}), s.setData({
|
|
options: t
|
|
});
|
|
},
|
|
onShow: function () {
|
|
var t = s.getCache("isIpx"), a = s.getCache("orderAddress"), e = s.getCache("orderShop");
|
|
e && this.setData({
|
|
carrierInfo: e
|
|
});
|
|
this.data.addressid;
|
|
a.id > 0 && (this.data.addressid = a.id, this.setData({
|
|
addressid: a.id
|
|
}), this.setData({
|
|
address: a
|
|
}), this.getDetail()), t ? this.setData({
|
|
isIpx: !0,
|
|
iphonexnavbar: "fui-iphonex-navbar"
|
|
}) : this.setData({
|
|
isIpx: !1,
|
|
iphonexnavbar: ""
|
|
}), "" == this.data.member && this.getDetail();
|
|
},
|
|
listChange: function (t) {
|
|
var s = this.data.member;
|
|
switch (t.target.id) {
|
|
case "realname":
|
|
s.realname = t.detail.value;
|
|
break;
|
|
|
|
case "mobile":
|
|
s.mobile = t.detail.value;
|
|
}
|
|
this.setData({
|
|
member: s
|
|
});
|
|
},
|
|
getDetail: function () {
|
|
var t = this, s = t.data.options;
|
|
console.log(s, "options"), a.get("creditshop/create", s, function (s) {
|
|
if (0 == s.error) {
|
|
s.goods.num = 1, t.setData({
|
|
storeids: s.goods.storeids,
|
|
goods: s.goods,
|
|
set: s.set,
|
|
shop: s.shop,
|
|
stores: s.stores,
|
|
isverify: s.goods.isverify,
|
|
member: s.member,
|
|
addressid: t.data.addressid ? t.data.addressid : s.address.id,
|
|
credittext: s.sysset.texts.credit
|
|
}), console.log(s.address.id, "addressssss");
|
|
0 == s.goods.isverify && 0 == s.goods.type && s.address.id > 0 ? (a.get("creditshop/create/getaddress", {
|
|
addressid: t.data.addressid
|
|
}, function (s) {
|
|
0 == s.error && t.setData({
|
|
address: s.address
|
|
});
|
|
}), t.dispatch()) : t.setData({
|
|
allprice: s.goods.money
|
|
});
|
|
}
|
|
});
|
|
},
|
|
dispatch: function () {
|
|
var t = this;
|
|
a.get("creditshop/create/dispatch", {
|
|
goodsid: t.data.goods.id,
|
|
addressid: t.data.addressid,
|
|
optionid: t.data.options.optionid
|
|
}, function (s) {
|
|
if (null != s.nodispatch_array) return e.toast(t, s.nodispatch_array.nodispatch),
|
|
void t.setData({
|
|
dispatch_error: s.nodispatch_array.nodispatch
|
|
});
|
|
var a = s.dispatch;
|
|
a = parseFloat(a) + parseFloat(t.data.goods.money), t.setData({
|
|
dispatchprice: s.dispatch,
|
|
allprice: a,
|
|
dispatch_error: ""
|
|
});
|
|
});
|
|
},
|
|
number: function (t) {
|
|
var s = this, i = s.data.goods, d = s.data.options, o = t.target.dataset.action;
|
|
"minus" == o ? i.num = parseInt(i.num) - 1 : "plus" == o && (i.num = parseInt(i.num) + 1),
|
|
i.num < 1 && (i.num = 1);
|
|
var r = i.num;
|
|
a.get("creditshop/create/number", {
|
|
goodsid: i.id,
|
|
optionid: d.id,
|
|
num: r,
|
|
addressid: s.data.addressid
|
|
}, function (t) {
|
|
if (0 == t.goods.canbuy) return i.num > 1 && (i.num = parseInt(i.num) - 1), s.setData({
|
|
goods: i
|
|
}), void e.toast(s, t.goods.buymsg);
|
|
(i = t.goods).num = r;
|
|
var a = parseFloat(100 * i.money * r / 100) + parseFloat(i.dispatch);
|
|
s.setData({
|
|
goods: i,
|
|
allprice: a
|
|
}), s.setData({
|
|
dispatchprice: t.goods.dispatch
|
|
});
|
|
});
|
|
},
|
|
pay: function () {
|
|
var t = this.data.goods, s = this.data.dispatchprice, a = t.money * t.num + parseFloat(s);
|
|
if (a = a.toFixed(2), t.canbuy) if ("" == this.data.dispatch_error) {
|
|
if (t.isverify > 0) {
|
|
var i = this.data.member;
|
|
if ("" == i.realname) return void e.toast(this, "请填写真实姓名");
|
|
if ("" == i.mobile) return void e.toast(this, "请填写联系电话");
|
|
if (0 == this.data.carrierInfo.length) return void e.toast(this, "请选择兑换门店");
|
|
}
|
|
if (0 == t.isverify && 0 == t.goodstype && 0 == t.type) {
|
|
var d = this.data.addressid;
|
|
if (0 == d || null == d) return void e.toast(this, "请选择收货地址");
|
|
}
|
|
1 == t.type && this.setData({
|
|
addressid: 0
|
|
}), 0 == a ? this.setData({
|
|
showmodal: !0
|
|
}) : this.setData({
|
|
paymentmodal: !0
|
|
});
|
|
} else e.toast(this, this.data.dispatch_error); else e.toast(this, this.data.goods.buymsg);
|
|
},
|
|
cancel: function () {
|
|
this.setData({
|
|
paymentmodal: !1,
|
|
showmodal: !1
|
|
});
|
|
},
|
|
payClick: function (t) {
|
|
var s = t.target.dataset.type;
|
|
this.setData({
|
|
paymentmodal: !1,
|
|
showmodal: !0,
|
|
paytype: s
|
|
});
|
|
},
|
|
confirm: function () {
|
|
var s, i = this, d = i.data.paytype;
|
|
1 != i.data.clickYes && (i.data.clickYes = 1, a.get("creditshop/detail/pay", (s = {
|
|
id: i.data.goods.id,
|
|
addressid: i.data.addressid,
|
|
optionid: i.data.options.optionid,
|
|
num: i.data.goods.num,
|
|
paytype: i.data.paytype
|
|
}, (0, t.default)(s, "addressid", i.data.addressid), (0, t.default)(s, "storeid", i.data.carrierInfo.id),
|
|
s), function (t) {
|
|
if (t.error > 0) return e.toast(i, t.message), void (i.data.clickYes = 0);
|
|
i.setData({
|
|
logid: t.logid
|
|
}), t.wechat && t.wechat.success && a.pay(t.wechat.payinfo, function (t) {
|
|
"requestPayment:ok" == t.errMsg && (i.lottery(), i.data.clickYes = 0);
|
|
}), "credit" == d && t.logid > 0 && (i.lottery(), i.data.clickYes = 0), "" == d && t.logid > 0 && (i.lottery(),
|
|
i.data.clickYes = 0);
|
|
}));
|
|
},
|
|
success: function () {
|
|
var t = this.data.logid;
|
|
wx.redirectTo({
|
|
url: "/pages/creditshop/log/detail/index?id=" + t
|
|
});
|
|
},
|
|
lottery: function () {
|
|
var t = this, s = t.data.goods.type, i = "";
|
|
0 == s ? a.get("creditshop/detail/lottery", {
|
|
id: t.data.goods.id,
|
|
logid: t.data.logid
|
|
}, function (s) {
|
|
s.error > 0 ? e.toast(t, s.message) : (2 == s.status && (i = "恭喜您,商品兑换成功"), 3 == s.status && (1 == s.goodstype ? i = "恭喜您,优惠券兑换成功" : 2 == s.goodstype ? i = "恭喜您,余额兑换成功" : 3 == s.goodstype && (i = "恭喜您,红包兑换成功")),
|
|
t.setData({
|
|
successmessage: i,
|
|
successstatus: !0
|
|
}));
|
|
}) : (i = "努力抽奖中,请稍后....", t.setData({
|
|
successmessage: i,
|
|
successstatus: !0
|
|
}), setTimeout(function () {
|
|
a.get("creditshop/detail/lottery", {
|
|
id: t.data.goods.id,
|
|
logid: t.data.logid
|
|
}, function (s) {
|
|
s.error > 0 ? e.toast(t, s.message) : (2 == s.status ? i = "恭喜您,您中奖啦" : 3 == s.status ? 1 == s.goodstype ? i = "恭喜您,优惠券已经发到您账户啦" : 2 == s.goodstype ? i = "恭喜您,余额已经发到您账户啦" : 3 == s.goodstype && (i = "恭喜您,红包兑换成功") : i = "很遗憾,您没有中奖",
|
|
t.setData({
|
|
successmessage: i,
|
|
successstatus: !0
|
|
}));
|
|
});
|
|
}, 1e3)), t.setData({
|
|
successmodal: !0
|
|
});
|
|
},
|
|
toggle: function (t) {
|
|
"" == this.data.togglestore ? this.setData({
|
|
togglestore: "toggleSend-group"
|
|
}) : this.setData({
|
|
togglestore: ""
|
|
});
|
|
}
|
|
}); |