<template>
  <view class="px-base">
    <CuNavbar title="任务详情">
      <template #right>
        <view class="text-sm text-white" @click="checkLogs">审核流程</view>
      </template>
    </CuNavbar>
    <view class="mt-30rpx card-shadow bg-white rounded-19rpx px-base text-[#333333] text-27rpx">
      <BaseData :data="data" :colums="baseColums" />
    </view>
  </view>
</template>
<script setup>
import CuNavbar from '@/components/cu-navbar/index'
import { onLoad } from '@dcloudio/uni-app'
import { http } from '@/utils/request'
import { ref, computed } from 'vue'
import { timeFormat } from '@climblee/uv-ui/libs/function'
import BaseData from '@/pages/audits/base-data'
import statusFun from '@/utils/status'

const baseColums = [
  {
    title: '审核状态',
    dataIndex: 'taskable.status',
    format: (value) => statusFun(value, 'task_hygienes', 'name'),
  },
  {
    title: '申请人',
    dataIndex: 'taskable.store_master.name',
  },
  {
    title: '所属门店',
    dataIndex: 'taskable.store.address',
  },
  {
    title: '电话号码',
    dataIndex: 'taskable.store_master.phone',
  },
  {
    title: '申请时间',
    dataIndex: 'created_format',
  },
  {
    title: '清洁范围',
    dataIndex: 'taskable.description',
    labelPosition: 'top',
  },
  {
    title: '清洁结果',
    dataIndex: 'taskable.photos',
    labelPosition: 'top',
    type: 'album'
  },
  {
    title: '未通过原因',
    dataIndex: 'taskable.workflow_check.check_remarks',
    labelPosition: 'top',
    isShow: (row) => {
      return row?.taskable?.status == 4
    }
  },
]
const id = ref(null)
const data = ref({})

onLoad((opt) => {
  id.value = opt.id
  getDetail()
})

const getDetail = async () => {
  const resdata = await http.get(`/tasks/${id.value}`)
  data.value = resdata
}

const checkLogs = () => {
  if (data.value.taskable.workflow_check.id) {
    return uni.navigateTo({
      url: `/pages/audits/log?id=${data.value.taskable.workflow_check.id}`
    })
  }
}

const getValue = (obj, path) => {
  return path.split('.').reduce((acc, key) => (acc ? acc[key] : undefined), obj)
}

const isFunction = (fn) => {
  return typeof fn === 'function'
}
</script>
