const currency = require("../../../../../utils/currency"),
    CNY = value => currency(value, {
        symbol: "￥",
        precision: 2
    }).format();
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;
                if (name == "price") item[name] = item[name] > item.marketprice ? item[name] = item.marketprice : (item[name] - 0).toFixed(2) - 0;
                item.amount = CNY(currency(item.price).multiply(item.qty));
                let obj = {};
                ["sa_project_itemsid", "itemid", "qty", "remarks", "marketprice", "price"].forEach(v => obj[v] = item[v]);
                this.triggerEvent("changeQueue", obj)
            }
            this.setData({
                list: this.data.list
            })
        },
        deleteProduct(e) {
            const {
                sa_project_itemsid,
                itemname
            } = e.currentTarget.dataset.item,
                that = this;
            wx.showModal({
                title: '提示',
                content: `是否确认删除“${itemname}”?`,
                complete: ({
                    confirm
                }) => {
                    if (confirm) that.triggerEvent("deleteItem", [sa_project_itemsid]);
                }
            })
        },
    }
})