<template>
    <div class="page-container">
        <div class="flex-wrap search-box">
            <div class="search-item">
                <a-select class="label-option" v-model="search.table_uid" @change="getTemplateList">
                    <a-select-option v-for="(table, index) in search.table_list" :key="index" :value="table.uid">
                        {{ table.name }}
                    </a-select-option>
                </a-select>
            </div>
            <div class="search-item">
                <a-select class="label-option" v-model="search.custom_search.key">
                    <a-select-option
                        v-for="(item,idx) in search.custom_search.keys"
                        :key="idx"
                        :value="item.value"
                    >
                        {{ item.label }}
                    </a-select-option>
                </a-select>
            </div>
            <div class="search-item">
                <a-select class="condition-option" v-model="search.custom_search.condition">
                    <a-select-option
                        v-for="(item,idx) in search.custom_search.conditions"
                        :key="idx"
                        :value="item.value"
                    >
                        {{ item.label }}
                    </a-select-option>
                </a-select>
            </div>
            <div class="search-item">
                <a-input-search
                    class="search-value"
                    placeholder="请输入"
                    :max-length="100"
                    v-model="search.custom_search.value"
                    @search="onSearch"
                />
            </div>
            <div class="search-item">
                <a-button @click="unsetSearch">
                    <a-icon type="reload"/>
                </a-button>
            </div>
            <div class="search-item">
                <a-dropdown>
                    <a-menu slot="overlay" @click="openModelAdd">
                        <a-menu-item v-for="(value,key) of search.add_type" :key="key">
                            {{ value }}
                        </a-menu-item>
                    </a-menu>
                    <a-button type="primary"> 添加
                        <a-icon type="down"/>
                    </a-button>
                </a-dropdown>
            </div>
        </div>
        <a-table
            :columns="tableData.columns"
            :loading="tableData.loading"
            :dataSource="tableData.data"
            :pagination="tableData.pager"
            @change="tableChange"
            :rowKey="(record, index) => {return index}"
            :scroll="{ x: 800, y: 400 }"
        >


            <template slot="type" slot-scope="text,record">
                {{ search.add_type[text] }}
            </template>

            <template slot="operation" slot-scope="record">
                <a @click="openModelEdit(record)">编辑</a>
                <a-divider type="vertical"/>
                <a-popconfirm
                    title="确定删除该信息吗"
                    ok-text="确定"
                    cancel-text="取消"
                    @confirm="() => handleDelete(record)"
                >
                    <a class="danger" @click.stop="">删除</a>
                </a-popconfirm>
            </template>
        </a-table>
        <a-modal
            v-model="model.isVisible"
            width="70%"
            centered
            :title="model.title"
            :confirmLoading="model.is_loading"
            @ok="handleOk"
            @cancel="handleCancle"
        >
            <a-form-model
                ref="form"
                :model="model.form"
                :rules="model.rules"
            >
                <a-form-model-item label="模板名称" prop="name">
                    <a-input v-model="model.form.name" type="text" placeholder="请输入"/>
                </a-form-model-item>
                <a-form-model-item label="排序">
                    <a-input-number v-model="model.form.listorder" :min="1" style="width: 100%"/>
                </a-form-model-item>
                <a-form-model-item label="筛选条件" v-if="model.form.type === 'list'">
                    <a-select v-model="model.form.condition_id" allowClear>
                        <a-select-option v-for="(item,idx) in model.condition_list"
                                         :key="idx"
                                         :value="item.uid">
                            {{ item.name }}
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="添加视图" v-if="model.form.type === 'list'">
                    <a-select v-model="model.form.setting.add_tpl" allowClear>
                        <a-select-option v-for="(item,idx) in model.view_list.add"
                                         :key="idx"
                                         :value="item.uid">
                            {{ item.name }} -- {{ item.uid }}
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="编辑视图" v-if="model.form.type === 'list'">
                    <a-select v-model="model.form.setting.edit_tpl" allowClear>
                        <a-select-option v-for="(item,idx) in model.view_list.edit"
                                         :key="idx"
                                         :value="item.uid">
                            {{ item.name }} -- {{ item.uid }}
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="查看视图" v-if="model.form.type === 'list'">
                    <a-select v-model="model.form.setting.view_tpl" allowClear>
                        <a-select-option v-for="(item,idx) in model.view_list.view"
                                         :key="idx"
                                         :value="item.uid">
                            {{ item.name }} -- {{ item.uid }}
                        </a-select-option>
                    </a-select>
                </a-form-model-item>
                <a-form-model-item label="字段设置">
                    <a-card>
                        <a-table
                            :columns="model.form.type==='list'?model.field_table.columns_list:model.field_table.columns_other"
                            :loading="model.field_table.loading"
                            :dataSource="model.form.setting.fieldsarr"
                            :pagination="false"
                            :rowKey="(record, index) => {return index}"
                            :scroll="{ y: 240 }"
                        >
                            <div
                                style="padding: 5px;width: 180px"
                                slot="name_filter"
                                slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
                            >
                                <a-input
                                    style="width: 100%; margin-bottom: 8px; display: block;"
                                    :value="selectedKeys[0]" @change="e => {
                    setSelectedKeys(e.target.value ? [e.target.value] : [])
                }"
                                    @pressEnter="confirm"
                                />
                                <a-button type="primary"
                                          icon="search"
                                          size="small"
                                          style="width: 50%; margin-right: 8px"
                                          @click="confirm"> 搜索
                                </a-button>
                                <a-button size="small" style="width: 30%;float: right" @click="clearFilters"> 重置
                                </a-button>
                            </div>
                            <template slot="display" slot-scope="text,record">
                                <a-select v-model="record.display">
                                    <a-select-option v-for="(value,key) in model.field_dispaly_setting"
                                                     :key="key"
                                                     :value="key">
                                        {{ value }}
                                    </a-select-option>
                                </a-select>
                            </template>
                            <template slot="width" slot-scope="text,record">
                                <a-input-number v-model="record.width">
                                </a-input-number>
                            </template>
                            <template slot="span" slot-scope="text,record">
                                <a-select v-model="record.span">
                                    <a-select-option :key="1" :value="24"> 100%</a-select-option>
                                    <a-select-option :key="2" :value="12"> 50%</a-select-option>
                                    <a-select-option :key="3" :value="8"> 33.33%</a-select-option>
                                </a-select>
                            </template>
                            <template slot="align" slot-scope="text,record">
                                <a-select v-model="record.align">
                                    <a-select-option :key="1" value="left">居左</a-select-option>
                                    <a-select-option :key="2" value="center">居中</a-select-option>
                                    <a-select-option :key="3" value="right">居右</a-select-option>
                                </a-select>
                            </template>
                        </a-table>
                    </a-card>
                </a-form-model-item>
                <a-form-model-item label="工具栏菜单">
                    <a-card>
                        <a-table
                            :columns="model.tool_table.columns"
                            :loading="model.tool_table.loading"
                            :dataSource="model.form.setting.barmenu"
                            :pagination="false"
                            :rowKey="(record, index) => {return index}"
                            :scroll="{ y: 240 }"
                        >
                            <template slot="sort" slot-scope="text,record">
                                <a-input-number v-model="record.sort">
                                </a-input-number>
                            </template>
                            <template slot="display" slot-scope="text,record">
                                <a-select v-model="record.display">
                                    <a-select-option v-for="(value,key) in model.btn_dispaly_setting"
                                                     :key="key"
                                                     :value="key">
                                        {{ value }}
                                    </a-select-option>
                                </a-select>
                            </template>
                        </a-table>
                    </a-card>
                </a-form-model-item>
                <a-form-model-item label="操作栏菜单" v-if="model.form.type === 'list'">
                    <a-card>
                        <a-table
                            :columns="model.action_table.columns"
                            :loading="model.action_table.loading"
                            :dataSource="model.form.setting.operation"
                            :pagination="false"
                            :rowKey="(record, index) => {return index}"
                            :scroll="{ y: 240 }"
                        >
                            <template slot="sort" slot-scope="text,record">
                                <a-input-number v-model="record.sort">
                                </a-input-number>
                            </template>
                            <template slot="display" slot-scope="text,record">
                                <a-select v-model="record.display">
                                    <a-select-option v-for="(value,key) in model.btn_dispaly_setting"
                                                     :key="key"
                                                     :value="key">
                                        {{ value }}
                                    </a-select-option>
                                </a-select>
                            </template>
                        </a-table>
                    </a-card>
                </a-form-model-item>

                <a-form-model-item label="描述">
                    <a-input
                        v-model="model.form.description" type="textarea" placeholder="请输入"/>
                </a-form-model-item>
            </a-form-model>
        </a-modal>
    </div>
</template>
<script>


import pager from "../../../config/pagination.conf"
import {deep_copy, merge_obj, gettype} from "../../../utils/functions";
import {createLogger} from "vuex";
import {forEach} from "lodash";

export default {
    name: "list",
    data() {
        return {
            tableData: {
                loading: false,
                data: [],
                columns: [
                    //排序 listorder 字段编号uid 字段名称name 字段别名alias 字段类型formtype 描述description 创建时间created  操作（编辑 删除）
                    {
                        title: '排序', //列头显示文字
                        dataIndex: 'listorder',//对应数据的 key
                        width: 80,//列宽度
                        key: 'listorder', //Vue 需要的 key
                        scopedSlots: {customRender: 'listorder'},// 设置字段的scopedSlots.customRender = SOMENAME ，在table中可以用template slot=SOMENAME slot-scope=dataIndex,record,index 使用该行数据
                    },
                    {
                        title: '模板编号', //列头显示文字
                        dataIndex: 'uid',//对应数据的 key
                        width: 200,//列宽度
                        key: 'uid',
                    },
                    {
                        title: '模板名称', //列头显示文字
                        dataIndex: 'name',//对应数据的 key
                        key: 'name',
                    },
                    {
                        title: '模板类型', //列头显示文字
                        dataIndex: 'type',//对应数据的 key
                        key: 'type',
                        scopedSlots: {customRender: 'type'},
                    },
                    {
                        title: '描述', //列头显示文字
                        dataIndex: 'description',//对应数据的 key
                        ellipsis: true,
                        key: 'description',
                    },
                    {
                        title: '创建时间', //列头显示文字
                        dataIndex: 'created',//对应数据的 key
                        key: 'created',
                    },
                    {
                        title: '操作',
                        key: 'operation',
                        scopedSlots: {customRender: 'operation'},
                    },
                ],
                pager: deep_copy(pager),
            },
            search: {
                table_list: [],
                table_uid: '',
                add_type: {
                    add: "添加视图",
                    edit: "编辑视图",
                    view: "查看视图",
                    list: "列表视图",
                },
                //list/add/edit/view
                custom_search: {
                    keys: [
                        {label: "模板编号", value: "uid",},
                        {label: "模板名称", value: "name",},
                    ],
                    conditions: [
                        {label: "包含", value: "like"},
                        {label: "等于", value: "="},
                        {label: "不等于", value: "!="},
                        {label: "小于", value: "<"},
                        {label: "小于等于", value: "<="},
                        {label: "大于", value: ">"},
                        {label: "大于等于", value: ">="},
                    ],
                    key: "uid",
                    condition: 'like',
                    value: ''
                }
            },
            model: {
                tool_list_template: {},//全部类型的工具
                btn_dispaly_setting: {
                    h: '隐藏',
                    v: '展示',
                },
                field_dispaly_setting: {},
                field_dispaly_setting_template: {
                    add: {
                        d: '禁止',
                        r: '只读',
                        w: '允许',
                        h: '隐藏',
                        v: '查看',
                    },
                    edit: {
                        d: '禁止',
                        r: '只读',
                        w: '允许',
                        h: '隐藏',
                        v: '查看',
                    },
                    view: {
                        h: '隐藏',
                        v: '查看',
                    },
                    list: {
                        d: '禁止',
                        v: '显示',
                        h: '隐藏',
                    },
                },
                isVisible: false,
                is_loading: false,
                title: "添加字段",
                rules: {
                    name: [{required: true, message: "请输入字段名称", trigger: "blur"},],
                },
                formtypes: [
                    {label: "单行文本", value: "text"},
                    {label: "多行文本", value: "textarea"},
                    {label: "日期时间", value: "datetime"},
                    {label: "选项", value: "box"},
                    {label: "图片", value: "image"},
                    {label: "附件", value: "file"},
                    {label: "数字", value: "number"},
                    {label: "联动菜单", value: "linkage"},
                ],
                field_table: { //中间管理字段的表格
                    loading: false,
                    columns_list: [
                        // {
                        //     title: '排序', //列头显示文字
                        //     dataIndex: 'listorder',//对应数据的 key
                        //     width: 80,//列宽度
                        //     key: 'listorder', //Vue 需要的 key
                        //     scopedSlots: {customRender: 'sort'},// 设置字段的scopedSlots.customRender = SOMENAME ，在table中可以用template slot=SOMENAME slot-scope=dataIndex,record,index 使用该行数据
                        // },
                        {
                            title: '字段名称', //列头显示文字
                            dataIndex: 'name',//对应数据的 key
                            key: 'name',
                            scopedSlots: {filterDropdown: 'name_filter'},
                            onFilter: (value, record) => record.name
                                .toString()
                                .toLowerCase()
                                .includes(value.toLowerCase()),
                        },
                        {
                            title: '字段别名', //列头显示文字
                            dataIndex: 'alias',//对应数据的 key
                            key: 'alias',
                        },
                        {
                            title: '字段权限', //列头显示文字
                            dataIndex: 'display',//对应数据的 key
                            key: 'display',
                            scopedSlots: {customRender: 'display'},
                        },
                        {
                            title: '宽度', //列头显示文字
                            dataIndex: 'width',//对应数据的 key
                            ellipsis: true,
                            key: 'width',
                            scopedSlots: {customRender: 'width'},
                        },
                        {
                            title: '位置', //列头显示文字
                            dataIndex: 'align',//对应数据的 key
                            ellipsis: true,
                            key: 'align',
                            scopedSlots: {customRender: 'align'},
                        },
                    ],
                    columns_other: [
                        // {
                        //     title: '排序', //列头显示文字
                        //     dataIndex: 'listorder',//对应数据的 key
                        //     width: 80,//列宽度
                        //     key: 'listorder', //Vue 需要的 key
                        //     scopedSlots: {customRender: 'sort'},// 设置字段的scopedSlots.customRender = SOMENAME ，在table中可以用template slot=SOMENAME slot-scope=dataIndex,record,index 使用该行数据
                        // },
                        {
                            title: '字段名称', //列头显示文字
                            dataIndex: 'name',//对应数据的 key
                            key: 'name',
                            scopedSlots: {filterDropdown: 'name_filter'},
                            onFilter: (value, record) => record.name
                                .toString()
                                .toLowerCase()
                                .includes(value.toLowerCase()),
                        },
                        {
                            title: '字段别名', //列头显示文字
                            dataIndex: 'alias',//对应数据的 key
                            key: 'alias',
                        },
                        {
                            title: '字段权限', //列头显示文字
                            dataIndex: 'display',//对应数据的 key
                            key: 'display',
                            scopedSlots: {customRender: 'display'},
                        },
                        {
                            title: '占用一行比例', //列头显示文字
                            dataIndex: 'span',//对应数据的 key
                            ellipsis: true,
                            key: 'span',
                            scopedSlots: {customRender: 'span'},
                        },
                    ],
                },
                tool_table: { //中间管理字段的表格
                    loading: false,
                    columns: [
                        {
                            title: '菜单类型', //列头显示文字
                            dataIndex: 'type',//对应数据的 key
                            key: 'type',
                        },
                        {
                            title: '菜单名称', //列头显示文字
                            dataIndex: 'name',//对应数据的 key
                            key: 'name',
                        },
                        {
                            title: '排序', //列头显示文字
                            dataIndex: 'sort',//对应数据的 key
                            key: 'sort',
                            scopedSlots: {customRender: 'sort'},
                        },
                        {
                            title: '显示', //列头显示文字
                            dataIndex: 'display',//对应数据的 key
                            key: 'display',
                            scopedSlots: {customRender: 'display'},
                        },
                    ],
                },
                action_table: { //中间管理字段的表格
                    loading: false,
                    columns: [
                        {
                            title: '菜单类型', //列头显示文字
                            dataIndex: 'type',//对应数据的 key
                            key: 'type',
                        },
                        {
                            title: '菜单名称', //列头显示文字
                            dataIndex: 'name',//对应数据的 key
                            key: 'name',
                        },
                        {
                            title: '排序', //列头显示文字
                            dataIndex: 'sort',//对应数据的 key
                            key: 'sort',
                            scopedSlots: {customRender: 'sort'},
                        },
                        {
                            title: '显示', //列头显示文字
                            dataIndex: 'display',//对应数据的 key
                            key: 'display',
                            scopedSlots: {customRender: 'display'},
                        },
                    ],
                },
                condition_list: [],
                view_list: {
                    add: [],
                    edit: [],
                    view: [],
                    list: [],
                },//view
                view_list_template: {
                    add: [],
                    edit: [],
                    view: [],
                    list: [],
                },//view
                form: {
                    table_id: '', //选择当前搜索中的table_id TBF1631524245352391
                    name: '',//模板名称
                    type: '',//list/add/edit/view
                    description: '',
                    listorder: 1, //排序：
                    condition_id: '', //条件uid
                    setting: {},//字段设置：
                },
                add_tpls: [],
                edit_tpls: [],
                view_tpls: [],
                template: {
                    basic: {
                        table_id: '', //选择当前搜索中的table_id TBF1631524245352391
                        name: '',//模板名称
                        type: '',//list/add/edit/view
                        description: '',
                        listorder: 1, //排序：
                        condition_id: '', //条件uid
                        setting: {},//字段设置：
                    },
                    setting: {
                        add: {
                            fieldsarr: [],
                            barmenu: [],
                        },
                        edit: {
                            fieldsarr: [],
                            barmenu: [],
                        },
                        view: {
                            fieldsarr: [],
                            barmenu: [],
                        },
                        list: {
                            page_size: 10,
                            fieldsarr: [],
                            barmenu: [],
                            operation: [
                                {
                                    "type": "系统菜单",
                                    "id": "sys_view",
                                    "name": "查看",
                                    "sort": 100,
                                    "display": "v"
                                },
                                {
                                    "type": "系统菜单",
                                    "id": "sys_edit",
                                    "name": "编辑",
                                    "sort": 100,
                                    "display": "v"
                                },
                                {
                                    "type": "系统菜单",
                                    "id": "sys_delete",
                                    "name": "删除",
                                    "sort": 100,
                                    "display": "v"
                                },
                            ],
                            add_tpl: "",//对应视图uid
                            edit_tpl: "",
                            view_tpl: ""
                        },
                    },
                },
            }
        };
    },
    created() {
        this.getTableList().then(this.getTemplateList())
        this.getTools()
        //获取tablelist
        //获取field-list
    },
    activated() {
        this.getTableList().then(this.getTemplateList())
    },
    methods: {
        show_ele($arr) {
            //是否展示当前的元素 取决于type是否在当arr中
            return $arr.indexOf(this.model.form.formtype) !== -1
        },
        getTableList() {
            return new Promise((resolve, reject) => {
                this.api.post("table_list").then(res => {
                    let data = res.result
                    this.search.table_list = data.data
                    this.search.table_uid = data.data[0].uid
                    resolve()
                })
            })
        },
        getTools() {
            let that = this
            this.api.post("template_tool").then(res => {
                that.model.tool_list_template = res.result
            })
        },
        unsetSearch() {
            this.search.custom_search.key = "uid"
            this.search.custom_search.condition = "like"
            this.search.custom_search.value = ""
            this.getTemplateList()
        },
        handleOk() {
            //提交表单
            let that = this
            const submit_data = deep_copy(this.model.form)
            let uri = submit_data.uid ? 'template_update' : 'template_create'
            that.$refs['form'].validate(valid => {
                if (valid) {
                    that.model.is_loading = true
                    that.api.post(uri, submit_data).then(res => {
                        that.model.isVisible = false
                        that.getTemplateList()
                        //这里处理提交完成的动作
                    }).catch().finally(() => {
                        that.resetFormData()
                        that.model.is_loading = false

                    })
                }
            });
        },
        handleCancle() {
            //关闭的时候清空数据
            this.resetFormData()
            this.model.isVisible = false
        },
        resetFormData() {
            this.model.view_list = deep_copy(this.model.view_list_template)
            this.model.form = deep_copy(this.model.template.basic)
        },
        onSearch () {
            this.pager.current = 1;
            this.getTemplateList();
        },
        getTemplateList() {
            let that = this
            let params = {
                page_size: that.tableData.pager.pageSize,
                page_index: that.tableData.pager.current
            }
            let where_and = []
            if (this.search.table_uid) {
                where_and.push(['table_id', '=', this.search.table_uid])
            }
            let search_value = this.search.custom_search.value.trim()
            if (search_value) {
                where_and.push([this.search.custom_search.key, this.search.custom_search.condition, search_value])
            }
            params.where_and = where_and
            that.tableData.loading = true
            this.api.post("template_list", params).then(res => {
                let data = res.result
                that.tableData.pager.total = data.total_records
                that.tableData.pager.current = data.page_index
                that.tableData.data = data.data
            }).catch().finally(() => {
                that.tableData.loading = false
            })
        },
        openModelAdd(e) {
            let that = this
            let type = e.key
            let table_uid = this.search.table_uid //获取tableid
            this.model.field_dispaly_setting = this.model.field_dispaly_setting_template[type]//初始化当前类型的 display 权限 mapping
            this.model.title = '添加：' + this.search.add_type[type] // 修改标题
            // this.model.form = deep_copy(this.model.template.basic) // 拷贝模板 配置
            this.model.form.setting = deep_copy(this.model.template.setting[type])
            this.model.form.setting.barmenu = this.model.tool_list_template[type + "_tools"]//当前类型可用的工具栏按钮
            this.model.form.table_id = table_uid
            this.model.form.type = type
            this.model.isVisible = true// 显示model
            //如果type=list 获取当前table的条件列表
            if (type === 'list') {
                that.getTableConditionList(table_uid).then(condition_list => {
                    that.model.condition_list = condition_list
                })
                that.getTableViewList(table_uid).then(view_list => {
                    for (let viewListElement of view_list) {
                        for (let basic_type in that.search.add_type) {
                            if (basic_type === viewListElement.type) {
                                that.model.view_list[basic_type].push(viewListElement)
                            }
                        }
                    }
                })
            }
            this.getTableFieldList(table_uid)
                .then(field_list => {
                    //这里拿到了field list  init
                    for (let data of field_list) {
                        data.id = data.uid
                        delete data.uid
                        data.width = 150
                        data.display = 'v'
                        data.align = 'left'
                        data.span = 12
                    }
                    that.model.form.setting.fieldsarr = field_list
                })
        },
        openModelEdit(record) {
            let type = record.type
            let that = this
            this.model.field_dispaly_setting = this.model.field_dispaly_setting_template[type]//初始化当前类型的 display 权限 mapping
            this.model.title = '编辑：' + this.search.add_type[type] // 修改标题
            // this.model.form = deep_copy(record)
            this.model.isVisible = true
            let table_uid = record.table_id //获取tableid
            //如果type=list 获取当前table的条件列表
            if (type === 'list') {
                that.getTableConditionList(table_uid).then(condition_list => {
                    that.model.condition_list = condition_list
                })
                that.getTableViewList(table_uid).then(view_list => {
                    for (let viewListElement of view_list) {
                        for (let basic_type in that.search.add_type) {
                            if (basic_type === viewListElement.type) {
                                that.model.view_list[basic_type].push(viewListElement)
                            }
                        }
                    }
                })
            }
            //编辑的时候展示的 form.setting.fieldsarr 以 接口 为准
            //先遍历 list 对list中的每一条，看form中有没有，如果有 被覆盖 如果没有 初始化
            this.getTableFieldList(table_uid).then(field_list => {
                for (let idx in field_list) { //uid
                    field_list[idx].id = field_list[idx].uid
                    delete field_list[idx].uid
                    field_list[idx].width = 150
                    field_list[idx].display = 'v'
                    field_list[idx].align = 'left'
                    field_list[idx].span = 12
                    for (let old_field of record.setting.fieldsarr) { //uid
                        if (old_field.id === field_list[idx].id) {
                            field_list[idx] = deep_copy(old_field)
                        }
                    }
                }
                this.model.form = deep_copy(record)
                this.model.form.setting.fieldsarr = deep_copy(field_list)
            })
        },
        getTableFieldList($table_uid) {
            let that = this
            return new Promise((resolve, reject) => {
                let params = {where_and: [['table_id', '=', $table_uid]], select: ['uid', 'name', 'alias']}
                that.model.field_table.loading = true
                this.api.post("field_list", params).then(res => {
                    resolve(res.result.data)
                }).catch().finally(() => {
                    that.model.field_table.loading = false
                })
            })
        },
        getTableConditionList($table_uid) {
            return new Promise((resolve, reject) => {
                let params = {where_and: [['table_id', '=', $table_uid]], select: ['uid', 'name']}
                this.api.post("condition_list", params).then(res => {
                    resolve(res.result.data)
                })
            })
        },
        getTableViewList($table_uid) {
            return new Promise((resolve, reject) => {
                let params = {where_and: [['table_id', '=', $table_uid]], select: ['uid', 'name', 'type']}
                this.api.post("template_list", params).then(res => {
                    resolve(res.result.data)
                })
            })
        },
        handleDelete(record) {
            let that = this
            that.api.post("template_delete", {uid: record.uid}).then(res => {
                that.getTemplateList()
            })
        },
        tableChange(pagination, filters, sorter, {currentDataSource}) {
            this.tableData.pager.current = pagination.current
            this.tableData.pager.pageSize = pagination.pageSize
            this.getTemplateList()
        }
    }
}
</script>

<style scoped>
</style>
