<template>
    <div class="detail" v-loading="loading">
        <KVTable title="机构详情" :list="list" :rightButton="rightButton">
            <!-- <template #slotValue="slot">
                <template v-if="slot.row.type === 1">
                    <template v-if="slot.row.value == 1">
                        <el-tag type="success">已处理</el-tag>
                    </template>
                    <template v-else>
                        <el-tag type="danger">未处理</el-tag>
                    </template>
                </template>
                <template v-else>
                    {{ slot.row.value }}
                </template>
            </template> -->
        </KVTable>
    </div>
</template>

<script>
import KVTable from '@/component/KVTable'
import { formatDate, notEmpty } from '@/utils/tool';

import { getOrgDetail } from '@/api/org';

export default {
    components: {
        KVTable,
    },
    data () {
        return {
            loading: false,
            rightButton: {},
            list: [],
        }
    },
    computed: {
        orgId() {
            return this.$route.params.id;
        },
    },
    mounted () {
        if (notEmpty(this.orgId)) {
            this.loadDetail();
        }
    },
    methods: {
        loadDetail() {
            this.loading = true;
            getOrgDetail(this.orgId).then(res => {
                this.setupList(res);
                this.loading = false;
            });
        },
        setupList(org) {
            let extract = '';
            if (org && org.last_extract_time) {
                extract = formatDate(org.last_extract_time, true);
            }
            let create = '';
            if (org && org.create_time) {
                create = formatDate(org.create_time, true);
            }
            let update = '';
            if (org && org.update_time) {
                update = formatDate(org.update_time, true);
            }
            this.list = [
                {
                    label: '机构名称',
                    value: org && org.enforce_org_name || '',
                },
                {
                    label: '机构编码',
                    value: org && org.enforce_org_code || '',
                },
                {
                    label: '机构简称',
                    value: org && org.short_name || '',
                },
                {
                    label: '机构简码',
                    value: org && org.short_number || '',
                },
                {
                    label: '机构等级',
                    value: org && org.enforce_org_levels || '',
                },
                {
                    label: '标记',
                    value: org && org.enforce_org_remark || '',
                },
                {
                    label: '上次抽取时间',
                    value: extract,
                },
                {
                    label: '经度',
                    value: org && org.longitude || '',
                },
                {
                    label: '纬度',
                    value: org && org.latitude || '',
                },
                {
                    label: '地址',
                    value: org && org.address || '',
                },
                {
                    label: '办公电话',
                    value: org && org.office_phone || '',
                },
                {
                    label: '电子邮件',
                    value: org && org.email || '',
                },
                {
                    label: '创建人',
                    value: org && org.create_user_name || '',
                },
                {
                    label: '创建时间',
                    value: create,
                },
                {
                    label: '更新人',
                    value: org && org.update_user_name || '',
                },
                {
                    label: '更新时间',
                    value: update,
                },
            ]
        }
    },
}
</script>