<template>
  <div>
    <QueryListPage ref="queryListPage" :pager-config="pagerConfig" :query-form="queryForm" :query-list="queryList" />
    <edit-subsystem ref="editSubsystem" />
  </div>
</template>

<script>
import { queryMapSystemPaged, deleteMapSystem } from '@/api/trainingPlatform';
import { getPublishMapListOnline } from '@/api/jmap/map';
import EditSubsystem from './editSubsystem';
const simTypeMap = {
    METRO: '地铁CBTC',
    RAILWAY: '大铁CTC',
    EMERGENCY: '应急调度'
};
const simUsageMap = {
    SINGLE_MEMBER: '单角色仿真',
    SINGLE_CLIENT: '单客户端仿真',
    JOINT: '综合演练'
};
export default {
    name: 'PublishMap',
    components: {
        EditSubsystem
    },
    data() {
        return {
            dialogVisible: false,
            pagerConfig: {
                pageSize: 'pageSize',
                pageIndex: 'pageNum'
            },
            queryForm: {
                labelWidth: '80px',
                reset: true,
                leftSpan: 18,
                queryObject: {
                    name: {
                        type: 'text',
                        label: '名称'
                    }
                }

            },
            queryList: {
                query: this.queryFunction,
                selectCheckShow: false,
                indexShow: true,
                columns: [
                    {
                        title: '名称',
                        prop: 'name'
                    },
                    {
                        title: '地图',
                        prop: 'mapId',
                        type: 'tag',
                        columnValue: (row) => { return this.$convertField(row.mapId, this.mapList, ['id', 'name']); },
                        tagType: () => { return 'success'; }
                    },
                    {
                        title: '系统',
                        prop: 'simType',
                        type: 'tag',
                        columnValue: (row) => { return simTypeMap[row.simType]; },
                        tagType: () => { return 'success'; }
                    },
                    {
                        title: '使用方式',
                        prop: 'simUsage',
                        type: 'tag',
                        columnValue: (row) => { return simUsageMap[row.simUsage]; },
                        tagType: () => { return ''; }
                    },
                    {
                        title: '描述',
                        prop: 'desc'
                    },
                    {
                        type: 'button',
                        title: '操作',
                        width: '300',
                        buttons: [
                            {
                                name: '更新',
                                handleClick: this.updateRow
                            },
                            {
                                name: '删除',
                                handleClick: this.deleteRow
                            }
                        ]
                    }
                ],
                actions: [
                    { text: '新建', handler: this.handleAddSubsystem },
                    { text: '返回', handler: this.goBack }
                ]
            }
        };
    },
    computed: {
        isShow() {
            return this.$store.getters['roles'].indexOf('05');
        }
    },
    created() {
        this.mapList = [];
        getPublishMapListOnline().then(resp => {
            this.mapList = resp.data;
        });
    },
    methods: {
        queryFunction(params) {
            params['mapId'] = this.$route.query.mapId;
            return queryMapSystemPaged(params);
        },
        deleteRow(row) {
            this.$confirm('删除子系统，是否继续？', '提 示', {
                confirmButtonText: '确 定',
                cancelButtonText: '取 消',
                type: 'warning'
            }).then(() => {
                deleteMapSystem(row.id).then(resp => {
                    this.reload();
                }).catch(error => {
                    this.$message.error(`删除子系统: ${error.message}`);
                });
            }).catch( () => { });
        },
        updateRow(index, row) {
            this.$refs.editSubsystem.doShow(row);
        },
        handleAddSubsystem() {
            this.$refs.editSubsystem.doShow();
        },
        reloadTable() {
            this.queryList.reload();
        },
        goBack() {
            this.$router.go(-1);
        }
    }
};
</script>
<style lang="scss" scoped>
/deep/
.el-button+.el-button{
	margin-top: 5px;
	margin-left: 5px;
}
</style>
