<!--
 * @Author: 曹捷
 * @Date: 2019-08-19 15:24:34
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-04-20 09:25:23
 * @Description: file content
 -->
<template>
  <a-modal class="obit-modal-default" v-if="showModal" :maskClosable="false" title="导入表" v-model:visible="showModal"
    @cancel="closeDialog" @ok="saveInfo" cancelText="取消" okText="确认" width="60%">
    <obitUniversalTable :pagination="pagination" class="importSearch">
      <template #search>
        <obit-search-form :params="params" :paramList="paramList" @search="pageQuery(true)">
        </obit-search-form>
      </template>
      <a-table :customRow="customRow" :loading="pageLoading" rowKey="roleId" :columns="tableColumns"
        :row-selection="rowSelection" :dataSource="pageDataList" :pagination="false" class="obit-atable"
        highlight-current-row style="width: 100%">
        <template #icon="{ record  }">
          <span class=" iconfont obit-link" :class="'icon-'+record.appIcon"></span>
        </template>
      </a-table>
    </obitUniversalTable>
  </a-modal>
</template>
<script>
import { getCurrentInstance, computed, inject, onMounted, reactive, ref, toRefs, watch } from 'vue'
import { useStore } from 'vuex'
import page from './../../../hook/page.js'
export default {
  // inheritAttrs: false,
  props: {
    open: {
      type: Boolean
    },
    detailsInfo: {
      type: Object,
    },
  },
  setup (props, context) {
    let http = inject('http')
    let store = useStore()
    let { proxy } = getCurrentInstance()
    let _data = reactive({
      showModal: props.open,
      tableColumns: [
        { dataIndex: 'tableName', title: '表名称' },
        { dataIndex: 'tableComment', title: '表描述' },
        { dataIndex: 'createTime', title: '创建时间' },
        { dataIndex: 'updateTime', title: '更新时间' },
      ],
      paramList: [
        { key: 'tableName', name: '表名称' },
        { key: 'tableComment', name: '表描述' },
      ],
      loading: false,
      tables: [],
      selectedRows: [],
      rowSelection: {
        onChange: (selectedRowKeys, selectedRows) => {
          _data.selectedRows = selectedRows
          console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
        }
      },
    })
    let pageIns = page({
      url: 'code/gen/db/pageList'
    })
    let _methods = {
      /** 导入按钮操作 */
      saveInfo () {
        _data.selectedRows.forEach(element => {
          _data.tables.push(element.tableName)
        })
        console.log(_data.tables)
        http.handleImportTable({ tables: _data.tables.join(",") }).then((res) => {
          context.emit('reload')
          context.emit('update:open', false)
          proxy.$message.success('导入成功')
        })
      },


    }
    watch(() => props.open, (value) => {
      console.log("value", props.detailsInfo)
      pageIns._method.pageQuery()
    })

    return {
      ...toRefs(pageIns._data),
      ...pageIns._method,
      ...toRefs(_data),
      ..._methods,
    }
  },
}
</script>
<style lang="less">
.importSearch {
  .background {
    background: #fff;
  }
}
</style>