Component({
    properties: {
        list: Array,
        deleteItem: Function,
        changeQueue: Function, //修改队列
        disabled: Boolean
    },
    options: {
        addGlobalClass: true
    },
    methods: {
        /* 修改产品数量/单价 */
        onBlur(e) {
            let {
                name,
                index
            } = e.currentTarget.dataset;
            let item = this.data.list[index];
            if (e.detail.value <= 0) {
                wx.showToast({
                    title: '非法数值',
                    icon: "none"
                });
            } else {
                if (item[name] == e.detail.value) return;
                item[name] = e.detail.value - 0;
                item.outamount = item.outqty * item.price;
                if (name == "price" && item[name] > item.marketprice) item[name] = item.marketprice;
                let obj = {};
                ["sa_salesforecastid", "itemid", "orderqty", "orderamount", "invoiceqty", "price", "invoiceamount", "outqty"].forEach(v => obj[v] = item[v]);
                this.triggerEvent("changeQueue", obj)
            }
            this.setData({
                list: this.data.list
            })
        },
        deleteProduct(e) {
            const {
                sa_salesforecastbillid,
                sa_salesforecastid,
                itemname
            } = e.currentTarget.dataset.item,
                that = this;
            wx.showModal({
                title: '提示',
                content: `是否确认删除“${itemname}”?`,
                complete: ({
                    confirm
                }) => {
                    if (confirm) that.triggerEvent("deleteItem", {
                        sa_salesforecastbillid,
                        sa_salesforecastid,
                        sa_projectid: 0
                    });
                }
            })
        },
    }
})