<template>
    <div class="goods_topic">
        <Header></Header>
        <section class="section">
            <div class="section__header">
                <div class="container">
                    <el-breadcrumb separator="/">
                        <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
                        <el-breadcrumb-item>商品专题</el-breadcrumb-item>
                    </el-breadcrumb>
                </div>
            </div>
            <div class="course_btns">
                <div class="meun_btns">
                    <div class="btns" @click="changeCouMeun()">
                        课程导航
                    </div>
                    <div class="slide-list">
                        <div
                            class="slide-list__item"
                            v-for="(type, typeItem) in typeList"
                            :key="'type' + typeItem"
                        >
                        <div class="title" @click="goCourse(type)">
                            {{ type.educationName }}
                        </div>
                        <ul class="nav">
                            <li
                                v-for="(slideItem, slideIndex) in slideList[typeItem]"
                                :key="'item' + slideIndex"
                                @click="goCourse(slideItem)"
                            >
                            <div class="text">
                                {{ slideItem.aliasName }}
                            </div>
                            </li>
                        </ul>
                        </div>
                    </div>
                </div>
                
            </div>
            <div class="mains">
                <div class="content_up">
                    <div class="banner_one">
                        <div class="one_bg">
                            <img class="bgimg" src="@/assets/topic/one_bg.png" alt="" />
                        </div>
                    </div>
                    <div class="banner_two">
                        <catalogue :goodsId='goodsId' :topicId="topicId"></catalogue>
                    </div> 
                </div>
                <div class="topic_detail">
                    <div class="titles">
                        <img src="@/assets/topic/icon_left.png" alt="" />
                        <span class="scheme">通关方案</span>
                        <img src="@/assets/topic/icon_right.png" alt="" />
                    </div>
                    <div class="min_title">2023年二级建造师考前培训</div>
                    <div class="details">
                        <div class="detail_one">
                            <div class="deatil_titles">黄金基础班</div>
                            <div class="detail_mid">
                                <div class="mid_item">
                                    <div class="lefts">全科</div>
                                    <div class="rights">
                                        <span class="price">￥980</span>
                                        <div class="right_buy"  @click="togoBuy(1, 1)">立即购买</div>
                                    </div>
                                </div>
                                <div class="mid_item">
                                    <div class="lefts">公共单科</div>
                                    <div class="rights">
                                        <span class="price">￥350</span>
                                        <div class="right_buy"  @click="togoBuy(2, 1)">立即购买</div>
                                    </div>
                                </div>
                                <div class="mid_item">
                                    <div class="lefts">实务单科</div>
                                    <div class="rights">
                                        <span class="price">￥500</span>
                                        <div class="right_buy"  @click="togoBuy(3, 1)">立即购买</div>
                                    </div>
                                </div>
                            </div>
                            <div class="down_img">
                                <img class="l_img" src="@/assets/topic/detail_one.png" alt="" />
                            </div>
                        </div>
                        <div class="detail_one">
                            <div class="deatil_titles two">钻石强化班</div>
                            <div class="detail_mid">
                                <div class="mid_item">
                                    <div class="lefts">全科</div>
                                    <div class="rights">
                                        <span class="price">￥1280</span>
                                        <div class="right_buy"  @click="togoBuy(1, 2)">立即购买</div>
                                    </div>
                                </div>
                                <div class="mid_item">
                                    <div class="lefts">公共单科</div>
                                    <div class="rights">
                                        <span class="price">￥450</span>
                                        <div class="right_buy"  @click="togoBuy(2, 2)">立即购买</div>
                                    </div>
                                </div>
                                <div class="mid_item">
                                    <div class="lefts">实务单科</div>
                                    <div class="rights">
                                        <span class="price">￥700</span>
                                        <div class="right_buy"  @click="togoBuy(3, 2)">立即购买</div>
                                    </div>
                                </div>
                            </div>
                            <div class="down_img">
                                <img class="l_img" src="@/assets/topic/detail_two.png" alt="" />
                            </div>
                        </div>

                        <div class="detail_one">
                            <div class="deatil_titles three">至尊私塾班</div>
                            <div class="detail_mid">
                                <div class="mid_item">
                                    <div class="lefts">全科</div>
                                    <div class="rights">
                                        <span class="price">￥1980</span>
                                        <div class="right_buy"  @click="togoBuy(1, 3)">立即购买</div>
                                    </div>
                                </div>
                                <div class="mid_item">
                                    <div class="lefts">公共单科</div>
                                    <div class="rights">
                                        <span class="price">￥700</span>
                                        <div class="right_buy"  @click="togoBuy(2, 3)">立即购买</div>
                                    </div>
                                </div>
                                <div class="mid_item">
                                    <div class="lefts">实务单科</div>
                                    <div class="rights">
                                        <span class="price">￥900</span>
                                        <div class="right_buy"  @click="togoBuy(3, 3)">立即购买</div>
                                    </div>
                                </div>
                            </div>
                            <div class="down_img">
                                <img class="l_img" src="@/assets/topic/detail_three.png" alt="" />
                            </div>
                        </div>
                        
                    </div>
                </div>
            </div>

        </section>

        <!-- 弹窗 -->
        <buy-dialog :buyModal.sync="buyModal" :topicId="topicId" :subjectType="subjectType" :type="type"></buy-dialog>
        <ToolBar></ToolBar>
        <Footer></Footer>
    </div>
</template>

<script>
import Header from "@/components/header/index.vue";
import Footer from "@/components/footer/index.vue";
import ToolBar from "@/components/toolbar/index.vue";
import buyDialog from './components/buyDialog.vue'
import catalogue from './components/catalogue.vue'
export default {
    name: '',
    components: { Header, Footer, ToolBar, buyDialog, catalogue },
    data() {
        return {
            buyModal: false,
            topicId: '',
            subjectType: 0,
            type: 0,
            goodsInfo: {},
            // goodsData: {},
            vid: '',
            vidzb: '',
            vodPlayerJs: "https://player.polyv.net/script/player.js",
            playerJs: "https://player.polyv.net/resp/live-h5-player/latest/liveplayer.min.js",
            uidzb: "egsxlptzdq",
            menuTab: [
                {
                    name: "1",
                    label: "章节目录",
                }
            ],
            courseTabIndex: "1",
            courseId: "",
            goodsId: "",
            gradeId: "",
            orderGoodsId: "",
            needOpen: true, //是否需要一进来展开第一章节
            menuIndex: [], //需要展开的章节索引值
            courseList: [],
            s_courseList: [],
            goodsAuditionConfigIdList: [],
            listenConfigList: [],
            courserIndex: 0,
            goodsDetail: {},
            goodsExamConfig: [],
            subList: [],
            subIndex: 0,
            typeList: [],
            slideList: [],
            showMeun: false,
        }
    },
    created() {
        this.topicId = this.$route.query.topicId || 1
        this.getgoodsInfo()
        this.educationTypeList()
    },
    methods: {
        educationTypeList() {
            this.$request.educationTypeList().then((res) => {
                this.typeList = res.rows.slice(0, 5);
                this.typeList.forEach((typeItem, index) => {
                    this.businessList(typeItem.id, index);
                });
            });
        },

        businessList(educationId, index) {
            this.$request
                .businessList({ educationId })
                .then((res) => {
                    let rows = res.rows.filter((item) => item.aliasName)
                    this.$set(this.slideList, index, rows);
                    if (rows.length >= 2) {
                        let newRows = rows.slice(0, 2);
                        let length = 0;
                        newRows.forEach((row) => {
                        let str = row.projectName + "-" + row.businessName;
                        length = length + str.length;
                        });

                        if (length >= 17) {
                            this.$set(this.typeList[index], "list", rows.slice(0, 1));
                        } else {
                            this.$set(this.typeList[index], "list", rows.slice(0, 2));
                        }
                    } else {
                        this.$set(this.typeList[index], "list", rows);
                    }
                    console.log('this.typeList:',this.slideList, this.typeList)
                })
                .catch((err) => {
                console.log(err, "err");
            });
        },
        changeCouMeun() {
            this.showMeun = !this.showMeun
        },
        goCourse(item) {
            if (item.topicId) {
                this.topicId = item.topicId
                return
            }
            this.$router.push({
                path: "/course-list",
                query: {
                    educationId: item.educationId ? item.educationId : item.id || "",
                    projectId: item.projectId || "",
                    businessId: item.educationId ? item.id : "",
                },
            });
        },
        getgoodsInfo() {
            this.$axios({
                url: `/app/common/get/goodsInfo/${this.topicId}`,
                method: 'get',
                noToken: true
            }).then(async(res) => {
                if (res.code == 200) {
                    this.goodsInfo = res.data
                    this.goodsId = res.data.goodsId
                }
            })
        },
        
        togoBuy(subjectType, type) {
            this.subjectType = subjectType
            this.type = type
            this.buyModal = true
        },
        
    }
}
</script>

<style lang="scss" scoped>
.goods_topic {
    width: 100%;
    .section {
        &__header {
            height: 40px;
            display: flex;
            align-items: center;
            padding: 0 20px;
        }
    }
    .course_btns {
        padding: 10px 10px 10px 115px;
        .meun_btns {
            width: 100px;
            .btns {
                width: 96px;
                height: 32px;
                line-height: 32px;
                text-align: center;
                background: #3F8DFD;
                border-radius: 4px;
                color: #fff;
                font-size: 14px;
                cursor: pointer;
                
            }
            &:hover {
                .slide-list {
                    display: block;
                }
            }
            .slide-list {
                display: none;
                transition: all 0.3s;
                width: 672px;
                background: #F8F8F8;
                position: absolute;
                top: 163px;
                left: 115px;
                padding-left: 24px;
                z-index: 10;
                border-radius: 4px;
                &__item {
                    min-height: 80px;
                    display: flex;
                    align-items: center;
                    border-bottom: 1px solid #ddd;

                    &:nth-last-of-type(1) {
                        border: 0;
                    }
                    .title {
                        cursor: pointer;
                        color: #fff;
                        width: 120px;
                        height: 28px;
                        border: 1px solid #ffffff;
                        border-radius: 14px;
                        background: #3f8dfd;
                        line-height: 26px;
                        text-align: center;
                        border-radius: 15px;
                        margin-right: 10px;
                    }

                    .nav {
                        flex: 1;
                        display: flex;
                        flex-wrap: wrap;
                        li {
                            margin: 9px 24px 9px 0;
                            display: flex;

                            .text {
                            cursor: pointer;
                            font-size: 14px;
                            font-family: Microsoft YaHei;
                            font-weight: 400;
                            color: #666;
                            }
                        }
                    }
                }
            }
        }
    }
    .mains {
        // width: 100%;
        // padding: 0px 116px;
        .content_up {
            width: 100%;
            height: 808px;
            .banner_one {
                width: 100%;
                height: 280px;
                background: url('../../assets/topic/banner_one.png') center center no-repeat;
                // background-size: 100% 100%;
                // display: flex;
                // align-items: center;
                // justify-content: center;
                .one_bg {
                    width: 1056px;
                    height: 280px;
                    margin: 0 auto;
                    >img {
                        width: 100%;
                        height: 100%;
                    }
                }
            }
            .banner_two {
                width: 100%;
                height: 528px;
                background: url('../../assets/topic/banner_two.png') center center no-repeat;
                background-size: 100% 100%;
                
            }
            
        }
        .topic_detail {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 100%;
            // height: 3444px;
            height: 3100px;
            background: url('../../assets/topic/topic_bg.png') center center no-repeat;
            background-size: 100% 100%;
            
            .titles {
                margin-top: 109px;
                >img {
                    width: 32px;
                    height: 20px;
                }
                .scheme {
                    font-size: 48px;
                    font-weight: bold;
                    color: #363543;
                    margin: 0px 40px;
                }
            }
            .min_title {
                margin: 13px 0px 50px;
                font-size: 28px;
                font-weight: 500;
                color: #363543;
            }
            
        }
        .details {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-right: -20px;
            .detail_one {
                width: 358px;
                height: 2753px;
                background-color: #fff;
                border-radius: 8px;
                margin-right: 20px;
                @media screen and (max-width: 1370px){
                    width: 300px;
                }
            }
            .deatil_titles {
                width: 100%;
                height: 110px;
                line-height: 110px;
                text-align: center;
                border-radius: 8px 8px 0px 0px;
                background: linear-gradient(45deg, #71A9F6 0%, #1658DA 100%);
                font-size: 32px;
                font-weight: bold;
                color: #FFFFFF;
                &.two {
                    background: linear-gradient(45deg, #FE8D6D 0%, #ED3531 100%);
                }
                &.three {
                    background: linear-gradient(45deg, #E3BC79 0%, #BF7D2E 100%);
                }
            }
            .detail_mid {
                width: 100%;
                padding: 0px 24px;
                
                .mid_item {
                    width: 100%;
                    height: 74px;
                    border-bottom: 1px solid #EAEAEA;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                }
                .lefts {
                    font-size: 18px;
                    font-weight: bold;
                    color: #363543;
                }
                .rights {
                    display: flex;
                }
                .price {
                    font-size: 18px;
                    font-weight: 500;
                    color: #FC3F3F;
                    margin-right: 20px;
                }
                .right_buy {
                    width: 76px;
                    height: 28px;
                    line-height: 28px;
                    text-align: center;
                    background: #FC3F3F;
                    border-radius: 50px;
                    font-size: 13px;
                    font-weight: 500;
                    color: #FFFFFF;
                    cursor: pointer;
                }
            }

            .down_img {
                width: 100%;
                height: 2369px;
                >.l_img {
                    width: 100%;
                    height: 100%;
                    display: block;
                }
            }
        }
    }
}
</style>