<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="suppliersName">
              <template #label><span title="供应商名称">供应商名称</span></template>
              <j-input placeholder="请输入供应商名称" v-model:value="queryParam.suppliersName" allow-clear></j-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="personInCharge">
              <template #label><span title="负责人">负责人</span></template>
              <j-input placeholder="请输入负责人" v-model:value="queryParam.personInCharge" allow-clear ></j-input>
            </a-form-item>
          </a-col>
            <a-col :lg="6">
              <a-form-item name="contactNumber">
                <template #label><span title="联系电话">联系电话</span></template>
                <j-input placeholder="请输入联系电话" v-model:value="queryParam.contactNumber" allow-clear ></j-input>
              </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-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
        <!-- <a-button type="primary" v-auth="'configSuppliersInfo:config_suppliers_info:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button> -->
        <a-button type="primary" v-auth="'configSuppliersInfo:config_suppliers_info:add'" @click="handleCheckAdd" preIcon="ant-design:plus-outlined"> 选择供应商</a-button>
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
      <template v-slot:bodyCell="{ column, record, index, text }">
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <NuBizSuppliersListModal ref="registerModal" @success="handleSuccess"></NuBizSuppliersListModal>
    <NuBizSuppliersMateriallInfoModal ref="wlRegisterModal" @success="handleSuccess"></NuBizSuppliersMateriallInfoModal>
  </div>
</template>

<script lang="ts" name="configSuppliersInfo-configSuppliersInfo" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, superQuerySchema } from './ConfigSuppliersInfo.data';
  import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './ConfigSuppliersInfo.api';
  import NuBizSuppliersListModal from '/@/views/invoicing/bizSuppliers/NuBizSuppliersListModal.vue'
  import NuBizSuppliersMateriallInfoModal from '/@/views/invoicing/bizSuppliers/NuBizSuppliersMateriallInfoModal.vue'
  import JInput from '/@/components/Form/src/jeecg/components/JInput.vue';
  import { useUserStore } from '/@/store/modules/user';
  import { defHttp } from '/@/utils/http/axios';
  import { useMessage } from '/@/hooks/web/useMessage';


  
  const { createMessage } = useMessage();
  const formRef = ref();
  const queryParam = reactive<any>({});
  const toggleSearchStatus = ref<boolean>(false);
  const registerModal = ref();
  const wlRegisterModal = ref();
  const userStore = useUserStore();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '供应商信息',
      api: list,
      columns,
      canResize:false,
      useSearchForm: false,
      actionColumn: {
        width: 180,
        fixed: 'right',
      },
      beforeFetch: async (params) => {
        return Object.assign(params, queryParam);
      },
    },
    exportConfig: {
      name: "供应商信息",
      url: getExportUrl,
      params: queryParam,
    },
	  importConfig: {
	    url: getImportUrl,
	    success: handleSuccess
	  },
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs:24,
    sm:4,
    xl:6,
    xxl:6
  });
  const wrapperCol = reactive({
    xs: 24,
    sm: 20,
  });



  function handleCheckAdd() {
    registerModal.value.disableSubmit = false;
    registerModal.value.checkAdd();
  }
  
   
  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    wlRegisterModal.value.disableSubmit = true;
    wlRegisterModal.value.edit(record);
  }
   
   
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
   
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
         {
           label: '物料详情',
           onClick: handleDetail.bind(null, record),
         }, 
      {
        label: '启用',
        onClick: handleWlQyty.bind(null, record),
        ifShow: record.izEnabled == 'N'
      }, 
      {
        label: '停用',
        onClick: handleWlQyty.bind(null, record),
        ifShow: record.izEnabled == 'Y'
      }, 
      {
        label: '更新物料',
        onClick: handleWlType.bind(null, record),
        ifShow: record.wlType == '0'
      }, 
    ];
  }

  //物料的启用停用
  function handleWlQyty(record){
    console.log("🚀 ~ handleWlQyty ~ record:", record)
    const izEnabled = record.izEnabled == 'N' ? 'Y' : "N"
    var params = {id:record.id,izEnabled}
    defHttp.post({ url: '/invoicing/configSuppliersInfo/edit', params }).then((res) => { 
      searchQuery()
    });
  }

  function handleWlType(record){
    console.log("🚀 ~ handleWlType ~ record:", record)
    var params = {id:record.id}
    defHttp.post({ url: '/invoicing/configSuppliersInfo/updateWlType', params ,timeout:100000}).then((res) => { 
      searchQuery()
    });
    setTimeout(() => { 
      createMessage.success("更新成功！")
      reload();
    }, 1000);

  }
   

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



</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>
