马宇豪
2024-04-15 b6a27b9ca71d636a1598751f8114c36a5d7007fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<template>
    <el-dialog
        :visible.sync="recordDialog"
        :close-on-click-modal="false"
        width="75%"
        :title="tableStatus?'仓库出库记录':'仓库入库记录'"
        center
        append-to-body
    >
        <div class="app-container">
            <div class="filter-container">
                <div style="display: flex;justify-content: space-between">
                    <div class="basic_search" style="padding-top: 10px">
                        <span style="font-size: 16px">在</span>
                        <el-date-picker
                            value-format="yyyy-MM-dd HH:mm:ss"
                            v-model="validTime"
                            type="datetimerange"
                            :default-time="['00:00:00','23:59:59']"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            @change="updateTime"
                        >
                        </el-date-picker>
<!--                        <span v-if="tableStatus" style="font-size: 16px">期间总计出库</span>-->
<!--                        <span v-else style="font-size: 16px">期间总计入库</span>-->
<!--                        <span style="font-size: 16px">2333</span>-->
<!--                        <span style="font-size: 16px">箱</span>-->
                    </div>
                    <div class="basic_search" style="margin-right: 10px;padding-top: 10px">
                        <el-radio-group v-model="tableStatus" @input="changeStatus">
                            <el-radio-button :label="true">出库记录</el-radio-button>
                            <el-radio-button :label="false">入库记录</el-radio-button>
                        </el-radio-group>
                    </div>
                </div>
            </div>
            <div class="table_content">
                <el-table
                    v-loading="listLoading"
                    :key="tableKey"
                    :data="stockRecords"
                    border
                    fit
                    highlight-current-row
                    style="width: 100%;"
                    v-if="tableStatus"
                >
                    <el-table-column label="序号" type="index" align="center" width="60"/>
                    <el-table-column label="出库单号" prop="ordercode" align="center"></el-table-column>
                    <el-table-column label="出库企业" prop="shop" align="center"></el-table-column>
                    <el-table-column label="创建时间" prop="createat" align="center"></el-table-column>
                    <el-table-column label="运输证号" prop="transportcert" align="center"></el-table-column>
                    <el-table-column label="数量(箱)" prop="realboxnum" align="center"></el-table-column>
                    <el-table-column prop="type" align="center">
                        <template slot-scope="scope">
                            <span type="text">{{scope.row.type == 1? '常规出库':scope.row.type == 2? '快速出库':scope.row.type == 3? '退货出库':'--'}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width" fixed="right">
                        <template slot-scope="scope">
                            <el-button type="text" @click="showDetails('out',scope.row)">查看</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-table
                    v-loading="listLoading"
                    :key="tableKey"
                    :data="stockRecords"
                    border
                    fit
                    highlight-current-row
                    style="width: 100%;"
                    v-if="!tableStatus"
                >
                    <el-table-column label="序号" type="index" align="center" width="60"/>
                    <el-table-column label="入库单号" prop="code" align="center"></el-table-column>
                    <el-table-column label="入库企业" prop="unit" align="center"></el-table-column>
                    <el-table-column label="创建时间" prop="createddate" align="center"></el-table-column>
                    <el-table-column label="运输证号" prop="transportcert" align="center"></el-table-column>
                    <el-table-column label="数量(箱)" prop="boxnum" align="center"></el-table-column>
                    <el-table-column :label="tableStatus?'出库类型':'入库类型'" prop="type" align="center">
                        <template slot-scope="scope">
                            <span type="text">{{scope.row.type == 1? '常规入库':scope.row.type == 2? '快速入库':scope.row.type == 3? '退货入库':'--'}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width" fixed="right">
                        <template slot-scope="scope">
                            <el-button type="text" @click="showDetails('in',scope.row)">查看</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    v-show="recordTotal>0"
                    :current-page="currentPage"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="pageSize"
                    :total="recordTotal"
                    layout="total, sizes, prev, pager, next, jumper"
                    background
                    style="float:right;"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                />
                <record-detail ref="detailRef"></record-detail>
            </div>
        </div>
    </el-dialog>
</template>
 
<script>
    import {computePageCount} from "@/utils";
    import {getInboundQuery, getOutboundQuery} from "../../../api/warehouse"
    import recordDetail from "./recordDetail";
    import Cookies from "_js-cookie@2.2.0@js-cookie";
 
    export default {
        name: "stockRecords",
        components: {recordDetail},
        data(){
            return{
                tableStatus: true,
                tableKey:'',
                listLoading:false,
                pageSize: 10,
                recordTotal: 0,
                currentPage: 1,
                validTime: ['', ''],
                stockRecords:[],
                recordDialog:false,
                listQuery: {
                    pageIndex: 1,
                    pageSize: 10,
                    filter: {
                        storehouseId: null,
                        starttime: '',
                        endtime: ''
                    }
                },
            }
        },
        created() {
            const t = this
        },
        methods:{
            open(row){
                this.listQuery.pageIndex = 1
                this.listQuery.filter.storehouseId = row.storehouseId || row.id
                this.initValidTime()
                if(this.tableStatus){
                    this.getOutbound()
                }else{
                    this.getInbound()
                }
                this.recordDialog = true
            },
 
            async getOutbound(){
                const res = await getOutboundQuery(this.listQuery)
                if(res.data.code == 200){
                   this.stockRecords = res.data.result.records
                    this.recordTotal = res.data.result.total
                }else{
                    this.$message({
                        type:'warning',
                        message: res.data.message
                    })
                }
            },
 
            async getInbound(){
                const res = await getInboundQuery(this.listQuery)
                if(res.data.code == 200){
                    this.stockRecords = res.data.result.records
                    this.recordTotal = res.data.result.total
                }else{
                    this.$message({
                        type:'warning',
                        message: res.data.message
                    })
                }
            },
 
            initValidTime() {
                const end = new Date();
                if (end.getDate() - 1 === 0) {
                    this.validTime[0] = [end.getFullYear(), end.getMonth()-1, this.returnDay(end.getMonth()-1, end.getFullYear())].join("-") + " 00:00:00";
                    this.validTime[1] = [end.getFullYear(), end.getMonth(), this.returnDay(end.getMonth(), end.getFullYear())].join("-") + " 23:59:59";
                } else if (end.getDate() - 1 === 0 && end.getMonth() === 0) {
                    this.validTime[0] = [end.getFullYear() - 1, 11, 30].join("-") + " 00:00:00";
                    this.validTime[1] = [end.getFullYear() - 1, 12, 31].join("-") + " 23:59:59";
                } else {
                    this.validTime[0] = [end.getFullYear(), end.getMonth(), end.getDate() - 1].join("-") + " 00:00:00";
                    this.validTime[1] = [end.getFullYear(), end.getMonth() + 1, end.getDate() - 1].join("-") + " 23:59:59";
                }
                this.listQuery.filter.starttime = this.validTime[0]
                this.listQuery.filter.endtime = this.validTime[1]
            },
            returnDay(value, year) {
                if (value === 1 || value === 3 || value === 5 || value === 7 || value === 8 || value === 10 || value === 12) {
                    return 31
                } else if (value === 2) {
                    if (year % 4 === 0) {
                        return 29
                    } else {
                        return 28
                    }
                } else {
                    return 30
                }
            },
            changeStatus(val){
              this.listQuery.pageIndex = 1
              if(val == true){
                  this.getOutbound()
              }else{
                  this.getInbound()
              }
            },
 
            updateTime(){
                this.listQuery.pageIndex = 1
                this.listQuery.filter.starttime = this.validTime[0]
                this.listQuery.filter.endtime = this.validTime[1]
                if(this.tableStatus == true){
                    this.getOutbound()
                }else{
                    this.getInbound()
                }
            },
 
            handleSizeChange(val) {
                this.listQuery.pageSize = val
                if(this.tableStatus == true){
                    this.getOutbound()
                }else{
                    this.getInbound()
                }
            },
            handleCurrentChange(val) {
                this.listQuery.pageIndex = val
                if(this.tableStatus == true){
                    this.getOutbound()
                }else{
                    this.getInbound()
                }
            },
 
            showDetails(type,row){
                this.$refs.detailRef.open(type,row,this.listQuery.filter.storehouseId)
            }
        }
    }
</script>
 
<style scoped>
    .basic_search{
        display:inline-block;
    }
</style>