<template>
  <view>
    <view class="form_card">
      <hs-cell
        title="房屋信息"
        required
        borderTop
        isLink
        :value="useModel?.formData?.value?.full_name"
        @click="method?.handleToSelectHouse"
      />
    </view>
    <view class="form_card">
      <hs-cell title="申请人" required>
        <hs-input v-model:valueModel="useModel.formData.value.apply_name" textAlign="right" />
      </hs-cell>
      <hs-cell title="申请人电话" required borderTop>
        <hs-input
          v-model:valueModel="useModel.formData.value.apply_phone"
          maxLength="11"
          type="number"
          textAlign="right"
        />
      </hs-cell>
      <hs-cell title="通行类型" borderTop required>
        <hs-radio
          :Enums="GoodsReleasesPassedTypeEnum"
          v-model:valueModel="useModel.formData.value.passed_type"
          required
        />
      </hs-cell>
    </view>
    <view class="form_card">
      <view class="card_title">
        物品信息
        <view class="add_card_btn" @click="method?.handleAddGoods" :style="getStyleColorInfo()">
          <uni-icons type="plusempty" size="14" :color="getStyleColorValueInfo()"></uni-icons> 增加
        </view>
      </view>
      <view
        class="card_goods"
        v-for="(i, index) in useModel?.formData?.value.goods"
        :key="`input_${index}`"
      >
        <view class="goods_info">
          <view class="goods_item_input">
            <view class="goods_name">
              <u-input placeholder="物品名称" v-model="i.name"></u-input>
            </view>
            <u-number-box v-model="i.number"></u-number-box>
          </view>
          <view class="goods_item_remark">
            <hs-input v-model:valueModel="i.remark" placeholder="物品备注" />
          </view>
        </view>
        <view class="goods_delete" v-if="index > 0" @click="method?.handleDeleteGoods(index)">
          <uni-icons type="trash-filled" color="#999" size="25"></uni-icons>
        </view>
      </view>
    </view>

    <view class="form_card">
      <hs-date-picker
        title="放行日期"
        v-model:valueModel="useModel.formData.value.passed_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 btnParimaryName="提交申请" @handleParmaryClick="method.handleSubmit" />
  </view>
</template>

<script setup lang="ts">
import { onShow, onUnload } from '@dcloudio/uni-app'
import method from './method'
import useModel from './model'
import { getStyleColorValueInfo, getStyleColorInfo } from "@/common/libraries/getPageConfig"
import { GoodsReleasesPassedTypeEnum } from '@/gen/Enums'

onShow(() => {
  method?.init()
})
onUnload(() => {
  useModel.formData.value = {
    goods: [
      {
        name: '',
        number: 1,
        remark: ''
      }
    ]
  }
})
</script>

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