<template>
  <view>
    <MyHeader />
    <view class="work_contents">
      <cc-scroll-loading :meta="useModel?.meta?.value" @load="method?.handleLoad">
        <view
          class="work_item"
          v-for="(i, index) in useModel?.dataList?.value"
          :key="`items_${index}`"
        >
          <view @click="method?.handleToDetail(i)">
            <view class="work_item_header">
              <view class="work_item_header_left">
                <view class="btn_type">
                  <hs-enum-tag :value="i?.type" :Enums="HouseWorkOrdersTypeEnum" />
                </view>
                <view class="btn_type" v-if="i?.location">
                  <hs-enum-tag :value="i?.location" :Enums="HouseWorkOrdersLocationEnum" />
                </view>
              </view>
              <view :class="`btn_status btn_status_${i?.status}`">
                <hs-enum-tag :value="i?.status" :Enums="HouseWorkOrdersStatusEnum" />
              </view>
            </view>
            <view class="work_item_houses">
              {{ i?.asset_house?.full_name }}
              <!-- <view class="item"> {{ i?.title }} </view> -->
            </view>
            <view class="work_item_des"> {{ i?.content }} </view>
            <view
              v-if="i?.expect_start_time && i?.status !== 'Closed' && i?.status !== 'Completed'"
              class="work_item_cell"
            >
              期望处理时间：{{ i?.expect_start_time }}(两小时内)
            </view>
            <view class="work_item_cell" v-if="i?.status === 'Completed' && !i?.accept_time">
              工单完成时间： {{ i?.accept_time }}
            </view>
            <view class="work_item_cell" v-else> 工单创建时间： {{ i?.created_at }} </view>
            <view class="work_item_cell" v-if="i?.evaluation_score">
              客户评价：<hs-up-rate :valueModel="i?.evaluation_score" />
            </view>
            <view class="work_item_cell" v-if="parseFloat(i?.amount) > 0">
              支付金额：<text>¥{{ i?.amount }}元</text>
            </view>
          </view>

          <view
            class="work_item_footer"
            v-if="i?.status !== 'Pending' && i?.status !== 'Closed' && !i?.evaluation_score"
          >
            <hs-button
              v-if="i?.status === 'Completed' && !i?.evaluation_score"
              type="ghost"
              label="工单评价"
              @click="method?.handleAssignEmployee(i)"
            />
            <hs-button
              v-if="i?.status === 'PendingPayment'"
              type="ghost"
              label="支付费用"
              @click="method?.handleAssignEmployee(i)"
            />
            <hs-button
              v-if="i?.status === 'PendingAcceptance'"
              type="ghost"
              label="验收工单"
              @click="method?.handleAssignEmployee(i)"
            />
            <hs-button
              v-if="i?.status === 'Processing'"
              type="ghost"
              label="联系处理人"
              @click="method?.handleAssignEmployee(i)"
            />
          </view>

          <!-- <view class="work_item_images">
            <view v-for="(k, idx) in i?.attachments" :key="`img_${index}_${idx}`" class="item">
              <image :src="k?.url" mode="aspectFill" />
            </view>
          </view> -->
        </view>
      </cc-scroll-loading>
    </view>
    <!-- <hs-footer btnParimaryName="新增工单" @handleParmaryClick="method?.handleAdd" /> -->

    <hs-popup-evaluate
      :show="useModel?.showEvaluate?.value"
      mode="bottom"
      :closeable="true"
      :round="20"
      :params="useModel?.evaluateParams?.value"
      @onSubmit="method?.handlepopupClose"
      @onClose="useModel.showEvaluate.value = false"
    />
  </view>
</template>
<script setup lang="ts">
import { onHide, onUnload, onShow } from '@dcloudio/uni-app'
import MyHeader from './components/header.vue'
import method from './method'
import useModel from './model'
import {
  HouseWorkOrdersTypeEnum,
  HouseWorkOrdersLocationEnum,
  HouseWorkOrdersStatusEnum
} from '@/gen/Enums'

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

onUnload(() => {
  useModel.currentTabs.value = 0
})

onHide(() => {
  useModel.showEvaluate.value = false
})
</script>
<style lang="scss">
@import './style.scss';
</style>
