<!--待付款-->
<template>
    <div id="toBePaid">
        <Nav :title="navTitle.title"></Nav>
        <div class="content">
            <template v-if="shoppingLsit.length">
                <div class="cell" v-for="item,index in shoppingLsit" :key="index">
                    <div class="top">
                        <div class="left" @click="clickCell(item)">
                            <van-image :src="requestUrl+item.faceImg" />
                        </div>
                        <div class="right" @click="clickCell(item)">
                            <div class="text">
                                <span>{{item.commodityName}}</span>
                            </div>
                            <div class="discount">
                                <div class="discountBox"></div>
                                <div class="delBox">
                                    <!-- <template v-if="navTitle.type==0">
                                        <van-icon @click="deletes(item.id)" name="delete-o" color="#999999" size="14" />
                                    </template> -->
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="bottom">
                        <div class="bottomCell"  @click="clickCell(item)">
                            <div>
                                <span>{{$t('toBePaid.location')}}</span>
                            </div>
                            <div class="def1">
                                <span>{{item.departurePlace}}</span>
                                <span>
                                    <van-icon name="arrow" color="#999999" size="15" />
                                </span>
                            </div>
                        </div>
                        <div class="bottomCell"  @click="clickCell(item)">
                            <div>
                                <span>{{$t('toBePaid.date')}}</span>
                            </div>
                            <div class="def1">
                                <span>{{item.departureDate}}</span>
                                <span>
                                    <van-icon name="arrow" color="#999999" size="15" />
                                </span>
                            </div>
                        </div>
                        <div class="butBox">
                            <!-- 待付款 -->
                            <template v-if="pageType==1">
                                <div>
                                    <van-button @click="cancel(item.id)" color="#38d0c9" size="small" plain block>{{$t('toBePaid.cancelOrder')}}</van-button>
                                </div>
                                <div>
                                    <van-button @click="payment(item)" color="#38d0c9" size="small" block>{{$t('toBePaid.payment')}}</van-button>
                                </div>
                            </template>
                            <!-- 待参加 -->
                            <template v-if="pageType==2">
                                <div>
                                    <van-button @click="refund(item.id)" color="#E94225" size="small" block>{{$t('toBePaid.refund')}}</van-button>
                                </div>
                            </template>
                            <!-- 已完成 -->
                            <template v-if="pageType==3">
                                <div>
                                    <van-button @click="evaluate(item)" color="#38d0c9" size="small" block>{{$t('toBePaid.evaluate')}}</van-button>
                                </div>
                            </template>
                        </div>
                    </div>
                </div>
            </template>
            <template v-else>
                <van-empty :description="$t('toBePaid.none')"></van-empty>
            </template>
        </div>
        <!-- 评价弹窗 -->
        <van-popup v-model="popupShow">
            <div class="evaluateBox">
                <div class="titleBox"><span>{{$t('toBePaid.evaluateContent')}}</span></div>
                <div class="textBox">
                    <div>
                        <van-cell-group inset>
                            <van-field v-model="popupShowMessage" rows="2" type="textarea" maxlength="50" placeholder="レビューを書く" show-word-limit />
                        </van-cell-group>
                    </div>
                </div>
                <div class="butsBox">
                    <span @click="butsCancel">{{$t('toBePaid.cancel')}}</span>
                    <span @click="butsConfirm">{{$t('toBePaid.confirm')}}</span>
                </div>
            </div>
        </van-popup>
        <van-overlay :show="loading" @click="loading = false">
            <div class="wrapper" @click.stop>
                <div class="block">
                    <van-loading color="#1989fa" size="50" />
                </div>
            </div>
        </van-overlay>
    </div>
</template>

<script>
import Nav from "@/components/pages/nav";
import { getOrderList,addOrderEvalute,delOrder,returnPay } from "@/api/comp/personal.js";
export default {
    data() {
        return {
            loading: true,
            shoppingLsit: [],
            pageType: null,
            childPageType:null,
            popupShow: false,
            popupShowMessage: "",
            navTitle: {
                title:'',
                type:null,
            },
            requestUrl: process.env.VUE_APP_BASE_API,
            evaluateId:null,
        };
    },
    mounted() {
        //判断进入页面的状态 1待付款 2待参加 3已完成 4已退款 5已评价
        this.pageType = this.$route.query.type;
        switch (Number(this.pageType)) {
            case 1:
                this.navTitle={
                    title:this.$t('toBePaid.toBePaid'),
                    type:0,
                };
                this.childPageType=1;
                break;
            case 2:
                this.navTitle={
                    title:this.$t('toBePaid.toBeAttended'),
                    type:1,
                };
                this.childPageType=2;
                break;
            case 3:
                this.navTitle={
                    title:this.$t('toBePaid.completed'),
                    type:2,
                };
                this.childPageType=3;
                break;
            case 4:
                this.navTitle={
                    title:this.$t('toBePaid.refunded'),
                    type:99,
                };
                this.childPageType=4;
                break;
            case 5:
                this.navTitle={
                    title:this.$t('toBePaid.evaluated'),
                    type:9,
                };
                this.childPageType=5;
                break;
        };
        this.getData();
    },
    methods: {
        getData(){
            this.loading = true;
            //写入用户信息
            let require={
                status:this.navTitle.type,
            }
            getOrderList(require).then(res=>{
                if(res.code==200){
                    this.shoppingLsit=res.data;
                    this.loading = false;
                }
            })
        },
        clickCell(item){
            // this.$store.commit("home/SET_ORDER_INFORMATION",commodityData);
            this.$store.commit("home/SET_PRODUCT", item);
            this.$router.push({
                path: "/detailTtoBePaid",
                query:{type:this.childPageType}
            });
        },
        //取消订单
        cancel(id) {
            this.$dialog
                .confirm({
                    title: this.$t('toBePaid.tips'),
                    message: this.$t('toBePaid.cancelConfirmTips'),
                })
                .then(() => {
                    delOrder(id).then(res=>{
                        if(res.code==200){
                            this.$toast({ type: "success", message: this.$t('toBePaid.cancelSuccessmassage') });
                            this.getData();
                        }
                    })
                })
                .catch(() => {
                    this.$notify({ type: "warning", message: this.$t('toBePaid.cancelMassage') });
                });
        },
        //待支付
        payment(item) {
            console.log(item);
            let commodityData={
                id:item.orderTotalId,
                list:[item]
            }
            this.$store.commit("home/SET_ORDER_INFORMATION",commodityData);
            this.$router.push({ path: "/confirmOrder"});
        },
        //退款
        refund(id) {
            this.$dialog
                .confirm({
                    title: this.$t('toBePaid.tips'),
                    message: this.$t('toBePaid.refundConfirmTips'),
                })
                .then(() => {
                    returnPay(id).then(res=>{
                        if(res.code==200){
                            this.$toast({ type: "success", message: this.$t('toBePaid.refundSuccessmassage')});
                            this.getData();
                        }
                    })
                })
                .catch(() => {
                    this.$notify({ type: "warning", message: this.$t('toBePaid.refundMassage') });
                });
        },
        //评价
        evaluate(item) {
            this.evaluateId=item.id;
            this.popupShow = true;
        },
        // deletes(id) {
        //     this.$dialog
        //         .confirm({
        //             title: "确认",
        //             message: "是否删除此订单？",
        //         })
        //         .then(() => {
                    
        //         })
        //         .catch(() => {
        //             this.$notify({ type: "warning", message: "取消了删除" });
        //         });
        // },
        //评价取消弹窗
        butsCancel() {
            this.$notify({ type: "warning", message: this.$t('toBePaid.commentMassage') });
            this.popupShow = false;
            this.evaluateId=null;
        },
        //评价取消确认
        butsConfirm() {
            if(!this.popupShowMessage){
                this.$toast({ type: "fali", message: this.$t('toBePaid.evaluateMessage') });
            }
            let quire={
                orderId:this.evaluateId,
                content:this.popupShowMessage,
            }
            addOrderEvalute(quire).then(res=>{
                if(res.code==200){
                    this.$toast({ type: "success", message: this.$t('toBePaid.commentSuccessmassage') });
                    this.popupShow = false;
                    this.popupShowMessage='';
                    location.reload();
                }
            })
        },
    },
    components: {
        Nav,
    },
};
</script>

<style lang="scss" scoped>
#toBePaid {
    .content {
        background: #f9f9f9;
        min-height: calc(100vh - 0.44rem /* 128/100 */);
        padding: 0.12rem /* 12/100 */;
        box-sizing: border-box;
        .cell {
            background: #fff;
            margin-bottom: 0.12rem /* 12/100 */;
            border-radius: 0.05rem /* 5/100 */;
            box-shadow: 0px 0px 5px #e9e9e9;
            .top {
                display: flex;
                padding: 0.12rem /* 12/100 */;
                box-sizing: border-box;
                height: 1.2rem /* 120/100 */;
                .left {
                    width: 30%;
                    display: flex;
                    align-items: center;
                    overflow: hidden;
                }
                .right {
                    width: 70%;
                    padding: 0 0 0 0.1rem /* 10/100 */;
                    box-sizing: border-box;
                    text-align: left;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    .text {
                        font-size: 0.16rem /* 16/100 */;
                    }
                    .discount {
                        font-size: 0.13rem /* 13/100 */;
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                    }
                }
            }
            .bottom {
                padding: 0.12rem /* 12/100 */;
                .bottomCell {
                    font-size: 0.15rem /* 15/100 */;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    padding: 0.14rem /* 14/100 */ 0;
                    > div:nth-child(1) {
                        > span:nth-child(1) {
                            margin-right: 0.1rem /* 10/100 */;
                        }
                        > span:nth-child(2) {
                            color: #e94225;
                        }
                    }
                    .def1 {
                        > span:nth-child(1) {
                            margin-right: 0.05rem /* 5/100 */;
                        }
                    }
                }
                .bottomCell {
                    border-bottom: 1px solid #eeeeee;
                }
                .butBox {
                    font-size: 0.14rem /* 14/100 */;
                    padding: 0.12rem /* 12/100 */ 0;
                    display: flex;
                    align-items: center;
                    justify-content: flex-end;
                    > div {
                        width: 30%;
                        button{
                        border-radius:30px;
                        }
                    }
                    > div:nth-child(2) {
                        margin-left: 10px;
                    }
                }
            }
        }
    }
    .evaluateBox {
        padding: 0.05rem 0 /* 12/100 */;
        background: #fff;
        border-radius: 0.05rem /* 5/100 */;
        box-sizing: border-box;
        text-align: left;
        width: 3rem /* 300/100 */;
        .titleBox {
            font-size: 0.16rem /* 16/100 */;
            // font-weight: bold;
            padding: 0.16rem /* 12/100 */ 0.12rem;
        }
        .textBox {
            padding: 0 0.12rem;
            > div {
                font-size: 0.14rem /* 14/100 */;
                border: 1px solid #6acdc8;
                border-radius: 0.04rem /* 1/100 */;
                margin-bottom: 0.12rem /* 12/100 */;
            }
        }
        .butsBox {
            font-size: 0.14rem /* 14/100 */;
            border-top: 1px solid #eeeeee;
            > span {
                display: inline-block;
                width: 50%;
                padding: 12px;
                box-sizing: border-box;
                text-align: center;
            }
            > span:nth-child(1) {
                color: #999999;
            }
            > span:nth-child(2) {
                color: #38d0c9;
                border-left: 1px solid #eeeeee;
            }
        }
    }
}
</style>
<style>
#toBePaid .van-popup {
    background: none;
}
#toBePaid .van-image{
    width: 100%;
    height: 100%;
}
#toBePaid .van-button--small {
    height: 32px;
    padding: 0 8px;
    font-size: 12px
}
</style>