zouyu
2023-11-10 789bd1e36e88e09a45fa24fa1569330ada4c45b7
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
<template>
  <el-dialog
    width="60%"
    :visible.sync="innerVisible"
    append-to-body
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
    :close-on-click-modal="false"
    class="product-out-form"
  >
    <div slot="title">
      <div style="display: inline-block;float: left">
        <span>{{
          parentInfo.stepRecordId == null ? '新增工步' : '编辑工步'
        }}</span>
        <span v-if="parentInfo.stepRecordId != null" style="color:red"
          >({{ formatterStep }})</span
        >
        <el-select
          v-if="parentInfo.stepRecordId == null"
          v-model="currStepId"
          placeholder="请选择工步"
          style="margin-left:10px"
        >
          <el-option
            v-for="item in steps"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </div>
    </div>
    <div style="float: left;width: 30%;padding-right: 34px;position: relative">
      <el-table
        stripe
        ref="stepRecordPersonList"
        :data="personBoardList"
        @selection-change="stepRecordPersonSelectionChange"
        :row-style="{ height: '26px' }"
        :cell-style="{ padding: '0' }"
      >
        <el-table-column type="selection" />
        <el-table-column
          label="人员名称"
          prop="staffName"
          align="center"
          min-width="75px"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="人员编号"
          prop="staffNo"
          align="center"
          min-width="75px"
          :show-overflow-tooltip="true"
        />
      </el-table>
      <div
        style="position: absolute;top:0px;right: 0px;height: 100%;width: 34px;border-left: 1px solid #f4f2ea;border-right: 1px solid #f4f2ea;"
      ></div>
    </div>
    <div style="float: left;width: 70%">
      <el-row style="">
        <el-col :span="4" class="product-out-form-header-col"
          ><span>序号</span></el-col
        >
        <el-col :span="8" class="product-out-form-header-col"
          ><span>人员</span></el-col
        >
        <el-col :span="8" class="product-out-form-header-col"
          ><span>数量</span></el-col
        >
        <el-col :span="4" class="product-out-form-header-col"
          ><span>操作</span></el-col
        >
      </el-row>
      <div class="product-out-form-body-div">
        <el-row v-for="(item, index) in staffSteps" :key="item.id">
          <el-col :span="4" class="product-out-form-body-col">
            <span>{{ index + 1 }}</span>
          </el-col>
          <el-col :span="8" class="product-out-form-body-col">
            <span>{{ item.staffName }}</span>
          </el-col>
          <el-col :span="8" class="product-out-form-body-col l-mes">
            <el-input v-model="item.number"></el-input>
          </el-col>
          <el-col :span="4" class="product-out-form-body-col">
            <span style="cursor: pointer;color: red;" @click="delStaff(index)"
              >删除</span
            >
          </el-col>
        </el-row>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <div style="display: inline-block;width: 30%;float: left">
        <el-button
          style="margin-right: 34px"
          type="primary"
          @click="addStaffStepsForPerson"
          >添加</el-button
        >
      </div>
      <el-button @click="innerVisible = false">取 消</el-button>
      <el-button type="primary" @click="saveStaffSteps">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { saveStepRecord } from '@/api/product/productstep'
export default {
  props: {
    currshowlist: {
      type: Boolean,
      default: false
    },
    parentInfo: {
      type: Object,
      default: () => {
        return {}
      }
    },
    personBoardList: {
      type: Array,
      default: () => {
        return []
      }
    },
    staffStepList: {
      type: Array,
      default: () => {
        return []
      }
    },
    steps: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      innerVisible: false,
      currStepId: null,
      personSelection: [],
      staffSteps: [],
      clickDateArr: []
    }
  },
  computed: {
    formatterStep() {
      var formatterLabel = ""
      if (this.currStepId != null) {
        var currStepInfo = this.steps.find(
          (item) => item.id === this.currStepId
        )
        formatterLabel = currStepInfo.name
      }
      return formatterLabel
    }
  },
  methods: {
    stepRecordPersonSelectionChange(val) {
      this.personSelection = val
    },
    delStaff(index) {
      this.staffSteps.splice(index, 1)
    },
    addStaffStepsForPerson() {
      if (this.personSelection != null && this.personSelection.length > 0) {
        var staffStepCopyList = this.staffSteps
        this.staffSteps = []
        var newStaffStep
        for (var i = 0; i < this.personSelection.length; i++) {
          newStaffStep = {}
          newStaffStep.staffName = this.personSelection[i].staffName
          newStaffStep.staffId = this.personSelection[i].staffId
          newStaffStep.number = null
          this.staffSteps.push(newStaffStep)
        }
        if (staffStepCopyList != null && staffStepCopyList.length > 0) {
          for (var i = 0; i < staffStepCopyList.length; i++) {
            this.staffSteps.push(staffStepCopyList[i])
          }
        }
      } else {
        this.$message.warning('若想添加人员工步,请先选中人员!')
      }
    },
    saveStaffSteps() {
      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) {
        if (this.staffSteps != null && this.staffSteps.length > 0) {
          if (this.currStepId != null) {
            var stepRecord = {}
            stepRecord.id = this.parentInfo.stepRecordId
            stepRecord.operationTaskId = this.parentInfo.operationTaskId
            stepRecord.stepId = this.currStepId
            var stepStaffList = []
            var stepStaff
            for (var i = 0; i < this.staffSteps.length; i++) {
              stepStaff = {}
              stepStaff.number = this.staffSteps[i].number
              stepStaff.staffId = this.staffSteps[i].staffId
              stepStaffList.push(stepStaff)
            }
            stepRecord.stepStaffList = stepStaffList
            saveStepRecord(stepRecord)
              .then((response) => {
                if (response.data.code === 0) {
                  this.$message.success('人员工步保存成功!')
                  this.$emit(
                    'refreshStepRecordList',
                    this.parentInfo.operationTaskId
                  )
                  this.innerVisible = false
                } else {
                  this.$message.error('人员工步保存失败!')
                }
              })
              .catch((error) => {
                console.log(error)
                console.log('人员工步保存异常')
              })
          } else {
            this.$message.warning('请选择工步!')
          }
        } else {
          this.$message.warning('无人员工步数据可提交!')
        }
      }
    }
  },
  watch: {
    currshowlist() {
      this.innerVisible = this.currshowlist
      if (this.currshowlist) {
        this.clickDateArr = []
        this.staffSteps = []
        for (var i = 0; i < this.staffStepList.length; i++) {
          this.staffSteps.push(this.staffStepList[i])
        }
        this.currStepId = this.parentInfo.stepId
        this.$nextTick(() => {
          this.$refs.stepRecordPersonList.clearSelection()
        })
      }
    }
  }
}
</script>