const _Http = getApp().globalData.http,
    currency = require("../../utils/currency"),
    CNY = (value, symbol = "￥", precision = 2) => currency(value, {
        symbol,
        precision
    }).format();
Component({
    options: {
        addGlobalClass: true
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
            this.setData({
                siteid: wx.getStorageSync('userMsg').siteid
            })
        }
    },
    properties: {

    },
    data: {
        showList: false,
        showList1: false,
        list: [],
        "content": {
            "nocache": true,
            "pageNumber": 1,
            "pageTotal": 1,
            "total": null,
            "where": {
                begdate: "",
                enddate: "",
            }
        }
    },
    methods: {
        getList(id, init) {
            let content = this.data.content;
            content.sa_projectid = id;
            if (init) {
                content.pageNumber = 1;
                content.total = null;
            }
            if (!this.data.showList && content.total != null) return;
            if (content.pageNumber > content.pageTotal) return;
            _Http.basic({
                "id": 20230715112104,
                content
            }).then(res => {
                console.log("产品配置明细", res)
                if (res.code != '1') return wx.showToast({
                    title: res.data,
                    icon: "none"
                })
                content.pageNumber = res.pageNumber + 1;
                content.pageSize = res.pageSize;
                content.pageTotal = res.pageTotal;
                content.total = res.total;
                res.data = res.data.map(v => {
                    if (v.itemsClassAmount) v.itemsClassAmount = v.itemsClassAmount.map(item => {
                        item.itemclassAmount = CNY(item.itemclassAmount)
                        return item
                    })
                    v.itemSumAmount = CNY(v.itemSumAmount / (wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000))
                    v.marketprice = CNY(v.marketprice)
                    v.price = CNY(v.price)
                    v.amount = CNY(v.amount)
                    return v
                })
                this.setData({
                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
                    content,
                    id: id,
                });
            })
        },
        shrinkChange({
            detail
        }) {
            this.setData({
                showList: detail
            })
        },
        shrinkChange1({
            detail
        }) {
            this.setData({
                showList1: detail
            })
        }
    }
})