<template>
    <section class="modules">
        <section class="m-head">
            <MOSTY.Assort :title="'待办任务'" />
            <el-link @click="handleGoToPage('/editPassword', '个人中心')" style="width: 100px;color: #048086;">查看更多
                》</el-link>
        </section>
        <el-divider style="margin: 0 !important;border-color: #EFEFEF;" />
        <section class="content_info">
            <span>您有{{ total }}个任务待办，请记得处理哟！</span>
        </section>
        <section class="content">
            <section class="content_child" v-if="tableData.length > 0" v-for="item in tableData" :key="item.id">
                <section class="content_radius"></section>
                <!-- 任务名称 -->
                <section style="font-size: 16px;color: black;">
                    {{ item.title }}
                   <el-link v-if="item.clzt == '01'"
                        style='color:#fff;margin-left: 10px;padding: 2px;background-color: red;font-size: 14px;'
                        @click="examine(item)">待处理</el-link>
                    <span v-if="item.clzt == '02'"
                        style='color:#fff;margin-left: 10px;padding: 2px;background-color: rgb(38, 15, 250);font-size: 14px;'>已处理</span>
                    <span v-if="item.clzt == '03'"
                        style='color:#fff;margin-left: 10px;padding: 2px;background-color: #048086;font-size: 14px;'>无需处理</span>
                    <span
                        style="background-color: #048086;margin-left: 10px;color: #fff;padding: 2px;font-size: 14px;">{{
                            item.title
                        }}</span>
                </section>
                <!-- 任务内容 -->
                <section style="font-size: 14px;color: #999999;margin-top: 10px;">
                    {{ item.info }}
                </section>
                <!-- 任务时间 -->
                <section style="font-size: 14px;color: #999999;margin-top: 10px;">
                    {{ item.addtime.split(' ')[0] }}
                </section>
            </section>
            <section class="content_nochild" v-else>
                暂无待办任务
            </section>
        </section>
    </section>
</template>

<script setup>
import { getApi, postApi } from "@/api/tobAcco_api.js";
import { ref, reactive, onMounted, getCurrentInstance } from 'vue'
import * as MOSTY from "@/components/MyComponents/index";
import draggable from "vuedraggable";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { getImgUrl } from "@/utils/tools.js"
import { ElMessage } from "element-plus";
const { proxy } = getCurrentInstance();
const router = useRouter();
const store = useStore();
// 跳转应用
const handleGoToPage = (_url, _title) => {
    if (_url) {
        store.commit(
            "app/addTagsViewList",
            {
                fullPath: _url,
                meta: {
                    meta: {
                        title: _title
                    }
                },
                name: _url,
                params: {},
                path: _url,
                query: {},
                title: _title
            },
            {
                immediate: true
            }
        );
        router.push(_url)
    }
}
const listQuery = reactive({
    pageCurrent: 1,
    pageSize: 2000,
    zdlx: "02",
    clzt: '01'
});
const tableData = ref([]);
const total = ref('');
const getListData = () => {
    getApi(listQuery, `/mosty-jcgl/rw/getRwPage`).then((res) => {
        if (res.records) {
            tableData.value = res.records;
            total.value = res.total;
        } else {
            tableData.value = [];
        }
    });
}
/** 更新为已读 */
const updateRw = (row) => {
    let params = {
        id: row.id,
        sfyd: "1",// 是否已读
        // clzt: "01"
    };
    postApi(params, "/mosty-jcgl/rw/updateRw")
}
const examine = (row) => {
    if (row.clzt == '01') {
        updateRw(row)
        console.log(row.rwlx, 'row.rwlx')
        switch (row.rwlx) {
            // 文化手册
            case '05':
                router.push({
                    path: "/dutyBook/whjs/index",
                    query: {
                        id: row.ywid,
                        rwid: row.id
                    }
                });
                break;
            // 危险作业详情
            case '07':
                router.push({
                    path: "/yxkzgl/wxzysq",
                    query: {
                        p1: row.p1,
                        id: row.ywid,
                        rwid: row.id
                    }
                });
                break;
            case '19':
                // 上岗证申办详情
                router.push({
                    path: "/yxkzgl/jsygl/sgzsbxq",
                    query: {
                        id: row.ywid,
                        rwid: row.id,
                        title: '任务处理',
                        p2: row.p2
                    }
                });
                break;
            case '22':
                // 安全投入（新）
                router.push({
                    path: "/dutyBook/anQuantrNew",
                    query: {
                        tab: '3',// tab 1.统计报表 2.预算填报 3.预算审核/批复 4.费用使用 5.费用使用情况分析
                    }
                });
                break;
            case '46':
                //工作计划要点审核
                router.push({
                    path: "/dutyBook/goalWay/workPlan",
                    query: {
                        p1: row.p1,
                        rwlx: row.rwlx,
                        ywid: row.ywid,
                        rwid: row.id
                    }
                });
                break;
            case '47':
                //工作计划要点审核
                router.push({
                    path: "/dutyBook/goalWay/workPlan",
                    query: {
                        p1: row.p1,
                        rwlx: row.rwlx,
                        ywid: row.ywid,
                        rwid: row.id
                    }
                });
                break;
            case '51':
                // 课件库-学习
                router.push({
                    path: "/safety/pxzyk/zxaqxxk",
                    query: {
                        rwlx: row.rwlx,
                        rwid: row.id,
                        ywid: row.ywid,
                        id: row.ywid
                    }
                });
                break;
            case '52':
                //值班记录
                router.push({
                    path: "/yjzb/yjgl/zbgl/zbjl",
                    query: {
                        rwlx: row.rwlx,
                        rwid: row.id,
                    }
                });
                break;
            case '53':
                //值班记录
                router.push({
                    path: "/yjzb/yjgl/zbgl/zbjl",
                    query: {
                        rwlx: row.rwlx,
                        rwid: row.id,
                    }
                });
                break;
            // 安全动态
            case '57':
                router.push({
                    path: "/dutyBook/aqdt/index",
                    query: {
                        p1: row.p1,
                        id: row.ywid,
                        ywid: row.ywid,
                        rwid: row.id
                    }
                });
                break;
            // 督办任务
            case '60':
                router.push({
                    path: "/supervision/tasks",
                    query: {
                    }
                });
                break;

            // 61-考题库
            case '61':
                router.push({
                    path: "/safety/pxzyk/ktk",
                    query: {
                        id: row.ywid,
                        ywid: row.ywid,
                        rwid: row.id,
                        p1: row.p1,
                    }
                });
                break;
            // 62-试卷库
            case '62':
                router.push({
                    path: "/safety/pxzyk/ktjmbgl",
                    query: {
                        id: row.ywid,
                        ywid: row.ywid,
                        rwid: row.id,
                        p1: row.p1,
                    }
                });
                break;
            // 63—课件库
            case '63':
                router.push({
                    path: "/safety/pxzyk/zxaqxxk",
                    query: {
                        id: row.ywid,
                        ywid: row.ywid,
                        rwid: row.id,
                        rwlx: row.rwlx,
                        p1: row.p1,
                    }
                });
                break;
            // // 64-师资库
            // case '64':
            //   router.push({
            //     path: "/safety/pxzyk/szk",
            //     query: {
            //       p1: row.p1,
            //       id: row.ywid,
            //       ywid: row.ywid,
            //       rwid: row.id
            //     }
            //   });
            //   break;
            // 65 — 典型案例
            case '65':
                router.push({
                    path: "/dutyBook/dianXal/index",
                    query: {
                        id: row.ywid,
                        ywid: row.ywid,
                        rwid: row.id,
                        p1: row.p1,
                    }
                });
                break;
            case '66':
                router.push({
                    path: "/dutyBook/tzgg/index",
                    query: {
                        id: row.ywid,
                        ywid: row.ywid,
                        rwid: row.id,
                        p1: row.p1,
                        file: row.file,
                    }
                });
                break;
            // 法律法规学习
            case '71':
                let params = {
                    id: row.ywid
                };
                studyShowId.value = row.id
                getApi(params, `/mosty-jcgl/lawRegulations/getLawRegulaById`).then((res) => {
                    editObjs.value = res;
                    dialogVisibleStudy.value = true
                    dialogVisible.value = false
                    saveBtnShow.value = false;
                });
                break;
            /** 事故月报 */
            case '70':
                router.push({
                    path: "/sggl/sgbg/sgyb",
                    query: {
                        rwlx: row.rwlx,
                        id: row.ywid,
                        ywid: row.ywid,
                        rwid: row.id,
                        p1: row.p1,
                    }
                });
                break;

            default: // 默认事件无 ==============================================================
                break;
        }
    }

};
onMounted(() => {
    getListData();
})
</script>
<style scoped lang="scss">
// @import '../style/index.scss';
.modules {
    height: 344px;
    background: #fff;
    padding: 0 16px;
    box-sizing: border-box;

    .m-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background-color: #fff;
    }

    .content_info {
        color: #fff;
        text-align: center;
        font-size: 18px;
        line-height: 40px;
        height: 40px;
        background: linear-gradient(314deg, #048086 0%, #63AFB2 100%);
        border-radius: 5px;
    }

    .content {
        height: 240px;
        overflow: auto;
        margin-top: 5px;

        .content_child {
            margin-left: 10px;
            padding-left: 10px;
            position: relative;
            //height: 80px;
            border-left: 2px dashed #5CABAFed;

            .content_radius {
                height: 16px;
                width: 16px;
                background-color: #5CABAF;
                border-radius: 50%;
                position: absolute;
                top: 0px;
                left: -10px;
            }
        }

        .content_nochild {
            text-align: center;
            font-size: 20px;
            line-height: 80px;
            height: 80px;
        }
    }
}
</style>