<template>
  <view class="emergency_list_page">
    <view class="header_search_box">
      <u-search
        placeholder="请输入关键词搜索"
        :showAction="false"
        v-model="useModel.formData.value.name"
        @search="method?.onSearch"
      ></u-search>
    </view>
    <view class="emergency_contents">
      <cc-scroll-loading :meta="useModel?.metaData?.value" @load="method?.handleLoad">
        <view
          v-for="(i, index) in useModel.listData.value"
          :key="`item_${index}`"
          class="emergency_items"
          @click="method?.handleDetail(i)"
        >
          <view class="emergency_items_header">
            <view class="emergency_items_level"> {{ i?.emergency_event_levels_name }} </view>
            <view :class="`status status_${i?.status}`">
              <hs-enum-tag :value="i?.status" :Enums="EmergencyEventsStatusEnum" />
            </view>
          </view>
          <view class="emergency_items_content"> {{ i?.name }} </view>
          <view class="emergency_items_cell">
            <image src="/static/svg/project_icon.svg" mode="aspectFit" />
            <text class="label"> {{ i?.asset_project?.name }} </text>
          </view>
          <view class="emergency_items_cell"> 提报时间：{{ i?.created_at }} </view>
          <view class="emergency_items_cell">
            上次跟进：{{ i?.emergency_event_follows?.[0]?.created_at || '-' }}
          </view>
        </view>
      </cc-scroll-loading>
    </view>

    <hs-footer btnParimaryName="新增突发事件" @handleParmaryClick="method?.handleAdd" />
  </view>
</template>
<script setup lang="ts">
import useModel from './model'
import method from './method'
import { EmergencyEventsStatusEnum } from '@/gen/Enums'
import { onLoad, onShow, onUnload } from '@dcloudio/uni-app'

onShow(() => {
  useModel.formData.value.page = 1
  useModel.listData.value = []
  method?.getList()
})

onUnload(() => {
  useModel.formData.value.name = ''
  useModel.formData.value.page = 1
  useModel.listData.value = []
})
</script>
<style lang="scss">
@import './style.scss';
</style>
