<template>
    <view>
        <view v-if="list.length > 0">
            <view v-for="(item, index) in list" :key="index">
                <view class="item">
                    <view class="item-top">
                        <view>任务编号：{{ item.task_no }}</view>
                        <view>任务类型：{{ getStatusName(item.execution_status) }}</view>
                    </view>
                    <view class="item-content">
                        <view class="item-content-left">
                            <view>任务名称：{{ item.inspection_plan_info.plan_name }}</view>
                            <view>路线编号：{{ item.inspection_plan_info.inspection_route_info.route_code }}</view>
                            <view>路线名称：{{ item.inspection_plan_info.inspection_route_info.route_name }}</view>
                            <view>任务开始时间：{{ item.start_time }}</view>
                            <view>任务结束时间：{{ item.end_time }}</view>
                            <view>巡检人：{{ item.inspection_plan_info.community_worker_info.name }}</view>
                        </view>
                        <view class="item-content-right">
                            <button class="Btn" @click="goInspection(item)">去巡检</button>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <view v-else>
            <view class="empty">
                <image
                    src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_nearbyList_empty.png"
                    mode="aspectFill"></image>
                暂无数据
            </view>
        </view>
    </view>
</template>
<script>
import {
    request,
    picUrl,
    uniqueByField,
    menuButtonInfo,
    NavgateTo,
} from "../../../utils";

import { apiArr } from "../../../api/routingInspection";

export default {
    data() {
        return {
            list: []
        }
    },
    onLoad(options) {
        this.communityId = JSON.parse(options.communityId);
        this.getList();
    },
    methods: {
        async getList() {
            const res = await request(apiArr.routingInspectionList, "POST", {
                community_id: this.communityId,
            });
            this.list = res.rows;
        },
        goInspection(item) {
            NavgateTo('/packages/workOrderDashboard/addRoutingInspection/index?item=' + JSON.stringify(item),)
        },
        
        // 将任务状态数字代码转换为中文名称
        getStatusName(status) {
            const statusMap = {
                1: '待开始',
                2: '进行中',
                3: '已超时',
                4: '已完成'
            };
            return statusMap[status] || status;
        }
    },
}
</script>

<style>
@import url("./index.css");
</style>