<template>
  <div class="p-2">
    <a-tabs v-model:activeKey="tabActiveKey" class="tabs-container">
      <a-tab-pane key="dataAsync" tab="配置信息">
        <!--引用表格-->
        <BasicTable @register="registerTable" style="padding: 0 !important;">
          <!--插槽:table标题-->
          <template #tableTitle>
            <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleAdd"> 新增</a-button>
          </template>
          <!--操作栏-->
          <template #action="{ record }">
            <TableAction :actions="getTableAction(record)"/>
          </template>
          <template v-slot:bodyCell="{ column, record, index, text }">
          </template>
        </BasicTable>
      </a-tab-pane>
      <a-tab-pane key="syncLogList" tab="同步历史">
        <SyncConfigLogList ref="syncConfigLogListRef" :serverType="serverType"></SyncConfigLogList>
      </a-tab-pane>
    </a-tabs>
  </div>
  <!-- 表单区域 -->
  <ConfigDrawer @register="registerDrawer" @success="handleSuccess" />
</template>

<script lang="ts" name="iot-nuIotCameraInfo" setup>
import {ref, reactive, createVNode, h, onMounted, watch, unref} from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { columns } from './config.data';
import { list } from './config.api';
import { useUserStore } from '/@/store/modules/user';
import { useDrawer } from "@/components/Drawer";
import { useRouter } from 'vue-router';
import ConfigDrawer from './components/ConfigDrawer.vue';
import SyncConfigLogList from '@/views/iot/ConfigLog/SyncConfigLogList.vue';

//注册drawer
const [registerDrawer, { openDrawer }] = useDrawer();
let router = useRouter();
const formRef = ref();
const serverType = ref('电水表');
const queryParam = reactive<any>({});
const userStore = useUserStore();
//注册table数据
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
  tableProps: {
    title: '配置信息',
    api: list,
    columns,
    canResize: false,
    showIndexColumn: true,
    actionColumn: {
      width: 100,
      fixed: 'right',
    },
    beforeFetch: async (params) => {
      params.column = 'id'
      params.order = 'asc'
      return Object.assign(params, queryParam);
    },
  },
});
const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
const labelCol = reactive({
  xs:24,
  sm:4,
  xl:6,
  xxl:4
});
const wrapperCol = reactive({
  xs: 24,
  sm: 20,
});

/**
 * 新增
 */
function handleAdd(record: Recordable) {
  openDrawer(true, {
    record,
    isUpdate: false,
    showFooter: true,
    tenantSaas: false,
  });
}

/**
 * 编辑
 */
function handleEdit(record: Recordable) {
  openDrawer(true, {
    record,
    isUpdate: true,
    showFooter: true,
    tenantSaas: false,
  });
}

/**
 * 成功回调
 */
function handleSuccess() {
  reload();
}

/**
 * 操作栏
 */
function getTableAction(record) {
  return [
    {
      label: '编辑',
      onClick: handleEdit.bind(null, record),
    },
  ];
}

</script>

<style lang="less" scoped>

.jeecg-basic-table-form-container {
  padding: 0;
  .table-page-search-submitButtons {
    display: block;
    margin-bottom: 24px;
    white-space: nowrap;
  }
  .query-group-cust{
    min-width: 100px !important;
  }
  .query-group-split-cust{
    width: 30px;
    display: inline-block;
    text-align: center
  }
  .ant-form-item:not(.ant-form-item-with-help){
    margin-bottom: 16px;
    height: 32px;
  }
  :deep(.ant-picker),:deep(.ant-input-number){
    width: 100%;
  }
}

.p-2{
  height: calc(100vh - 120px);
}

.tabs-container {
  width: 100%;
  background-color: white;
  padding: 14px;
  border-radius: 8px !important;
}


</style>
