马宇豪
2024-02-23 4cfbfd1b425f7b22b876ae6cae95c4fc29ae6bfb
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-row style="padding-top: 10px">
        <div style="display: block;">
        <div class="basic_search">
          <span>地域:&emsp;&emsp;</span>
          <el-select
            v-model="queryForm.province"
            placeholder="请选择省份"
            clearable
            filterable
            @change="changeArea('province')">
            <el-option
              v-for="item in provinceList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
          </el-select>
        </div>
        <div class="basic_search">
          <el-select v-model="queryForm.city" prop="city" clearable filterable @change="changeArea('city')">
            <el-option
              v-for="item in cityList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
          </el-select>
        </div>
        <div class="basic_search">
          <el-select v-model="queryForm.area" clearable filterable @change="changeArea('area')">
            <el-option
              v-for="item in districtList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
          </el-select>
        </div>
        <div class="basic_search">
          <el-select v-model="queryForm.town" clearable filterable @change="changeArea('town')" >
            <el-option
              v-for="item in streetList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
          </el-select>
        </div>
        <div class="basic_search">
          <el-select v-model="queryForm.community" clearable filterable>
            <el-option
              v-for="item in committeeList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
          </el-select>
        </div>
      </div>
 
      </el-row>
      <el-row style="padding-top: 10px">
        企业名称:
        <el-input v-model="queryForm.name" class="filter-item" placeholder="企业名称" style="width: 20%;padding-right: 15px"
                  @keyup.enter.native="queryHandle"/>
 
        企业类型:
        <el-select
          v-model.trim="queryForm.enterpriseType"
          placeholder="请选择企业类型"
          style="width:13%;">
          <el-option
            v-for="(item,index) in checkTypeList"
            :label="item.text"
            :value="item.text"
            :key="index"/>
        </el-select>
          许可证有效状态:
          <el-select
              v-model.trim="queryForm.licenseValid"
              placeholder="请选择许可证有效状态"
              style="width:13%;">
              <el-option
                  v-for="item in licenseValidList"
                  :label="item.text"
                  :value="item.id"
                  :key="item.id"/>
          </el-select>
<!--          <el-button class="filter-item" style="margin-left: 15px;" type="primary" icon="el-icon-refresh"-->
<!--                     @click="refreshHandle">立即更新-->
<!--          </el-button>-->
          <el-button class="filter-item" style="margin-left: 15px;" type="primary" icon="el-icon-download"
                     @click="exportAllHandle">导出
          </el-button>
          <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-search"
                     @click="queryHandle"/>
          <el-button v-if="userType === 1" class="filter-item" style="margin-left: 10px; background-color: #f56c6c" type="danger" icon="el-icon-delete"
                     @click="clearHandle">清空库存
          </el-button>
      </el-row>
 
    </div>
    <div class="table_content">
      <el-table
        v-loading="listLoading"
        :key="tableKey"
        :data="stockTotalData"
        ref="multipleTable"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        @sort-change="sortChange"
        @selection-change="handleSelectionChange"
      >
          <el-table-column
              type="selection"
              width="55"/>
        <el-table-column type="index" label="序号" align="center" width="80"/>
        <el-table-column label="企业名称" prop="enterpriseName" align="center" sortable="custom">
          <template slot-scope="scope">
            <el-link type="primary" v-if="scope.row.enterpriseName !== '总计'" @click="showDetail(scope.row.owner)">{{ scope.row.enterpriseName }}</el-link>
            <span v-if="scope.row.enterpriseName === '总计'">总计</span>
          </template>
        </el-table-column>
          <el-table-column label="地区"  align="center" sortable="custom">
              <template slot-scope="scope">
                  {{[scope.row.province,scope.row.city,scope.row.district].filter(item=>item!=="" &item!=null).join("-")}}
              </template>
          </el-table-column>
 
        <el-table-column label="库存总数(箱)" prop="stockNum" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.stockNum }}</span>
          </template>
        </el-table-column>
          <el-table-column label="爆竹类(箱)" prop="firecracker" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.firecracker }}</span>
              </template>
          </el-table-column>
          <el-table-column label="喷花类(箱)" prop="spray" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.spray }}</span>
              </template>
          </el-table-column>
          <el-table-column label="旋转类(箱)" prop="rotation" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.rotation }}</span>
              </template>
          </el-table-column>
          <el-table-column label="吐珠类(箱)" prop="bead" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.bead }}</span>
              </template>
          </el-table-column>
          <el-table-column label="玩具类(箱)" prop="toy" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.toy }}</span>
              </template>
          </el-table-column>
          <el-table-column label="组合烟花类(箱)" prop="combined" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.combined }}</span>
              </template>
          </el-table-column>
          <el-table-column label="更新时间" prop="updateat" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.updateat }}</span>
              </template>
          </el-table-column>
      </el-table>
      <br>
      <el-pagination
        v-show="recordTotal>0"
        :current-page="currentPage"
        :page-sizes="[30, 50, 100, 200]"
        :page-size="pageSize"
        :total="recordTotal"
        layout="total, sizes, prev, pager, next, jumper"
        background
        style="float:right;"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
        <br>
    </div>
  </div>
 
</template>
 
<script>
    import {getManufacturerTree} from "../../api/product";
    import {computePageCount, parseTime} from "../../utils";
    import {parseError} from "../../utils/messageDialog";
    import {clearStock, enterpriseStockList, refreshStock} from "../../api/stock";
    import Cookies from 'js-cookie'
    import {getCityListData, getProvinceListData} from "../../api/area";
    import {dictionaryAllItems} from "../../api/dictionary";
    import {mapGetters} from "vuex";
 
    export default {
    name: "enterpriseStock",
    data(){
      return{
        pageSize: 30,
        recordTotal: 0,
        currentPage: 1,
        pageTotal: 0,
        tableKey: 0,
        stockData:[],
        selectData:[],
        listLoading: true,
        manufacturerTree:[],
        provinceList:[],
        cityList:[],
        districtList:[],
        streetList:[],
        committeeList:[],
        checkTypeList:[],
        dateRange:[],
          licenseValidList:[{id:1,text:'有效'},{id:0, text:'无效'}],
        isSupervision : Cookies.get('isSupervision'),
        queryForm: {
          name: '',
          beginDate:'',
          endDate:'',
          province:'',
          city:'',
 
 
          area:'',
          town:'',
          community:'',
          enterpriseType:'',
            licenseValid:1,
        },
        totalRow:{'enterpriseName':"总计",'stockNum':0}
      }
    },
    mounted(){
      getManufacturerTree().then(res=>{
        this.manufacturerTree=(res.data) ;
      });
      this.queryDateHandle();
      this.getDictionaryCheckType();
      if (this.isSupervision === 'null'){
        this.queryForm.enterpriseType = "烟花爆竹批发经营"
      }
      this.getStockList()
      this.getProvince();
    },
    computed: {
      ...mapGetters([
        'userType',
        'username'
      ]),
      stockTotalData(){
        const tbody = this.stockData
        this.totalRow['enterpriseName'] = this.totalRow.name
        return tbody.length ?[...tbody,this.totalRow]:[]
      }
    },
    methods:{
      getStockList(){
        const _this = this;
        _this.queryForm.beginDate = _this.formatTime(_this.dateRange[0]);
        _this.queryForm.endDate = _this.formatTime(_this.dateRange[1]);
        const params = {};
        params['pageIndex'] = _this.currentPage;
        params['pageSize'] = _this.pageSize;
        params['sort'] = _this.sort;
        params['order'] = _this.order;
        params['operator'] = Cookies.get('userName') ;
        params['licenseValid'] = Cookies.get('userName') ;
        for (const i in _this.queryForm) {
            params[i] = _this.queryForm[i]
        }
        _this.listLoading = true;
        enterpriseStockList(params).then(response => {
          const res = response.data;
          if (res.code === "200") {
            const result = res.result;
            _this.recordTotal = result.totalCount;
            _this.pageSize = result.pageSize;
            _this.pageTotal = computePageCount(result.totalCount, result.pageSize);
            _this.currentPage = result.pageIndex;
            _this.stockData = result.result
            _this.totalRow = result.extension
          } else {
            parseError({error: res.message, vm: _this})
          }
          _this.listLoading = false;
        }).catch(error => {
          _this.listLoading = false;
          parseError({error: error, vm: _this})
        })
      },
      showDetail(owner){
        this.$router.push({path:'/stockInfo/info',query:{owner:owner,beginDate:this.queryForm.beginDate,endDate:this.queryForm.endDate}})
      },
      refreshHandle: function () {
          refreshStock().then(response => {
              const res = response.data
              if (res.code === "200") {
                  this.dialogFormVisible = false
                  this.$message({
                      message: '刷新成功',
                      type: 'success'
                  });
                  this.getStockList()
              } else {
                  parseError({error: res.message, vm: _this})
              }
          }).catch(error => {
              parseError({error: error, vm: _this})
          })
      },
      queryHandle: function () {
        this.currentPage = 1;
        this.getStockList();
      },
      handleSizeChange: function (val) {
        this.pageSize = val;
        this.currentPage = 1;
        this.getStockList();
      },
      handleCurrentChange: function (val) {
        this.currentPage = val;
        this.getStockList();
      },
      sortChange(param){
        this.sort = param.prop;
        this.order = param.order;
        this.getStockList();
      },
      //获取省
      async getProvince(){
        let res = await getProvinceListData()
        if(res.data.code === "200"){
          this.provinceList = res.data.result.provinceList
        }
      },
      async changeArea(value){
        if(value === 'province'){
          this.queryForm.city = ''
          this.queryForm.area = ''
          this.queryForm.town = ''
          this.queryForm.community = ''
          this.areaListQuery = {
            type: 2,
            parenttype: 1,
            parentname: this.queryForm.province,
          }
          let res = await getCityListData(this.areaListQuery)
          if(res.data.code === "200"){
            this.cityList = res.data.result
          }
        }else if(value === 'city'){
          this.queryForm.area = ''
          this.queryForm.town = ''
          this.queryForm.community = ''
          this.areaListQuery = {
            type: 3,
            parenttype: 2,
            parentname: this.queryForm.city,
          }
          let res = await getCityListData(this.areaListQuery)
          if(res.data.code === "200"){
            this.districtList = res.data.result
          }
        }else if(value === 'area'){
          this.queryForm.town = ''
          this.queryForm.community = ''
          this.areaListQuery = {
            type: 4,
            parenttype: 3,
            parentname: this.queryForm.area,
          }
          let res = await getCityListData(this.areaListQuery)
          if(res.data.code === "200"){
            this.streetList = res.data.result
          }
        }else if(value === 'town'){
          this.queryForm.community = '';
          this.areaListQuery = {
            type: 5,
            parenttype: 4,
            parentname: this.queryForm.town,
          }
          let res = await getCityListData(this.areaListQuery)
          if(res.data.code === "200"){
            this.committeeList = res.data.result
          }
        }
      },//市、镇、街道、委员会
      getDictionaryCheckType() {
        const _this = this;
        if (_this.checkTypeList && _this.checkTypeList.length > 0) {
          return
        }
        const params = {};
        params['dictionaryType'] = '安全监管分类';
        dictionaryAllItems(params).then(response => {
          const res = response.data;
          if (res.code === "200") {
            _this.checkTypeList = res.result
          } else {
            parseError({ error: res.message, vm: _this })
          }
        }).catch(error => {
          parseError({ error: error, vm: _this })
        })
      },
 
        clearHandle(){
            const _selectData = this.$refs.multipleTable.selection;
            let owners = "";
            let count = 0;
            if (_selectData == null || _selectData.length < 1){
                parseError({ error: "未选中企业信息", vm: this })
            }
            _selectData.forEach(item =>{
                if (item.enterpriseName !== '总计'){
                    owners += item.owner;
                    owners += ",";
                    count++;
                }
            });
            this.$confirm('此操作将永久清除选中的 '+count+' 家企业库存, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                const params = {}
                params['owners'] = owners;
                clearStock(params).then(response =>{
                    const res = response.data;
                    if (res.code === "200") {
                        const result = res.result;
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    }
                });
 
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        handleSelectionChange(val){
            this.selectData = val
        },
      queryDateHandle(){
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
        start.setHours(0);
        start.setMinutes(0);
        start.setSeconds(0);
        this.dateRange.push(start,end);
        this.queryForm.beginDate = start;
        this.queryForm.endDate = end;
      },
      exportAllHandle () {
        const _this = this;
        const params = {};
        params['pageIndex'] = 1;
        params['pageSize'] = 100000;
        params['sort'] = _this.sort;
        params['order'] = _this.order;
        const userName = Cookies.get('userName');
        const name = Cookies.get('name');
        params['operator'] = name + '(' + userName + ')';
        for (const i in _this.queryForm) {
          if (_this.queryForm[i] != undefined && _this.queryForm[i].toString() !== '') {
            params[i] = _this.queryForm[i]
          }
        }
        enterpriseStockList(params).then(response => {
          const res = response.data;
          if (res.code === "200") {
            const allData = res.result.result;
            if (allData.length == 0) {
              parseError({ error: '当前没有数据', vm: _this });
              return
            }
            allData.push(this.totalRow)
            import('@/vendor/Export2Excel').then(excel => {
              const tHeader = ['企业名称','地区', '库存总数(箱)','爆竹类(箱)','喷花类(箱)','旋转类(箱)','吐珠类(箱)','玩具类(箱)','组合烟花类(箱)'];
              // const filterVal = ['enterpriseName', 'stockNum'];
 
              const data = allData.map(item=>{
                return [
                  item.enterpriseName,
                  [item.province,item.city,item.district].filter(item=>item!=="" &item!=null).join("-"),
                    item.stockNum,
                    item.firecracker,
                    item.spray,
                    item.rotation,
                    item.bead,
                    item.toy,
                    item.combined,
                ]
              })
              excel.export_json_to_excel({
                header: tHeader,
                data,
                filename: '库存汇总'
              })
            })
          } else {
            parseError({ error: res.message, vm: _this })
          }
        }).catch(error => {
          parseError({ error: error, vm: _this })
        })
      },
 
      formatJson(filterVal, jsonData) {
        return jsonData.map((v) =>
          filterVal.map((j) => {
            if (j === 'createddate') {
              return parseTime(v[j], '{y}-{m}-{d}')
            }else {
              return v[j]
            }
          })
        )
      },
      formatTime: function(value) {
        let date = new Date(value);
        let y = date.getFullYear();
        let MM = date.getMonth() + 1;
        MM = MM < 10 ? "0" + MM : MM;
        let d = date.getDate();
        d = d < 10 ? "0" + d : d;
        let h = date.getHours();
        h = h < 10 ? "0" + h : h;
        let m = date.getMinutes();
        m = m < 10 ? "0" + m : m;
        let s = date.getSeconds();
        s = s < 10 ? "0" + s : s;
        return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
      }
    },
 
  }
</script>
 
<style scoped>
  .basic_search{
    display:inline-block;
  }
</style>