<template>
  <view class="form_content">
    <view class="share_card" v-if="useModel?.formData?.value?.page_type !== 'share'">
      <view> 为保证信息正确，您可分享至微信好友填写 </view>
      <view class="share_btn">
        <button open-type="share">
          分享转发 <uni-icons type="right" size="14" color="#fff"></uni-icons>
        </button>
      </view>
    </view>
    <view class="form_card">
      <hs-cell
        title="房屋信息"
        required
        isLink
        v-if="useModel?.formData?.value?.page_type !== 'share'"
        :value="useModel?.formData?.value?.full_name"
        @click="method?.handleToSelectHouse"
      />
      <hs-cell title="房屋信息" required v-else :value="useModel?.formData?.value?.full_name" />
    </view>

    <view class="form_card">
      <hs-cell title="访客姓名" required>
        <hs-input v-model:valueModel="useModel.formData.value.visitor_name" textAlign="right" />
      </hs-cell>
      <hs-cell title="访客电话" required borderTop>
        <hs-input
          v-model:valueModel="useModel.formData.value.visitor_phone"
          maxLength="11"
          textAlign="right"
          type="number"
        />
      </hs-cell>
      <hs-radio-cell-picker
        title="来访事由"
        required
        isLink
        borderTop
        :Enums="VisitReasonEnum"
        v-model:valueModel="useModel.formData.value.visit_reason"
      />
    </view>
    <view class="form_card">
      <view class="card_title">
        随访人信息
        <view class="add_card_btn" @click="method?.handleAddGoods">
          <uni-icons type="plusempty" size="14" color="#2a7efb"></uni-icons> 增加
        </view>
      </view>
      <view
        class="card_goods"
        v-for="(i, index) in useModel?.formData?.value?.companions_json"
        :key="`input_${index}`"
      >
        <view class="goods_info">
          <view class="goods_item_remark">
            <hs-input v-model:valueModel="i.name" placeholder="随访人姓名" />
          </view>
        </view>
        <view class="goods_delete" @click="method?.handleDeleteGoods(index)">
          <uni-icons type="trash-filled" color="#999" size="22"></uni-icons>
        </view>
      </view>
    </view>

    <view class="form_card">
      <hs-date-picker
        title="预计到访时间"
        v-model:valueModel="useModel.formData.value.visit_start_time"
        required
        isLink
      />
      <hs-date-picker
        title="预计离开时间"
        borderTop
        v-model:valueModel="useModel.formData.value.visit_end_time"
        required
        isLink
      />
      <view class="refund_info">
        <view class="label"> 其他备注 </view>
        <view class="refund_reason">
          <textarea
            v-model="useModel.formData.value.remark"
            placeholder-style="color:#C9CDD4;font-size:28rpx;"
            placeholder="输入其他备注"
          />
        </view>
      </view>
    </view>
    <hs-footer>
      <view class="footer_page">
        <view class="filing_btn" @click="method?.handleToApplyRecords">
          <view class="icon">
            <u-icon name="order" size="24"></u-icon>
          </view>
          <view class="label"> 申请记录 </view>
        </view>

        <view class="footer_group_btn">
          <hs-button label="提交申请" @click="method.handleSubmit" type="primary" size="md" />
        </view>
      </view>
    </hs-footer>
  </view>
</template>

<script setup lang="ts">
import { onLoad, onShareAppMessage, onShow, onUnload } from '@dcloudio/uni-app'
import method from './method'
import useModel from './model'
import { VisitReasonEnum } from '@/gen/Enums'

onShow(() => {
  method?.init({})
})

onLoad(e => {
  console.log(e, 'show_e')
  if (e?.page_type === 'share') {
    useModel.formData.value = e
    method?.init(e)
  }
})
onUnload(() => {
  useModel.formData.value = {
    companions_json: [
      {
        name: ''
      }
    ]
  }
})

onShareAppMessage(() => {
  return {
    title: '好友邀请你填写访客信息！',
    path: `/INDEX/visitor_applies/add/index?id=${useModel?.formData.value?.asset_houses_id}&full_name=${useModel?.formData.value?.full_name}&page_type=share`,
    imageUrl:
      'https://pay-prod-1369486729.cos.ap-guangzhou.myqcloud.com/uploads/cs-test/01KFYMMS6X8YP52NQQ4TCFED51.jpg'
  }
})
</script>

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