const _Http = getApp().globalData.http,
    currency = require("../../../../utils/currency"),
    CNY = value => currency(value, {
        symbol: "￥",
        precision: 2
    }).format();
Component({
    options: {
        addGlobalClass: true
    },
    properties: {
        ownertable: {
            type: String
        },
        ownerid: {
            type: String
        },
        disabled: {
            type: Boolean,
            value: true
        }
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    data: {
        content: {
            nocache: true,
            pageNumber: 1,
            pageSize: 20,
            pageTotal: 1,
            total: null,
            where: {
                condition: ""
            }
        },
        list: [],
        showSearch: false,
        focus: false,
        condition: ""
    },
    methods: {
        toSearch() {
            if (this.data.showSearch && this.data.content.where.condition) {
                this.data.content.where.condition = '';
                this.getList("", true);
            } else if (this.data.condition) {
                this.data.content.where.condition = this.data.condition;
                this.setData({
                    condition: this.data.condition
                })
                this.getList("", true);
            }
            this.setData({
                showSearch: !this.data.showSearch
            })
            setTimeout(() => {
                this.setData({
                    focus: this.data.showSearch
                })
            }, 300)
        },
        onChange({
            detail
        }) {
            this.data.condition = detail;
        },
        onSearch({
            detail
        }) {
            this.data.content.where.condition = detail;
            this.getList("", true)
        },
        getList(id, init = false) {
            let content = this.data.content
            if (id) content.sa_contractid = id;
            if (init) {
                content.pageNumber = 1
                content.pageTotal = 1
            }
            _Http.basic({
                "id": 2025022115343002,
                content
            }).then(res => {
                console.log("关联订单", res)
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                });
                let list = res.data.map(v => {
                    v.amount = CNY(v.amount)
                    return v
                })
                this.setData({
                    "content.pageNumber": res.pageNumber + 1,
                    "content.pageTotal": res.pageTotal,
                    "content.total": res.total,
                    list: res.pageNumber == 1 ? list : this.data.list.concat(list)
                })
            })
        },
    }
})