//app.js



App({
    data: {
        minscreenHeight: 0,
    },
    onLaunch: function () {
        this.getHeight(1)
    },
    getHeight: function (n) {
        var _this = this;
        wx.getSystemInfo({
            success: function (res) {
                _this.data.minscreenHeight = res.windowHeight * n
            }
        })
    },
    goTop: function () {
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 100
        })
    },

    /**
  * 自定义post函数,返回Promise
  * +-------------------
  * @param {String} url 接口网址
  * @param {arrayObject} data 要传的数组对象 like: {name: 'name', age: 32}
  * +-------------------
  * @return {Promise} promise 返回promise供后续操作
  */
    post: function (url, data, headerParams) {
        wx.showNavigationBarLoading()
        wx.showLoading({
            title: '加载中',
        })
        var promise = new Promise((resolve, reject) => {
            let that = this;
            let postData = data;
            let baseUrl = 'https://ruiwechat.w.broteam.cn/';
            //网络请求
            let header = {
                'content-type': 'application/x-www-form-urlencoded'
            }
            header = Object.assign(header, headerParams)
            wx.request({
                url: baseUrl + url,
                data: postData,
                method: 'POST',
                header: header,
                success: function (res) {//返回取得的数据
                    if (res.data.code == '200') {
                        resolve(res.data.data);
                    } else if (res.data.code == '10001') {//用户未
                        // wx.showModal({
                        // title: '提示',
                        // content: res.data.msg,
                        // showCancel: false,
                        // success: function (res) {
                        // if (res.confirm) {
                        // wx.removeStorageSync('token');
                        // wx.navigateTo({
                        // url: '/pages/start/start',
                        // })
                        // }
                        // }
                        // })
                    } else if (res.data.code == '40000') {
                        wx.showModal({
                            title: '提示',
                            content: res.data.msg,
                            showCancel: false,
                            success: function (res) { }
                        })
                    } else if (res.data.code == '40005') {

                    } else if (res.data.code == '40006') {

                    } else {
                        wx.showModal({
                            title: '提示',
                            content: res.data.msg,
                            showCancel: false,
                        })
                        reject(res.data)
                    }
                    wx.hideLoading()
                    wx.hideNavigationBarLoading()
                },
                error: function (e) {
                    console.log(e)
                    reject('网络出错');
                    // wx.hideLoading()
                    wx.hideNavigationBarLoading()
                }
            })
        });

        return promise;
    },
    globalData: {
        userInfo: null
    },


    //   动画
    //渐入,渐出实现 
    show: function (that, param, opacity) {
        var animation = wx.createAnimation({
            //持续时间800ms
            duration: 800,
            timingFunction: 'ease',
        });
        //var animation = this.animation
        animation.opacity(opacity).step()
        //将param转换为key
        var json = '{"' + param + '":""}'
        json = JSON.parse(json);
        json[param] = animation.export()
        //设置动画
        that.setData(json)
    },

    //滑动渐入渐出
    slideupshow: function (that, param, px, opacity) {
        var animation = wx.createAnimation({
            duration: 1000,
            timingFunction: 'ease',
        });
        animation.translateY(px).opacity(opacity).step()
        //将param转换为key
        var json = '{"' + param + '":""}'
        json = JSON.parse(json);
        json[param] = animation.export()
        //设置动画
        that.setData(json)
    },

    //向右滑动渐入渐出
    sliderightshow: function (that, param, px, opacity) {
        var animation = wx.createAnimation({
            duration: 1500,
            timingFunction: 'ease',
        });
        animation.translateX(px).opacity(opacity).step()
        //将param转换为key
        var json = '{"' + param + '":""}'
        json = JSON.parse(json);
        json[param] = animation.export()
        //设置动画
        that.setData(json)
    },
    globalData: {
        userInfo: null,
        baseImgUrl: 'http://pjq0ww1cj.bkt.clouddn.com/'
    }
})