<!--
 * @Author       : yuanrunwei
 * @Date         : 2021-12-03 15:18:11
 * @LastEditors  : yuanrunwei
 * @LastEditTime : 2021-12-07 16:02:13
 * @FilePath     : \spfm-market-front\src\pages\main\performance\analysis.vue
-->
<template>
    <div class="simple-container">
        <simple-table
            :list="table_list"
            :config="table_config"
            :loading="table_loading"
            @delete="handleDelete"
            @modify="handleModify"
            @check="handleCheck"
            @edit="handleEdit"
        ></simple-table>
    </div>
</template>

<script>
import simpleTable from "./components/table.vue";
export default {
    props: {
        edit: {
            type: Boolean,
            default: false,
        },
    },
    components: {
        simpleTable,
    },
    data() {
        return {
            table_list: [],
            table_loading: false,
            table_config: [
                {
                    label: "序号",
                    props: "index",
                    width: 50,
                },
                {
                    label: "指标名称",
                    props: "subject",
                },
                // {
                //     label: "来源",
                //     props: "origin",
                //     width: 100,
                // },

                {
                    label: "工作内容",
                    props: "content",
                    width: 300,
                    type: "textarea",
                    align: "left",
                },
                {
                    label: "负责人",
                    props: "leader",
                },

                // {
                //     label: "完成标志及计分方法（需体现出完成时间）",
                //     props: "mark",
                //     width: 500,
                //     type: "textarea",
                //     align: "left",
                // },
                // {
                //     label: "分值",
                //     width: 50,
                //     props: "score",
                // },

                {
                    label: "本月绩效自评",
                    props: "personal_month",
                    width: 300,
                    children: [
                        {
                            label: "完成情况",
                            props: "personal_month_status",
                        },
                        {
                            label: "完成情况自评",
                            props: "personal_month_self",
                        },
                        // {
                        //     label: "工作内容",
                        //     props: "personal_month_content",
                        // },
                    ],
                },
                {
                    label: "下月绩效计划",
                    props: "next_month",
                    children: [
                        {
                            label: "工作内容",
                            props: "next_month_content",
                        },
                        {
                            label: "计分方法",
                            props: "next_month_method",
                        },
                        {
                            label: "分值",
                            width: 50,
                            props: "score",
                        },
                    ],
                },
            ],
        };
    },
    watch: {
        edit() {
            this.handleInit();
        },
    },
    methods: {
        handleInit() {
            this.table_list = JSON.parse(
                sessionStorage.global_data
            )[0].template_excel;
            this.table_config.forEach((element) => {
                if (["personal_month", "next_month"].includes(element.props)) {
                    element.children.forEach((element) => {
                        element.type = this.edit ? "edit" : "";
                    });
                }
            });
        },
        handleEdit() {},
        handleCheck() {},
        handleDelete() {},
        handleModify(params) {
            const object = JSON.parse(sessionStorage.global_data)[0];
            sessionStorage.setItem(
                "global_data",
                JSON.stringify([
                    {
                        ...object,
                        template_excel: params,
                    },
                ])
            );
            // this.table_list = JSON.parse(
            //     sessionStorage.global_data
            // )[0].template_excel;
        },
    },
    mounted() {
        this.handleInit();
    },
};
</script>

<style></style>
