<template>
  <div class="p-2">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form ref="formRef" @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item name="categoryId">
              <template #label><span title="物料类别">物料类别</span></template>
              <j-dict-select-tag type='list' placeholder="请选择物料类别" v-model:value="queryParam.categoryId" dictCode="nu_config_material_category,category_name,id,iz_enabled = 0 and del_flag = 0" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="typeId">
              <template #label><span title="物料类型">物料类型</span></template>
              <j-dict-select-tag type='list' placeholder="请选择物料类别" v-model:value="queryParam.typeId" :dictCode="`nu_config_material_type,type_name,id,iz_enabled = 0 and del_flag = 0 and category_id = ${queryParam.categoryId || -1}`" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :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-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
   <BasicTable @register="registerTable" >
     <!--插槽:table标题-->
      <template #tableTitle>
          <a-button type="primary" v-auth="'ConfigMaterial:config_material_category:add'" @click="handleCategoryAdd" preIcon="ant-design:plus-outlined"> 物料类别</a-button>
          <a-button type="primary" v-auth="'ConfigMaterial:config_material_type:add'" @click="handleTypeAdd" preIcon="ant-design:plus-outlined"> 物料类型</a-button>
          <a-button type="primary" v-auth="'ConfigMaterial:config_material_medication:add'" @click="handleMedicationAdd" preIcon="ant-design:plus-outlined"> 用药类型</a-button>
      </template>
      <!--字段回显插槽-->
      <template v-slot:bodyCell="{ column, record, index, text }">
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <ConfigMaterialCategoryListModal @register="registerDrawer" @success="handleSuccess"></ConfigMaterialCategoryListModal>
    <ConfigMaterialTypeListModal @register="registerTypeDrawer" @success="handleSuccess"></ConfigMaterialTypeListModal>
    <ConfigMaterialMedicationListModal @register="registerMedicationDrawer" @success="handleSuccess"></ConfigMaterialMedicationListModal>
  </div>
</template>

<script lang="ts" name="ConfigMaterial-configMaterialCategory" setup>
  import {ref, reactive, computed, unref} from 'vue';
  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import {useModal} from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage'
  import ConfigMaterialCategoryModal from './components/ConfigMaterialCategoryModal.vue'
  import {allColumns, searchFormSchema, superQuerySchema} from './ConfigMaterialCategory.data';
  import {selectMaterialList, deleteOne, batchDelete, getImportUrl,getExportUrl} from './ConfigMaterialCategory.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import { useUserStore } from '/@/store/modules/user';
  import JSelectMultiple from '/@/components/Form/src/jeecg/components/JSelectMultiple.vue';
  import ConfigMaterialCategoryListModal from '/@/views/invoicing/ConfigMaterial/ConfigMaterialCategoryListModal.vue';
  import ConfigMaterialTypeListModal from '/@/views/invoicing/ConfigMaterial/ConfigMaterialTypeListModal.vue';
  import ConfigMaterialMedicationListModal from '/@/views/invoicing/ConfigMaterial/ConfigMaterialMedicationListModal.vue';
  import { useDrawer } from '/@/components/Drawer';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  const formRef = ref();
  const queryParam = reactive<any>({});
  const checkedKeys = ref<Array<string | number>>([]);
  const userStore = useUserStore();
  //注册model
  const [registerModal, {openModal}] = useModal();
  //注册drawer
  const [registerDrawer, { openDrawer:openCategoryDrawer }] = useDrawer();
  const [registerTypeDrawer, { openDrawer: openTypeDrawer }] = useDrawer();
  const [registerMedicationDrawer, { openDrawer:openMedicationDrawer }] = useDrawer();
  //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '物料类别',
           api: selectMaterialList,
           columns: allColumns,
           canResize:false,
           showActionColumn: false,
           showIndexColumn: true,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
            beforeFetch: (params) => {
              params.column = '',params.order = ''
              return Object.assign(params, queryParam);
            },
      },
  })
  const labelCol = reactive({
    xs:24,
    sm:4,
    xl:6,
    xxl:4
  });
  const wrapperCol = reactive({
    xs: 24,
    sm: 20,
  });

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext


  //物料类别
  function handleCategoryAdd(){
    openCategoryDrawer(true, {
      isUpdate: false,
      showFooter: false,
      tenantSaas: false,
    });

  }
  //物料类型
  function handleTypeAdd(){
    openTypeDrawer(true, {
      isUpdate: false,
      showFooter: false,
      tenantSaas: false,
    });
    
  }
  //用药类型
  function handleMedicationAdd(){
    openMedicationDrawer(true, {
      isUpdate: false,
      showFooter: false,
      tenantSaas: false,
    });
    
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
  
  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }

function handleSuccess(){
  searchQuery()
}
</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>