var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/regenerator")), e = require("../../@babel/runtime/helpers/asyncToGenerator"), a = (getApp(), 
require("../../utils/login.js"));

Page({
    data: {
        showLoding: !0,
        num: 1,
        token: "",
        name: "",
        mobile: "",
        totalprice: "",
        price: "",
        info: {},
        currency: "",
        useMoney: 0,
        allowMaxNum: 0
    },
    onLoad: function(t) {
        this.setData({
            token: t.token
        }), this.getOrder();
    },
    changeNum: function(t) {
        var e = t.currentTarget.dataset.types;
        if ("money" == t.currentTarget.dataset.name) {
            if ("plus" == e) this.data.useMoney < this.data.allow_useintegralmax && this.data.useMoney++; else {
                if (this.data.useMoney <= 0) return !1;
                this.data.useMoney--;
            }
            this.setData({
                useMoney: this.data.useMoney
            });
        } else {
            if ("plus" == e) {
                if (this.data.num >= this.data.allowMaxNum) return wx.showToast({
                    title: "不能再加了啦~",
                    icon: "none"
                }), !1;
                this.data.num++;
            } else {
                if (this.data.num <= 1) return wx.showToast({
                    title: "不能再少了哟~",
                    icon: "none"
                }), !1;
                this.data.num--;
            }
            this.setData({
                num: this.data.num
            }), this.getPrice();
        }
    },
    input: function(t) {
        "money" == t.currentTarget.dataset.name ? this.setData({
            useMoney: t.detail.value
        }) : (this.setData({
            num: t.detail.value
        }), this.getPrice());
    },
    setMoney: function() {
        var t = this.data.num * this.data.info.price, e = (t + "").split(".");
        e[1] = e[1].padEnd(2, "0").slice(0, 2), t = e.join("."), this.setData({
            totalMoney: t
        });
    },
    blur: function() {
        this.data.num <= 1 && this.setData({
            num: 1
        });
    },
    inputtext: function(t) {
        var e = t.detail.value;
        "name" == t.currentTarget.dataset.text ? this.setData({
            name: e
        }) : this.setData({
            mobile: e
        });
    },
    getOrder: function() {
        var n = this;
        return e(t.default.mark(function e() {
            var s, r;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, t.next = 3, a.request(a.baseUrl + "shop/order/create", {
                        token: n.data.token
                    }, !0);

                  case 3:
                    s = t.sent, r = s.data, n.setData({
                        showLoding: !1,
                        totalprice: r.totalprice,
                        allow_useintegral: r.allow_useintegral,
                        allow_useintegralmax: r.allow_useintegralmax,
                        currency: r.currency,
                        money: r.money,
                        shoppingCartList: r.shoppingCartList,
                        address: r.address,
                        name: r.address.username || "",
                        mobile: r.address.telnumber ? r.address.telnumber + "" : "",
                        allowMaxNum: Math.min(r.shoppingCartList.shop.stock, r.shoppingCartList.shop.purchase_num)
                    }), t.next = 11;
                    break;

                  case 8:
                    t.prev = 8, t.t0 = t.catch(0), console.log(t.t0);

                  case 11:
                  case "end":
                    return t.stop();
                }
            }, e, null, [ [ 0, 8 ] ]);
        }))();
    },
    getPrice: function() {
        var n = this;
        return e(t.default.mark(function e() {
            var s, r;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, t.next = 3, a.request(a.baseUrl + "shop/order/num", {
                        uniqid: n.data.shoppingCartList.uniqid,
                        cartnum: n.data.num
                    }, !0);

                  case 3:
                    s = t.sent, r = s.data, 200 == s.code && n.setData({
                        totalprice: r.totalprice
                    }), t.next = 11;
                    break;

                  case 8:
                    t.prev = 8, t.t0 = t.catch(0), console.log(t.t0);

                  case 11:
                  case "end":
                    return t.stop();
                }
            }, e, null, [ [ 0, 8 ] ]);
        }))();
    },
    pay: function() {
        return "" == this.data.name.trim() ? (wx.showModal({
            title: "提示",
            content: "请输入姓名"
        }), !1) : "" == this.data.mobile.trim() ? (wx.showModal({
            title: "提示",
            content: "请输入手机号码"
        }), !1) : (wx.setStorageSync("goodsInfo", this.data.info), void wx.redirectTo({
            url: "/pages/orderPay/orderPay?uniqid=".concat(this.data.shoppingCartList.uniqid, "&name=").concat(this.data.name, "&mobile=").concat(this.data.mobile, "&amount=").concat(this.data.useMoney)
        }));
    }
});