<template>
  <view class="bind_house_form_page" v-if="useModel?.bindHouseFormPage?.value">
    <view class="form_card">
      <hs-cell title="客户姓名" required borderTop>
        <hs-input v-model:valueModel="useModel.formData.value.name" textAlign="right" />
      </hs-cell>
      <hs-cell title="手机号" required borderTop>
        <hs-input v-model:valueModel="useModel.formData.value.phone" maxLength="11" type="number" textAlign="right" />
      </hs-cell>
    </view>
    <hs-footer btnParimaryName="下一步" btnOtherName="邀请客户绑定" btnOtherShow @handleParmaryClick="method?.nextStep"
      @handleOtherClick="method?.handleInviteCustomer" />
  </view>
  <view class="bind_house_select_page" v-if="useModel?.bindHouseSelectPage?.value">
    <view class="house_title"> 请选择需要绑定的房屋 </view>
    <view class="house_select_content">
      <hs-empty v-if="!useModel?.listData?.value?.length" />
      <view class="house_select_item" v-for="(i, index) in useModel?.listData?.value" :key="`house_${index}`"
        @click="method?.selectHouse(i, index)">
        <view class="house_info">
          <view class="house_name">
            {{ i?.asset_project?.name }}{{ i?.asset_building?.name }}{{ i?.asset_unit?.name
            }}{{ i?.asset_house?.name }}
          </view>
          <view class="house_identity">
            身份：<hs-enum-tag :value="i?.house_relation" size="md" :Enums="HouseOccupantsHouseRelationEnum" />
            <hs-enum-tag :value="i?.residential_relation" size="md" v-if="i?.residential_relation"
              :Enums="HouseOccupantsResidentialRelationEnum" />
          </view>
        </view>
        <uni-icons v-if="i?.isSelect" type="checkbox-filled" size="18" color="#0082FA"></uni-icons>
        <uni-icons v-else type="circle" size="18" color="#666"></uni-icons>
      </view>
    </view>
    <hs-footer btnParimaryName="绑定房屋" btnOtherShow :btnOtherName="useModel?.bindPhone?.value ? '绑定其他房屋' : '上一步'"
      @handleParmaryClick="method?.handleBindHouse" @handleOtherClick="method?.handleBack" />
  </view>
</template>
<script setup lang="ts">
import { useWeAppAuthStore } from '@/common'
import { HouseOccupantsHouseRelationEnum, HouseOccupantsResidentialRelationEnum } from '@/gen/Enums'
import { onLoad, onUnload } from '@dcloudio/uni-app'
import { getCurrentInstance } from 'vue'
import method from './method'
import useModel from './model'
const auth = useWeAppAuthStore()
onLoad(async e => {
  await getCurrentInstance()?.appContext.config.globalProperties.$onLaunched
  if (e?.phone) {
    useModel.bindPhone.value = true
    useModel.formData.value = e
    method?.nextStep('phone')
  }
  if (auth?.data?.environment === 'wxwork') {
    uni.qy.getCurExternalContact({
      success: function (res: any) {
        useModel.formData.value.external_userid = res?.userId
        console.log('开始2', res)
      }
    })
  }
})
onUnload(() => {
  useModel.bindHouseSelectPage.value = false
  useModel.bindHouseFormPage.value = true
  useModel.formData.value = {}
})
</script>
<style lang="scss">
@import './style.scss';
</style>
