Component({
    properties: {
        list: Array,
        deleteItem: Function,
        changeQueue: Function, //修改队列
        disabled: Boolean
    },
    options: {
        addGlobalClass: true
    },
    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,
                itemclassname
            } = e.currentTarget.dataset.item,
                that = this;
            wx.showModal({
                title: '提示',
                content: `是否确认删除“${itemclassname}”?`,
                complete: ({
                    confirm
                }) => {
                    if (confirm) that.triggerEvent("deleteItem", [sa_contract_itemsaleclassid]);
                }
            })
        },
    }
})