<template>
    <div class="financingRequire">
        <div class="filter">
            <div class="first">
                <div class="name">融资阶段</div>
                <span :class="show.stageType.id === '' ? 'active' : false" @click="getTab('融资阶段', '')">全部</span>
                <span
                    v-for="n in rzjdList"
                    :key="n.value"
                    :class="show.stageType.id === n.label ? 'active' : false"
                    @click="getTab('融资阶段', n.label)"
                    >{{ n.label }}</span
                >
            </div>
            <div class="second">
                <div class="name">融资类型</div>
                <span :class="show.industryType.id === '' ? 'active' : false" @click="getTab('融资类型', '')"
                    >全部</span
                >
                <span
                    :class="show.industryType.id === n.label ? 'active' : false"
                    v-for="n in sblxList"
                    :key="n.value"
                    @click="getTab('融资类型', n.label)"
                    >{{ n.label }}</span
                >
            </div>
        </div>
        <div class="content">
            <div class="con_header">
                <span :class="active == true ? 'active' : ''" @click="clearDate"> 综合顺序</span>
                <span @click="changeDate" :class="active != true ? 'active' : ''">发布时间</span>
                <!-- <button v-if="menu_tab === 4"><img src="../assets/button_icon.png" />发布技术</button> -->
                <button @click="releaseGo"><img src="../../assets/button_icon.png" />发布需求</button>
            </div>
            <div class="con_main">
                <ul>
                    <li
                        v-for="item in tableData"
                        :key="item.id"
                        @click="
                            $router.push({
                                name: 'resourceFanceDetail',
                                query: { id: item.id, type: 'FINANCING_DEMAND' }
                            })
                        "
                    >
                        <img :src="(item.images || [])[0] || require('../../assets/sup_def.jpg')" />
                        <div class="con_main_right">
                            <div class="con_main_tit">
                                <!-- <i :class="item.state === 1 ? 'wait' : ''">{{
                                    item.state === 1 ? '等待对接' : '正在对接'
                                }}</i> -->
                                <i class="wait" v-if="item.conversationStatus === 'AWAIT'"> 等待对接 </i>
                                <i v-if="item.conversationStatus === 'CONDUCTED'"> 正在对接</i>
                                <span>{{ item.name }}</span>
                            </div>
                            <div class="con_info">
                                <div class="con_info_item">
                                    <i>计划融资</i><span>{{ item.resSnDPropertyList[0].value }}</span>
                                </div>
                                <div class="con_info_item">
                                    <i>融资阶段</i><span>{{ item.resSnDPropertyList[1].value }}</span>
                                </div>
                                <div class="con_info_item">
                                    <i>融资类型:</i>
                                    <span>{{ item.resSnDPropertyList[2].value }}</span>
                                </div>
                            </div>
                            <span class="con_time">{{ item.createdAt }}</span>
                        </div>
                    </li>
                </ul>
            </div>
            <el-row style="text-align: center;">
                <el-pagination
                    @size-change="onSizeChange"
                    @current-change="onCurrentChange"
                    :current-page="page"
                    :page-sizes="[10, 20, 30, 40, 50]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalElements"
                >
                </el-pagination>
            </el-row>
        </div>
    </div>
</template>

<script>
import pageableTable from '@/mixins/pageableTable';
export default {
    mixins: [pageableTable],
    name: 'financingRequire',
    data() {
        return {
            search: '',
            // url: '/financingNeeds/all',
            // query: { stageType: { id: 0 }, dataType: { id: 0 }, state: '1,3' },
            // url: '/resourceSupplyAndDemand/all',
            // query: { type: 'FINANCING_DEMAND', resSnDPropertyList: '' },
            show: { stageType: { id: '' }, industryType: { id: '' } },
            pageSize: 5,
            active: true
            // planMoney: '',
            // resSnDPropertyList: {},
            // list: {}
        };
    },
    computed: {
        userInfo() {
            return this.$store.state.userInfo;
        }
    },
    methods: {
        beforeGetData() {
            if ((this.search, this.query)) {
                return { search: this.search, query: this.query };
            }
        },
        changeDate() {
            this.active = false;
            this.tableData.sort(function(a, b) {
                return a.createdAt < b.createdAt ? 1 : -1;
            });
        },
        clearDate() {
            this.active = true;
            this.getData();
        },
        releaseGo() {
            if (this.$store.state.userInfo) {
                this.$router.push({ name: 'releaseRequirement' });
            } else {
                this.$alert('用户未登录，请先进行登录', '提示', {
                    confirmButtonText: '确定',
                    type: 'warning'
                });
            }
        },
        getData() {
            this.$http
                .post(
                    '/resourceSupplyAndDemand/allDTO',
                    {
                        query: { type: 'FINANCING_DEMAND', property: this.property, status: 'PASS' }
                    },
                    { body: 'json' }
                )
                .then(res => {
                    this.tableData = res.content;
                    this.totalPages = res.totalPages;
                    this.totalElements = res.totalElements;
                    if (this.afterGetData) {
                        this.afterGetData(res);
                    }
                });
        },
        getTab(strType, id) {
            if (strType == '融资阶段') {
                if (id !== '') {
                    this.property = { 融资阶段: id };

                    this.show.stageType.id = id;
                } else {
                    this.property = {};
                    this.show.stageType.id = '';
                    console.log(this.property);
                }
            } else if (strType == '融资类型') {
                if (id !== '') {
                    this.property = { 融资类型: id };
                    this.show.industryType.id = id;
                } else {
                    this.property = {};
                    this.show.industryType.id = '';
                }
            }

            this.getData();
        }
    },
    created() {
        this.getDataType({ query: { keyType: 'rzjd' } }, this.rzjdList);
        this.getDataType({ query: { keyType: 'rzhy' } }, this.sblxList);
        this.getData();
    },
    mounted() {
        if (this.$route.query.tabId) {
            let tabId = this.$route.query.tabId;
            this.show.industryType.id = tabId;
        }
    }
};
</script>
<style lang="less" scoped>
.filter {
    height: 100px;
    background-color: #fff;
    padding: 20px;
    box-sizing: border-box;
    .first {
        margin-bottom: 16px;
    }
    .name {
        display: inline-block;
        margin-right: 26px;
        color: #939599;
        font-size: 13px;
    }
    span {
        color: #313233;
        line-height: 22px;
        height: 22px;
        font-size: 13px;
        cursor: pointer;
        &.active {
            background: #bf1616;
            border-radius: 2px;
            color: #fff;
            padding: 4px;
        }
        + span {
            margin-left: 30px;
        }
    }
}
.content {
    // height: 748px;
    background-color: #fff;
    margin-top: 5px;
    padding: 0 20px 40px;
    .con_header {
        height: 60px;
        line-height: 60px;

        span {
            cursor: pointer;
            margin-right: 40px;
            font-size: 13px;
            color: #818999;
            &.active {
                color: #bf1616;
            }
        }
        button {
            width: 130px;
            height: 36px;
            background: #bf1616;
            border-radius: 4px;
            color: #fff;
            font-size: 12px;
            position: relative;
            padding-left: 20px;
            box-sizing: border-box;
            cursor: pointer;
            float: right;
            margin-top: 12px;
            img {
                width: 18px;
                height: 18px;
                position: absolute;
                top: 0;
                bottom: 0;
                margin: auto;
                left: 22px;
            }
        }
    }
    .con_main {
        margin-bottom: 40px;
        li {
            overflow: hidden;
            cursor: pointer;
        }
        li + li {
            margin-top: 20px;
        }
        img {
            width: 100px;
            height: 100px;
            float: left;
        }
        .con_main_right {
            float: left;
            width: 840px;
            padding-left: 16px;
            box-sizing: border-box;
            .con_main_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;
                }
            }
            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;
            }
            .con_time {
                color: #939599;
                font-size: 13px;
            }
        }
        .con_card_ul {
            overflow: hidden;
        }
        .con_card {
            display: flex;
            flex-direction: column;
            width: 223px;
            float: left;
            margin: 0 16px 20px 0;
            img {
                width: 223px;
                height: 223px;
            }
            h5 {
                font-size: 14px;
                color: #000;
                margin: 10px 0;
            }
            p {
                font-size: 12px;
                color: #939599;
                margin: 0;

                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }
        }
        .con_card:nth-child(4n) {
            margin-right: 0;
        }
        .con_info {
            overflow: hidden;
            margin: 15px 0 10px;
            .con_info_item {
                float: left;
                font-size: 13px;
                margin-right: 40px;
                i {
                    font-style: normal;
                    color: #939599;
                    margin-right: 4px;
                }
                span {
                    color: #bf1616;
                }
            }
        }
    }
}
</style>
