app.js 9.97 KB
var t = require("setting.js"), o = require("./utils/auth.js"), a = require("./utils/request.js"), e = require("./utils/common.js"), ut = require("./utils/util.js");
var os=t;
var regeneratorRuntime = require('./utils/runtime.js');
var api = require("./api/api.js")

//公共方法和变量
App({
    globalData: {
        setting: t,
        wechatUser: null,
        userInfo: null,
        config: null,   //门店参数
        config2: null,  //门店配置
        code: null,
        heigth:0,
        user_id: null,// 4379287,//  null,// 5682068,
        buy_now:null,
        picklist:null,    //门店列表
        wuliuprice: null, //物流价格表
        wuliu: null,      //物流公司
        baddr:null,
        mobile: null,  //记录手机
        getu:null,     //记录会员信息
        sessionKey: null,//记录会员信息
        openid: null,    //记录会员信息

        to_group:null,     //参团传递的数据
        wxapp_buy_obj:null,//微信小程序购买的Object

    },
    auth: o,
    request: a,
    onLaunch: function() {
        this.initExt();
        var t = this.globalData.setting;
        t.resourceUrl = t.url + "/template/mobile/rainbow";
        var clientWidth = wx.getSystemInfoSync().windowWidth;
        var rpxR = 750 / clientWidth;
        var calc = wx.getSystemInfoSync().windowHeight * rpxR;
        this.globalData.heigth=calc;

        var app=this;
        if(!app.globalData.userInfo){
            var user = wx.getStorageSync("userinfo");
            if (user && user.user_id){
               app.globalData.userInfo=wx.getStorageSync("userinfo");
               app.globalData.user_id= app.globalData.userInfo.user_id;
            }
        }

    },

    //---初始化第三方----
    initExt: function() {
        var tt=t;
        console.log("initExt");
        console.log(11);
        var t = wx.getExtConfigSync(), o = this.globalData.setting;
        console.log(t);
        t.appName ? (o.appName = t.appName, o.stoid = t.stoid) : tt=1;
    },

    //首页的第一次登录
    getUserFir(t){
      var s = this;
      if (o.isAuth()) "function" == typeof t && t(s.globalData.userInfo, s.globalData.wechatUser); else {
        if (!o.isAuth()) return o.wxLogin_fir(t);
        if (null == s.globalData.userInfo) {
          return o.wxLogin_fir(t);
        }
      }
    },

    getUserInfo: function(t, n, i) {
        var s = this;
        if (o.isAuth()) "function" == typeof t && t(s.globalData.userInfo, s.globalData.wechatUser); else {
          if (!o.isAuth()) return o.auth(t);
          if (null == s.globalData.userInfo){
            return o.auth(t);
          }
          /*---
            a.get("/api/user/userInfo", {
                isShowLoading: void 0 === i || i,
                success: function(o) {
                    s.globalData.userInfo = o.data.result, s.globalData.userInfo.head_pic = e.getFullUrl(s.globalData.userInfo.head_pic),
                    "function" == typeof t && t(s.globalData.userInfo, s.globalData.wechatUser);
                }
            });--*/
        }
    },
    //----------------获取配置参数--------------------
    getConfig: function(t, o) {
      var e = this; if(this.globalData.config==undefined) this.globalData.config=null;
      this.globalData.config ? "function" == typeof t && t(this.globalData.config) : e.request.get("/api/weshop/store/get/" + e.globalData.setting.stoid, {
            success: function(o) {
                console.log('getConfig');
		            if(o.data.code==0){
                    e.globalData.config = o.data.data, "function" == typeof t && t(e.globalData.config);
                }
            }
        });
    },

    //----------------获取配置参数--------------------
    getConfig2: function (t, o) {
      var e = this;
      this.globalData.config2 && !o ?
        "function" == typeof t && t(this.globalData.config2) : a.get("/api/weshop/storeconfig/get/" + e.globalData.setting.stoid, {
        success: function (o) {
          console.log('getConfig2');
          if (o.data.code == 0) {
            e.globalData.config2 = o.data.data, "function" == typeof t && t(e.globalData.config);
          }
        }
      });
    },

  //----------------获取商家开启的物流--------------------
  getwuliu: function (t, o){
    var th = this, st = this.globalData.setting;
    this.globalData.wuliu && !o ?
      "function" == typeof t && t(this.globalData.wuliu) : a.get("/api/weshop/storeshipping/list", {
        data: { store_id: st.stoid, status: 1, pageSize:600 },
        success: function (o) {
          console.log('getwuliu');
          console.log(o);
          if (o.data.code == 0) {
            var arr = o.data.data.pageData;
            console.log(arr);
            arr.forEach(function(item,index){
                arr[index].code = item.shipping_code; arr[index].name = item.shipping_name;
            })
            th.globalData.wuliu = arr, "function" == typeof t && t(arr);
          }
        }
      });
  },

  //----------------获取物流价格表--------------------
  getwuliuprice: function (t, o) {
    var e = this,th=e, st = this.globalData.setting;
    this.globalData.wuliuprice && !o ?
      "function" == typeof t && t(this.globalData.wuliuprice) : a.get("/api/weshop/shippingarea/list",{
        data: { store_id: st.stoid,pageSize: 600 },
        success: function (o) {
          console.log('getwuliuprice');
          console.log(o);
          if (o.data.code == 0) {
               var arr=o.data.data.pageData;
               console.log(arr);
               if (arr.length>0){
                  for (var i = 0; i < arr.length;i++){
                       arr[i].code = arr[i].shipping_code;
                       if (arr[i].json_config != "" && arr[i].json_config != undefined && arr[i].json_config != null )
                             arr[i].config = JSON.parse(arr[i].json_config);
                  }
               }
              th.globalData.wuliuprice = o.data.data, "function" == typeof t && t(e.globalData.wuliuprice);
          }
        }
      });
  },
    //----------------设置立即购买数组--------------------
   set_b_now: function (d) { this.globalData.buy_now=d;},
   get_b_now: function () {return this.globalData.buy_now},

    getPrevPageData: function(t) {
        void 0 === t && (t = 1);
        var o = getCurrentPages();
        return o[o.length - t - 1].data;
    },
    showLoading: function(t, o) {
        void 0 === o && (o = 1500), wx.showToast({
            title: "加载中",
            icon: "loading",
            duration: o,
            mask: !0,
            complete: function() {
                "function" == typeof t && setTimeout(t, o);
            }
        });
    },
    showSuccess: function(t, o, a) {
        void 0 === a && (a = 1e3), wx.showToast({
            title: t,
            icon: "success",
            duration: a,
            mask: !0,
            complete: function() {
                "function" == typeof o && setTimeout(o, a);
            }
        });
    },
    showWarning: function(t, o, a, e) {
        //var imghost=this.globalData.setting.imghost;
        !a && (a = 1500), void 0 === e && (e = !0), wx.showToast({
            title: t,
            mask: e,
            duration: a,
            image:"/images/gt.png",
            complete: function() {
                "function" == typeof o && setTimeout(o, a);
            }
        });
    },

    confirmBox: function(t, o) {
        wx.showModal({
            title: t,
            showCancel: !1,
            complete: function() {
                "function" == typeof o && o();
            }
        });
    },

    //----------获取所有的门店------------
    get_allsto(func){
        var th=this;
        if (this.globalData.picklist!=null){
           "function" == typeof func && func(th.globalData.picklist);
        }else{
          th.request.get("/api/weshop/pickup/page", {
            data: { store_id: th.globalData.setting.stoid, pageSize: 600 },
            success: function (da) {
               //设置门店
               //th.setData({ allsto: da.data.data.pageData });
               th.globalData.picklist = da.data.data.pageData;
              "function" == typeof func && func(th.globalData.picklist);
            }
          })
        }
    },

    //同步化,在调用的时候要await
   async get_isbuy() {

      var th=this;
      await api.check_isbuy({ store_id: t.stoid, type: 5 }).then(res=>{
         var o=res;
         if (o.data.code == 0) {
          var ob = { isout: 0, isbuy: 1 };
          var arr = o.data.data.pageData;
          var isbuy = 0;
          //----如果数组不为空----
          if (arr.length > 0) {
            arr.forEach(function (val, ind) {
              if (val.is_sy == 0 && val.type == 5) {
                isbuy = 1;
                var now = ut.gettimestamp();
                if (now > val.end_time) ob.isout = 1;
                return false;
              }
            })
          }
          ob.isbuy = isbuy;
          th.globalData.wxapp_buy_obj=ob;
        }
      })
    },

    //--同步化,在调用的时候要await,获取商家config--
    async getConfig_ays(){
      if(this.globalData.config!=null) return false;
      var th=this;
      await api.get_config(this.globalData.setting.stoid).then(res=>{
        var o=res;
        if(o.data.code==0){
          th.globalData.config = o.data.data;
        }
      })
    },

    //----智能跳转,判断 非tabBar,tabBar页面的跳转----
    goto:function (url) {
        var arr_tabbar=["/pages/index/index/index","/pages/goods/categoryList/categoryList",
                       "/pages/cart/cart/cart","/pages/user/index/index"];
        if(arr_tabbar.indexOf(url)!=-1){
            wx.switchTab({ url: url, })  //跳到tabbar页
        }else{
            wx.navigateTo({ url: url, })  //跳到非tabbar页
        }
    },

    //显示提示,word提示内容,type 0失败,提示   1成功
    my_warnning(word,type,that){
        var warn = that.selectComponent("#warn"); //组件的id
        warn.open(word,type);
        return 1;
    }

});