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

const getList = () => {
  getApiLoading(Apis.Meter.HouseMeterReadings.List, useModel?.formData?.value).then(res => {
    useModel.listData.value = [...useModel.listData.value, ...res?.data]
    useModel.metaData.value = res?.meta
  })
}
const handleTabSearch = () => {
  useModel.formData.value.page = 1
  useModel.listData.value = []
  getList()
}
export default {
  getList,
  handleSearch(){
    handleTabSearch()
  },
  handleChangeTabs(idx: number, e: any) {
    useModel.currentTabs.value = idx
    useModel.formData.value.meter_type = e?.value
    handleTabSearch()
  },
  handleLoad(page: number) {
    useModel.formData.value.page = page
    getList()
  },
   handleChangeFilter(e:any){
      useModel.formData.value ={
        ...useModel.formData.value,
        ...e,
        pahe:1,
      }
      useModel.listData.value = []
      getList()
    },
  handleToDetail(e:any) {
    uni.navigateTo({
      url: `/ME/instrument/log_show/index?id=${e?.id}`
    })
  }
}
