84 lines
2.7 KiB
JavaScript
84 lines
2.7 KiB
JavaScript
var o = getApp();
|
|
|
|
Page({
|
|
data: {
|
|
nav_select: !1,
|
|
options: {},
|
|
address: null,
|
|
exist_address: !1,
|
|
goods: {},
|
|
disabled: !1,
|
|
hasError: !1,
|
|
error: "",
|
|
utype: 0
|
|
},
|
|
onLoad: function(o) {
|
|
this.data.options = o, console.log(o), this.getUserDetail();
|
|
},
|
|
onShow: function() {
|
|
this.getOrderData(), this.getUserDetail();
|
|
},
|
|
getUserDetail: function() {
|
|
var r = this;
|
|
o._get("user.index/detail", {}, function(o) {
|
|
console.log(o), r.setData({
|
|
utype: o.data.userInfo.utype
|
|
});
|
|
});
|
|
},
|
|
getOrderData: function() {
|
|
var r = this, t = r.data.options, e = 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) {
|
|
e(o);
|
|
}) : "cart" === t.order_type && o._get("order/cart", {}, function(o) {
|
|
e(o);
|
|
});
|
|
},
|
|
selectAddress: function() {
|
|
wx.navigateTo({
|
|
url: "../address/" + (this.data.exist_address ? "index?from=flow" : "create")
|
|
});
|
|
},
|
|
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 e = 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"), e(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"), e(o);
|
|
}, function(o) {
|
|
console.log("fail");
|
|
}, function() {
|
|
console.log("complete"), r.data.disabled = !1;
|
|
});
|
|
}
|
|
}); |