schangxiang@126.com
2024-06-08 d939d095aa38879953884ea263eb45984b3876e7
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
<!--
 * @Author: 陈祝文 15821704398@163.com
 * @Date: 2023-03-17 10:33:58
 * @LastEditors: 陈祝文 15821704398@163.com
 * @LastEditTime: 2023-03-17 14:33:36
 * @FilePath: \iwara-scada-web\src\views\main\WorkPieceInfo\editForm.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <a-modal
    title="质量状态修改"
    :width="450"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <a-form-model :model="form" ref="formRef" :label-col="labelCol" :wrapper-col="wrapperCol" :rules="rules">
      <a-form-model-item label="质量状态" >
        <a-radio-group v-model="form.status">
          <a-radio v-for="item in statusArr" :key="item.value" :value="item.value">{{ item.title }}</a-radio>
        </a-radio-group>
      </a-form-model-item>
 
      <a-form-model-item label="工序" >
        <a-select allow-clear v-model="form.workingProcedureCurrent" placeholder="请选择工序">
          <a-select-option v-for="(item, index) in processSelectData" :key="index" :value="item.code">
            {{ item.name }}
          </a-select-option>
        </a-select>
      </a-form-model-item>
 
      <a-form-model-item label="密码" prop="pwd">
        <a-input v-model="form.pwd" type="password" placeholder="请输入密码"></a-input>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
 
<script>
import { updatePieceStatus } from '@/api/modular/main/WorkPieceInfoManage'
export default {
  props: {
    selectedRows: { type: Array, default: () => [] },
    processSelectData: { type: Array, default: () => [] }
  },
  emits: ['refresh'],
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 15 }
      },
      visible: false,
      confirmLoading: false,
      form: {
        status: '',
        pwd: ''
      },
      statusArr: [
        { value: '1', title: '合格' },
        { value: '2', title: '不合格' },
        { value: '3', title: '疑似' }
      ],
      rules: {
        status: [{ required: true, message: '质量状态不能为空', trigger: 'blur' }],
        workingProcedureCurrent: [{ required: true, message: '工序不能为空', trigger: 'blur' }],
        pwd: [{ required: true, message: '密码不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    handleSubmit() {
      this.$refs.formRef.validate((vali) => {
        if (vali) {
          // 判断是否选中同一种
          const status = this.selectedRows[0].qualityState
          console.log(status, 'status')
          const count = this.selectedRows.reduce((curr, item) => {
            if (item.qualityState == status) {
              curr++
            }
            return curr
          }, 0)
 
          if (count != this.selectedRows.length) {
            return this.$message.error('选中的质量状态包含多种')
          }
 
          this.confirmLoading = true
          const checkPiece = this.selectedRows.reduce((curr, item) => {
            curr.push({
              workPieceID: item.workPieceID,
              qualityHistoryState: item.qualityState,
              workingProcedureCurrent: item.workingProcedureCurrent,
              id: item.id
            })
            return curr
          }, [])
          const param = {
            workPieceInfoLst: checkPiece,
            qualityState: this.form.status,
            workingProcedureCurrent: this.form.workingProcedureCurrent,
            password: this.form.pwd
          }
          updatePieceStatus(param)
            .then((res) => {
              this.confirmLoading = false
              this.$message.success('修改成功')
              this.handleCancel()
              this.visible = false
              this.$emit('refresh')
            })
            .catch((err) => {
              console.log(err)
              this.confirmLoading = false
            })
        } else {
          this.confirmLoading = false
          this.$message.error('表单验证失败')
        }
      })
    },
    handleCancel() {
      this.form = {
        status: '',
        pwd: ''
      }
      this.visible = false
    }
  }
}
</script>