spring
2025-04-08 d1faa4f23135dabad9e2948842ba415eddfcc08b
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
<template>
  <div>
    <el-dialog :title="operationType === 'add' ? '新增' : '编辑'" :visible.sync="editFormDia" width="500px"
      @close="closeDia">
      <el-form ref="editForm" :model="editForm" :rules="editFormRules" label-width="120px" label-position="right">
        <el-form-item label="场所:" prop="laboratoryId">
          <el-select v-model="editForm.laboratoryId" clearable placeholder="请选择" size="small" style="width: 100%">
            <el-option v-for="item in laboratoryList" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检验对象:" prop="specimenName">
          <el-input v-model="editForm.specimenName" clearable size="small"></el-input>
        </el-form-item>
        <el-form-item label="检验对象EN:" prop="specimenNameEn">
          <el-input v-model="editForm.specimenNameEn" clearable size="small"></el-input>
        </el-form-item>
        <!-- <el-form-item label="对象代号:" prop="code">
          <el-input v-model="editForm.code" clearable size="small"></el-input>
        </el-form-item> -->
        <el-form-item label="对象类型:" prop="objectType">
          <el-select v-model="editForm.objectType" clearable placeholder="请选择" size="small" style="width: 100%">
            <el-option v-for="item in dict.type.product_classification" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车间:" prop="objectType" v-if="editForm.objectType == '原辅材' || editForm.objectType == '包材'">
          <el-select v-model="editForm.workShopId" placeholder="请选择" size="small">
            <el-option v-for="item in workshopList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDia">取 消</el-button>
        <el-button :loading="editLoad" type="primary" @click="handleEdit">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
 
import { obtainItemParameterList } from "@/api/structural/laboratoryScope";
import { addTestObject, upTestObject } from "@/api/structural/capability";
import { selectWorkShop } from "@/api/structural/workshop.js"
 
export default {
  name: "EditForm",
  // import 引入的组件需要注入到对象中才能使用
  dicts: ['product_classification'],
  components: {},
  data() {
    // 这里存放数据
    return {
      editFormDia: false,
      editLoad: false,
      editForm: {
        id: '',
        laboratoryId: '', // 场所
        specimenName: '', // 检验对象
        specimenNameEn: '', // 检验对象EN
        // code: '', // 对象代号
        objectType: '', // 对象类型
        workShopId: '',//车间
      },
      laboratoryList: [],
      editFormRules: {
        laboratoryId: [
          { required: true, message: '请选择场所', trigger: 'change' }
        ],
        specimenName: [
          { required: true, message: '请输入检验对象', trigger: 'blur' }
        ],
        objectType: [
          { required: true, message: '请输入对象类型', trigger: 'change' }
        ],
        workShopId: [
          { required: true, message: '请选择车间', trigger: 'change' }
        ],
      },
      operationType: '',
      workshopList: []
    }
  },
  // 方法集合
  methods: {
    selectWorkShop() {
      selectWorkShop({ size: -1, current: -1 }).then(res => {
        this.workshopList = res.data.records
      })
    },
    openDia(type, row) {
      this.operationType = type
      this.obtainItemParameterList()
      this.selectWorkShop()
      this.editFormDia = true
      if (type === 'add') {
        this.resetForm("editForm");
        this.editForm = {}
      } else {
        this.editForm = { ...row }
      }
    },
    // 提交编辑
    handleEdit() {
      this.$refs.editForm.validate(valid => {
        if (valid) {
          this.editLoad = true
          if (this.editForm.objectType != '原辅材' && this.editForm.objectType != '包材') {
            this.editForm.workShopId = ''
          }
          this.editForm.workShopName = this.editForm.workShopId ? this.workshopList.find(m => m.id == this.editForm.workShopId).name : ''
          if (this.editForm.id) {
            // 修改
            upTestObject(this.editForm).then(res => {
              this.editLoad = false
              if (res.code === 500) {
                return
              }
              this.$message.success('修改成功')
              this.closeDia()
              this.$emit('refreshList')
            }).catch(e => {
              this.editLoad = false
            })
          } else {
            // 新增
            addTestObject(this.editForm).then(res => {
              this.editLoad = false
              if (res.code === 500) {
                return
              }
              this.$message.success('添加成功')
              this.closeDia()
              this.$emit('refreshList')
            }).catch(e => {
              this.editLoad = false
            })
          }
        }
      })
    },
    // 关闭弹框
    closeDia() {
      this.editFormDia = false
      this.resetForm("editForm");
    },
    // 获取场所下拉框的值
    obtainItemParameterList() {
      obtainItemParameterList().then(res => {
        let data = []
        res.data.forEach(a => {
          data.push({
            label: a.laboratoryName,
            value: a.id
          })
        })
        this.laboratoryList = data
      })
    },
  },
}
</script>
 
<style scoped></style>