<template>
    <sort-list
        @init="init"
        v-model="list"
        :sortKey="sortKey"
        :defaultQuery="defaultQuery"
        ref="list"
        url="/policyLaw/all"
        :filters="filters"
    >
        <template v-for="item in list">
            <policy-row :key="item.id" :info="item"></policy-row>
        </template>
    </sort-list>
</template>

<script>
import PolicyRow from '../../components/list/PolicyRow.vue';
import SortList from '../../components/page/SortList.vue';
export default {
    components: { SortList, PolicyRow },
    created() {
        this.init();
    },
    data() {
        return {
            typeSettingIdOptions: [],
            list: [],
            defaultQuery: {
                category: 'POLICY'
            }
        };
    },
    computed: {
        filters() {
            return [
                {
                    name: '政策层级',
                    key: 'typeSettingId',
                    type: 'select',
                    list: [...this.typeSettingIdOptions]
                },
                {
                    name: '政策名称',
                    key: 'name'
                },
                {
                    name: '发布年份',
                    key: 'issuedAt',
                    type: 'date'
                },
                {
                    name: '发文单位',
                    key: 'issuedBy'
                },
                {
                    name: '发文号',
                    key: 'issuedCode'
                }
            ];
        },
        sortKey() {
            return [
                {
                    name: '发布时间',
                    key: 'issuedAt'
                }
            ];
        }
    },
    methods: {
        init() {
            let flag = 7;
            if (this.$route.query.category == 'NEWS') {
                flag = 8;
            } else if (this.$route.query.category == 'LAW') {
                flag = 9;
            }
            this.$http
                .post('/setting/byFlag', { flag: flag })
                .then(res => {
                    if (res.length > 0) {
                        this.typeSettingIdOptions = 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>
