/*
 * @Author       : ldc 951052117@qq.com
 * @Date         : 2023-06-13 10:40:30
 * @LastEditors  : ldc 951052117@qq.com
 * @LastEditTime : 2023-11-16 16:03:22
 * @Description  : table serch
 */
import { reactive, ref } from 'vue'
const useTablePgSearch = (searchApi, pageSize, defaultData) => {
  const tableList = ref([])
  const searchForm = ref({})

  if (defaultData) searchForm.value = JSON.parse(JSON.stringify(defaultData))
  const page = reactive({
    currentPage: 1,
    pageSize: pageSize || 10,
    total: 0,
  })
  const initTable = () => {
    page.pageSize = pageSize || 10
    page.currentPage = 1
    search()
  }
  const resetSearch = () => {
    page.pageSize = pageSize || 10
    page.currentPage = 1
    searchForm.value = (defaultData && JSON.parse(JSON.stringify(defaultData))) || {}
    search()
  }
  const handleCurrentChange = val => {
    page.currentPage = val
    search()
  }
  const handleSizeChange = val => {
    page.pageSize = val
    search()
  }
  const search = searchApi
  return {
    searchForm,
    page,
    tableList,
    search,
    resetSearch,
    initTable,
    handleCurrentChange,
    handleSizeChange,
  }
}
export default useTablePgSearch
