<template>
    <KVTable title="基本信息" :list="list" :rightButton="rightButton"></KVTable>
</template>

<script>
import KVTable from '@/component/KVTable';

import { getOneStandard } from "@/api/system";
import { resourceMixin } from '@/mixin/resource';
import { isEmpty } from '@/utils/tool';

export default {
    components: {
        KVTable
    },
    mixins: [resourceMixin],
    data () {
        return {
            loading: false,
            list: [],
            rightButton: {},
        }
    },
    computed: {
        id() {
            return this.$route.params.id
        },
    },
    mounted () {
        this.initData()
    },
    methods: {
        initData() {
            if (this.id) {
                this.loading = true;
                getOneStandard(this.id).then(res => {
                    this.setupList(res);
                    this.loading = false;
                })
            }
        },
        parseStandardType(str) {
            if (isEmpty(str)) {
                return '';
            }
            const arr = str.split(',');
            const res = [];
            arr.map(item => {
                const name = this.parseUnitSize(item);
                if (name) {
                    res.push(name);
                }
            });
            return res.join('/');
        },
        setupList(data) {
            this.list = [
                {
                    label: '抽查事项：',
                    value: data.event || '',
                },
                {
                    label: '抽查依据：',
                    value: data.standard || '',
                },
                {
                    label: '抽查对象：',
                    value: this.parseStandardType(data.enforce_obj_type) || '',
                },
                {
                    label: '抽查主体：',
                    value: data.target || '',
                },
                {
                    label: '抽查比例：',
                    value: data.proportion || '',
                },
                {
                    label: '抽查次数：',
                    value: data.times || '',
                },
                {
                    label: '抽查方式：',
                    value: data.way || '',
                },
                {
                    label: '抽查内容及要求：',
                    value: data.content || '',
                },
                {
                    label: '备注：',
                    value: data.remark || '',
                    row: true
                },
            ]
        }
    }
}
</script>