import useModel from './model'
import { showToast } from '@/common/libraries/naviHelper'
import { Apis } from '@/gen/Apis'
import { getApiLoading } from '@/common/libraries/apiLoading'
import getUserLogin from '@/common/libraries/userUserLogin'
const getList = () => {
  getApiLoading(Apis.Grid.Grids.GridAssetHouse, useModel?.formData?.value).then(res => {
    useModel.listData.value = res?.data || []
    useModel.metaData.value = res?.meta || {}
    console.log(res)
  })
}

const handleSearch = () => {
  useModel.formData.value.page = 1
  useModel.listData.value = []
  getList()
}

export default {
  handleChangeBuilding(e: { id: string }) {
    if (e?.id !== useModel.formData.value.asset_buildings_id) {
      useModel.formData.value.asset_buildings_id = e?.id
      handleSearch()
    }
    console.log(e, 'e')
  },
  getGridAssetBuilding() {
    getApiLoading(Apis.Grid.Grids.GridAssetBuilding, {}).then(res => {
      useModel.buildingData.value = res?.data || []
      if (res?.data?.length) {
        useModel.formData.value.asset_buildings_id = res?.data[0]?.id
        getList()
      }
      console.log(res)
    })
  },
  handleSearch,
  toDetaile(e: { id: string }) {
    uni.navigateTo({
      url: `/BILL/outstanding_fee/show/index?id=${e?.id}`
    })
  }
}
