<div id="orderaAction{{ order.id }}">
    <p class=" has-text-weight-bold pt-1 pb-1 has-text-right">共{{ count__sum }}件商品，总金额{{ total_price }}元（含运费）</p>
    <div class=" buttons is-justify-content-end">
    {% if order.status == 1 %}
        <a class="button is-primary is-small" href="{% url 'shop:order-cash' order.id %}">立即支付</a>
    {% elif order.status == 3 %}
        <button class="button is-primary is-small" @click="ConfirmReceipt('{{ order.id }}')">确认收货</button>
    {% elif order.status == 4 and not payorder.is_commented %}
        <a class=" button is-primary is-small" href="{% url 'shop:comment' order.id %}">立即评价</a>
    {% endif %}
    <a href="{% url 'shop:orders-detail' order.id %}" class="button is-small">订单详情</a>
    </div>
</div>


<script>
    var confirmAction = new Vue({
        el: '#orderaAction{{ order.id }}',
        delimiters: ['{$', '$}'],
        methods: {
            // 确认收货
            ConfirmReceipt(id){
                console.log(id)
                this.$buefy.dialog.confirm({
                    message: '是否确认收货?',
                    cancelText: '取消',
                    confirmText: '确认',
                    onConfirm: () => {
                        fetch("{% url 'shop:shopapi:confirm-receipt' %}", {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/json',
                                'X-Requested-With': 'XMLHttpRequest',
                                'X-CSRFToken': bayke.getCookie('csrftoken'),
                            },
                            body: JSON.stringify({orderid: id}),
                        }).then(response => bayke.handleJSONResponse(response)).then(data => {
                            // 处理响应数据
                            // bayke.toastMessage('is-success', '确认收货成功！')
                            // location.replace(data.payurl)
                            location.reload()
                        }).catch(error => {
                            // 处理错误
                            let message = Object.values(error).join()
                            bayke.toastMessage('is-danger', message)
                        });
                    }
                })
                
            }
        }
    })
</script>