const _Http = getApp().globalData.http;

Page({
    data: {
        loading: true,
        active: 0,
        amount: 0,
        "content": {
            "isExport": 0,
            "sys_enterpriseid":"",
            "isCheck":0,
            "pageNumber": 1,
            "pageTotal": 1,
            "pageSize": 20,
            total: 0,
            "where": {
                "condition": "",
                "status": "",
                "brandname": "",
                "tradefield": ""
            },
            sort: []
        },
        filter: []
    },
    onLoad(options) {
        this.getList()
    },
    /* 处理筛选 */
    handleFilter({
        detail
    }) {
        this.setData({
            'content.where.startdate':detail.startdate,
            'content.where.enddate':detail.enddate,
        })
        this.getList(true)
    },
    /* 获取产品 */
    getList(init = false) {
        if (init.detail != undefined) init = init.detail;
        let content = this.data.content;
        if (init) content.pageNumber = 1;
        if (content.pageNumber > content.pageTotal) return;
        _Http.basic({
            "id": 20230104194002,
            content
        }).then(res => {
            console.log("订单列表", res)
            this.selectComponent('#ListBox').RefreshToComplete();
            this.setData({
                list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                "content.pageNumber": res.pageNumber + 1,
                "content.pageTotal": res.pageTotal,
                "content.sort": res.sort,
                "content.total": res.total,
                loading: false,
                amount: res.tips.rebate || 0
            })
            console.log(this.data.list);
        })
    },
    /* 搜索 */
    onSearch({
        detail
    }) {
        console.log(detail);
        this.setData({
            "content.where.condition": detail
        });
        this.getList(true)
    },
    /* 切换tabs */
    tabsChange(e) {
        let status = "";
        switch (e.detail.title) {
            case '全部':
                status = "";
                break;
            default:
                status = e.detail.title
                break;
        }
        this.setData({
            active: e.detail.index,
            "content.where.status": status
        });
        this.getList(true);
    },
    onReady() {
        this.setListHeight()
    },
    /* 设置页面高度 */
    setListHeight() {
        this.selectComponent("#ListBox").setHeight(".tips", this);
    },
})