<script setup>
import { getWorkDataInfoApi } from '@/api/elevator'
import { useUniApi } from '@/composables/use-uni-api'

// 电梯名称 工作选项 工作状态 创建时间 发布人员 期望时间 工作描述 被困人数 受伤人数 备注 其它原因
const cellData = ref([
  { key: '电梯名称', value: '', field: 'elevatorName' },
  { key: '故障类型', value: '', field: 'faultType' },
  { key: '发生时间', value: '', field: 'happenTime' },
  { key: '恢复时间', value: '', field: 'restoreTime' },
  { key: '工作描述', value: '', field: 'description' }
])

const { navigateTo } = useUniApi()
const toRecord = () => {
  const { id, elevatorNum } = dataDetail.value
  navigateTo(
    `/pages/views/elevator-maintenance/work-sheet?id=${id}&elevatorNum=${elevatorNum}`
  )
}

const dataDetail = ref({})
const getDetail = async () => {
  const { error, data } = await getWorkDataInfoApi({
    ...options.value
  })
  if (error) {
    return
  }
  dataDetail.value = data
}
// 是否显示维保记录
const showMaintainRecord = computed(() => {
  const { state } = dataDetail.value
  return [4, 7].includes(state)
})
const options = ref({})
onLoad(async (e) => {
  dataDetail.value = {}
  options.value = e
  await getDetail()
})
</script>

<template>
  <view px-28>
    <up-cell-group :border="false">
      <up-cell
        v-for="(item, index) in cellData"
        :key="index"
        :title="item.key"
        :value="dataDetail[item.field] || item.value"
      />
    </up-cell-group>
  </view>
</template>
