zss
2023-11-17 2518e47a3ac999978fbf14612c967c3bbf421d25
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
<template>
  <el-dialog
    width="60%"
    title="编辑物料"
    top="5vh"
    :visible.sync="innerVisible"
    append-to-body
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
    class="part-dialog"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      label-width="120px"
      class="l-mes"
    >
      <el-form-item label="零件" prop="partId">
        <el-input v-model="dataForm.partName" placeholder="" readonly>
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="openPartDialog()"
          ></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>
    <div slot="footer" class="dialog-footer">
      <el-button @click="innerVisible = false">取 消</el-button>
      <el-button
        type="primary"
        :disabled="isSubmit"
        v-thinclick="`saveSelectRow`"
        >保 存</el-button
      >
    </div>
    <!-- 选择弹框 -->
    <part-dialog
      :currshowlist.sync="showPart"
      @listenToPartEvent="selectPart"
    />
  </el-dialog>
</template>
<script>
import {
  addOperationTaskMaterial,
  updateOperationTaskMaterial,
  getOperationTaskMaterial
} from '@/api/plan/operationtask'
import { mapGetters } from 'vuex'
import { validateSixDecimalNotNull } from '@/util/validate'
import PartDialog from '@/views/common/part'
export default {
  props: {
    currshowlist: {
      type: Boolean,
      default: false
    },
    materialObj: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      innerVisible: false,
      isSubmit: false,
      showPart: false,
      dataForm: {
        partName: null,
        partNo: null,
        partId: null,
        qpa: null,
        id: 0,
        operationTaskId: null,
        quantityRequired: null
      },
      dataRule: {
        partId: [{ required: true, message: '零件不能为空', trigger: 'blur' }],
        qpa: [
          {
            required: true,
            message: '单位产出所需数量不能为空',
            trigger: 'blur'
          },
          { validator: validateSixDecimalNotNull, trigger: 'blur' }
        ]
      }
    }
  },
  components: { PartDialog },
  watch: {
    currshowlist() {
      this.innerVisible = this.currshowlist
      this.initData()
      if (this.currshowlist) {
        this.$nextTick(() => {
          // this.getData()
          if (this.materialObj.id != null) {
            // 查询已有需求物料信息
            getOperationTaskMaterial(this.materialObj.id).then((response) => {
              const resData = response.data
              if (resData.code === 0) {
                const resObj = resData.data
                this.dataForm.partName = resObj.partName
                this.dataForm.partNo = resObj.partNo
                this.dataForm.partId = resObj.partId
                this.dataForm.qpa = resObj.qpa
                this.dataForm.id = resObj.id
                this.dataForm.quantityRequired = resObj.quantityRequired
              }
            })
          }
        })
      }
    }
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  created() {},
  methods: {
    saveSelectRow() {
      this.isSubmit = true
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          // 去除零件编号两边的空格
          if (this.dataForm.id) {
            updateOperationTaskMaterial(this.dataForm)
              .then((data) => {
                this.$message.success('修改成功')
                this.innerVisible = false
                this.isSubmit = false
                this.$emit('refreshOperationMaterialList')
              })
              .catch((error) => {
                this.isSubmit = false
                console.log(error)
              })
          } else {
            addOperationTaskMaterial(this.dataForm)
              .then((data) => {
                this.$message.success('添加成功')
                this.innerVisible = false
                this.isSubmit = false
                this.$emit('refreshOperationMaterialList')
              })
              .catch((error) => {
                this.isSubmit = false
                console.log(error)
              })
          }
        } else {
          this.isSubmit = false
        }
      })
    },
    initData() {
      this.dataForm.partName = null
      this.dataForm.partNo = null
      this.dataForm.partId = null
      this.dataForm.qpa = null
      this.dataForm.id = 0
      this.dataForm.operationTaskId = this.materialObj.opTaskId
      this.dataForm.quantityRequired = null
    },
    // 零件选择
    openPartDialog() {
      this.showPart = true
    },
    selectPart(part) {
      if (part) {
        this.dataForm.partNo = part.partNo
        this.dataForm.partName = part.partName
        this.dataForm.partId = part.id
      }
    }
  }
}
</script>