import { getApiLoading } from '@/common/libraries/apiLoading'
import { Apis } from '@/gen/Apis'
import useModel from './model'
import { showToastBack, showToast } from '@/common/libraries/naviHelper'
import { useWeAppAuthStore, useWorkStore } from '@/common'
import getUserLogin from '@/common/libraries/userUserLogin'
const work = useWorkStore()

const getHouseList = () => {
  if (!getUserLogin?.getLoginStatus()) return
  getApiLoading(Apis.Grid.Grids.GridSelectHouse, useModel?.formData?.value).then(res => {
    useModel.dataList.value = res?.data
    console.log(res)
  })
}

export default {
  getHouseList,
  // getHouseRegistersList,
  handleLoadMore(page: number) {
    useModel.formData.value.page = page
    if (useModel.currentTabs.value === 0) {
      getHouseList()
    }
    // if (useModel.currentTabs.value === 1) {
    //   getHouseRegistersList()
    // }
  },
  handleSelectedHouse(e: { value: string }) {
    useModel.selectedHouseEd.value = { id: e?.value }
    if (useModel?.selectType?.value === 'work_add') {
      work.selectWorkHouse = e
      showToastBack('选择成功！', 1, true)
      return
    }
  },
  hadnleNewBindingHouse() {
    uni.navigateTo({
      url: getUserLogin?.getLoginStatus() ? '/INDEX/binding/index' : '/pages/login'
    })
  },
  handleQueryHouseArchives(e: { asset_houses_id: string }) {
    uni.navigateTo({
      url: `/INDEX/archive_houses/index?id=${e?.asset_houses_id}`
    })
  }
}
