<template>
    <filter-list v-model="list" ref="list" url="/funding/all" :filters="filters" labelWidth="78px" @init="init">
        <template v-for="item in list">
            <funding-row :key="item.id" :info="item"></funding-row>
        </template>
    </filter-list>
</template>

<script>
import FilterList from '../../components/page/FilterList.vue';
import { loanTermOptions } from '../../utils/variables';
import FundingRow from '../../components/list/FundingRow.vue';
export default {
    components: { FilterList, FundingRow },
    data() {
        return {
            loanTermOptions,
            purposeOptions: [], //融资目的,
            list: []
        };
    },
    created() {
        this.init();
    },
    computed: {
        filters() {
            return [
                {
                    name: '融资目的',
                    key: 'purpose',
                    list: [...this.purposeOptions]
                },
                {
                    name: '期望贷款期限',
                    key: 'loanTerm',
                    list: [...this.loanTermOptions]
                }
            ];
        }
    },
    methods: {
        init() {
            this.$http
                .post('/setting/byFlag', { flag: 5 })
                .then(res => {
                    if (res.length > 0) {
                        this.purposeOptions = res.map(item => {
                            return {
                                label: item.name,
                                value: item.id
                            };
                        });
                    }

                    this.$nextTick(() => {
                        this.$refs.list.init();
                    });
                })
                .catch(e => {
                    console.log(e);
                    this.$message.error(e.error);
                });
        }
    }
};
</script>

<style lang="less" scoped></style>
