<template>
  <hs-popup-custom :show="show_bangding_house" mode="center" title="入住登记提醒">
    <view class="popup_custom_content">
      <view class="bind_des"> 为了给您提供更精准的社区服务<br />请先完成房屋绑定哦～ </view>
      <view class="bind_house_popup_footer">
        <hs-button
          label="前往入住登记"
          @click="hadnleNewBindingHouse('/INDEX/binding/index')"
          size="md"
          type="primary"
        />
        <view class="bind_house_popup_footer_later" @click="handleClosePopup"> 稍后绑定 </view>
      </view>
    </view>
    <template v-slot:footer>
      <view class="bind_house_popup_close" @click="handleClosePopup">
        <uni-icons type="close" size="35" color="#fff"></uni-icons>
      </view>
    </template>
  </hs-popup-custom>
  <hs-popup-custom :show="show_review_house" mode="center" title="住户审核通知">
    <view class="popup_custom_content">
      <view class="bind_des"> 您有一条房屋绑定审核申请<br />请及时处理～ </view>
      <view class="bind_house_popup_footer">
        <hs-button
          label="前往审核"
          @click="hadnleNewBindingHouse('/INDEX/owner_audit_list/index')"
          size="md"
          type="primary"
        />
        <view class="bind_house_popup_footer_later" @click="handleClosePopup"> 稍后处理 </view>
      </view>
    </view>
    <template v-slot:footer>
      <view class="bind_house_popup_close" @click="handleClosePopup">
        <uni-icons type="close" size="35" color="#fff"></uni-icons>
      </view>
    </template>
  </hs-popup-custom>
</template>
<script setup lang="ts">
import { getApiLoading } from '@/common/libraries/apiLoading'
import { Apis } from '@/gen/Apis'
import { useWeAppAuthStore } from '@/common'
import { onHide, onShow } from '@dcloudio/uni-app'
import { computed, getCurrentInstance, ref, watch } from 'vue'
const audit_status = ref(false)
const auth = useWeAppAuthStore()
const show_bangding_house = ref(false)
const show_review_house = ref(false)

const hadnleNewBindingHouse = (url?: string) => {
  uni.navigateTo({
    url: url || ''
  })
}

const handleClosePopup = () => {
  show_bangding_house.value = false
  show_review_house.value = false
}

onHide(() => {
  handleClosePopup()
})

const handleSelectResidentialRelation = () => {
  //获取产权人是否有审核
  if (audit_status.value) return
  getApiLoading(Apis.Archive.HouseRegisters.GetOwnerIsAudit, {}).then(res => {
    if (res?.data) {
      show_review_house.value = true
      audit_status.value = true
    }
    console.log(res)
  })
}

//如果注册了，但是没有绑定过，也没有提交过
watch(
  () => auth?.data?.is_house_exist,
  () => {
    if (auth?.data?.user && !auth?.data?.house_occupant && !auth?.data?.house_register) {
      show_bangding_house.value = true
    }
    console.log(auth?.data?.house_occupant, 'house_occupant2')
  },
  {
    deep: true
  }
)

watch(
  () => auth?.data?.user,
  () => {
    // if (auth?.data?.user && !auth?.data?.house_occupant && !auth?.data?.house_register) {
    //   show_bangding_house.value = true
    //   return
    // }
    if (auth?.data?.user && auth?.data?.selected_house) {
      //获取产权人是否有审核
      // handleSelectResidentialRelation()
    }
  },
  {
    deep: true
  }
)

onShow(async () => {
  await getCurrentInstance()?.appContext.config.globalProperties.$onLaunched
  if (auth?.data?.user && auth?.data?.selected_house) {
    //获取产权人是否有审核
    handleSelectResidentialRelation()
  }
})

// onShow(() => {
//   if (auth?.data?.user && !auth?.data?.house_occupant && !auth?.data?.house_register) {
//     show_bangding_house.value = true
//   }
// })
</script>
<style lang="scss" scoped>
.popup_custom_content {
  text-align: center;
  .bind_des {
    line-height: 50rpx;
    padding: 10rpx 0;
  }
  .bind_house_popup_footer {
    padding: 40rpx 40rpx 0 40rpx;
    .bind_house_popup_footer_later {
      text-align: center;
      color: #000;
      font-size: 28rpx;
      padding: 30rpx 0;
    }
  }
}
.bind_house_popup_close {
  text-align: center;
  padding-top: 40rpx;
}
</style>
