<!--积分记录-->
<template>
    <div id="integralRecord">
        <Nav :title="$t('integralRecord.title')"></Nav>
        <div class="content">
            <div class="divTop">
                <div class="divList">
                    <van-icon size="18" color="#fff" class="iconfont" class-prefix="icon" name="zuanshi"></van-icon>
                    <span>{{$t('integralRecord.myintegral')}}</span>
                </div>
                <div class="divRight">{{integral}}</div>
            </div>
            <template v-if="recordList.length">
                <div class="cell" v-for="item,index in recordList" :key="index">
                    <div class="top">

                        <div>
                            <template v-if="item.integralType==1||item.integralType==4||item.integralType==5||item.integralType==9">
                                <!-- <div class="title"><span>{{item.commodityName}}</span></div> -->
                                <!-- <div><span>{{$t('integralRecord.category')}}:</span><span>{{item.typeName}}</span></div>
                                <div><span>{{$t('integralRecord.orderNum')}}:</span><span>{{item.orderNo}}</span></div> -->
                                <div v-if="item.integralType==1" class="title"><span>注文</span></div>
                                <div v-if="item.integralType==4" class="title"><span>ポイント利用</span></div>
                                <template v-if="item.integralType==9">
                                    <div class="title"><span>キャンセル</span></div>
                                    <div><span>{{$t('integralRecord.orerName')}}:</span><span>{{item.commodityName}}</span></div>
                                    <div><span>{{$t('integralRecord.category')}}:</span><span>{{item.typeName}}</span></div>
                                    <div><span>{{$t('integralRecord.orderNum')}}:</span><span>{{item.orderNo}}</span></div>
                                </template>
                                <template v-if="item.integralType==5">
                                    <div class="title"><span>ポイント付与</span></div>
                                    <div><span>{{$t('integralRecord.orerName')}}:</span><span>{{item.commodityName}}</span></div>
                                    <div><span>{{$t('integralRecord.category')}}:</span><span>{{item.typeName}}</span></div>
                                    <div><span>{{$t('integralRecord.orderNum')}}:</span><span>{{item.orderNo}}</span></div>
                                </template>
                            </template>
                            <template v-else>
                                <template v-if="item.integralType==2">
                                    <div class="title"><span>{{$t('integralRecord.transferPoints')}}</span></div>
                                    <div><span>{{$t('integralRecord.transferor')}}:</span><span>{{item.turnOutPhone}}</span></div>
                                </template>
                                <template v-if="item.integralType==3">
                                    <div class="title"><span>{{$t('integralRecord.integralTransfer')}}</span></div>
                                    <div><span>{{$t('integralRecord.recipient')}}:</span><span>{{item.turnInPhone}}</span></div>
                                </template>
                            </template>
                        </div>
                        <div>
                            <div><span :style="{color:item.integralType==3||item.integralType==4||item.integralType==9?'#FF976A':'#38d0c9'}">{{item.integralType==3||item.integralType==4||item.integralType==9?'-':'+'}}{{item.integralNum}}</span></div>
                            <div><span>{{$t('integralRecord.integral')}}</span></div>
                        </div>
                    </div>
                    <div class="bottom">
                        <div>
                            <span>{{item.createTime}}</span>
                        </div>
                    </div>
                </div>
            </template>
            <template v-else>
                <van-empty :description="$t('integralRecord.none')"></van-empty>
            </template>
        </div>
        <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 { getCustomerIntegralRecord } from "@/api/comp/personal.js";
export default {
    data() {
        return {
            loading: true,
            recordList: [],
        };
    },
    mounted() {
        this.getData();
        // setTimeout(() => {
        //     for (let i = 0; i < 5; i++) {
        //         this.recordList.push({
        //             title: "商品标题商品标题商品标题商品标题",
        //             category: "XXXXXX",
        //             number: "1834792012318",
        //             integral: i%2==0?'+300':'-200',
        //             tiem: "2022-08-12  13:30",
        //             type:i%2==0?1:2//1转入2转出
        //         });
        //     }
        //     this.loading = false;
        // }, 1000);
    },
    computed: {
        integral() {
            let num = 0;
            //获取用户信息
            let userInfo = this.$store.state.user.userInfo;
            // console.log(userInfo,"00000");
            if (userInfo.integral) {
                num = userInfo.integral;
            }
            return num
        },
    },
    methods: {
        getData() {
            this.loading = true;
            //获取用户信息
            let userInfo = this.$store.state.user.userInfo;
            //写入用户信息
            let username = userInfo.name;
            let nickName = userInfo.nickName;
            let require = {
                name: username,
                nickName: nickName,
            };
            console.log(require);
            getCustomerIntegralRecord(require).then((res) => {
                if (res.code == 200) {
                    this.recordList = res.data;
                    this.loading = false;
                }
            });
        },
    },
    components: {
        Nav,
    },
};
</script>

<style lang="scss" scoped>
#integralRecord {
    .content {
        background: #f9f9f9;
        padding: 0.12rem /* 12/100 */;
        box-sizing: border-box;
        color: #333333;
        min-height: calc(100vh - 0.44rem /* 128/100 */);
        .cell {
            width: 100%;
            background: #fff;
            border-radius: 0.05rem /* 5/100 */;
            box-shadow: 0px 0px 5px #e9e9e9;
            padding: 0.12rem /* 12/100 */;
            box-sizing: border-box;
            text-align: left;
            margin-bottom: 0.12rem /* 12/100 */;
            .top {
                font-size: 0.14rem /* 15/100 */;
                // font-weight: bold;
                display: flex;
                justify-content: space-between;
                padding-bottom: 0.12rem /* 12/100 */;
                border-bottom: 1px solid #eeeeee;
                > div:nth-child(1) {
                    > div {
                        > span:nth-child(1) {
                            margin-right: 0.08rem /* 5/100 */;
                            line-height: 0.26rem /* 22/100 */;
                        }
                    }
                    > div.title {
                        font-size: 0.15rem /* 15/100 */;
                        font-weight: bold;
                    }
                }
                > div:nth-child(2) {
                    text-align: center;
                    > div:nth-child(1) {
                        padding-bottom: 0.05rem /* 10/100 */;
                        > span {
                            font-size: 0.17rem /* 17/100 */;
                            // color: #38d0c9;
                        }
                    }
                    > div:nth-child(2) {
                        > span {
                            font-size: 0.14rem /* 17/100 */;
                        }
                    }
                }
            }
            .bottom {
                font-size: 0.13rem /* 13/100 */;
                padding: 0.12rem /* 12/100 */ 0;
                > div {
                    > span {
                        color: #999999;
                    }
                    > span:nth-child(1) {
                        margin-right: 0.08rem /* 5/100 */;
                    }
                }
            }
        }
    }
}
.divTop {
    width: 100%;
    height: 0.72rem /* 72/100 */;
    background: url("../../../../../public/static/images/integralBg.png")
        no-repeat;
    background-size: 100% 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.16rem /* 16/100 */;
    box-sizing: border-box;
    margin-bottom: 0.1rem;
    .divList {
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 0.14rem /* 14/100 */;
        color: #fff;
        > span {
            margin-left: 0.05rem /* 10/100 */;
        }
    }
    .divRight {
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 0.24rem /* 24/100 */;
        color: #fff;
    }
}
</style>