<template>
    <div>
        <div class="rec_card_title">为你推荐</div>
        <div class="rec_card_line"></div>
        <div class="rec_card" @click="Go">
            <!-- <img :src="list[this.index] ? list[this.index].images : null" />
            <div class="rec_card_name">{{ list[this.index] ? list[this.index].name : null }}</div> -->
            <img :src="list[0] ? list[0].images : null" />
            <div class="rec_card_name">{{ list[0] ? list[0].name : null }}</div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'recommendToU',
    props: ['type', 'dataType'],
    data() {
        return {
            query: { size: 1, page: 1, dataType: { id: 0 } },
            url: '',

            list: []
            // index: 0
        };
    },

    methods: {
        Go() {
            if (this.type === 'FINANCING_DEMAND') {
                this.$router.push({
                    name: 'resourceFanceDetail',
                    query: { id: this.list[0].id, type: this.type }
                });
            } else {
                this.$router.push({ name: 'resourceDetail', query: { id: this.list[0].id, type: this.type } });
            }
        },
        getData() {
            this.type;
            console.log(this.type);
            this.dataType;
            // if (this.type == 'TECH_DEMAND') {
            //     // this.url = '/artNeed/all';
            // } else if (this.type == 'PRODUCT_DEMAND') {
            //     // this.url = '/productNeed/all';
            // } else if (this.type == 'FINANCING_DEMAND') {
            //     // this.url = '/financingNeeds/all';
            // }
            // this.query.dataType.id = this.dataType;
            this.$http
                .get('/resourceSupplyAndDemand/all', { query: { type: this.type } })
                .then(res => {
                    this.list = res.content;
                    // this.index = Math.floor(Math.random() * (this.list.length - 0) + 0);
                })
                .catch(e => {
                    console.log(e);
                    this.$message.error(e.error);
                });
        }
    },
    created() {
        this.getData();
    }
};
</script>
<style lang="less" scoped>
.rec_card_title {
    font-size: 16px;
    font-weight: 500;
    color: #000000;
}
.rec_card_line {
    width: 180px;
    height: 1px;
    background: #f2f3f5;
    margin: 7px 0 16px;
}
.rec_card {
    border: 1px solid #f5f7fa;
    margin-bottom: 16px;
    img {
        width: 180px;
        height: 180px;
    }

    .rec_card_name {
        height: 44px;
        line-height: 44px;
        padding-left: 12px;
        font-size: 14px;
    }
}
</style>
