<template>
    <div class="saletask-cart">
        <mu-button icon @click="handleClickCartButton" class="cart-button">
            <van-badge :content="qty" max="99" :color="badgeColor">
                <i class="iconfont icon-gouwuche iconstyle" />
            </van-badge>
        </mu-button>
    </div>
</template>

<script>
export default {
    name: "lj-saletask-cart",
    components: {      
    },
    props: {
        // 是否弹出列表显示购物车信息
        ifPopup: {
            type: Boolean,
            default: false
        },
        badgeColor: {
            type: String,
            default: "red"
        }
    },
    data() {
        return {
            qty: 0,
            productDraft:"saletask-edit-product-draft"
        }
    },
    created() {
        let self = this;
        this.refreshQty()

        $lj.removeEventListener("cart_refresh");
        $lj.addEventListener("cart_refresh", function (rsp) {
            self.refreshQty();
        });
    },
    methods: {
        handleClickCartButton() {
            // 刷新购物车列表
            $lj.sendEvent("saletask_edit_refresh");
            $lj.openWin("saletask-edit", {
                winMode: 0
            });
        },
        refreshQty() {
            let task = $lj.getStorage(this.productDraft);
            if(!task) return;

            this.qty = task.mxList.length;
        },
    }
}
</script>
<style>
.van-badge--fixed{
    top: 3px;
    right: 3px;
}
</style>
<style lang="less" scoped>
.saletask-cart {
    
}
</style>