<template>
    <div class="search">
        <div class="container">
            <div class="search_info">
                <input placeholder="搜索..." v-model="title" />
                <div class="btn-search">
                    <img src="../../assets/icon_search.png" @click="getToData()" />
                </div>
            </div>
            <!-- 搜索列表 -->
            <div class="tab">
                <span :class="current == 0 ? 'active' : ''" @click="getIndex(0)">通知公告</span>
                <span :class="current == 1 ? 'active' : ''" @click="getIndex(1)">政策法规</span>
                <span :class="current == 2 || current == 3 || current == 4 ? 'active' : ''" class="clearmargin">
                    <el-select
                        placeholder="需求信息"
                        v-model="needIndex"
                        @change="needShow()"
                        :class="current == 2 || current == 3 || current == 4 ? 'active' : ''"
                    >
                        <el-option
                            v-for="item in needsoptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                            :disabled="item.disabled ? item.disabled : false"
                        >
                        </el-option>
                    </el-select>
                </span>

                <span :class="current == 5 || current == 6 || current == 7 ? 'active' : ''" class="clearmargin">
                    <el-select
                        placeholder="供应信息"
                        v-model="resIndex"
                        @change="resShow()"
                        :class="current == 5 || current == 6 || current == 7 ? 'active' : ''"
                    >
                        <el-option
                            v-for="item in resOptions"
                            :key="item.value"
                            :label="item.label"
                            :disabled="item.disabled ? item.disabled : false"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </span>
                <span :class="current == 8 || current == 9 || current == 10 ? 'active' : ''" class="clearmargin">
                    <el-select
                        placeholder="民政互动"
                        v-model="civilIndex"
                        @change="civilShow()"
                        :class="current == 8 || current == 9 || current == 10 ? 'active' : ''"
                    >
                        <el-option
                            v-for="item in civilOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                            :disabled="item.disabled ? item.disabled : false"
                        >
                        </el-option>
                    </el-select>
                </span>
            </div>
            <!-- 通知公告 -->
            <div v-if="current === 0" class="content">
                <div
                    class="notice"
                    v-for="item in tableData"
                    :key="item.id"
                    @click="$router.push({ name: 'article', query: { id: item.id } })"
                >
                    <div class="notice_con">
                        <i></i>
                        <div>
                            {{ item.title }}
                        </div>
                    </div>
                    <span class="notice_time">{{ item.createdAt }}</span>
                </div>
            </div>
            <!-- 政策法规 -->
            <div v-if="current === 1" class="content">
                <div
                    class="policy"
                    v-for="item in tableData"
                    :key="item.id"
                    @click="$router.push({ name: 'policyArticle', query: { id: item.id } })"
                >
                    <div class="policy_info">
                        <img :src="item.cover" />
                        <div>
                            <h5>{{ item.title }}</h5>
                            <!-- <p>{{ item.name }}</p> -->
                        </div>
                    </div>
                    <div class="policy_time">{{ item.createdAt }}</div>
                </div>
            </div>
            <!--需求信息 -->
            <div v-if="current === 2 || current === 3 || current === 4" class="content">
                <div class="supply" v-for="(item, index) in tableData" :key="item.id" @click="needsGo(index)">
                    <img :src="item.images" />
                    <div class="supply_info">
                        <div class="supply_tit">
                            <!-- <i>正在对接</i><span>{{ item.name }}</span> -->
                            <i class="wait" v-if="item.conversationStatus === 'AWAIT'"> 等待对接 </i>
                            <i v-if="item.conversationStatus === 'CONDUCTED'"> 正在对接</i>
                            <span>{{ item.name }}</span>
                        </div>
                        <p>
                            {{ item.description }}
                        </p>
                        <span class="supply_time">{{ item.createdAt }}</span>
                    </div>
                </div>
            </div>
            <!-- 供应信息 -->
            <div v-if="current === 5 || current === 6 || current === 7">
                <div class="supply" v-for="(item, index) in tableData" :key="item.id" @click="needsGo(index)">
                    <img :src="item.images ? item.images[0] : null" />
                    <div class="supply_info">
                        <div class="supply_tit">
                            <!-- <i>正在对接</i><span>{{ item.name }}</span> -->
                            <i class="wait" v-if="item.conversationStatus === 'AWAIT'"> 等待对接 </i>
                            <i v-if="item.conversationStatus === 'CONDUCTED'"> 正在对接</i>
                            <span>{{ item.name }}</span>
                        </div>
                        <p>
                            {{ item.description }}
                        </p>
                        <span class="supply_time">{{ item.createdAt }}</span>
                    </div>
                </div>
            </div>
            <!-- 政民互动 -->
            <div v-if="current === 9 || current === 10">
                <div class="interactive" v-for="(item, index) in tableData" :key="item.id" @click="needsGo(index)">
                    <span class="title">{{ item.title }}</span>
                    <span class="name">{{ item.name }}</span>
                    <span class="num"
                        >回复&nbsp;<span style="color:#939599">{{ item.commentNum }}</span></span
                    >
                    <span class="time">{{ item.createdAt }}</span>
                </div>
            </div>
            <!-- 政民互动 -->
            <div v-if="current === 8">
                <div class="interactive" v-for="(item, index) in tableData" :key="item.id" @click="needsGo(index)">
                    <span class="title">{{ item.title }}</span>
                    <!-- <span class="name">{{ item.name }}</span> -->
                    <span class="num">{{ item.commentNum >= 0 ? '已回复' : '未回复' }}</span>
                    <span class="time">{{ item.createdAt }}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import pageableTable from '@/mixins/pageableTable';
export default {
    name: 'search',
    mixins: [pageableTable],
    data() {
        return {
            url: '/article/all',
            current: 0,
            query: { type: { keyType: 'gg' }, size: 10 },
            search: '',
            title: '',
            pageSize: 10,
            needIndex: 100,
            resIndex: 100,
            civilIndex: 100,
            needsoptions: [
                {
                    label: '需求信息',
                    value: 100,
                    disabled: true
                },
                {
                    label: '技术需求',
                    value: 2
                },
                {
                    label: '产品需求',
                    value: 3
                },
                {
                    label: '融资需求',
                    value: 4
                }
            ],
            resOptions: [
                {
                    disabled: true,
                    label: '供应信息',
                    value: 100
                },
                {
                    label: '产品',
                    value: 5
                },
                {
                    label: '技术产品',
                    value: 6
                },
                {
                    label: '共享资源',
                    value: 7
                }
            ],
            civilOptions: [
                {
                    disabled: true,
                    label: '民政互动',
                    value: 100
                },
                {
                    label: '官方问答',
                    value: 8
                },
                {
                    label: '热议话题',
                    value: 9
                },
                {
                    label: '互动提问',
                    value: 10
                }
            ]
        };
    },
    created() {
        if (this.$route.params.search) {
            this.title = this.$route.params.search;
        }
        if (this.$route.params.value) {
            this.current = this.$route.params.value;
            console.log(this.current);
            this.getToData();
        }
    },
    methods: {
        getToData() {
            if (this.current <= 1) {
                this.getIndex(this.current);
            } else if (this.current >= 2 && this.current <= 4) {
                this.needIndex = this.current;
                this.needShow();
            } else if (this.current >= 5 && this.current <= 7) {
                this.resIndex = this.current;
                this.resShow();
            } else if (this.current >= 8 && this.current <= 10) {
                this.civilIndex = this.current;
                this.civilShow();
            }
        },
        beforeGetData() {
            if (this.search || this.query) {
                return { search: this.search, query: this.query };
            }
        },
        resShow() {
            this.url = '/resourceSupplyAndDemand/all';
            if (this.resIndex === 5) {
                // this.url = '/product/all';
                this.query = { type: 'PRODUCT_SUPPLY' };
                this.search = this.title;
                this.pageSize = 5;
                this.getData();
            } else if (this.resIndex === 6) {
                // this.url = '/artProduct/all';
                this.query = { type: 'TECH_SUPPLY' };
                this.search = this.title;
                this.pageSize = 5;
                this.getData();
            } else if (this.resIndex === 7) {
                // this.url = '/tresource/all';
                this.query = { type: 'RES_SUPPLY' };
                this.search = this.title;
                this.pageSize = 5;
                this.getData();
            }
            this.current = this.resIndex;
        },
        needShow() {
            this.url = '/resourceSupplyAndDemand/all';
            if (this.needIndex === 2) {
                // this.url = '/artNeed/all';
                // this.query = {};
                // this.search = this.title;
                // this.pageSize = 5;
                // this.getData();
                this.query = { type: 'TECH_DEMAND' };
                this.search = this.title;
                this.pageSize = 5;
                this.getData();
            } else if (this.needIndex === 3) {
                this.query = { type: 'PRODUCT_DEMAND' };
                this.search = this.title;
                this.pageSize = 5;
                this.getData();
            } else if (this.needIndex === 4) {
                this.query = { type: 'FINANCING_DEMAND' };
                this.search = this.title;
                this.pageSize = 5;
                this.getData();
            }
            this.current = this.needIndex;
        },
        civilShow() {
            this.url = '/post/allDTO';
            if (this.civilIndex === 8) {
                this.query = { type: 'OFFICIAL' };
                this.search = this.title;
                this.pageSize = 5;
                this.getData();
            } else if (this.civilIndex === 9) {
                this.query = { type: 'TOPIC' };
                this.search = this.title;
                this.pageSize = 5;
                this.getData();
            } else if (this.civilIndex === 10) {
                this.search = this.title;
                this.query = { type: 'QA' };
                this.pageSize = 5;
                this.getData();
            }
            this.current = this.civilIndex;
        },
        getIndex(index) {
            this.current = index;
            if (this.current === 0) {
                this.url = '/article/all';
                this.search = this.title;
                this.query = { type: { keyType: 'gg' } };
                this.pageSize = 10;
                this.getData();
            } else if (this.current === 1) {
                this.url = '/article/all';
                this.search = this.title;
                this.query = { type: { keyType: 'zcfg' } };
                this.pageSize = 10;
                this.getData();
            }
        },
        needsGo(index) {
            if (this.current === 2) {
                this.$router.push({
                    name: 'resourceDetail',
                    query: { id: this.tableData[index].id, type: 'TECH_DEMAND' }
                });
            } else if (this.current === 3) {
                this.$router.push({
                    name: 'resourceDetail',
                    query: { id: this.tableData[index].id, type: 'PRODUCT_DEMAND' }
                });
            } else if (this.current === 4) {
                this.$router.push({
                    name: 'resourceFanceDetail',
                    query: { id: this.tableData[index].id, type: 'FINANCING_DEMAND' }
                });
            } else if (this.current === 5) {
                this.$router.push({
                    name: 'resourceRelease',
                    query: { id: this.tableData[index].id, type: 'PRODUCT_SUPPLY' }
                });
            } else if (this.current === 6) {
                this.$router.push({
                    name: 'resourceRelease',
                    query: { id: this.tableData[index].id, type: 'TECH_SUPPLY' }
                });
            } else if (this.current === 7) {
                this.$router.push({
                    name: 'resourceRelease',
                    query: { id: this.tableData[index].id, type: 'RES_SUPPLY' }
                });
            } else if (this.current === 8) {
                console.log(this.tableData[index]);
                this.$router.push({
                    name: 'interactDetail',
                    query: { id: this.tableData[index].id, type: 'OFFICIAL' }
                });
            } else if (this.current === 9) {
                // console.log(this.tableData[index]);
                this.$router.push({ name: 'interactDetail2', query: { id: this.tableData[index].id, type: 'TOPIC' } });
            } else if (this.current === 10) {
                // console.log(this.tableData[index]);
                this.$router.push({ name: 'interactDetail2', query: { id: this.tableData[index].id, type: 'QA' } });
            }
        }
    }
};
</script>
<style lang="less" scoped>
.container {
    width: 980px;
    margin: auto;
}
.search_info {
    margin: auto;
    width: 644px;
    height: 48px;
    border: 1px solid #bf1616;
    display: flex;
    align-items: center;
    box-sizing: border-box;

    input {
        width: 569px;
        height: 48px;
        padding: 20px 13px;
    }
    .btn-search {
        cursor: pointer;
        float: right;
        width: 75px;
        height: 48px;
        background: #bf1616;
        display: flex;
        align-items: center;
        justify-content: center;
        img {
            width: 24px;
            height: 24px;
        }
    }
}
.tab {
    position: relative;
    height: 60px;
    line-height: 60px;
    border-bottom: 1px solid #f2f3f5;
    margin-top: 10px;
    span {
        width: 52px;
        height: 18px;
        font-size: 13px;
        color: #818999;
        line-height: 18px;
        margin: 0 15px;
        cursor: pointer;
        &.active {
            color: #bf1616;
        }
    }
}
.content {
    height: 500px;
    overflow-y: auto;
}
.notice {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    // cursor: pointer;
    &:hover .notice_con div {
        color: #bf1616;
    }
    // &:hover {
    //     cursor: pointer;
    //     z-index: 99;
    // }
    .notice_con {
        cursor: pointer;
        i {
            float: left;
            width: 4px;
            height: 4px;
            background: #e3e4e6;
            margin: 10px 6px 10px 0px;
        }
        div {
            float: left;
            width: 755px;
            height: 24px;
            font-size: 14px;
            color: #000000;
            line-height: 24px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }
    .notice_time {
        // width: 75px;
        height: 24px;
        font-size: 14px;
        color: #939599;
        line-height: 24px;
    }
}
.policy {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    cursor: pointer;
    &:hover .policy_info h5 {
        color: #bf1616;
    }
    .policy_info {
        img {
            float: left;
            width: 140px;
            height: 100px;
            margin-right: 12px;
        }
        div {
            float: left;
        }
        h5 {
            width: 613px;
            height: 22px;
            font-size: 16px;
            margin: 0;
            font-weight: 400;
            color: #000000;
            line-height: 22px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }
        p {
            width: 613px;
            height: 24px;
            font-size: 14px;
            color: #939599;
            line-height: 24px;
            margin: 3px 0 0;
        }
    }
    .policy_time {
        // width: 75px;
        height: 24px;
        font-size: 14px;
        color: #939599;
        line-height: 24px;
    }
}
.supply {
    margin-top: 20px;
    overflow: hidden;
    cursor: pointer;
    &:hover {
        background-color: #f5f7fa;
    }
    img {
        width: 100px;
        height: 100px;
        float: left;
    }
    .supply_info {
        float: left;
        width: 840px;
        padding-left: 16px;
        box-sizing: border-box;
        .supply_tit {
            margin-top: 3px;
            i {
                font-style: normal;
                font-size: 12px;
                color: #22b197;
                background: #ebf9f7;
                padding: 5px 3px;
                margin-right: 6px;
            }
            .wait {
                background-color: #ffebe8;
                color: #ff4a33;
            }
            span {
                font-size: 14px;
                color: #000;
                font-weight: 500;
            }
        }
        p {
            font-size: 13px;
            line-height: 22px;
            color: #939599;
            margin: 10px 0 5px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }
        .supply_time {
            color: #939599;
            font-size: 13px;
        }
    }
}
.interactive {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    cursor: pointer;
    &:hover .title {
        color: #bf1616;
    }
    .title {
        width: 500px;
        height: 24px;
        font-size: 14px;
        color: #000000;
        line-height: 24px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .name {
        width: 20%;
        height: 24px;
        font-size: 14px;
        color: #939599;
        line-height: 24px;
    }
    .time {
        width: 25%;
        font-size: 14px;
        color: #939599;
    }
    // .author {
    //     width: 20%;
    //     color: #939599;
    //     font-size: 14px;
    // }
    .num {
        width: 15%;
        font-size: 14px;
        color: #c8c9cc;
    }
}
.select {
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    .option {
        cursor: pointer;
        text-align: center;
        background-color: #fff;
        width: 80px;
        height: 40px;
        line-height: 40px;
        color: #333;
        font-size: 13px;
        &:hover {
            color: #bf1616;
        }
    }
}
.select01 {
    position: absolute;
    top: 50px;
    left: 164px;
}
</style>
<style lang="less" scoped>
/deep/.el-select-dropdown__item {
    text-align: center;
}
/deep/.el-input--small .el-input__inner {
    height: 46px;
    line-height: 46px;
    border: none;
    text-align: center;
    width: 80px;
}
/deep/.clearmargin {
    margin: 0 !important;
}
/deep/.el-input--suffix .el-input__inner {
    padding-right: 0px;
    padding-left: 0px;
}
/deep/.el-input__suffix {
    right: -5px;
}
/deep/.el-input__inner::placeholder {
    color: #818999;
    text-align: center;
    &.active {
        color: red;
    }
}
</style>
