<template>
  <view v-if="useModel?.loading?.value" class="customer_assets_page">
    <view class="customer_card">
      <view class="card_user_header">
        <view class="avatar"> </view>
        <view class="user_info">
          <view class="name">
            {{ useModel?.showData?.value?.customer?.customer_name || '请补充姓名' }}
          </view>
        </view>
      </view>
      <view>
        <hs-cell title="手机号" :value="useModel?.showData?.value?.customer?.customer_phone" />
      </view>
    </view>

    <view class="house_contents">
      <view class="house_title"> 已绑定的房屋 </view>
      <hs-empty v-if="!useModel?.showData?.value?.houseList?.length" />
      <view
        v-for="(i, index) in useModel?.showData?.value?.houseList"
        :key="`iten_${index}`"
        class="customer_item"
      >
        <view>
          <view class="customer_item_head"> {{ i?.asset_house?.full_name }} </view>
          <view class="customer_item_identity">
            身份：
            <hs-enum-tag
              :value="i?.house_relation"
              size="md"
              v-if="i?.house_relation === 'Owner'"
              :Enums="HouseOccupantsHouseRelationEnum"
            />
            <hs-enum-tag
              :value="i?.residential_relation"
              size="md"
              v-else
              :Enums="HouseOccupantsResidentialRelationEnum"
            />
          </view>
        </view>
        <view v-if="i?.house_relation !== 'Owner'">
          <MyUnBindpopup
            :data="{ ...i, external_userid: useModel?.formData?.value?.external_userid }"
            @success="method?.getList"
          />
        </view>
      </view>
    </view>

    <hs-footer btnParimaryName="绑定新房屋" @handleParmaryClick="method?.handleBindHouse" />
  </view>
</template>

<script setup lang="ts">
import { onLoad, onShow } from '@dcloudio/uni-app'
import { getCurrentInstance } from 'vue'
import getUserLogin from '@/common/libraries/userUserLogin'
import useModel from './model'
import method from './method'
import { HouseOccupantsHouseRelationEnum, HouseOccupantsResidentialRelationEnum } from '@/gen/Enums'
import MyUnBindpopup from './components/unBindpopup.vue'

onShow(async (e: any) => {
  await getCurrentInstance()?.appContext.config.globalProperties.$onLaunched
  if (getUserLogin?.onBindPhone()) {
    console.log('onShow_21')
    uni.qy.getCurExternalContact({
      success: function (res: any) {
        useModel.showData.value = {}
        useModel.formData.value.external_userid = res?.userId
        method?.getList()
        console.log('开始2', res)
      },
      fail: function (res: any) {
        method?.getList()
        console.log('失败', res)
      }
    })
  }
})
</script>

<style lang="scss">
@import './style.scss';
</style>
