Newer
Older
miniCreditFactory / pages / index / index.js
bello on 2 Jun 2020 3 KB add water text
//index.js
//获取应用实例
const app = getApp()

const test = require('../../utils/testData.js')

var U = require('../../utils/Urls.js')
var Api = require('../../utils/api.js')


Page({
    data: {
        motto: '获取openid',
        pageNo: 1,
        pageSize: 10,
        orderList: [],
    },

    onLoad: function() {
        wx.showLoading({
            title: 'loading...',
        })

        var that = this
        // 获取wx系统参数
        wx.getSystemInfo({
            success: function (res) {
                console.log(res)
                app.globalData.wxBrand = res.windowHeight
                app.globalData.wxModel = res.model
                app.globalData.wxPixelRatio = res.pixelRatio
                app.globalData.wxScreenWidth = res.screenWidth
                app.globalData.wxScreenHeight = res.screenHeight
                app.globalData.wxWindowWidth = res.windowWidth
                app.globalData.wxWindowHeight = res.windowHeight
                app.globalData.wxStatusBarHeight = res.statusBarHeight
                app.globalData.wxVersion = res.version
                app.globalData.wxSystem = res.system
                app.globalData.wxPlatform = res.platform
            },
        })

        this.onPullDownRefresh();

        // this.setData({
        //     // 设置模拟数据
        //     orderList: test.testList.rows
        // })

        
    },

    

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function(e) {
        var that = this
        wx.stopPullDownRefresh({
            success: (res) => {
                that.setData({
                    pageNo: 1
                })
                this.getList()
            }
        })
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        // this.setData({
        //     pageNo: this.data.pageNo + 1
        // })

        wx.showLoading({
            title: 'loading...',
        })

        this.getList()
    },

    /**
     * 获取任务列表数据
     */
    getList: function() {

        var that = this;

        var info = {
            pageNo: this.data.pageNo,
            pageSize: 10,
            taskType: '01'
        };

        // 请求列表数据
        Api.Request(info, U.URLS['missionList'], function(r) {
            wx.hideLoading()
            console.log(r)
            if (r != null) {
                var list = []
                if (r['rows'] != null && r['rows'].length > 0) {
                    if (r['pageNo'] == 1) {
                        list = r['rows']
                    } else {
                        list = that.data.orderList.concat(r['rows'])
                    }
                    that.setData({
                        pageNo: r['pageNo']+1,
                        orderList: list
                    })
                }
            }
        });

    },

    // 登录获取openid
    login: function(e) {
        console.log('login start ...')
        var that = this
        wx.login({
            success(res) {
                console.log('code => ' + res.code)
                if (res.code) {
                    wx.request({
                        url: 'http://192.168.102.183:8088/wxLogin',
                        data: {
                            code: res.code
                        },
                        success(r) {
                            that.setData({
                                motto: r.data.data.openid + '\n根据openid绑定手机号码,然后获取到用户id'
                            })
                        }

                    })
                }
            }

        })
    },

    // 打开详情页
    openDetail: function(e) {
        var order = e.currentTarget.dataset.order
        var model = encodeURIComponent(JSON.stringify(order))
        wx.navigateTo({
            url: '/pages/detail/detail?model='+model,
        })
    },


})