let myPro = require("../../../utils/wxRequest.js");
let util = require("../../../utils/util.js");
Page({
    /**
     * 页面的初始数据
     */
    data: {
		imgUrl: getApp().globalData.imgUrl,
		active: 0, // 0待审核 -1驳回 1通过 
		dataList: [],
		page: 1,
		size: 10,
		finished: false,
		loading: false // 全局loading
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
		let that = this;
		if(options.status != null){
			that.setData({
				active: options.status
			});
		};
		that.getDataList();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
		let that = this;
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
		let that = this;
		if(!that.data.finished){
			that.getDataList();
		};
    },
	// 获取商家订单列表
	getDataList(){
		let that = this;
		let params = {
			page: that.data.page,
			size: that.data.size,
			status: that.data.active
		};
		that.setData({
			loading: true
		});
		myPro.wxRequest("store/tx/log","GET",params).then(res=>{
			that.setData({
				loading: false
			});
			let tempList = res.result;
			// 无数据
			if(tempList.length == 0){
				wx.showToast({
					title: "暂无更多数据",
					icon: "none"
				});
				that.setData({
					finished: true
				});
			}else{
				// 有数据
				let list = that.data.dataList;
				list = list.concat(tempList);
				that.setData({
					dataList: list,
					page: that.data.page+1
				});
			}
		}).catch(err=>{
			that.setData({
				loading: false
			});
			console.log('报错信息',err);
			wx.showToast({
				title: err,
				icon: "none"
			})
		});
	},
	// 切换列表
	onClickTab(event){
		// console.log('event',event)
		let that = this;
		that.setData({
			active: event.detail.name,
			page: 1,
			dataList: [],
			finished: false
		})
		that.getDataList();
	}
})