// pages/agent/billCanUseProduct/index.vue.js
import api from '../../api/api'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        param: {
            "id": "20230206161703",
            "version": 1,
            "content": {
                "pageSize": 20,
                "pageNumber": 1,
                "sa_serviceorderid": 0,
                "isAll": 0,
                "sa_orderid": 0,
                "where": {
                    "condition": ""
                }
            }
        },
        value: '',
        list: [],
        selection: []
    },
    onLoad(options) {
        console.log(options)
        if (options.id) {
            this.data.param.id = 20230421095904;
            this.data.param.content.sa_workorderid = options.id;
        }
        let pages = getCurrentPages();
        let prePage = pages[pages.length - 2];
        if (prePage) {
            this.data.param.content.sa_serviceorderid = prePage.data.sa_serviceorderid
            this.data.param.content.sa_orderid = prePage.data.sa_orderid
        }
        this.listData();
    },
    tabChange(e) {
        this.data.param.content.isAll = e.detail.title == '产品库' ? '1' : '0';
        this.data.param.content.pageNumber = 1;
        this.setData({
            list: []
        })
        this.listData()
    },
    search(data) {
        this.data.param.content.where.condition = data.detail.value
        this.data.list = []
        this.data.param.content.pageNumber = 1
        this.listData()
    },
    clear() {
        this.data.param.content.where.condition = ''
        this.data.list = []
        this.data.param.content.pageNumber = 1
        this.listData();
    },
    async listData() {
        console.log(this.data.param)
        const res = await api._post(this.data.param)
        console.log("产品列表", res)
        this.setData({
            list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
        })
    },
    handleGroupChange(event) {
        this.setData({
            selection: event.detail.value,
        });
    },
    refresh() {
        this.setData({
            selection: []
        })
    },
    onConfirm() {
        let pages = getCurrentPages();
        let prePage = pages[pages.length - 2];
        prePage.getAdd(this.data.selection)
        wx.navigateBack()
    },
    onPullDownRefresh() {
        this.data.list = []
        this.data.param.content.pageNumber = 1
        this.listData()
    },
    onReachBottom() {
        this.data.param.content.pageNumber++
        this.listData()
    },
})