<template>
  <div>
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form ref="formRef" :model="queryParam" :label-col="labelCol"
              :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item name="deviceType">
              <template #label><span title="设备类型">设备类型</span></template>
              <j-dict-select-tag v-model:value="queryParam.deviceType" :showLabel="false" dictCode="tplink_device_type" placeholder="请选择设备类型"  allow-clear />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="dimension">
              <template #label><span title="设备维度">设备维度</span></template>
              <a-select v-model:value="queryParam.dimension" placeholder="请选择设备维度" allow-clear>
                <a-select-option value="机构维度">机构维度</a-select-option>
                <a-select-option value="区域维度">区域维度</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset"
                          style="margin-left: 8px">重置</a-button>
                <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleAdd" style="margin-left: 8px"> 新增设备</a-button>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>

      </template>
      <template #bodyCell="{ column, record, index, text }">
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)"/>
      </template>
    </BasicTable>
    <DeviceConfigModal ref="registerDrawer" @success="handleSuccess" />
  </div>
</template>

<script lang="ts" name="iot-nuIotElectricitynInfo" setup>
  import {reactive, ref,h} from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useUserStore } from '/@/store/modules/user';
  import {Modal} from "ant-design-vue";
  import {list} from './config.api';
  import { columns, searchFormSchema } from './config.data';
  import {useModal} from "@/components/Modal";
  import DeviceConfigModal from "./components/DeviceConfigModal.vue";
  import { defHttp } from '/@/utils/http/axios';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';

  const formRef = ref();
  const queryParam = reactive<any>({});
  const registerDrawer = ref();
  const tipVisible = ref(false);
  //注册model
  const [registerModal, {openModal}] = useModal();
  //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
    tableProps:{
      title: '物联设备配置',
      api: list,
      columns,
      canResize:false,
      showIndexColumn: true,
      formConfig: {
        //labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter:true,
        showAdvancedButton:false,
        fieldMapToNumber: [
        ],
        fieldMapToTime: [
        ],
      },
      pagination: {
        current: 1,
        pageSize: 15,
        pageSizeOptions: ['15', '50', '70', '100'],
      },
      actionColumn: {
        width: 290,
        fixed:'right'
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam);
      },
    },
  })

  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs:24,
    sm:8,
    xl:8,
    xxl:8
  });
  const wrapperCol = reactive({
    xs: 24,
    sm: 16,
  });

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }

  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    //刷新数据
    searchQuery();
  }


  /**
   * 编辑
   */
  function handleAdd() {
    registerDrawer.value.disableSubmit = false;
    registerDrawer.value.add();
  }

  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    registerDrawer.value.disableSubmit = false;
    registerDrawer.value.edit(record);
  }

  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    registerDrawer.value.disableSubmit = true;
    registerDrawer.value.edit(record);
  }

  function handleCancel() {
    tipVisible.value = false;
  }
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }

  /**
   * 操作栏
   */
  function getTableAction(record){
    return [
      {
        label: '详情',
        onClick: handleDetail.bind(null, record),
      },
      {
        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%;
  }
}
</style>
