<!--
 * @Author: micky
 * @Date: 2024-09-05 16:15:45
 * @LastEditors: micky
 * @LastEditTime: 2024-10-27 20:58:36
 * @FilePath: \chargingpile-uniapp\src\pages\client\workOrder\repair-card.vue
-->
<template>
    <w-order-card>
        <template #title>
            <view class="flex justify-between items-center">
                <view>工单编号：{{ item.orderNo }}</view>
                <template v-if="activeStatus == RepairOrderStatusEnum.INREVIEW">
                    <view
                        v-if="item.reviewRequest == AuditItemsClassifyEnum.MATERIAL"
                        class="audit-status"
                        :style="{
                            color: materialApplyStatusColor[item.auditStatus],
                            background: materialApplyStatusBgColor[item.auditStatus]
                        }"
                    >
                        {{ materialApplyStatusMap[item.auditStatus] }}
                    </view>
                    <view
                        v-else
                        class="audit-status"
                        :style="{
                            color: RepaireOrderAuditStatusColor[item.auditStatus],
                            background: RepaireOrderAuditStatusBgColor[item.auditStatus]
                        }"
                    >
                        {{ RepaireOrderAuditStatusMap[item.auditStatus] }}
                    </view>
                </template>
            </view>
        </template>
        <template #content>
            <view class="order-content-wrapper" @click="toDetail(item)">
                <view>
                    <text>模块代码</text>
                    <text>{{ item.moduleCode }}</text>
                </view>
                <view>
                    <text>模块型号</text>
                    <text>{{ item.moduleNumber }}</text>
                </view>
                <view>
                    <text>功率</text>
                    <text>{{ parseModulePower(item.modulePower) }}</text>
                </view>
                <view v-if="item.receiverName">
                    <text>接单人</text>
                    <text>{{ item.receiverName }}</text>
                </view>
                <!-- <view v-if="item.receiverTime">
                    <text>派单时间</text>
                    <text>{{ item.receiverTime }}</text>
                </view> -->
                <template v-if="activeStatus == RepairOrderStatusEnum.INREVIEW">
                    <view>
                        <text>排查结果</text>
                        <text
                            :style="{
                                color: checkResultColor[item.scrapOrNot]
                            }"
                        >
                            {{ checkResultMap[item.scrapOrNot] }}
                        </text>
                    </view>
                    <template v-if="item.repaireOrderAuditStatus == MaterialApplyStatusEnum.NOPASS">
                        <view>
                            <text>审核结果</text>
                            <text class="text-error">审核不通过</text>
                        </view>
                        <view>
                            <text>审核意见</text>
                            <text>{{ item.auditOpinion }}</text>
                        </view>
                    </template>
                </template>
                <view v-if="activeStatus == RepairOrderStatusEnum.COMPLETE">
                    <text>维修结果</text>
                    <text
                        :style="{
                            color: checkResultColor[item.maintenanceResult]
                        }"
                    >
                        {{ getDictName(dictData.repairConclusion, item?.maintenanceResult) }}
                    </text>
                </view>
                <view v-if="item.orderAccomplishTime">
                    <text>完成时间</text>
                    <text>{{ item.orderAccomplishTime }}</text>
                </view>
                <!-- 模块维修单且不报废 -->
                <!-- <view
                    v-if="
                        item.orderStatus == RepairOrderStatusEnum.TOCONFIRM &&
                        item.scrapOrNot == YesOrNoEnum.NO
                    "
                >
                    <text>领料状态</text>
                    <text :style="{ color: receiveFlowColor[item.receiveStatus] }">
                        {{ receiveFlowMap[item.receiveStatus] }}
                    </text>
                </view> -->
            </view>
        </template>
        <!-- <template #btns>
            <view class="order-btns-wrapper">
                <u-button
                    shape="circle"
                    type="primary"
                    @click="scrapShow = true"
                    v-if="
                        item.scrapOrNot == YesOrNoEnum.YES &&
                        item.orderStatus == RepairOrderStatusEnum.TOCONFIRM &&
                        item.scrapConfirmation != YesOrNoEnum.YES
                    "
                >
                    确认报废
                </u-button>
            </view>
        </template> -->
    </w-order-card>
    <!-- <w-confirm-popup contentText="是否确认报废？" v-model="scrapShow" @confirm="confirmScrap" /> -->
</template>

<script setup lang="ts">
// import { ref } from 'vue'
// import { apiConfirmScrap } from '@/api/client'
import {
    RepairOrderStatusEnum,
    AuditItemsClassifyEnum,
    RepaireOrderAuditStatusMap,
    RepaireOrderAuditStatusColor,
    RepaireOrderAuditStatusBgColor,
    materialApplyStatusMap,
    materialApplyStatusColor,
    materialApplyStatusBgColor,
    MaterialApplyStatusEnum,
    checkResultMap,
    checkResultColor
} from '@/enums/businessEnums'
// import { toast } from '@/utils/util'
import { useModulePower } from '@/hooks/useLockFn'
import { useDictData, getDictName } from '@/hooks/useDictOptions'

const props = defineProps<{
    item: RepairItem
    activeStatus: number | string
}>()
const emits = defineEmits(['refresh'])
const { parseModulePower } = useModulePower()
const { dictData }: { dictData: any } = useDictData(['repairConclusion'])
const toDetail = (row: any) => {
    uni.navigateTo({
        url: `/bundle/pages/repair/order-detail?id=${row.id}&pageSource=0`
    })
}

// 确认报废
// const confirmScrap = async () => {
//     await apiConfirmScrap({
//         id: props.item.id
//     })
//     toast('已确认报废')
//     emits('refresh')
// }
</script>
<style scoped lang="scss">
.priority {
    @apply absolute -right-[18rpx] top-0  px-[24rpx] h-[60rpx] leading-[60rpx] text-[28rpx];
    &.urgent,
    &.normal {
        border-top-right-radius: 16rpx;
        border-bottom-left-radius: 32rpx;
    }
    &.urgent {
        @apply bg-[#fff7d8];
    }
    &.normal {
        @apply bg-[#CFE3FF];
    }
}
</style>
