list.vue 4.55 KB
<template>
    <layout-body>
        <layout-filter>
            <filter-item :label="filters.orderCode.label">
                <Input v-model.trim="filters.orderCode.model"
                       :placeholder="filters.orderCode.holder" :maxlength="9" ></Input>
            </filter-item>

            <filter-item :label="filters.productSku.label">
                <Input v-model.trim="filters.productSku.model"
                       :placeholder="filters.productSku.holder" :maxlength="9"></Input>
            </filter-item>

            <filter-item>
                <Button type="primary" @click="getSellBack">筛选</Button>
                <Button @click="clearFilters">清空条件</Button>
            </filter-item>
        </layout-filter>

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

        <edit-img ref="showImgEdit" @on-success="editSuccess"></edit-img>

    </layout-body>
</template>

<script>
    import store from './store';
    import EditImg from './components/edit-img.vue';
    import SellService from 'services/repository/sellback-service';

    export default {
        created() {
            this.sellService = new SellService();
        },
        data() {
            return store.call(this);
        },
        mounted() {
            this.getSellBack();
        },
        methods: {
            editImg(row) {
                this.$refs.showImgEdit.show(row);
            },
            editSuccess() {
                this.getImg();
            },
            clearFilters() {
                this.filters.orderCode.model = null;
                this.filters.productSku.model = null;
                this.pageData.current = 1;

                this.getSellBack();
            },
            pageChange(page) {
                this.pageData.current = page;
                this.getSellBack();
            },
            filtersParams() {
                let params = {};
                let orderCode = this.filters.orderCode.model;
                let productSku = this.filters.productSku.model;

                let pageNo = this.pageData.current;
                let pageSize = this.pageData.pageSize;

                if (this.filters.orderCode.model) {
                    if (this.isNumber(this.filters.orderCode.model)) {
                        params.orderCode = this.filters.orderCode.model;
                    } else {
                        return Promise.reject('订单号必须是数字');
                    }
                }

                if (this.filters.productSku.model) {
                    if (this.isNumber(this.filters.productSku.model)) {
                        params.productSku = this.filters.productSku.model;
                    } else {
                        return Promise.reject('sku必须是数字');
                    }
                }

                params.pageSize = this.pageData.pageSize;
                params.pageNo = this.pageData.current;

                return Promise.resolve({
                    params,
                    productSku,
                    orderCode,
                    pageNo,
                    pageSize
                });
            },
            getSellBack() {
                this.$Loading.start();
                return this.filtersParams().then((params) => {
                    return this.sellService.list(params);
                }).then((result) => {
                    if (result.code === 200) {
                        this.pageData.total = result.data.totalCount;
                        this.pageData.current = result.data.pageNo;
                        this.tableData = result.data.records;
                    }
                    this.$Loading.finish();
                }).catch((err) => {
                    this.$Loading.finish();
                    this.$Message.error(err);
                });
            },
            isNumber(numStr) {
                const isNumber = /^[0-9]+$/;

                return isNumber.test(numStr);
            },
            getImg() {
                return this.filterParams().then((params) => {
                    return this.sellService.imgDetail(params).then((result) => {
                        if (result.code === 200) {
                            this.tableData = result.data;
                        }
                    });
                });
            },
        },
        components: {
            EditImg
        }
    };
</script>