require("../../utils/util.js");

var a = require("../../utils/network.js");

require("../../utils/util.js"), getApp();

Page({
    data: {
        banners: [],
        recom: [],
        scrollHeight: 0,
        goods: [],
        code: "",
        hidden: !1,
        page: 1,
        hasMore: !0,
        hasRefesh: !1
    },
    getgoods: function() {
        var e = this;
        a.POST({
            url: "index/ajax_goods_home",
            header: "application/x-www-form-urlencoded",
            params: {
                p: e.data.page
            },
            success: function(a) {
                if (console.log(a), wx.showNavigationBarLoading(), "success" == a.data.state) {
                    var o = a.data.goods;
                    e.setData({
                        goods: o
                    }), wx.hideNavigationBarLoading();
                }
            }
        });
    },
    loadMore: function(e) {
        var o = this;
        o.setData({
            hasMore: !0
        }), o.data.hasMore && (++o.data.page, a.POST({
            url: "index/ajax_goods_home",
            header: "application/x-www-form-urlencoded",
            params: {
                p: o.data.page
            },
            success: function(a) {
                console.log(a), wx.showNavigationBarLoading(), "success" == a.data.state && (o.setData({
                    goods: o.data.goods.concat(a.data.goods),
                    hasMore: !1
                }), wx.hideNavigationBarLoading());
            }
        }));
    },
    goSearch: function() {
        wx.navigateTo({
            url: "search/search"
        });
    },
    gogoods: function(a) {
        var e = a.currentTarget.id;
        wx.navigateTo({
            url: "goodsdetail/goodsdetail?id=" + e
        });
    },
    onLoad: function() {
        var a = this;
        wx.getSystemInfo({
            success: function(e) {
                a.setData({
                    scrollHeight: e.windowHeight
                });
            }
        }), a.getgoods();
    },
    getopenid: function() {
        var e = this;
        wx.getStorage({
            key: "userInfo",
            success: function(o) {
                a.POST({
                    url: "User/register",
                    header: "application/x-www-form-urlencoded",
                    params: {
                        code: e.data.code,
                        nickname: o.nickName,
                        headimg: o.avatarUrl
                    },
                    success: function(a) {
                        wx.setStorage({
                            key: "ouid",
                            data: a.data.ouid
                        });
                    },
                    fail: function() {}
                });
            }
        });
    },
    getbanner: function() {
        var e = this;
        new Object();
        a.GET({
            url: "index/index",
            header: "application/x-www-form-urlencoded",
            params: "",
            success: function(a) {
                200 == a.statusCode && e.setData({
                    banners: a.data.banners,
                    recom: a.data.recom
                });
            },
            fail: function() {}
        });
    },
    onShow: function() {
        this.getbanner();
    },
 onShareAppMessage: function (options) {
  let that = this;
  let ouid;
  // 设置菜单中的转发按钮触发转发事件时的转发内容
  var shareObj = {
   title: '嗒咕商场', // 默认是小程序的名称(可以写slogan等)
   path: '/pages/start/start?share_id=' + wx.getStorageSync('ouid'), // 默认是当前页面,必须是以‘/’开头的完整路径
   imgUrl: '',//自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
   success: function (res) {
    // 转发成功之后的回调
    if (res.errMsg == 'shareAppMessage:ok') { }
   },
   fail: function () {
    // 转发失败之后的回调
    if (res.errMsg == 'shareAppMessage:fail cancel') {
     // 用户取消转发
    } else if (res.errMsg == 'shareAppMessage:fail') {
     // 转发失败,其中 detail message 为详细失败信息
    }
   },
   complete: function () {
    // 转发结束之后的回调(转发成不成功都会执行)
   }
  }
  return shareObj;
 },
});