Fixiaobai
2023-11-16 5676e658cf19f371ca059104889c33685a6416b9
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
<template>
  <el-dialog :close-on-click-modal="false" :visible.sync="visible">
    <el-table
      :data="dataList"
      border
      @selection-change="handleSelectionChange"
      v-loading="dataListLoading"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <template v-for="(col, index) in this.cols">
        <el-table-column
          :prop="col.prop"
          :label="col.label"
          header-align="center"
          align="center"
        >
        </el-table-column>
      </template>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
import { getObj, addObj, putObj, getResource } from '@/api/aps/connector'
export default {
  data() {
    return {
      cols: [
        { label: '资源编号', prop: 'resourceNo' },
        { label: '资源名称', prop: 'resourceName' },
        { label: '备注', prop: 'remark' },
        { label: '工作站id', prop: 'workstationId' }
      ],
      dataListLoading: false,
      dataList: [],
      record: [],
      visible: false,
      fromId: '',
      toId: '',
      dataForm: {
        id: 0,
        fromResourceId: '',
        toResourceId: '',
        transportTime: ''
      },
      clickDateArr: []
    }
  },
  methods: {
    handleSelectionChange(val) {
      this.record = val
    },
    init(id) {
      this.visible = true
      this.fromId = id
      this.clickDateArr = []
      this.getDataList()
    },
    getDataList() {
      this.dataListLoading = true
      getResource(
        Object.assign({
          current: this.pageIndex,
          size: this.pageSize
        }),
        this.fromId
      ).then((response) => {
        this.dataList = response.data.data.records
        this.totalPage = response.data.data.total
      })
      this.dataListLoading = false
    },
    commit() {
      const transferData = {
        fromResourceId: this.fromId,
        toResourceId: this.toId,
        transportTime: ''
      }
      addObj(transferData).then((data) => {
        this.$message.success('添加成功')
        this.visible = false
        this.$emit('refreshDataList')
      })
    },
    // 表单提交
    dataFormSubmit() {
      var canClickFlag = true
      this.clickDateArr.push(new Date().getTime())
      if (this.clickDateArr.length > 1) {
        if (
          this.clickDateArr[this.clickDateArr.length - 1] -
            this.clickDateArr[this.clickDateArr.length - 2] <
          2000
        ) {
          // 小于2秒则认为重复提交
          canClickFlag = false
        }
      }
      if (canClickFlag) {
        for (let i = 0; i < this.record.length; i++) {
          this.toId = this.record[i].id
          this.commit()
        }
      }
    }
  }
}
</script>