import { Apis } from '@/gen/Apis'
import { useWeAppAuthStore, useWorkStore } from '@/common'
const auth = useWeAppAuthStore()
const work = useWorkStore()
export const getIsHouseExist = (res?: any) => {
  if (!auth?.data?.user) {
    uni.navigateTo({
      url: '/pages/login'
    })
    return false
  }
  if (!auth?.data?.selected_house && auth?.data?.house_occupant) {
    work.selectedHouse += 1
    uni.switchTab({
      url: '/pages/index/index'
    })
    return false
  }
  if (!res?.is_bind_house) {
    // 不拦截部分功能，可以不绑定房屋
    return true
  }
  if (!auth?.data?.house_occupant && !auth?.data?.house_register) {
    uni.showModal({
      title: '提示',
      content: '未绑定房屋，请先绑定房屋！',
      confirmText: '去绑定',
      confirmColor: '#0082FA',
      success: function (res) {
        if (res.confirm) {
          uni.navigateTo({
            url: '/INDEX/binding/index'
          })
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
    return false
  }
  console.log('已绑定房屋', auth?.data)
  if (!auth?.data?.house_occupant && auth?.data?.house_register) {
    uni.showModal({
      title: '提示',
      cancelText: '继续绑定',
      content: '有房屋还在审核中！',
      confirmText: '去查看',
      confirmColor: '#0082FA',
      success: function (res) {
        if (res.confirm) {
          uni.navigateTo({
            url: '/INDEX/owner_audit_list/index?type=1'
          })
          console.log('用户点击确定')
        } else if (res.cancel) {
          uni.navigateTo({
            url: '/INDEX/binding/index'
          })
          console.log('用户点击取消')
        }
      }
    })
    return false
  }
  return true
}
