longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
<template>
  <flex-layout>
    <div class="table-layout filter-box-table" slot="header">
      <div class="table-row">
        <div class="table-cell text-right">入库时间:</div>
        <div class="table-cell">
          <el-date-picker
            v-model="time_start"
            size="small"
            class="time_box"
            :picker-options="pickerOptions0"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
          -
          <el-date-picker
            v-model="time_end"
            size="small"
            class="time_box"
            :picker-options="pickerOptions1"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </div>
        <div class="table-cell text-right">品牌:</div>
        <div class="table-cell">
          <el-select
            v-model="batt_Producer"
            :filterable="true"
            size="small"
          >
            <el-option label="全部" value=""></el-option>
            <el-option
              v-for="item in battProducerList"
              :key="item"
              :label="item"
              :value="item"
            ></el-option>
          </el-select>
        </div>
        <div class="table-cell text-right">型号:</div>
        <div class="table-cell">
          <el-input
            v-model="BattModel"
            size="small"
            placeholder="请输入型号"
          ></el-input>
        </div>
        <div class="table-cell text-right">库存:</div>
        <div class="table-cell">
          <el-select
            v-model="mon_count"
            :filterable="true"
            size="small"
          >
            <!-- <el-option label="全部" value=""></el-option> -->
            <el-option
              v-for="(item, idx) in inventoryTypeList"
              :key="'inventory_' + idx"
              :label="item.label"
              :value="item.id"
            ></el-option>
          </el-select>
        </div>
        <div class="table-cell text-right">包机组:</div>
        <div class="table-cell">
          <el-select
            v-model="batt_baoji"
            :filterable="true"
            size="small"
          >
            <el-option label="全部" value=""></el-option>
            <el-option
              v-for="(item, idx) in baoji_group_list"
              :key="'filter_baoji_' + idx"
              :label="item.baoji_group_name"
              :value="item.baoji_group_id"
            ></el-option>
          </el-select>
        </div>
      </div>
    </div>
    <div class="flex-page-content">
      <el-table
        stripe
        size="mini"
        header-row-class-name="header-primary"
        height="100%"
        :data="table.data"
      >
        <el-table-column
          v-for="header in table.header"
          :key="header.prop"
          :prop="header.prop"
          :label="header.label"
          :min-width="header.minWidth"
          :resizable="false"
          align="center"
        >
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="320" align="center">
          <template slot-scope="scope">
            <el-button
              icon="el-icon-folder-add"
              @click="putIn(scope.row)"
              type="danger"
              size="mini"
              >入库</el-button
            >
            <el-button
              icon="el-icon-folder-remove"
              type="primary"
              size="mini"
              @click="putOut(scope.row)"
              :disabled="scope.row.MonCount == 0"
              >出库</el-button
            >
            <el-button
              icon="el-icon-tickets"
              type="danger"
              size="mini"
              @click="storageHistory(scope.row)"
              >出入库纪录</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="flex-page-footer" slot="footer">
      <div class="el-pagination-btns">
        <el-button
          type="primary"
          @click="searchData"
          round
          size="mini"
          icon="el-icon-search"
          >查询</el-button
        >
        <el-button
          type="primary"
          round
          size="mini"
          icon="el-icon-wallet"
          @click="exportFile"
          >导出</el-button
        >
      </div>
      <el-pagination
        size="mini"
        :current-page="page.pageCurr"
        :page-sizes="[10, 20, 30, 50, 100]"
        :page-size="page.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.pageAll"
        @current-change="currentChange"
        @size-change="sizeChange"
      ></el-pagination>
      <div class="el-pagination-btns">
        <el-button
          type="primary"
          @click="addDialog = true"
          round
          size="mini"
          icon="el-icon-plus"
          >新增</el-button
        >
      </div>
    </div>
    <!-- 添加备件 -->
    <el-dialog
      title="添加备件"
      width="800px"
      :visible.sync="addDialog"
      :close-on-click-modal="false"
      top="0"
      class="dialog-center bg-white"
      :modal-append-to-body="false"
    >
      <div class="dialog_content">
        <el-form
          size="mini"
          ref="addForm"
          :model="params"
          :rules="rules"
          label-position="top"
          class="params-dialog"
        >
          <el-row :gutter="layout.gutter">
            <el-col :span="layout.span">
              <el-form-item label="电池品牌" prop="BattProducer">
                <el-select
                  v-model="params.BattProducer"
                  placeholder="请选择"
                  @change="battProducerChange"
                  :filterable="true"
                >
                  <el-option
                    v-for="item in linkage.battProducers"
                    :key="item"
                    :label="item"
                    :value="item"
                  >
                  </el-option>
                  <el-option label="其他" value="其他"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="layout.span">
              <el-form-item label="电池型号" prop="model">
                <el-input v-model="params.model"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="layout.span">
              <el-form-item label="入库日期" prop="date">
                <el-date-picker
                  v-model="params.date"
                  type="date"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="layout.span">
              <el-form-item label="单体数量" prop="count">
                <el-input v-model="params.count"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="layout.span">
              <el-form-item label="包机组" prop="baoji_group_id">
                <el-select
                  v-model="params.baoji_group_id"
                  placeholder="请选择"
                  @change="battProducerChange"
                >
                  <el-option
                    v-for="(item, idx) in baoji_group_list"
                    :key="'baoji_' + idx"
                    :label="item.baoji_group_name"
                    :value="item.baoji_group_id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="" slot="footer">
        <el-button type="primary" @click="add" size="mini">添加</el-button>
        <el-button type="warning" @click="addDialog = false" size="mini"
          >取消</el-button
        >
      </div>
    </el-dialog>
    <!-- 电池品牌 -->
    <el-dialog
      top="0"
      class="dialog-center"
      title="请输入电池品牌"
      :visible.sync="battProducer.dialogVisible"
      width="280px"
      append-to-body
    >
      <el-form size="small">
        <el-form-item label="电池品牌">
          <el-input v-model="battProducer.value"></el-input>
        </el-form-item>
      </el-form>
      <div style="text-align: right">
        <el-button type="primary" size="mini" @click="battProducerOk"
          >确定</el-button
        >
        <el-button size="mini" @click="battProducer.dialogVisible = false"
          >取消</el-button
        >
      </div>
    </el-dialog>
    <!-- 入库 -->
    <el-dialog
      top="0"
      class="dialog-center"
      title="请输入入库数量"
      :visible.sync="putInStorage.show"
      width="280px"
      append-to-body
    >
      <el-form size="small" ref="putIn" :model="putInStorage" :rules="rules_storage">
        <el-form-item label="单体数量" prop="putIn">
          <el-input v-model="putInStorage.putIn"></el-input>
        </el-form-item>
      </el-form>
      <div style="text-align: right">
        <el-button type="primary" size="mini" @click="putInStorageOk"
          >确定</el-button
        >
        <el-button size="mini" @click="putInStorage.show = false"
          >取消</el-button
        >
      </div>
    </el-dialog>
    <!-- 出库 -->
    <el-dialog
      top="0"
      class="dialog-center"
      title="请输入出库数量"
      :visible.sync="putOutStorage.show"
      width="280px"
      append-to-body
    >
      <el-form size="small" ref="putOut" :model="putOutStorage" :rules="rules_storage">
        <el-form-item :label="'单体数量 (当前库存:' + cur_obj.MonCount + ')'" prop="putOut">
          <el-input v-model.number="putOutStorage.putOut"></el-input>
        </el-form-item>
      </el-form>
      <div style="text-align: right">
        <el-button type="primary" size="mini" @click="putOutStorageOk"
          >确定</el-button
        >
        <el-button size="mini" @click="putOutStorage.show = false"
          >取消</el-button
        >
      </div>
    </el-dialog>
    <!-- 出入库纪录 -->
    <el-dialog
      title="备件出入库纪录"
      width="800px"
      :visible.sync="storageHis.show"
      :close-on-click-modal="false"
      top="0"
      class="dialog-center bg-white storage_his"
      :modal-append-to-body="false"
    >
      <div class="dialog_content">
        <el-timeline>
          <el-timeline-item
            v-for="(item, idx) in storageRecord"
            :key="'record_' + idx"
            :timestamp="item.operationTime"
            placement="top">
            <el-card>
              <el-tag effect="dark" :type="item.operationType != -1 ? '' : 'warning'">{{item.operationType != -1 ? '入库' : '出库'}}</el-tag>
              <em>{{item.eventInfo}}</em>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </div>
      <div class="" slot="footer">
        <el-button type="warning" @click="storageHis.show = false" size="mini"
          >关闭</el-button
        >
      </div>
    </el-dialog>
  </flex-layout>
</template>
 
<script>
import { testVal } from "@/assets/js/tools";
// 引入导出表格
import { export_json_to_excel } from "../../assets/js/excel/Export2Excel.js";
 
import Timeout from "@/assets/js/tools/Timeout";
let rules = {
  // 单体节数
  MonCount: {
    pattern: /^[0-9]{1,3}$/,
    regVal: true,
    min: 1,
    max: 240,
    msg: "取值范围1~240",
  },
};
// TODO
const inventoryTypeList = [
  {
    label: '库存为0',
    id: 0
  },
  {
    label: '库存大于0',
    id: 1
  }
];
export default {
  name: "repairBattery",
  data() {
    let self = this;
    return {
      time_start: "2000-01-01",
      time_end: new Date(Date.now()).format("yyyy-MM-dd"),
      BattModel: "",
      batt_baoji: '',
      mon_count: 1,
      batt_Producer: "",
      timer: new Timeout(),
      addDialog: false,
      table: {
        header: [
          {
            prop: "battProducer",
            label: "电池品牌",
            minWidth: 200,
          },
          {
            prop: "BattModel",
            label: "电池型号",
            minWidth: 200,
          },
          {
            prop: "battspare_date",
            label: "入库时间",
            minWidth: 200,
          },
          {
            prop: "MonCount",
            label: "单体数量",
            minWidth: 200,
          },
        ],
        data: [],
      },
      page: {
        pageCurr: 1,
        pageSize: 10,
        pageAll: 0,
      },
      pickerOptions0: {
        disabledDate: (time) => {
          if (this.time_end) {
            return new Date(time.getTime()) > new Date(this.time_end);
          }
        },
      },
      pickerOptions1: {
        disabledDate: (time) => {
          return (
            new Date(time.getTime() + 24 * 60 * 60 * 1000) <
            new Date(this.time_start)
          );
        },
      },
      params: {
        BattProducer: "",
        model: "",
        date: "",
        count: 0,
        baoji_group_id: ''
      },
      rules: {
        BattProducer: [
          { required: true, message: "电池品牌不能为空", trigger: "blur" },
        ],
        model: [
          { required: true, message: "电池型号不能为空", trigger: "blur" },
        ],
        date: [{ required: true, message: "请选择入库日期", trigger: "blur" }],
        count: [
          { required: true, message: "请输入单体数量", trigger: "blur" },
          {
            validator(rule, value, callback) {
              testVal(rule, value, callback, rules.MonCount);
            },
            trigger: ["change", "blur"],
          },
        ],
        baoji_group_id: [
          { required: true, message: "包机组不能为空", trigger: "blur" },
        ]
      },
      rules_storage: {
        putIn: [
          { required: true, message: "入库单体数量不能为空", trigger: "blur" },
          {
            validator(rule, value, callback) {
              testVal(rule, value, callback, rules.MonCount);
            },
            trigger: ["change", "blur"],
          },
        ],
        putOut: [
          { required: true, message: "出库单体数量不能为空", trigger: "blur" },
          {
            validator(rule, value, callback) {
              if (value < 1) {
                callback(new Error('出库单体数量须大于0'));
              } else if (value > self.cur_obj.MonCount) {
                callback(new Error('出库单体数量应小于' + self.cur_obj.MonCount));
              } else {
                callback();
              }
            },
            trigger: ["change", "blur"],
          },
        ]
      },
      layout: {
        gutter: 16,
        span: 12,
      },
      battProducerList: [],
      linkage: {
        battProducer: "",
        battProducers: [],
      },
      battProducer: {
        dialogVisible: false,
        value: "",
      },
      putInStorage: {
        show: false,
        putIn: ''
      },
      putOutStorage: {
        show: false,
        putOut: ''
      },
      storageHis: {
        show: false
      },
      baoji_group_list: [],
      inventoryTypeList: inventoryTypeList,
      // 当前操作的对象 出库 入库 查纪录
      cur_obj: {
        MonCount: 0
      },
      storageRecord: []
    };
  },
  methods: {
    currentChange(value) {
      this.page.pageCurr = value;
      this.searchData();
    },
    sizeChange(value) {
      this.page.pageCurr = 1;
      this.page.pageSize = value;
      this.searchData();
    },
    // 导出表格
    exportFile() {
      let tHeader = [];
      let filterVal = [];
      let list = this.table.data;
      this.table.header.map((item) => {
        tHeader.push(item.label);
        filterVal.push(item.prop);
      });
      let excelData = this.formatJson(filterVal, list);
      export_json_to_excel(tHeader, excelData, "备件电池信息管理数据");
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) => filterVal.map((j) => v[j]));
    },
    searchData() {
      let param = {
        battspare_time: this.time_start,
        battspare_time1: this.time_end,
        battProducer: this.batt_Producer,
        BattModel: this.BattModel,
        MonCount: this.mon_count,
        page: {
          pageCurr: this.page.pageCurr,
          pageSize: this.page.pageSize,
        },
      };
      // baojiGroupId 所属包机组 选全部则不传此参数
      if (this.batt_baoji) {
        param['baojiGroupId'] = this.batt_baoji;
      }
      this.$apis.dataMager.repairBatts
        .getList(param)
        .then((res) => {
          res = JSON.parse(res.data.result);
          // console.log('list', res);
          let list = [];
          if (res.code) {
            list = res.data;
            this.page.pageAll = list[list.length - 1].page.pageAll;
          }
          list.forEach((v) => {
            v["battspare_date"] = new Date(v.battspare_time).format(
              "yyyy-MM-dd"
            );
          });
          this.table.data = list;
        })
        .catch((err) => {
          console.error(err);
        });
    },
    add() {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          let params = {
            battProducer: this.params.BattProducer,
            BattModel: this.params.model,
            battspare_time: this.params.date,
            MonCount: this.params.count,
          };
          this.$apis.dataMager.repairBatts
            .add(params)
            .then((res) => {
              res = JSON.parse(res.data.result);
              // console.log(res);
              if (res.code) {
                this.addDialog = false;
              }
              this.$layer.msg(res.msg);
            })
            .catch((err) => {
              console.error(err);
            });
        } else {
          this.$layer.msg("存在校验未通过的数据!");
        }
      });
    },
    searchBattProducer() {
      // 查询后台
      this.$apis.dataMager.battGroupMager
        .searchBattProducer()
        .then((res) => {
          let rs = JSON.parse(res.data.result);
          let data = [];
          if (rs.code == 1) {
            data = rs.data.map((item) => {
              return item.BattProducer;
            });
          }
          this.linkage.battProducers = data;
          this.battProducerList = data;
        })
        .catch((error) => {
          console.log(error);
        });
    },
    battProducerChange(value) {
      // 点击其他
      if (value == "其他") {
        // 恢复上一次选择的内容
        this.params.BattProducer = this.linkage.battProducer;
        this.battProducer.dialogVisible = true;
        this.battProducer.value = "";
      } else {
        this.linkage.battProducer = value;
      }
    },
    battProducerOk() {
      var value = this.battProducer.value;
      // 获取选择的值
      this.params.BattProducer = value;
      // 记录选择的内容
      this.linkage.battProducer = value;
      if (this.linkage.battProducers.indexOf(value) == -1) {
        this.linkage.battProducers.push(value);
      }
      // 修改面板显示状态为关闭
      this.battProducer.dialogVisible = false;
    },
    // 查询当前用户所有包机组列表
    getGroupInfo () {
      this.$apis.userMager.baojiGroup.getGroupInfo().then((res) => {
        res = JSON.parse(res.data.result);
        let data = [];
        if (res.code) {
          // console.log(res);
          // baoji_group_id: 100011
          // baoji_group_name: "默认包机组"
          data = res.data;
        }
        this.baoji_group_list = data;
      }).catch((err) => {
        console.error(err);
      });
    }
    // 入库
    ,putIn (obj) {
      this.cur_obj = obj;
      this.putInStorage.show = true;
      this.$nextTick(() => {
        this.$refs.putIn.resetFields();
      });
    }
    ,putOut (obj) {
      this.cur_obj = obj;
      this.putOutStorage.show = true;
      this.$nextTick(() => {
        this.$refs.putOut.resetFields();
      });
    }
    ,storageHistory (obj) {
      // this.cur_obj = obj;
      this.storageHis.show = true;
      this.$apis.dataMager.repairBatts.getSparetRecord({spareId: obj.num}).then((res) => {
        res = JSON.parse(res.data.result);
        let data = [];
        if (res.code) {
          // console.log(res);
          data = res.data;
          // eventInfo: "执行了备件出库操作,出库数量为:5,备件库存数为:42"
          // operationTime: "2021-10-21 16:32:31"
          // operationType: -1
        }
        this.storageRecord = data;
      }).catch((err) => {
        console.error(err);
      });
    }
    ,putInOrOut (param) {
      this.$apis.dataMager.repairBatts.putInOrOut(param).then((res) => {
        res = JSON.parse(res.data.result);
        if (res.code) {
          // console.log(res, 'res');
          if (param.operationType == 1) {
            this.putInStorage.show = false;
          } else {
            this.putOutStorage.show = false;
          }
        } else {
          this.$message({
            type: 'warning',
            message: res.msg
          });
        }
      }).catch((err) => {
        console.error(err);
      });
    }
    ,putInStorageOk () {
      let param = {
        spareId: this.cur_obj.num,
        operationNum: this.putInStorage.putIn,
        operationType: 1
      };
      this.putInOrOut(param);
    }
    ,putOutStorageOk () {
      // console.log('出库');
      let param = {
        spareId: this.cur_obj.num,
        operationNum: this.putOutStorage.putOut,
        operationType: -1
      };
      this.putInOrOut(param);
    }
  },
  mounted() {
    this.timer.start(() => {
      this.searchData();
      this.timer.open();
    }, 1000);
    // 查询已存在的电池品牌
    this.searchBattProducer();
    this.getGroupInfo();
  },
  beforeDestroy() {
    this.timer.stop();
  },
 
};
</script>
 
<style scoped>
.time_box {
  width: 48.6%;
}
.dialog_content {
  padding: 4px 10px;
}
.bg-white >>> .el-dialog {
  background: #fff;
}
.storage_his >>> .dialog_content {
  height: 400px;
  overflow-y: auto;
}
.storage_his >>> .dialog_content .el-tag {
  margin-right: 1em;
}
</style>