import { getApiLoading } from '@/common/libraries/apiLoading'
import { Apis } from '@/gen/Apis'
import useModel from './model'

const getList = () => {
  getApiLoading(Apis.Emergency.EmergencyEvents.List, useModel?.formData?.value).then(res => {
    useModel.listData.value = [...useModel.listData.value, ...res?.data]
    useModel.metaData.value = res?.meta
  })
}
const handleSearch = () => {
  useModel.formData.value.page = 1
  useModel.listData.value = []
  getList()
}
export default {
  getList,
  handleChangeTabs(idx: number, e: any) {
    handleSearch()
  },
  handleLoad(res: any) {
    useModel.formData.value.page = res?.page
    getList()
  },
  handleAdd() {
    uni.navigateTo({
      url: '/ME/emergency/add/index'
    })
  },
  onSearch() {
    handleSearch()
  },
  handleDetail(e: { id: string }) {
    uni.navigateTo({
      url: `/ME/emergency/show/index?id=${e?.id}`
    })
  }
}
