zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-row type="flex" justify="space-between"
      ><el-col :span="15">
        <el-form
          :model="dataForm"
          :rules="dataRule"
          ref="dataForm"
          class="l-mes"
          label-width="80px"
        >
          <el-form-item label="工作站" prop="workstationName">
            <el-input
              class="innerClass"
              v-model="dataForm.workstationName"
              placeholder="请选择工作站"
              readonly
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="openWorkstationDialog()"
              ></el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="产出" prop="productNo">
            <el-input
              class="innerClass"
              v-model="dataForm.productNo"
              placeholder="请选择产出"
              readonly
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="openProductoutDialog()"
              ></el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="异常类型" prop="exceptionType">
            <el-select
              v-model="dataForm.exceptionType"
              style="width:100%;"
              placeholder="异常类型"
            >
              <el-option
                v-for="item in exceptionHandleTypeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="异常描述" prop="exceptionDescription">
            <el-input
              type="textarea"
              :rows="2"
              v-model="dataForm.exceptionDescription"
              placeholder="异常描述"
            ></el-input>
          </el-form-item>
          <el-form-item label="处理人" prop="processUserName">
            <el-input
              class="innerClass"
              v-model="dataForm.processUserName"
              placeholder="请选择处理人"
              readonly
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="openUserDialog()"
              ></el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="微信通知组" prop="notifierGroupId">
            <el-select
              v-model="dataForm.notifierGroupId"
              style="width:100%;"
              placeholder="微信通知组"
            >
              <el-option
                v-for="item in wxNoticeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input
              type="textarea"
              :rows="2"
              v-model="dataForm.remark"
              placeholder="备注"
            ></el-input>
          </el-form-item>
        </el-form> </el-col
      ><el-col :span="8">
        <div v-if="!dataForm.id">
          <el-upload
            class="upload-demo"
            action="/mes/exception/addQualityException"
            :headers="headers"
            :data="postData"
            :file-list="fileList"
            list-type="picture"
            :with-credentials="true"
            :auto-upload="false"
            :on-success="uploadSuccess"
            :on-error="uploadError"
            :limit="1"
            :on-exceed="handleExceed"
            :before-upload="beforeUpload"
            ref="exceptionUpload"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              只能上传jpg图片,且不超过2MB
            </div>
          </el-upload>
        </div>
        <div v-if="dataForm.id">
          <div v-for="(ele, index) in fileList" :key="index">
            <el-image
              :src="ele.url"
              fit="fill"
              :preview-src-list="[ele.url]"
            ></el-image>
          </div>
        </div> </el-col
    ></el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button
        type="primary"
        :disabled="isSubmit"
        v-thinclick="`dataFormSubmit`"
        >确定</el-button
      >
    </span>
    <workstation-dialog
      :currshowlist.sync="workstationVisible"
      @listenToWorkStationEvent="selectWorkstation"
    />
    <productout-dialog
      :currshowlist.sync="productoutVisible"
      :paramObj="paramObj"
      @listenToproductionEvent="selectProductout"
    />
    <user-dialog
      :currshowlist.sync="userVisible"
      @listenToUserEvent="selectUser"
    />
  </el-dialog>
</template>
 
<script>
import { getObj, putObj } from '@/api/quality/exception'
import { fetchList } from '@/api/quality/wxnotice'
import workstationDialog from '@/views/common/workstation.vue'
import productoutDialog from '@/views/common/productout.vue'
import { getStore } from '../../../util/store'
import { remote } from '@/api/admin/dict'
import userDialog from '@/views/common/user.vue'
 
export default {
  components: { workstationDialog, productoutDialog, userDialog },
  data() {
    return {
      paramObj: {},
      productoutVisible: false,
      workstationVisible: false,
      visible: false,
      dataForm: {
        id: 0,
        code: '',
        workstationId: 0,
        productoutId: 0,
        exceptionType: '',
        exceptionDescription: '',
        handleWay: '',
        handleUser: '',
        createTime: '',
        remark: '',
        workstationName: '',
        productNo: '',
        notifierGroupId: null,
        processUser: null,
        processUserName: null
      },
      dataRule: {
        workstationName: [
          { required: true, message: '工作站不能为空', trigger: 'blur' }
        ],
        productNo: [
          { required: true, message: '产出不能为空', trigger: 'blur' }
        ]
      },
      isSubmit: false,
      headers: {
        Authorization: 'Bearer ' + getStore({ name: 'access_token' })
      },
      postData: {},
      fileList: [],
      exceptionHandleTypeOptions: [],
      wxNoticeOptions: [],
      userVisible: false
    }
  },
  created() {
    this.getExceptionHandleType()
    this.getWxNoticeList()
  },
  methods: {
    init(id) {
      this.dataForm.workstationId = 0
      this.dataForm.productoutId = 0
      this.dataForm.id = id || 0
      this.fileList = []
      this.visible = true
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields()
        if (this.dataForm.id) {
          getObj(this.dataForm.id).then((response) => {
            this.dataForm = response.data.data
            this.fileList = response.data.data.urlList
          })
        }
      })
    },
    // 弹出工作站
    openWorkstationDialog() {
      this.workstationVisible = true
    },
    selectWorkstation(workstation) {
      if (workstation) {
        this.dataForm.workstationId = workstation.id
        this.paramObj = { workstationId: workstation.id }
        this.dataForm.workstationName = workstation.name
      }
    },
    openProductoutDialog() {
      if (this.dataForm.workstationId) {
        this.productoutVisible = true
      } else {
        this.$message.error('请先选择工作站')
      }
    },
    selectProductout(productout) {
      if (productout) {
        this.dataForm.productoutId = productout.id
        this.dataForm.productNo = productout.productNo
      }
    },
    handleExceed(files, fileList) {
      this.$message.warning('新增时,限制上传一个图片')
    },
    // 表单提交
    dataFormSubmit() {
      this.isSubmit = true
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          if (this.dataForm.id) {
            putObj(this.dataForm).then((data) => {
              this.$message.success('修改成功')
              this.visible = false
              this.isSubmit = false
              this.$emit('refreshDataList')
            })
          } else {
            this.postData.workstationId = this.dataForm.workstationId
            this.postData.productoutId = this.dataForm.productoutId
            this.postData.exceptionType = this.dataForm.exceptionType
            this.postData.exceptionDescription = this.dataForm.exceptionDescription
            this.postData.remark = this.dataForm.remark
            this.postData.notifierGroupId = this.dataForm.notifierGroupId
            this.postData.processUser = this.dataForm.processUser
            this.postData.processUserName = this.dataForm.processUserName
 
            this.$refs.exceptionUpload.submit()
            this.isSubmit = false
          }
        } else {
          this.isSubmit = false
        }
      })
    },
    uploadSuccess(response, file, fileList) {
      this.visible = false
      this.isSubmit = false
      this.$emit('refreshDataList')
      this.$message.success('添加成功')
    },
    uploadError(err, file, fileList) {
      // console.log(err)
      // this.$message.error('请先选择图片')
    },
    getExceptionHandleType() {
      remote('exception_handle_type').then((response) => {
        if (response.data.code === 0) {
          this.exceptionHandleTypeOptions = response.data.data
        } else {
          this.exceptionHandleTypeOptions = []
        }
      })
    },
    getWxNoticeList() {
      this.wxNoticeOptions = []
      fetchList({ current: 1, size: 1000 }).then((response) => {
        const resRecords = response.data.data.records
        resRecords.forEach((ele) => {
          this.wxNoticeOptions.push({
            value: ele.id,
            label: ele.groupName
          })
        })
      })
    },
    selectUser(param) {
      if (param) {
        this.dataForm.processUser = param.userId
        this.dataForm.processUserName = param.username
      }
    },
    openUserDialog() {
      this.userVisible = true
    },
    beforeUpload(file) {}
  }
}
</script>