<template>
    <view class="permissinon-btn">
        <or-button v-if="isShow" @click="$emit('click:button')"><slot>退款</slot></or-button>
    </view>
</template>

<script>
import orButton from "./button.vue";
import { mapState } from 'vuex';
/**
 * 全部订单都能退两次, 所有订单最多只能退2次款
 * 只要订单金额是未全退的，都能退
 * 0元订单不能退
 * 
*/
export default {
    components: {
        orButton
    },
    props: [ 'pay_amount', 'refund_amount', 'refund_times' ],
    computed: {
        ...mapState([ 'brandInfo' ]),
        payAmount(){
            let { pay_amount } = this;
            return +pay_amount || 0
        },
        refundAmount(){
            let { refund_amount } = this;
            return +refund_amount || 0
        },
        isShow(){
            let { payAmount, refundAmount, refund_times, brandInfo } = this;
            console.log('brandInfo', payAmount, refundAmount, refund_times, brandInfo)
            if(
                payAmount - refundAmount > 0
                &&[0, 1].includes(refund_times)
                &&brandInfo?.permission?.['1018'] // 退款权限
            ){
                return true
            }
            return false
        }
    },
}
</script>

<style>

</style>