<!--
 * @Author: your name
 * @Date: 2021-11-09 16:27:20
 * @LastEditTime: 2021-11-10 14:56:39
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /data-show/src/views/ModelForumDetails/MainPostUserAnalysis/index.vue
-->
<template>
    <div class="mpua-outter" v-loading="load">
        <v-label-div title="主帖用户分析" :showLine="false" :eStyle="{'border-style': 'none'}">
            <v-tab-group :btns="['性别', '认证']" @change="handlerTab"></v-tab-group>
        </v-label-div>
        <div class="mpua-inner">
            <v-echarts :opt="opt"></v-echarts>
        </div>
    </div>
</template>

<script>
import { getAttestationSex, getUserAttestation } from "@/api/ModelForumDetails";
import createOpt from "./opt";
export default {
    name: "MainPostUserAnalysis",
    data() {
        return {
            load: false,
            form: {
                sBrand: "",
                token: "",
                sSeriesName: "",
                iBBsType: 2,
            },
            sex: [],
            rz: [],
            opt: {},
            colors: [
                "#3373CC",
                "#54BF93",
                "#CC9D12",
                "#f15c80",
                "#e4d354",
                "#8085e8",
                "#8d4653",
                "#91e8e1",
                "#f7a35c",
                "#90ed7d",
                "#54BF93",
                "#3373CC",
                "#CC9D12",
                "#f15c80",
                "#e4d354",
                "#8085e8",
                "#8d4653",
                "#91e8e1",
                "#f7a35c",
                "#90ed7d",
            ],
        };
    },
    created() {
        this.form.token = this.getToken;
        this.form.sBrand = this.getBrand.brandname || '奥迪';
        this.form.sSeriesName = this.getModel.name;
        this.load = true;
        Promise.all([this.getAttestationSex(), this.getUserAttestation()]).then(() => {
            this.handlerTab(0)
            this.load = false;
        })
    },
    methods: {
        // 性别
        getAttestationSex() {
            return new Promise((resolve, reject) => {
                let obj = Object.assign({}, this.getCtime2, this.form);
                getAttestationSex(obj)
                    .then((res) => {
                        let data = res.data || {};
                        let arr = [];
                        for (let key in data) {
                            let o = {
                                key: key,
                                value: data[key],
                            };
                            arr.push(o);
                        }
                        this.sex = arr;
                        resolve(true);
                    })
                    .catch(() => {
                        reject(false);
                    });
            });
        },
        // 认证
        getUserAttestation() {
            return new Promise((resolve, reject) => {
                let obj = Object.assign({}, this.getCtime2, this.form);
                getUserAttestation(obj)
                    .then((res) => {
                        let data = res.data || {};
                        let arr = [];
                        for (let key in data) {
                            let o = {
                                key: key,
                                value: data[key],
                            };
                            arr.push(o);
                        }
                        this.rz = arr;
                        resolve(true);
                    })
                    .catch(() => {
                        reject(false);
                    });
            });
        },
        handlerTab(n) {
            switch (n) {
                case 0:
                    this.opt = createOpt(this.sex, this.colors)
                    break;
                case 1:
                    this.opt = createOpt(this.rz, this.colors)
                    break;
                default:
                    break;
            }
        },
    },
};
</script>

<style lang="less" scoped>
.mpua-outter {
    width: 472px;
    height: 412px;
    .mpua-inner {
        width: 100%;
        height: calc(100% - 48px);
    }
}
</style>
