stock.vue 3.55 KB
<template>
    <layout-body>
        <layout-filter>
            <filter-item :label="filters.brandId.label">
                <select-brand v-model="filters.brandId.model"></select-brand>
            </filter-item>
            <filter-item :label="filters.createTime.label">
                <Date-picker v-model="filters.createTime.model"
                             type="daterange" format="yyyy-MM-dd" placeholder="选择日期">
                </Date-picker>
            </filter-item>
            <filter-item>
                <Button @click="returnPage">返回对账单列表</Button>
                <Button type="primary" @click="search">筛选</Button>
                <Button @click="reset">清空条件</Button>
            </filter-item>
        </layout-filter>
        <layout-list>
            <Button type="success" @click="print" class="table-btn">打印</Button>
            <Table border :columns="tableCols" :data="tableData"></Table>
            <Page :total="pageData.total" :current="pageData.pageNo"
                        @on-change="pageChange" :page-size="20" show-total></Page>
        </layout-list>
    </layout-body>
</template>

<script>
import stock from './store/stock';
import FinanceService from 'services/finance/finance-service';
import _ from 'lodash';

export default {
    data() {
        return stock.call(this);
    },
    created() {
        this.FinanceService = new FinanceService();
        this.search();
    },
    computed: {
        startTime() {
            let createTime = this.filters.createTime.model;

            if (_.isEmpty(createTime)) {
                return 0;
            } else {
                return createTime[0] ? createTime[0].getTime() / 1000 : 0;
            }
        },
        endTime() {
            let createTime = this.filters.createTime.model;

            if (_.isEmpty(createTime)) {
                return 0;
            } else {
                return createTime[1] ? parseInt(createTime[1].getTime() / 1000, 10) : 0;
            }
        }
    },
    methods: {
        search() {
            let params = {
                brandId: +this.filters.brandId.model,
                beginTime: this.startTime || this.curDay,
                endTime: this.endTime || this.curDay,
                pageSize: this.pageData.pageSize,
                pageNo: this.pageData.pageNo
            };

            params = _.pickBy(params, val => val);

            this.FinanceService.inventoryLedgerList(params).then(ret => {
                this.tableData = _.get(ret, 'data.records', []);
                this.pageData.total = _.get(ret, 'data.totalCount', 0);
                this.pageData.pageNo = _.get(ret, 'data.pageNo', 1);
            });
        },
        reset() {
            this.filters.brandId.model = null;
            this.filters.createTime.model = null;
            this.pageData.pageNo = 1;
            this.pageData.total = 0;
            this.search();
        },
        pageChange(val) {
            this.pageData.pageNo = val;
            this.search();
        },
        print() {
            const href = `/finance/print/clearing/stock.html?brandId=${this.filters.brandId.model}&begin=${this.startTime}&end=${this.endTime}&page=${this.pageData.pageNo}`;

            window.open(href, '_blank');
        },
        returnPage() {
            this.$router.push({
                name: 'finance.clearing'
            });
        }
    }
};
</script>

<style lang="scss">
.ivu-date-picker .ivu-select-dropdown {
    left: -284px !important;
}

.table-btn {
    margin-bottom: 20px;
}

.ivu-date-picker {
    width: 190px;
}
</style>