Fixiaobai
2023-11-16 4bf457a5c8433c9ec6f0ec86b2c1c20c5e667391
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
<template>
  <el-dialog
    append-to-body
    :title="title"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      label-width="120px"
      class="l-mes"
    >
      <el-form-item label="零件" prop="partId">
        <el-input v-model="partStr" placeholder="" readonly>
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="openPartDialog()"
            :disabled="partIsDisabled"
          ></el-button>
        </el-input>
      </el-form-item>
      <el-form-item label="消耗工序" prop="operationId">
        <el-input v-model="dataForm.operationName" placeholder="" readonly>
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="openOperationDialog()"
          ></el-button>
        </el-input>
      </el-form-item>
      <el-form-item label="单位产出所需数量" prop="qpa">
        <el-input v-model="dataForm.qpa" placeholder=""></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
 
    <!-- 选择弹框 -->
    <part-dialog
      :currshowlist.sync="showPart"
      @listenToPartEvent="selectPart"
    />
    <operation-dialog
      :currshowlist.sync="showOperation"
      @listenToOperationEvent="selectOperation"
    />
  </el-dialog>
</template>
 
<script>
import PartDialog from '@/views/common/part'
import OperationDialog from '@/views/common/operation'
import { validateSixDecimalNotNull } from '@/util/validate'
 
export default {
  components: {
    PartDialog,
    OperationDialog
  },
  props: {
    partIsDisabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      title: '',
      visible: false,
      showPart: false,
      showOperation: false,
      dataForm: {
        partName: '',
        partNo: '',
        partId: '',
        operationName: '',
        operationNo: '',
        operationId: '',
        qpa: ''
      },
      dataRule: {
        partId: [{ required: true, message: '零件不能为空', trigger: 'blur' }],
        operationId: [
          { required: true, message: '工序不能为空', trigger: 'blur' }
        ],
        qpa: [
          {
            required: true,
            message: '单位产出所需数量不能为空',
            trigger: 'blur'
          },
          { validator: validateSixDecimalNotNull, trigger: 'blur' }
        ]
      },
      components: [],
      index: -1
    }
  },
  computed: {
    partStr: function() {
      return this.dataForm.partId
        ? this.dataForm.partName + '  ' + this.dataForm.partNo
        : ''
    }
  },
  methods: {
    init(row, index, components) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields()
        this.components = components
        if (row) {
          this.title = '修改结构组件'
          this.index = index
          this.dataForm = JSON.parse(JSON.stringify(row))
        } else {
          this.title = '新增结构组件'
          this.index = -1
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          if (this.index !== -1) {
            this.$emit('modifyComp', {
              partId: this.dataForm.partId,
              partName: this.dataForm.partName,
              partNo: this.dataForm.partNo,
              operationId: this.dataForm.operationId,
              operationName: this.dataForm.operationName,
              operationNo: this.dataForm.operationNo,
              qpa: this.dataForm.qpa
            })
            this.visible = false
          } else {
            this.$message.success('添加成功')
            this.components.push(JSON.parse(JSON.stringify(this.dataForm)))
            this.visible = false
          }
        }
      })
    },
 
    // 零件选择
    openPartDialog() {
      this.showPart = true
    },
    selectPart(part) {
      if (part) {
        this.dataForm.partNo = part.partNo
        this.dataForm.partName = part.partName
        this.dataForm.partId = part.id
        this.$refs.dataForm.validateField('partId', (valid) => {})
      }
    },
    // 工序选择
    openOperationDialog() {
      this.showOperation = true
    },
    selectOperation(operation) {
      if (operation) {
        this.dataForm.operationName = operation.name
        this.dataForm.operationNo = operation.operationNo
        this.dataForm.operationId = operation.id
      }
    }
  }
}
</script>