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

<script>
    import { superAdmin } from '@/router';
    import { getSkinStyleList } from '@/api/management/mapskin'
    import { getRunPlanLoadList, createRunPlanCommon, runPlanTemplateList } from '@/api/runplan';
    import { UrlConfig } from '@/router/index';

    export default {
        name: 'RunPlanCommon',
        data() {
            return {
                skinStyleList: [],
                pagerConfig: {
                    pageSize: 'pageSize',
                    pageIndex: 'pageNum'
                },
                queryForm: {
                    labelWidth: '140px',
                    reset: true,
                    queryObject: {
                        mapName: {
                            type: 'text',
                            label: '地图名称'
                        },
                        runPlanName: {
                            type: 'text',
                            label: '运行图名称'
                        }
                    }
                },
                queryList: {
                    query: this.queryFunction,
                    selectCheckShow: false,
                    indexShow: true,
                    columns: [
                        {
                            title: '地图名称',
                            prop: 'mapName'
                        },
                        {
                            title: '运行图名称',
                            prop: 'runPlanName'
                        },
                        {
                            type: 'button',
                            title: '操作',
                            width: '350',
                            hide: () => { return this.$store.state.user.roles.indexOf(superAdmin) < 0; },
                            buttons: [
                                // {
                                //     name: '删除',
                                //     handleClick: this.handleDelete,
                                //     type: 'danger',
                                // },
                                {
                                    name: '预览',
                                    handleClick: this.handleView,
                                    type: '',
                                }
                            ]
                        }
                    ],
                    actions: [
                        { text: '创建', btnCode: 'employee_insert', handler: this.handleCreateCommonPlan },
                    ]
                },

                currentModel: {}
            }
        },
        methods: {
            convertField(fieldValue, enumList, converFormat) {
                if (converFormat && converFormat.length >= 2) {
                    let value = converFormat[0];
                    let label = converFormat[1];
                    for (let i = 0; enumList && i < enumList.length; i++) {
                        if ('' + fieldValue === '' + enumList[i][value]) {
                            return enumList[i][label];
                        }
                    }
                }
            },
            queryFunction(params) {
                params['userId'] = '';
                return getRunPlanLoadList(params);
            },
            handleCreateCommonPlan() {
                this.$router.push({ path: `${UrlConfig.publish.runPlanCommon}/add` });
            },
            // 删除
            // handleDelete(index, row) {
            //     this.$confirm('此操作将删除此通用运行图, 是否继续?', '提示', {
            //         confirmButtonText: '确定',
            //         cancelButtonText: '取消',
            //         type: 'warning'
            //     }).then(() => {

            //     }).catch(() => { })
            // },
            // 预览
            handleView(index, row) {
                runPlanTemplateList({ pageSize: 10000 }).then(resp => {
                    let list = resp.data.list || [];
                    let index = list.findIndex(elem => { return list.id == row.templateId; });
                    if (index >= 0) {
                        this.$router.push({ path: `${UrlConfig.publish.runPlanView}/common`, query: { skinStyle: list[index].skinStyle, planId: list[index].id } });
                    }
                })
            },
            reloadTable() {
                this.queryList.reload()
            }
        }
    }
</script>