<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <Search :schema="[...RawMaterialConsumptionInfo.allSchemas.searchSchema]" @search="setSearchParams" @reset="setSearchParams" />
  </ContentWrap>

    <!-- 列表头部 -->
    <TableHead
      :HeadButttondata="HeadButttondata"
      @button-base-click="buttonBaseClick"
      :routeName="routeName"
      @updataTableColumns="updataTableColumns"
      @searchFormClick="searchFormClick"
      :allSchemas="RawMaterialConsumptionInfo.allSchemas"
    />

  <!-- 列表 -->
  <ContentWrap>
    <Table v-clientTable
      :columns="tableColumns"
      :data="tableObject.tableList"
      :loading="tableObject.loading"
      :pagination="{
        total: tableObject.total
      }"
      v-model:pageSize="tableObject.pageSize"
      v-model:currentPage="tableObject.currentPage"
      v-model:sort="tableObject.sort"
    >
      <template #action="{ row,$index }">
        <ButtonBase :Butttondata="butttondata(row,$index)" @button-base-click="buttonTableClick($event,row)" />
      </template>
    </Table>
  </ContentWrap>

</template>

<script setup lang="ts">
import download from '@/utils/download'
import * as defaultButtons from '@/utils/disposition/defaultButtons'
import * as RawMaterialConsumptionInfoApi from '@/api/wms/rawMaterialConsumptionInfo'
import { getAccessToken } from '@/utils/auth'
import {
  RawMaterialConsumptionInfo
} from './rawMaterialConsumptionInfo.data'
import { getJmreportBaseUrl } from '@/utils/systemParam'

// 装配收货记录主
defineOptions({ name: 'RawMaterialConsumptionInfo' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const route = useRoute() // 路由信息
const routeName = ref()
routeName.value = route.name
const tableColumns = ref([...RawMaterialConsumptionInfo.allSchemas.tableColumns])

const mesModelVisible = ref(false)
const { tableObject: tableObject, tableMethods: tableMethods } =useTable({
  getListApi: RawMaterialConsumptionInfoApi.getRawMaterialConsumptionInfoPage
})
// 字段设置 更新主列表字段
const updataTableColumns = (val) => {
  tableColumns.value = val
}

// 获得表格的各种操作
const { getList, setSearchParams } = tableMethods

// 列表头部按钮
const HeadButttondata = [
  // defaultButtons.defaultExportBtn({hasPermi:'wms:productreceipt-record-main:export'}), // 导出
  defaultButtons.defaultFreshBtn(null), // 刷新
  defaultButtons.defaultFilterBtn(null), // 筛选
  defaultButtons.defaultSetBtn(null), // 设置
 
]

// 头部按钮事件
const buttonBaseClick = (val, item) => {
  if (val == 'export') { // 导出
    // handleExport()
  } else if (val == 'refresh') { // 刷新
    if (tableObject.params.filters && tableObject.params.filters.length > 0 ) {
      searchFormClick({
        filters: tableObject.params.filters
      })
    } else {
      getList()
    }
  } else if (val == 'filtrate') { // 筛选
  } else { // 其他按钮
    console.log('其他按钮', item)
  }
}

// 筛选提交
const searchFormClick = (searchData) => {
  tableObject.params = {
    isSearch: true,
    filters: searchData.filters
  }
  getList() // 刷新当前列表
}

/** 初始化 **/
onMounted(async () => {
  getList()
})
</script>
