<template>
  <view class="workorder_page">
    <!-- <view class="card_form">
      <hs-cell title="工单类型" required>
        <hs-radio
          :Enums="HouseWorkOrdersTypeEnum"
          v-model:valueModel="useModel.formData.value.type"
          @onChange="method?.handleChangeType"
        />
      </hs-cell>
    </view> -->
    <view class="card_form">
      <hs-radio-cell-picker
        :Enums="HouseWorkOrdersComplaintTypeEnum"
        title="投诉类型"
        borderTop
        v-if="useModel.formData.value.type === 'Complaint'"
        v-model:valueModel="useModel.formData.value.complaint_type"
        required
      />
      <!-- <hs-cell title="报事位置" required v-if="useModel.formData.value.type !== 'Complaint'">
        <hs-radio
          :Enums="HouseWorkOrdersLocationEnum"
          v-model:valueModel="useModel.formData.value.location"
        />
      </hs-cell> -->
      <hs-cell
        title="房屋信息"
        required
        borderTop
        isLink
        v-if="
          useModel.formData.value.type !== 'Complaint' &&
          useModel.formData.value.location === 'MyHome'
        "
        :value="useModel?.formData?.value?.full_name"
        @click="method?.handleToSelectHouse"
      />
      <hs-cell-textarea
        borderTop
        required
        title="问题描述"
        placeholder="请详细描述问题情况，包括具体位置现象等"
        v-model:valueModel="useModel.formData.value.content"
      />
      <hs-upload
        borderTop
        title="上传图片"
        :count="6"
        v-model:valueModel="useModel.formData.value.attachments"
      />
    </view>

    <view class="card_form">
      <hs-cell title="匿名投诉" v-if="useModel.formData.value.type === 'Complaint'">
        <switch color="#0082FA" @change="method.handleSwitchChange" />
      </hs-cell>
      <hs-reservation-picker
        title="期望上门时间"
        required
        v-if="
          useModel.formData.value.location === 'MyHome' &&
          useModel.formData.value.type !== 'Complaint'
        "
        v-model:valueExpectStartTime="useModel.formData.value.expect_start_time"
        v-model:valueExpectEndTime="useModel.formData.value.expect_end_time"
      />
    </view>

    <view class="card_form" v-if="useModel.formData.value.type !== 'Complaint'">
      <hs-cell title="联系人" required>
        <hs-input v-model:valueModel="useModel.formData.value.reporter_name" />
      </hs-cell>
      <hs-cell title="联系电话" required borderTop>
        <hs-input v-model:valueModel="useModel.formData.value.reporter_phone" />
      </hs-cell>
    </view>

    <hs-footer btnParimaryName="提交" @handleParmaryClick="method?.handleSubmit" />
  </view>
</template>

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

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

onLoad(e => {
  useModel.formData.value.type = e?.type || ''
  useModel.formData.value.location = e?.location || ''
})

onUnload(() => {
  useModel.formData.value = { is_anonymous: false }
})
</script>
<style lang="scss">
@import './style.scss';
</style>
