<template>
  <div class="title">
    批量操作
    <div class="close-button" @click="emits('changeBatchProcessingModal',false)"></div>
  </div>
  <div class="modal-content">
    <div class="control-button-div">
      <div :class="`control-button ${control == 0? 'active': ''}`" @click="changeControl(0)">批量导入</div>
      <div :class="`control-button ${control == 1? 'active': ''}`" @click="changeControl(1)">更新数据</div>
      <div :class="`control-button ${control == 2? 'active': ''}`" @click="changeControl(2)">批量导出</div>
      <div :class="`control-button ${control == 3? 'active': ''}`" @click="changeControl(3)">批量操作</div>
    </div>
    <div class="content">
      <ImportComponent @changeBatchProcessingModal="changeBatchProcessingModal" :tableName="props.tableName" :tableColumn="tableColumn" v-if="control == 0"/>
      <UpdateComponent @changeBatchProcessingModal="changeBatchProcessingModal" :tableName="props.tableName" :tableColumn="tableColumn" v-if="control == 1"/>
      <ExportComponent @changeBatchProcessingModal="changeBatchProcessingModal" :applicationName="props.applicationName" :tableName="props.tableName" :tableColumn="tableColumn" v-if="control == 2"/>
      <BatchOperationsComponent @changeBatchProcessingModal="changeBatchProcessingModal" :tableName="props.tableName" :tableColumn="tableColumn" v-if="control == 3"/>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, defineEmits, defineProps, onMounted } from "vue"
import ImportComponent from './ImportComponent/index.vue'
import UpdateComponent from './UpdateComponent/index.vue'
import ExportComponent from './ExportComponent/index.vue'
import BatchOperationsComponent from './BatchOperationsComponent/index.vue'
import { GetTableColumnList } from '@/api/demo/BatchProcessingModal'
const emits = defineEmits(['changeBatchProcessingModal'])
const props = defineProps(['tableName','applicationName'])
const control = ref(0)
const tableColumn = ref([])

onMounted(() => {
  GetTableColumnList({tableName: props.tableName}).then(res => {
    console.log(res)
    tableColumn.value = res.map(item => {
      return {
        label: `${item.column_name}(${item.description})`,
        value: item.column_name,
        type: item.data_type
      }
    })
  })
})

const changeControl  = (type) => {
  control.value = type
}
const changeBatchProcessingModal = (type: boolean) => {
  emits('changeBatchProcessingModal', type)
}
</script>

<style lang="scss" scoped>
.title{
  height: 86px;
  padding-left: 43px;
  padding-right: 43px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: PingFangSC-Regular;
  font-weight: 400;
  font-size: 36px;
  color: #1E1E20;
  line-height: 50px;
  user-select: none;
  border-bottom: 1px solid #E4E4E7;
  .close-button{
    width: 30px;
    height: 30px;
    background-image: url('/public/components/BatchProcessingModal/close_icon.png');
    background-size: 100% 100%;
    cursor: pointer;
  }
}
.modal-content{
  width: 100%;
  height: 790px;
  padding: 28px 44px 27px 34px;
  .control-button-div{
    display: flex;
    border-bottom: 2px solid #E9E9EC;
    .control-button{
      width: 169px;
      height: 54px;
      background: #F2F3F6;
      border-radius: 16px 16px 0px 0px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 24px;
      color: #191A1B;
      line-height: 33px;
      margin-right: 4px;
      cursor: pointer;
      user-select: none;
    }
    .active{
      background-color: #0464D2;
      color: #fff;
    }
  }
}
.content{
  height: 707px;
}
</style>
