<!--
 * @Author: micky
 * @Date: 2024-10-06 20:42:13
 * @LastEditors: micky
 * @LastEditTime: 2024-10-26 20:45:00
 * @FilePath: \chargingpile-uniapp\src\bundle\pages\repair\my-apply\stash.vue
-->
<template>
    <z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" height="100%">
        <block v-for="(item, index) in dataList" :key="`${index} + 'unique'`">
            <w-order-card>
                <template #title>
                    <view class="flex justify-between relative" @click="toPage(item.repairOrderId)">
                        <view>单据编号：{{ item.orderNo }}</view>
                        <view
                            :style="{ color: repaireOrderAuditColor[item.auditStatus] }"
                            class="text-sm"
                        >
                            {{ repaireOrderAuditMap[item.auditStatus] }}
                        </view>
                    </view>
                </template>
                <template #content>
                    <view class="order-content-wrapper" @click="toPage(item.repairOrderId)">
                        <view>
                            <text>模块代码</text>
                            <text>{{ item.moduleCode }}</text>
                        </view>
                        <view>
                            <text>难修原因</text>
                            <text>{{ item.reasonForWithdrawal }}</text>
                        </view>
                        <view>
                            <text>申请时间</text>
                            <text>{{ item.createTime }}</text>
                        </view>
                        <view v-if="item.auditStatus == RepaireOrderAuditEnum.NOPASS">
                            <text>不通过原因</text>
                            <text>{{ item.auditOpinion }}</text>
                        </view>
                    </view>
                </template>
                <template #btns>
                    <view class="order-btns-wrapper">
                        <u-button
                            shape="circle"
                            type="primary"
                            class="gray-btn"
                            @click="applyAgain(item.moduleCode)"
                            v-if="item?.orderStatus == RepaireOrderAuditEnum.NOPASS"
                        >
                            重新申请
                        </u-button>
                    </view>
                </template>
            </w-order-card>
        </block>
    </z-paging>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { apiReturnStashList } from '@/api/repair'
import {
    repaireOrderAuditColor,
    repaireOrderAuditMap,
    RepaireOrderAuditEnum
} from '@/enums/businessEnums'
import cache from '@/utils/cache'
import { USER_INFO } from '@/enums/cacheEnums'
import { useZPaging } from '@/hooks/useZPaging'

const userInfo = cache.get(USER_INFO)
const dataList = ref<any>([])

const params = ref({
    applicantId: userInfo.id,
    reviewRequest: 0
})
const { paging, queryList, refresh } = useZPaging(params.value, apiReturnStashList)
const toPage = (id: number) => {
    uni.navigateTo({
        url: `/bundle/pages/repair/order-detail?id=${id}&pageSource=1`
    })
}

const setParams = payload => {
    params.value = {
        ...params.value,
        ...payload
    }
    refresh(params.value)
}

const applyAgain = (code: string) => {
    uni.navigateTo({
        url: `/bundle/pages/repair/apply-return-stash?code=${code}`
    })
}

defineExpose({
    setParams
})
</script>
<style scoped lang="scss">
.order-content-wrapper view text {
    color: #7c7e82 !important;
}
</style>
