<template>
  <view class="release_items_page">
    <view class="release_content" v-if="useModel?.formData?.value?.source === '2'">
      <view v-if="useModel?.isExpired?.value" class="expired">
        <view>
          <uni-icons type="info" size="50" color="#FF4D4F"></uni-icons>
        </view>
        <view class="des"> 通行证已失效 </view>
        <view class="sub_des"> 该二维码已失效，请和客户确认出入信息 </view>
      </view>

      <view class="user_info" v-else>
        <view class="avatar"><u-avatar :src="useModel?.userInfo?.value?.worker_photo &&
          useModel?.userInfo?.value?.worker_photo[0]?.url
          " size="70"></u-avatar></view>
        <view class="name">{{ useModel?.showData?.value?.visitor_name || '-' }}</view>
        <view class="phone">{{ useModel?.showData?.value?.visitor_phone || '-' }}</view>
      </view>
      <view class="outer_info">
        <view class="cell_items">
          <view class="label"> 关联房屋 </view>
          <view class="value">
            {{ useModel?.showData?.value?.asset_house?.full_name || '-' }}
          </view>
        </view>
        <view class="cell_items">
          <view class="label"> 状态 </view>
          <view v-if="useModel?.isExpired?.value" class="status status_expired"> 已失效 </view>
          <view v-else :class="`value status_${useModel?.showData?.value?.status}`">
            {{
              VisitorAppliesStatusEnum[
                useModel?.showData?.value?.status as keyof typeof VisitorAppliesStatusEnum
              ]?.text
            }}
          </view>
        </view>
        <view class="cell_items" v-if="useModel?.showData?.value?.remark">
          <view class="label"> 事项 </view>
          <view class="value"> {{ useModel?.showData?.value?.remark || '-' }} </view>
        </view>
        <view class="cell_items">
          <view class="label"> 上次进入时间 </view>
          <view class="value">
            {{ useModel?.showData?.value?.last_enter_record?.enter_time || '-' }}
          </view>
        </view>
        <view class="cell_items">
          <view class="label"> 上次离开时间 </view>
          <view class="value">
            {{ useModel?.showData?.value?.last_exit_record?.exit_time || '-' }}
          </view>
        </view>
      </view>
    </view>

    <view class="release_content" v-if="useModel?.formData?.value?.source === '4'">
      <view class="user_info">
        <view class="avatar"><u-avatar size="70"></u-avatar></view>
        <view class="name">{{ useModel?.showData?.value?.house?.full_name || '-' }}</view>
        <view class="phone">{{ useModel?.showData?.value?.occupant_name || '-' }}</view>
      </view>
    </view>

    <hs-footer btnParimaryName="进入小区" btnOtherShow
      v-if="useModel?.showData?.value?.status === 'Approved' && !useModel?.isExpired?.value && useModel?.formData?.value?.source === '2'"
      btnOtherName="离开小区" @handleParmaryClick="method?.handleSubmit('enter')"
      @handleOtherClick="method?.handleSubmit('exit')" />
    <hs-footer btnParimaryName="进入小区" btnOtherShow v-if="useModel?.formData?.value?.source === '4'" btnOtherName="离开小区"
      @handleParmaryClick="method?.handleSubmit('enter')" @handleOtherClick="method?.handleSubmit('exit')" />
  </view>
</template>
<script setup lang="ts">
import { VisitorAppliesStatusEnum } from '@/gen/Enums'
import { onLoad } from '@dcloudio/uni-app'
import method from './method'
import useModel from './model'

onLoad((e: any) => {
  method?.init(e)
  console.log(e)
})
</script>
<style lang="scss">
@import './style.scss';
</style>
