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

const getList = () => {
  getApiLoading(Apis.Meter.HouseMeters.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()
  },
  handleChangeFilter(e:any){
    useModel.formData.value ={
      ...useModel.formData.value,
      ...e,
      pahe:1,
    }
    useModel.listData.value = []
    getList()
  },
  handleChangeFilterReadingStatus(e:any){
    useModel.formData.value ={
      ...useModel.formData.value,
      reading_status: e?.value || undefined,
    }
    useModel.listData.value = []
    getList()
  },
  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()
  },
  handleToAdd(i: any) {
    uni.navigateTo({
      url: `/ME/instrument/add/index?id=${i?.id}`
    })
  },
  handleToLog(){
    uni.navigateTo({
      url: `/ME/instrument/log/index?id=`
    })
  }
}
