Component({
    properties: {
        list: {
            type: Array
        },
        deleteItem: {
            type: Function
        },
        changeQueue: {
            type: Function
        }, //修改队列
        disabled: {
            type: Boolean
        }
    },
    options: {
        addGlobalClass: true
    },
    lifetimes: {
        attached: function () {
            getApp().globalData.Language.getLanguagePackage(this)
        }
    },
    methods: {
        /* 步进器回调 */
        onBlur(e) {
            let {
                index
            } = e.currentTarget.dataset,
                detail = (e.detail.value - 0).toFixed(2),
                item = this.data.list[index];
            console.log(detail)
            if (detail >= 100) {
                item.discountrate = 100
            } else if (detail <= 0) {
                item.discountrate = 1
            } else {
                item.discountrate = detail;
            }
            this.setData({
                [`list[${index}]`]: item
            })
            let obj = {};
            ["itemclassid", "sa_contract_itemsaleclassid", "discountrate", "sa_quotedprice_itemclassid"].forEach(v => obj[v] = item[v]);
            obj.discountrate = (obj.discountrate / 100).toFixed(4);
            this.triggerEvent("changeQueue", obj)
        },
        /* 计算百分比 */
        getPercent(num, total) {
            num = parseFloat(num);
            total = parseFloat(total);
            if (isNaN(num) || isNaN(total)) {
                return "-";
            }
            return total <= 0 ? "0%" : Math.round((num / total) * 10000) / 100;
        },
        deleteProduct(e) {
            const {
                sa_contract_itemsaleclassid,
                sa_quotedprice_itemclassid,
                itemclassname
            } = e.currentTarget.dataset.item,
                that = this;
            wx.showModal({
                title: getApp().globalData.Language.getMapText('提示'),
                content: getApp().globalData.Language.getMapText('是否确认删除') + `“${itemclassname}”?`,
                cancelText: getApp().globalData.Language.getMapText('取消'),
                confirmText: getApp().globalData.Language.getMapText('确定'),
                complete: ({
                    confirm
                }) => {
                    if (confirm) that.triggerEvent("deleteItem", {
                        sa_contract_itemsaleclassids: sa_contract_itemsaleclassid ? [sa_contract_itemsaleclassid] : [],
                        sa_quotedprice_itemclassids: sa_quotedprice_itemclassid ? [sa_quotedprice_itemclassid] : [],
                    });
                }
            })
        },
    }
})