<template>
    <view class="person_cards_wrap">
        <view class="cards_container">
            <!-- 今天消耗 -->
            <view class="card_item today">
                <view class="card_item_content">
                    <view class="card_header">
                        <text class="card_title">今天消耗（元）</text>
                    </view>
                    <view class="card_content">
                        <text class="card_value">{{ cardData.todayConsume }}</text>
                    </view>
                </view>
                <view class="card_item_content">
                    <view class="card_header">
                        <text class="card_title">今天业绩（元）</text>
                    </view>
                    <view class="card_content">
                        <text class="card_value">{{ cardData.todayPerformance }}</text>
                    </view>
                </view>
            </view>
            <!-- 条数统计 -->
            <view class="card_item card_item_full">
                <view class="card_header count">
                    <image class="count_icon" src="../../../static/icons/statistics.png" alt=""></image>
                    <text class="card_title">条数统计</text>
                </view>
                <view class="card_content">
                    <view class="count_stats">
                        <view class="count_item">
                            <text class="count_value">{{ cardData.countTypeA }}</text>
                            <text class="count_label">A类</text>
                        </view>
                        <view class="count_item">
                            <text class="count_value">{{ cardData.countTypeB }}</text>
                            <text class="count_label">B类</text>
                        </view>
                        <view class="count_item">
                            <text class="count_value">{{ cardData.countTypeC }}</text>
                            <text class="count_label">C类</text>
                        </view>
                    </view>
                </view>
            </view>

            <!-- 上门 -->
            <view class="card_item card_item_full">
                <view class="card_content">
                    <view class="visit_stats">
                        <view class="visit_item">
                            <text class="visit_label">上门</text>
                            <text class="visit_value visitc_count">{{ cardData.visitCount }}</text>
                        </view>
                        <view class="visit_item">
                            <text class="visit_label">上门率</text>
                            <text class="visit_value">{{ cardData.visitRate }}</text>
                        </view>
                        <view class="visit_item">
                            <text class="visit_label">成交率</text>
                            <text class="visit_value">{{ cardData.dealRate }}</text>
                        </view>
                        <view class="visit_item">
                            <text class="visit_label">投产比</text>
                            <text class="visit_value">{{ cardData.roi }}</text>
                        </view>
                    </view>
                </view>
            </view>

            <!-- 当前排名 -->
            <view class="card_item card_item_full">
                <view class="card_content">
                    <view class="ranking_stats">
                        <view class="ranking_info">
                            <view class="ranking_icon">
                                <image class="ranking_icon_img" src="../../../static/icons/trophy.png" alt=""></image>
                            </view>
                            <view class="ranking_info_text">
                                <text class="card_title">当前排名</text>
                                <text class="ranking_text">击败了{{ cardData.beatRate }}%的同事</text>
                            </view>
                        </view>
                        <view class="ranking_details">
                            <view class="ranking_detail_item">
                                <text class="ranking_detail_value">{{ cardData.level }}</text>
                                <text class="ranking_detail_label">等级</text>
                            </view>
                            <view class="ranking_detail_item">
                                <text class="ranking_detail_value">{{ cardData.score }}</text>
                                <text class="ranking_detail_label">评分</text>
                            </view>
                        </view>
                    </view>
                </view>
            </view>

            <!-- 折线图 -->
            <view class="card_item" v-if="false">
                <view class="chart_header">
                    <image class="chart_icon" src="../../../static/icons/line.png" alt=""></image>
                    <text class="card_title">近7天排名折线图</text>
                </view>
                <view class="charts_box">
                    <qiun-data-charts type="line" :chartData="chartData" canvasId="uniqueLineChart" :opts="opts"
                        width="700rpx" height="350rpx" backgroundColor="#ffffff" />
                </view>
            </view>
        </view>
        <!-- 最新线索 -->
        <view class="latest_clue" v-if="clueList.length > 0">
            <view class="clue_header">
                <text class="card_title">最新线索</text>
                <view class="more_btn" @click="toPrivateClue">
                    <text>更多</text>
                    <u-icon name="arrow-right" size="16" color="#2563eb"></u-icon>
                </view>
            </view>
            <view class="clue_list">
                <view class="clue_item" v-for="(item, index) in clueList" :key="index">
                    <view class="clue_star">
                        <u-icon name="star-fill" size="20" color="#facc15"></u-icon>
                        <text class="clue_name">{{ item.star }}</text>
                    </view>
                    <text class="clue_name">{{ item.name }}</text>
                    <view class="clue_info">
                        <text class="clue_title">{{ item.prodTitle }}</text>
                        <text class="clue_desc">{{ item.desc }}</text>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            // 卡片数据
            cardData: {
                todayConsume: '-',
                todayPerformance: '-',
                countTypeA: '-',
                countTypeB: '-',
                countTypeC: '-',
                visitCount: '-',
                visitRate: '-',
                dealRate: '-',
                roi: '-',
                beatRate: '-',
                level: '-',
                score: '-'
            },
            chartData: {},
            opts: {
                color: ["#1890FF"],
                padding: [10, 10, 0, 0],
                dataLabel: false,
                dataPointShape: false,
                enableScroll: false,
                legend: {
                    show: false
                },
                xAxis: {
                    disableGrid: true
                },
                yAxis: {
                    gridType: "dash",
                    dashLength: 2,
                    axisLabel:{
                        show: false
                    }
                },
                extra: {
                    line: {
                        type: "curve",
                        width: 3,
                        activeType: "hollow",
                        linearType: "custom",
                        onShadow: true,
                        animation: "horizontal"
                    }
                }
            },
            clueList: [],
        };
    },

    methods: {
        getCardData() {
            uni.$u.api.getPersonCards({ userId: this.$store.state.user.userInfo.userId }).then(res => {
                if (res.code === 200) {
                    this.cardData = res.data;
                }
            });
        },
        getClueList() {
            uni.$u.api.getPersonLatestClue({ userId: this.$store.state.user.userInfo.userId }).then(res => {
                if (res.code === 200) {
                    this.clueList = res.data;
                }
            });
        },
        async getChartData() {
            const res = await uni.$u.api.getPersonRanking({ userId: this.$store.state.user.userInfo.userId });
            if (res.code === 200) {
                let data = {
                    categories: res.data.map(item => item.x),
                    series: [
                        {
                            name: "近7天排名",
                            data: res.data.map(item => item.y),
                            setShadow: [
                                3,
                                8,
                                15,
                                "#1890FF"
                            ],
                        }
                    ]
                }
                this.chartData = JSON.parse(JSON.stringify(data))
            }
        },
        // 跳转私有线索页面
        toPrivateClue() {
            uni.switchTab({ url: '/pages/privateClue/index' });
        },
    },
    mounted() {
        if (this.$store.state.user.userInfo.userId === '12234') {
            this.getCardData();
            this.getClueList();
            this.$nextTick(() => {
                this.getChartData();
            })
        }
    },

};
</script>

<style lang="scss" scoped>
@import './styles/index.scss';
</style>