75 lines
2.4 KiB
JavaScript
75 lines
2.4 KiB
JavaScript
var o = getApp();
|
|
|
|
Page({
|
|
data: {
|
|
nav_select: !1,
|
|
options: {},
|
|
address: null,
|
|
exist_address: !1,
|
|
goods: {},
|
|
disabled: !1,
|
|
hasError: !1,
|
|
error: ""
|
|
},
|
|
onLoad: function(o) {
|
|
this.data.options = o, console.log(o);
|
|
},
|
|
onShow: function() {
|
|
this.getOrderData();
|
|
},
|
|
getOrderData: function() {
|
|
var r = this, t = r.data.options, s = function(t) {
|
|
if (1 !== t.code) return o.showError(t.msg), !1;
|
|
t.data.has_error ? (r.data.hasError = !0, r.data.error = t.data.error_msg, o.showError(r.data.error)) : (r.data.hasError = !1,
|
|
r.data.error = ""), r.setData(t.data);
|
|
};
|
|
"buyNow" === t.order_type ? o._get("order/buyNow", {
|
|
goods_id: t.goods_id,
|
|
goods_num: t.goods_num,
|
|
goods_sku_id: t.goods_sku_id
|
|
}, function(o) {
|
|
s(o);
|
|
}) : "cart" === t.order_type && o._get("order/cart", {}, function(o) {
|
|
s(o);
|
|
});
|
|
},
|
|
selectAddress: function() {
|
|
wx.navigateTo({
|
|
url: "../address/" + (this.data.exist_address ? "index?from=flow" : "createa")
|
|
});
|
|
},
|
|
submitOrder: function() {
|
|
var r = this, t = r.data.options;
|
|
if (r.data.disabled) return !1;
|
|
if (r.data.hasError) return o.showError(r.data.error), !1;
|
|
var s = function(r) {
|
|
if (-10 === r.code) return o.showError(r.msg, function() {
|
|
wx.redirectTo({
|
|
url: "../pays/pays"
|
|
});
|
|
}), !1;
|
|
wx.redirectTo({
|
|
url: "../pays/pays"
|
|
});
|
|
};
|
|
r.data.disabled = !0, wx.showLoading({
|
|
title: "正在处理..."
|
|
}), "buyNow" === t.order_type ? o._post_form("order/buyNow", {
|
|
goods_id: t.goods_id,
|
|
goods_num: t.goods_num,
|
|
goods_sku_id: t.goods_sku_id
|
|
}, function(o) {
|
|
console.log("success"), s(o);
|
|
}, function(o) {
|
|
console.log("fail");
|
|
}, function() {
|
|
console.log("complete"), r.data.disabled = !1;
|
|
}) : "cart" === t.order_type && o._post_form("order/cart", {}, function(o) {
|
|
console.log("success"), s(o);
|
|
}, function(o) {
|
|
console.log("fail");
|
|
}, function() {
|
|
console.log("complete"), r.data.disabled = !1;
|
|
});
|
|
}
|
|
}); |