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

Page({
    data: r({
        showLoding: !0,
        tapid: "",
        scrollid: "",
        id: "",
        user: {},
        info: {},
        share: {},
        formData: [],
        merchantList: [],
        token: "",
        recommendedList: [],
        scrolltocontent: !1,
        height: {
            merchantList: "",
            needknow: "",
            infomes: ""
        }
    }, "formData", []),
    onLoad: function(e) {
        this.setData({
            id: e.id || "1"
        }), this.getData();
    },
    onShareAppMessage: function() {
        return {
            title: this.data.share.title || this.data.info.name,
            imageUrl: this.data.share.pic
        };
    },
    getData: function() {
        var s = this;
        return a(e.default.mark(function a() {
            var o, c;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return s, e.prev = 1, e.next = 4, n.request(n.baseUrl + "shop/details", {
                        id: s.data.id
                    }, !0);

                  case 4:
                    o = e.sent, (c = o.data).recommendedList.forEach(function(e) {
                        var a = e.price.split("."), r = t(a, 2);
                        e.price_buck = r[0], e.price_cent = r[1];
                    }), c.info.message && (c.info.message = i.replaceDetail(c.info.message)), s.setData(r({
                        showLoding: !1,
                        formData: c.formData,
                        info: c.info,
                        merchantList: c.merchantList,
                        share: c.share,
                        user: c.user,
                        token: c.token,
                        recommendedList: c.recommendedList
                    }, "formData", c.formData)), s.watchView(), e.next = 15;
                    break;

                  case 12:
                    e.prev = 12, e.t0 = e.catch(1), console.log(e.t0);

                  case 15:
                  case "end":
                    return e.stop();
                }
            }, a, null, [ [ 1, 12 ] ]);
        }))();
    },
    watchView: function() {
        var t = this;
        return a(e.default.mark(function a() {
            var r, n, i, s, o;
            return e.default.wrap(function(e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    r = t, e.prev = 1, n = [ "header", "title", "merchantList", "needknow", "infomes" ], 
                    i = 0, s = 0;

                  case 5:
                    if (!(i < n.length)) {
                        e.next = 15;
                        break;
                    }
                    return e.next = 8, r.getHeight(n[i]);

                  case 8:
                    o = e.sent, console.log("height", o), i >= 2 && (r.data.height[n[i]] = s, r.setData({
                        height: t.data.height
                    })), s += o, i++, e.next = 5;
                    break;

                  case 15:
                    e.next = 20;
                    break;

                  case 17:
                    e.prev = 17, e.t0 = e.catch(1), console.log(e.t0);

                  case 20:
                  case "end":
                    return e.stop();
                }
            }, a, null, [ [ 1, 17 ] ]);
        }))();
    },
    getHeight: function(e) {
        return new Promise(function(t, a) {
            var r = wx.createSelectorQuery();
            r.select("#".concat(e)).boundingClientRect(), r.exec(function(e) {
                t(e[0].height);
            });
        });
    },
    toId: function(e) {
        var t = e.currentTarget.dataset.id;
        this.setData({
            tapid: t,
            scrollid: t
        });
    },
    bindscroll: function(e) {
        var t = this, a = e.detail.scrollTop;
        [ "infomes", "needknow", "merchantList" ].every(function(e) {
            return !(a > t.data.height[e]) || (t.setData({
                tapid: e,
                scrolltocontent: !0
            }), !0, !1);
        }), a >= this.data.height.merchantList ? this.setData({
            scrolltocontent: !0
        }) : this.setData({
            scrolltocontent: !1
        });
    }
});