<template>
      <a-modal :title="title" :width="900" :visible="pagevisible" :footer="null"
      @cancel="handleCancel" >
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline">
                <a-row :gutter="30">
                    <a-col :md="20">
                        <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                        </span>
                    </a-col>
                </a-row>
                <a-row :gutter="24">
                    <a-col :md="24" :sm="24" style="text-align: right;">
                        <a-button type="primary" style="right: 10px" icon="plus" @click="handleAdd">新建</a-button>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域 --> 
        <a-row :gutter="30" style="padding: 0 10px;">
            <a-col :md="24">
                <div class="linese"></div>
                <!-- 表格区域 -->
                <div style="height:calc(100vh - 316px);background: #e6e9f1;overflow:hidden;padding: 15px;">
                    <a-table size="middle" bordered :columns="columns" :data-source="dataSource" 
                        :pagination="false" :scroll="{ y: 'calc(100vh - 380px)' }" rowKey="id"
                      >
                        <span slot="transfStrategy" slot-scope="text, record">
                           <span v-if="text == 1">转大写</span>
                           <span v-if="text == 2">转小写</span>
                        </span>
                        <span slot="action" slot-scope="text, record">
                            <a @click="handleEdit(record)">编辑</a>
                            <a-divider type="vertical" />
                            <a @click="handleRemove(record.id)">删除</a>
                        </span>
                    </a-table>
                </div>
                <div class="linese"></div>
            </a-col>
        </a-row> 

        <rulesModel ref="modalForm" @fatherMethod="getTableInfo" />
    </a-card>
</a-modal>
</template>
<script> 
import { deleteRules, queryRulesByTableName } from '@/api/dataformatsRules'
import rulesModel from './rulesModel.vue'
export default {
    name: "subpage2",
    components: { 
        rulesModel
    },
    data() {
        return {  
            title: '',
            datetypeF: '',
            pagevisible: false,
            queryParam: { 
                tableName: null
            },
            dataSource: [],
            columns: [
                {
                    title: '序号',
                    width: 70,
                    customRender: (text, record, index) => `${index + 1}`,
                },
                {
                    title: '表名',
                    align: "center",
                    dataIndex: 'tableName',
                },
                {
                    title: '转换字段',
                    align: "center",
                    dataIndex: 'transfFileds',
                },
                {
                    title: '格式策略',
                    align: "center",
                    dataIndex: 'transfStrategy',
                    scopedSlots: { customRender: 'transfStrategy' },
                },
                {
                    title: '操作',
                    key: 'action',
                    width: 130,
                    align: "center",
                    scopedSlots: { customRender: 'action' },
                },
            ]
        }
    },

    mounted() {

    },
    computed: {

    },
    created() {  },
    methods: {
        getTableInfo() {
            queryRulesByTableName(this.queryParam).then(res => {
                if (res.code == 200) {
                    this.dataSource = res.result
                } else {
                    this.$notification.error({
                        message: '系统提示',
                        description: res.message
                    })
                }
            })
        },
        handleAdd() {
            this.$refs.modalForm.add( this.queryParam.tableName, this.datetypeF);
            this.$refs.modalForm.title = "新增";
        },
        handleEdit(record) {
            this.$refs.modalForm.eidt(record, this.datetypeF);
            this.$refs.modalForm.title = "编辑";
        },
        handleRemove(recordId) {
            console.log('dfs', recordId)
            const _that = this
            _that.$confirm({
                title: '你确认执行删除操作吗?',
                okText: '确认',
                cancelText: '取消',
                onOk() {
                    console.log('dfs', recordId)
                    deleteRules({ id: recordId }).then(res => {
                        if (res.code === 200) {
                            _that.$notification.success({
                                message: '系统提示',
                                description: res.message
                            })
                            _that.getTableInfo()
                        } else {
                            _that.$notification.warning({
                                message: '系统提示',
                                description: res.message
                            })
                        }
                    })
                },
                onCancel() { }
            })
        },
        handleCancel() {
            this.pagevisible = false
        },
    }
}
</script>