<template>
    <div>
        <div class="content">
            <dataBreadcrumb :breads="breads"></dataBreadcrumb>
            <changeNav :navs="navs"></changeNav>
            <h1>项目状态:{{ remark }}</h1>
            <div class="flex state">
                <ul class="flex-left">
                    <li v-for="(item, index) in states" :key="index" class="flex">
                        <div>{{ item.title }}</div>
                        <ul class="inside flex">
                            <li v-for="(mods, index) in item.modulars" :key="index" class="flex-center">
                                <div :class="mods.bright ? 'active' : ''" @click="jump(mods)">{{ mods.label }}</div>
                            </li>
                        </ul>
                    </li>
                </ul>
                <!-- <ul class="flex">
					<li v-for="(item,index) in states" :key="index">
						<el-button type="primary" @click="jump(item.button,item.uri)">{{ item.button }}</el-button>
					</li>
				</ul> -->
            </div>
            <div class="centerButton">
                <el-button type="primary" @click="back">返回</el-button>
            </div>
        </div>
    </div>
</template>

<script>
import { projectEnd } from '@api/common/list';
import { projectConsole } from '@api/purchaser/bid';
import dataBreadcrumb from '@components/dataBreadcrumb.vue';
import changeNav from '@components/changeNav.vue';
export default {
    components: {
        dataBreadcrumb,
        changeNav
    },
    data() {
        return {
            states: [
                {
                    title: '公告',
                    modulars: [
                        {
                            id: 1,
                            label: '变更公告管理',
                            url: '/purchaser/bid/bidStage/changeList',
                            bright: false
                        },
                        {
                            id: 2,
                            label: '流标公告管理',
                            url: '/purchaser/bid/bidStage/failList',
                            bright: false
                        }
                    ]
                },
                {
                    title: '招标',
                    modulars: [
                        {
                            id: 3,
                            label: '项目信息',
                            url: '/purchaser/bid/seeProject',
                            bright: false
                        },
                        {
                            id: 4,
                            label: '发布询价公告',
                            url: '/purchaser/bid/reviewed/inquiryAnnouncement',
                            bright: false
                        },
                        {
                            id: 5,
                            label: '发布招标公告',
                            url: '/purchaser/bid/reviewed/tenderAnnouncement',
                            bright: false
                        },
                        /* {
                            id: 6,
                            label: '投标邀请书',
                            url: '1',
                            bright: false
                        }, */
                        {
                            id: 7,
                            label: '招标文件澄清管理',
                            url: '/purchaser/bid/bidStage/clearManagement',
                            bright: false
                        }
                    ]
                },
                {
                    title: '投标',
                    modulars: [
                        {
                            id: 8,
                            label: '投标信息查看',
                            url: '/purchaser/bid/bidStage/tenderInformationlist',
                            bright: false
                        }
                    ]
                },
                {
                    title: '开标',
                    modulars: [
                        {
                            id: 9,
                            label: '开标设置',
                            url: '/purchaser/bid/bidStage/bidSet',
                            bright: false
                        },
                        {
                            id: 10,
                            label: '开标大厅',
                            url: '/purchaser/bid/bidOpen/bidOpenhal',
                            bright: false
                        },
                        {
                            id: 11,
                            label: '开标过程纪录查看',
                            url: '/purchaser/bid/bidEvaluation/hallInformation',
                            bright: false
                        }
                    ]
                },
                {
                    title: '评标',
                    modulars: [
                        {
                            id: 12,
                            label: '评标管理',
                            url: '/purchaser/bid/bidEvaluation/projectManager/content',
                            bright: false
                        },
                        {
                            id: 13,
                            label: '开始评标',
                            url: '/purchaser/bid/bidEvaluation/review/review',
                            bright: false
                        }
                    ]
                },
                {
                    title: '定标',
                    modulars: [
                        {
                            id: 14,
                            label: '发布中标候选人公示',
                            url: '/purchaser/bid/bidSure/publicity',
                            bright: false
                        },
                        {
                            id: 15,
                            label: '确认中标人',
                            url: '/purchaser/bid/bidSure/determine',
                            bright: false
                        },
                        {
                            id: 16,
                            label: '发布中标公告',
                            url: '/purchaser/bid/bidSure/notice',
                            bright: false
                        },
                        {
                            id: 17,
                            label: '查看中标通知书',
                            url: '/purchaser/bid/bidSure/winBid/list',
                            bright: false
                        },
                        {
                            id: 18,
                            label: '发布招标结果通知书',
                            url: '/purchaser/bid/bidSure/bidResult/list',
                            bright: false
                        },
                        {
                            id: 19,
                            label: '合同管理',
                            url: '/purchaser/bid/bidSure/contract',
                            bright: false
                        }
                    ]
                },
                {
                    title: '费用',
                    modulars: [
                        {
                            id: 20,
                            label: '标书费缴纳管理',
                            url: '/purchaser/bid/bidStage/tenderFeelist',
                            bright: false
                        },
                        {
                            id: 21,
                            label: '保证金缴纳管理',
                            url: '/purchaser/bid/bidStage/bondList',
                            bright: false
                        }
                    ]
                },
                {
                    title: '功能',
                    modulars: [
                        {
                            id: 22,
                            label: '项目终止',
                            url: '1',
                            bright: false
                        }
                    ]
                }
            ],
            breads: ['招标管理', '招标项目管理 ', '工作台'],
            navs: ['工作台'],
            remark: '',
            buttonList: []
        };
    },
    methods: {
        geturl(url, status) {
            let newUrl = '';
            if (status == 0) {
                newUrl = url;
            } else if (status == 1) {
                newUrl = `${url}?type=1`; //编辑
            } else {
                newUrl = `${url}?type=2`; //查看
            }
            return newUrl;
        },
        getlabel(label, status) {
            let newlabel = '';
            if (status == 0) {
                newlabel = label;
            } else if (status == 1) {
                newlabel = label;
                newlabel = label.replace('发布', '编辑');
            } else {
                newlabel = label.replace('发布', '查看');
            }
            return newlabel;
        },
        back() {
            this.$router.go(-1);
        },
        jump(mods) {
            // if (mods.bright) {
                if (mods.label == '项目终止') {
                    this.$confirm('确定要终止吗？', '提示', {
                        type: 'warning'
                    })
                        .then(async () => {
                            let projectId = localStorage.getItem('projectId');
                            const { msg, code } = await projectEnd(projectId);
                            if (code == 200) {
                                this.$message({
                                    message: msg,
                                    type: 'success',
                                    duration: 1500
                                });
                                setTimeout(() => {
                                    this.$router.go(-1);
                                }, 1500);
                            } else {
                                this.$message.error(msg);
                            }
                        })
                        .catch(() => {});
                } else {
                    this.$router.push(mods.url);
                }
            // }
        },
        async getprojectConsole() {
            try {
                let message = {};
                message.projectId = localStorage.getItem('projectId');
                message.type = 1;
                const { data, msg, code } = await projectConsole(message);
                if (code == 200) {
                    let states=this.states
                    for (let item of states) {
                        for (let item1 of item.modulars) {
                            for (let item2 of data) {
                                if (item1.id == item2.buttonId) {
                                    item1.bright = true;
                                    if (item2.buttonId == 4 && item2.status == 2) {
                                        item1.url = '/purchaser/bid/reviewed/SeeinquiryAnnouncement';
                                        item1.label = '查看询价公告';
                                    } else if (item2.buttonId == 5 && item2.status == 2) {
                                        item1.url = '/purchaser/bid/reviewed/SeetenderAnnouncement';
                                        item1.label = '查看招标公告';
                                    } else if (item2.buttonId == 9 && item2.status == 2) {
                                        item1.url = '/purchaser/bid/bidStage/seeBidSet';
                                        item1.label = '开标设置查看';
                                    } else if (item2.buttonId == 3 && item2.status == 1) {
                                        item1.url = '/purchaser/bid/editProject';
                                        item1.label = '编辑项目信息';
                                    } else if (item2.buttonId == 12 && item2.status == 2) {
                                        item1.url = '/purchaser/bid/bidSure/see';
                                        item1.label = '查看评标';
                                    } else {
                                        item1.url = this.geturl(item1.url, item2.status);
                                        item1.label = this.getlabel(item1.label, item2.status);
                                    }
                                }
                            }
                        }
                    }
                    this.states=states
                    console.log(this.states)
                    this.remark = data[0].remark;
                } else {
                    this.$message.error(msg);
                }
            } catch (e) {
                console.log(e);
            }
        }
    },
    created() {
        this.getprojectConsole();
    }
};
</script>

<style scoped>
.state {
    margin-top: 30px;
    margin-left: 50px;
}

.state > ul {
    flex-wrap: wrap;
}

.state > ul > li {
    margin-right: 50px;
    cursor: pointer;
}

.flex-left > li {
    font-weight: bold;
    font-size: 20px;
    height: 70px;
    line-height: 70px;
}

.flex-left > li > div {
    margin-right: 50px;
    padding-right: 30px;
    border-right: 1px solid #000;
}

.inside > li > div {
    padding: 0 10px;
    background: #ccc;
    color: #ffff;
    font-size: 14px;
    margin-right: 30px;
    border-radius: 2px;
    line-height: 35px;
    height: 35px;
}
.inside > li > .active {
    background: #ff5203;
}
</style>
