undone.vue 7.98 KB
<template>
    <div class="un-done">
        <LayoutFilter>
            <FilterItem :label="filters.orderNo.label">
                <Input v-model.trim="filters.orderNo.model"
                       :placeholder="filters.orderNo.holder" number></Input>
            </FilterItem>
            <FilterItem :label="filters.prodCode.label">
                <Input v-model.trim="filters.prodCode.model"
                       :placeholder="filters.prodCode.holder" number></Input>
            </FilterItem>
            <FilterItem :label="filters.merChantCode.label">
                <Input v-model.trim="filters.merChantCode.model"
                       :placeholder="filters.merChantCode.holder"></Input>
            </FilterItem>
            <FilterItem :label="filters.prodBarCode.label">
                <Input v-model.trim="filters.prodBarCode.model"
                       :placeholder="filters.prodBarCode.holder"></Input>
            </FilterItem>
            <FilterItem :label="filters.orderTime.label">
                <Date-picker type="date" placeholder="选择日期"
                             @on-change="dateChange" :value="filters.orderTime.model"></Date-picker>
            </FilterItem>
            <FilterItem :label="filters.prodStatus.label">
                <Select v-model.trim="filters.prodStatus.model">
                    <Option v-for="option in filters.prodStatus.options"
                            :value="option.value"
                            :key="option.value">{{option.label}}</Option>
                </Select>
            </FilterItem>
            <FilterItem>
                <Button type="primary" @click="filterSearch">筛选</Button>
                <Button @click="clearFilter">清空条件</Button>
            </FilterItem>
        </LayoutFilter>

        <LayoutAction>
            <Button type="primary" @click="sendOut">发货</Button>
        </LayoutAction>

        <LayoutList>
            <Table border :context="self" :columns="table.cols" :data="table.list"
                   :row-class-name="rowClassName" @on-selection-change="selectChange"></Table>
            <Page :total="page.total" :current="page.current"
                  @on-change="pageChange" :page-size="20" show-total></Page>
        </LayoutList>

        <ModalDeliver
            ref="deliverModal"
            :deliver-rows="deliverRows">
        </ModalDeliver>
        <ModalStockOut
            ref="stockOutModal">
        </ModalStockOut>
    </div>
</template>

<script>
    import _ from 'lodash';
    import moment from 'moment';
    import service from 'trade-service';
    import Store from '../store/undone';
    import { ModalDeliver, ModalStockOut } from 'components/modal' ;
    import { CellPrdInfo, CellDispatch, CellDeliver, CellStockOut, CellSkuImage } from '../components';

    export default {
        name: 'TabUndone',
        data() {
            return {
                self: this,
                filters: {},
                page: {},
                table: {},
                useFilterSign: false,
                showOutStock: false,
                deliverRows: []
            };
        },
        created() {
            const store = Store();

            this.filters = store.filters;
            this.page = store.page;
            this.table = store.table;

            const params = {
                pageNo: 1,
                pageSize: 20
            };

            this.productList(params);
        },
        methods: {
            params(){
                let data = {
                    pageNo: 1,
                    pageSize: 20
                };
                const mapKeys = {
                    proReqFormId: 'orderNo',
                    productSkn: 'prodCode',
                    sknFactoryCode: 'merChantCode',
                    skuFactoryCode: 'prodBarCode',
                    startTime: 'orderTime',
                    endTime: 'orderTime',
                    isOvertime: 'prodStatus'
                };

                let modelVal;
                _.each(mapKeys, (v, k) => {
                    modelVal = this.filters[v].model;
                    if((modelVal+'').length) {
                        data[k] = this.filters[v].model;
                    }
                });

                const ot = data.isOvertime;
                const date = data.startTime;

                if(date && moment(date).isValid()) {
                    data.startTime = +moment(date).format('X');
                    data.endTime = +moment(date).add(1, 'days').format('X');
                } else {
                    data.endTime = '';
                    data.startTime = '';
                }
                data.isOvertime = ot === -1 ? '' : ( ot === 1 ? 'N' : 'Y');

                data = _.pickBy(data, (v) => {
                    return (v+'').length;
                });

                return data;
            },
            productList(params){
                service.allotPurchaseList(
                    _.merge(params || {}, {
                        statusList: [1],
                        pageSize: 20
                    }))
                    .then(res => {
                        const fmt = 'YYYY-MM-DD HH:mm:ss';
                        const list = res.data.records;

                        _.each(list, i => {
                            i.createTime = moment(i.createTime).format(fmt);
                        });

                        this.table.list = list;
                        this.page.total = res.data.totalCount;
                    });
            },
            filterSearch(){
                const params = this.params();

                this.useFilterSign = true;
                this.productList(params);
                this.page.current = 1;
            },
            clearFilter(){
                this.filters = Store().filters;
                this.productList();
                this.useFilterSign = false;
                this.page.current = 1;
            },
            pageChange(page) {
                let params = {};
                this.page.current = page;

                if(this.useFilterSign) {
                    params = this.params();
                }

                _.merge(params, {
                    page
                });

                this.productList(params);
            },
            selectChange(rows){
                this.deliverRows = rows;
            },
            deliverChange(data) {
                const i = data.index;
                const v = data.value;
                this.table.list[i].inputDeliverNum = +v;
            },
            sendOut(){
                const len = this.deliverRows.length;
                if(!len) {
                    this.$Message.error('请先勾选要发货的订单');
                    return;
                }
                this.$refs.deliverModal.show();
            },
            setModel(k, v) {
                this.filters[k].model = v;
            },
            dateChange(date){
                this.setModel('orderTime', date);
            },
            rowClassName(row) {
                if(row.isOvertime === 'Y') {
                    return 'over-time';
                }
                return '';
            },
            lackNumChange(data) {
                const i = data.index;
                const v = data.value;
                this.table.list[i].inputLackNum = +v;
            },
            showUploadModal(index) {
                const row = this.table.list[index];
                const lackNum = row.inputLackNum;

                if(!lackNum) {
                    this.$Message.error('请输入缺货数量');
                    return;
                }
                this.$refs.stockOutModal.show(row);
            }
        },
        components: {
            CellPrdInfo,
            CellDispatch,
            CellDeliver,
            CellStockOut,
            CellSkuImage,
            ModalStockOut,
            ModalDeliver
        }
    };
</script>

<style lang="scss">
    .ivu-table .over-time td{
        background-color: #2db7f5;
        color: #fff;
    }
</style>