Fixiaobai
2023-11-15 a12fbf14327027e7081eea89a777cb3e3012c170
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
<template>
  <el-dialog
    :title=" type ?'修改节点': '新增节点' "
    :close-on-click-modal="false"
    :visible.sync="visible"
    append-to-body>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px" class="l-mes">
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item label="零件" prop="partId">
            <el-input v-model="partStr" placeholder="" readonly>
              <el-button slot="append" icon="el-icon-search" @click="openPartDialog()"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="数量" prop="qpa">
            <el-input v-model="dataForm.qpa" placeholder=""></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </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"/>
  </el-dialog>
</template>
 
<script>
  import {insertMpsStructureComponent, updateMpsStructureComponent} from '@/api/plan/masterproductionschedule'
  import {validateSixDecimalNotNull} from '@/util/validate'
  import PartDialog from '@/views/common/part'
 
  export default {
    components: {
      PartDialog
    },
    data() {
      return {
        visible: false,
        showPart: false,
        mpsId: 0,
        type: 0,
        dataForm: {
          qpa: '',
          label: '',
          partNo: '',
          partId: '',
        },
        dataRule: {
          qpa: [
            {required: true, message: '需求数量不能为空', trigger: 'blur'},
            {validator: validateSixDecimalNotNull, trigger: 'blur'}
          ],
          partId: [
            {required: true, message: '零件不能为空', trigger: 'blur'}
          ]
        }
      }
    },
    computed: {
      partStr: function () {
        return this.dataForm.partId ? (this.dataForm.label + '  ' + (this.dataForm.partNo ? this.dataForm.partNo : '') ) : ''
      }
    },
    methods: {
      clearDataForm() {
        this.dataForm = {
          qpa: '',
          label: '',
          partNo: '',
          partId: '',
        }
      },
      init(currentComponent, type) {
        this.type = type
        this.clearDataForm()
        if (this.type) {
          this.dataForm = currentComponent
          this.visible = true
        } else {
          this.mpsId = currentComponent.mpsId
          this.dataForm.parentId = currentComponent.id
          this.visible = true
        }
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if (this.type) {
              updateMpsStructureComponent(this.dataForm).then(response => {
                this.$message.success('修改成功')
                this.visible = false
              })
            } else {
              insertMpsStructureComponent(this.dataForm, this.mpsId).then(response => {
                this.$message.success('添加成功')
                this.visible = false
                this.$emit('refreshDataList', response.data.data)
              })
            }
          }
        })
      },
      // 零件选择
      openPartDialog() {
        this.showPart = true
      },
      selectPart(part) {
        if (part) {
          this.dataForm.partNo = part.partNo
          this.dataForm.label = part.partName
          this.dataForm.partId = part.id
          this.$refs['dataForm'].validateField('partId', valid => {
          })
        }
      },
    },
  }
</script>