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
<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      label-width="160px"
      class="l-mes"
    >
      <el-row>
        <el-col :span="20">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="dataForm.remark" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="检测标准编号(计划)" prop="moTestStandardId">
            <el-select
              v-model="dataForm.moTestStandardId"
              placeholder=""
              filterable
              style="width: 100%"
              @change="selectChanged"
            >
              <el-option
                v-for="item in dataForm.testStandardList"
                :key="item.id"
                :label="item.standardNo"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="20">
          <el-form-item label="已有的合格数量" prop="qtyArrived">
            <el-input v-model="dataForm.qtyArrived" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="不合格数量" prop="unqualifiedArrived">
            <el-input
              v-model="dataForm.unqualifiedArrived"
              placeholder=""
              @change="updataQtyArrived()"
            ></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>
  </el-dialog>
</template>
 
<script>
import { getApplyPart, batchUpdateApplyPart } from '@/api/quality/apply'
import {
  accSub,
  validateInteger,
  validatePositiveInteger,
  validateSixDecimalPositive,
  validateSixDecimalPositives
} from '../../../util/validate'
 
export default {
  data() {
    return {
      booleanOptions: [
        { value: true, label: '是' },
        { value: false, label: '否' }
      ],
      visible: false,
      unqualifiedArrivedNumber: '',
      dataForm: {
        id: 0,
        isQualified: null,
        testStandardNo: '',
        moTestStandardId: 0,
        remark: '',
        testStandardList: [],
        unqualifiedArrived: '',
        qtyArrived: ''
      },
      dataRule: {
        unqualifiedArrived: [
          { validator: validateSixDecimalPositives, trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields()
        if (this.dataForm.id) {
          getApplyPart(this.dataForm.id).then((response) => {
            this.dataForm = response.data.data
            this.qtyArrivedNumber = this.dataForm.qtyArrived
            this.unqualifiedArrivedNumber = this.dataForm.unqualifiedArrived
          })
        }
      })
    },
    updataQtyArrived() {
      if (
        Number(this.dataForm.unqualifiedArrived) > Number(this.qtyArrivedNumber)
      ) {
        this.$message.error('不合格数量不能超过合格数量')
        this.dataForm.qtyArrived = this.qtyArrivedNumber
        this.dataForm.unqualifiedArrived = this.unqualifiedArrivedNumber
        return
      }
      if (this.dataForm.unqualifiedArrived < 0) {
        return
      }
      var number = accSub(
        this.dataForm.unqualifiedArrived,
        this.unqualifiedArrivedNumber
      )
      this.dataForm.qtyArrived = accSub(this.qtyArrivedNumber, number)
    },
    selectChanged(value) {
      if (value) {
        const testStandard = this.dataForm.testStandardList.find(
          (e) => e.id === value
        )
        if (testStandard && testStandard.standardNo) {
          this.dataForm.testStandardNo = testStandard.standardNo
        }
      }
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          if (this.dataForm.id) {
            const arr = []
            arr.push(this.dataForm)
            batchUpdateApplyPart(arr, 0).then((data) => {
              this.$message.success('修改成功')
              this.visible = false
              this.$emit('refreshDataList')
            })
          }
        }
      })
    }
  }
}
</script>