list.vue 3.9 KB
<template>
    <layout-body>
        <layout-filter>
            <filter-item :label="filters.subject.label">
                <Input v-model.trim="filters.subject.model"
                    :placeholder="filters.subject.holder"></Input>
            </filter-item>
            <filter-item :label="filters.emergency.label">
                <Select v-model.trim="filters.emergency.model" clearable>
                    <Option v-for="option in filters.emergency.options"
                        :value="option.value"
                        :key="option.value">{{option.label}}</Option>
                </Select>
            </filter-item>
            <filter-item :label="filters.brand.label">
                <select-brand v-model="filters.brand.model"></select-brand>
            </filter-item>
            <filter-item :label="filters.status.label">
                <Select v-model.trim="filters.status.model" clearable>
                    <Option v-for="option in filters.status.options"
                        :value="option.value"
                        :key="option.value">{{option.label}}</Option>
                </Select>
            </filter-item>
            <filter-item>
                <Button type="primary" @click="doSearch">筛选</Button>
                <Button @click="reset">清空条件</Button>
            </filter-item>
        </layout-filter>

        <layout-list>
            <Table border :columns="columns" :data="dataList"></Table>
            <Page :total="page.total" :current="page.current"
                  @on-change="pageChange" :page-size="20" show-total></Page>
        </layout-list>
    </layout-body>
</template>

<script>
import _ from 'lodash';
import {list as diffList} from './store';
import {DiffService} from 'services/repository';

export default {
    data() {
        return diffList.apply(this);
    },
    created() {
        this.DiffService = new DiffService();
        this.search(this.params());
    },
    methods: {
        search(params) {
            this.$Loading.start();
            this.DiffService.list(params)
                .then(res => {
                    this.$Loading.finish();
                    this.dataList = res.data.records;
                    this.page.total = res.data.totalCount;
                }, () => {
                    this.$Loading.finish();
                });

        },
        params() {
            const defVal = {
                pageNo: 1,
                pageSize: 20,
                statuses: [3, 21, 22]
            };
            const keyMap = {
                brandId: 'brand',
                statuses: 'status',
                subject: 'subject',
                emergencyDegree: 'emergency'
            };

            if (this.enableFilter) {
                let model;

                _.each(keyMap, (val, key) => {
                    model = this.filters[val].model;

                    if (('' + model).length) {
                        if (key === 'statuses') {
                            defVal[key] = [model];
                        } else {
                            defVal[key] = model;
                        }
                    }
                });
            }

            return defVal;
        },
        reset() {
            _.each(this.filters, item => {
                item.model = '';
            });
            this.page.current = 1;
            this.enableFilter = false;
            this.search(this.params());
        },
        doSearch() {
            this.enableFilter = true;
            this.search(this.params());
        },
        pageChange(no) {
            let params;

            params = this.params();
            params.pageNo = no;
            this.search(params);
            this.page.current = no;
        },
        toDetail(id) {
            this.$router.push({
                query: { id },
                name: 'repository.diff.detail',
            });
        }
    }
};
</script>

<style lang="scss">
</style>