Crunchy
2025-04-29 e5454b769d44a34af423bf87ac8a740bf8c20341
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<template>
  <div class="capacity-scope">
    <div class="search">
      <div>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
          <el-form-item label="实验室名称" prop="laboratoryName">
            <el-input size="small" placeholder="请输入" clearable v-model="queryParams.laboratoryName"
              @keyup.enter.native="refreshTable"></el-input>
          </el-form-item>
          <el-form-item label="实验室编码" prop="laboratoryNumber">
            <el-input size="small" placeholder="请输入" clearable v-model="queryParams.laboratoryNumber"
              @keyup.enter.native="refreshTable"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="mini" @click="refreshTable">查询</el-button>
            <el-button size="mini" @click="refresh">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div>
        <el-button size="small" type="primary" @click="openAdd('add')" icon="el-icon-plus">新增</el-button>
      </div>
    </div>
    <div class="table">
      <lims-table :tableData="tableData" :column="column" :height="'calc(100vh - 250px)'" @pagination="pagination"
        :page="page" :tableLoading="tableLoading"></lims-table>
    </div>
    <!--    新增实验室-->
    <el-dialog :title="formTitle" :visible.sync="addDia" width="450px">
      <el-form ref="laboratoryForm" :model="laboratoryForm" :rules="userRules" label-position="right"
        label-width="100px">
        <el-form-item label="实验室名称" prop="laboratoryName">
          <el-input v-model="laboratoryForm.laboratoryName" size="small" clearable></el-input>
        </el-form-item>
        <el-form-item label="场所编码" prop="laboratoryNumber">
          <el-input v-model="laboratoryForm.laboratoryNumber" size="small" clearable></el-input>
        </el-form-item>
        <el-form-item label="实验室代号" prop="laboratoryCode">
          <el-input v-model="laboratoryForm.laboratoryCode" size="small" clearable></el-input>
        </el-form-item>
        <el-form-item label="负责人" prop="head">
          <el-input v-model="laboratoryForm.head" size="small" clearable></el-input>
        </el-form-item>
        <el-form-item label="负责人电话" prop="phoneNumber">
          <el-input v-model="laboratoryForm.phoneNumber" size="small" clearable></el-input>
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="laboratoryForm.address" size="small" clearable></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="reset">取 消</el-button>
        <el-button type="primary" @click="customAdd" :loading="loading">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="印章管理" :visible.sync="fileVisible" width="60vw">
      <div class="btns">
        <el-button size="medium" type="primary" @click="openUpload">更新印章</el-button>
      </div>
      <lims-table :tableData="fileComponentData" :column="fileComponentDataColumn" @pagination="fileComponentPagination"
        height="500px" :page="fileComponentPage" :tableLoading="fileComponentTableLoading"></lims-table>
    </el-dialog>
    <el-dialog title="更新印章" :visible.sync="upFileVisible" width="400px">
      <el-form ref="dataForm" :model="dataForm" :rules="dataFormRules" label-position="right" label-width="80px">
        <el-form-item label="印章类型" prop="type">
          <el-cascader v-model="dataForm.type" :options="options" :show-all-levels="false" :props="props"
            placeholder="请选择" size="small" style="width:100%" collapse-tags clearable></el-cascader>
        </el-form-item>
        <el-form-item label="印章图片" prop="address">
          <el-upload class="avatar-uploader" :action="action" :headers="uploadHeader"
            accept='image/jpg,image/jpeg,image/png' :show-file-list="false" :on-success="handleSuccess"
            :on-change="beforeUpload" ref="upload" :on-error="onError">
            <img v-if="dataForm.address" :src="javaApi + '/img/' + dataForm.address" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="upFileVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmConnect" :loading="loading">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import limsTable from "@/components/Table/lims-table.vue";
import {
  addParameter,
  addSeal,
  delParameter,
  selectItemParameter,
  selectSeal,
  upParameter
} from "@/api/structural/laboratoryScope";
import { getCertificationDetail } from "@/api/structural/laboratory";
export default {
  components: {
    limsTable
 
  },
  computed: {
    action() {
      return this.javaApi + '/deviceScope/uploadFile'
    }
  },
  data() {
    return {
      queryParams: {
        laboratoryName: '',
        laboratoryNumber: '',
      },
      tableData: [],
      tableLoading: false,
      column: [
        { label: '实验室名称', prop: 'laboratoryName' },
        { label: '场所编码', prop: 'laboratoryNumber' },
        { label: '实验室代号', prop: 'laboratoryCode' },
        { label: '负责人', prop: 'head' },
        { label: '负责人电话', prop: 'phoneNumber' },
        { label: '地址', prop: 'address' },
        { label: '创建人', prop: 'createUserName' },
        { label: '创建时间', prop: 'createTime' },
        {
          dataType: 'action',
          label: '操作',
          operation: [
            {
              name: '编辑',
              type: 'text',
              clickFun: (row) => {
                this.openAdd('edit', row);
              },
            },
            {
              name: '删除',
              type: 'text',
              clickFun: (row) => {
                this.delete(row);
              },
            },
            {
              name: '印章管理',
              type: 'text',
              clickFun: (row) => {
                this.fileManagement(row);
              },
            },
          ]
        }
      ],
      page: {
        total: 0,
        size: 10,
        current: 1
      },
      addDia: false,
      formTitle: '',
      laboratoryForm: {
 
      },
      operationType: '',
      userRules: {
        laboratoryName: [{ required: true, message: '请输入实验室名称', trigger: 'blur' }],
        laboratoryNumber: [{ required: true, message: '请输入场所编码', trigger: 'blur' }],
        head: [{ required: true, message: '请输入负责人', trigger: 'blur' }],
        phoneNumber: [{ required: true, message: '请输入负责人电话', trigger: 'blur' }],
      },
      currentRow: {},
      fileComponentTableLoading: false,
      fileComponentData: [],
      fileComponentDataColumn: [
        { label: '实验室名称', prop: 'laboratoryName' },
        { label: '印章图片', prop: 'address', dataType: 'image' },
        { label: '印章类型', prop: 'type' },
      ],
      fileComponentPage: {
        total: 0,
        size: 10,
        current: 1,
        layout: 'total, prev, pager, next'
      },
      fileVisible: false,
      upFileVisible: false,
      loading: false,
      dataForm: {
        type: '',
        address: '',
      },
      dataFormRules: {
        type: [{ required: true, message: '请选择印章类型', trigger: 'change' }],
        address: [{ required: false, message: '请上传图片', trigger: 'change' }],
      },
      props: { multiple: false, emitPath: false, },
      options: [
        {
          value: '实验室资质',
          label: '实验室资质',
          children: []
        },
        {
          value: '委托报告',
          label: '委托报告',
          children: null
        },
        {
          value: '进厂报告',
          label: '进厂报告',
          children: null
        },
      ],
    }
  },
  mounted() {
    this.refreshTable()
  },
  methods: {
    refreshTable() {
      this.tableLoading = true
      selectItemParameter({ ...this.page, ...this.queryParams }).then(res => {
        this.tableLoading = false
        if (res.code === 200) {
          this.tableData = res.data.records
          this.page.total = res.data.total
        }
      }).catch(err => {
        this.tableLoading = false
      })
    },
    // 重置
    refresh() {
      this.resetForm('queryForm')
      this.refreshTable()
    },
    // 分页切换
    pagination(page) {
      this.page.size = page.limit
      this.refreshTable()
    },
    openAdd(type, row) {
      this.formTitle = type === 'add' ? '新增实验室' : '编辑实验室'
      this.operationType = type
      if (type === 'edit') {
        this.laboratoryForm = this.HaveJson(row)
      }
      this.addDia = true
    },
    // 提交新增、编辑实验室表单
    customAdd() {
      this.$refs['laboratoryForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          if (this.operationType === 'add') {
            addParameter(this.laboratoryForm).then(res => {
              this.loading = false
              if (res.code !== 200) return
              this.$message.success('新增成功')
              this.refreshTable()
              this.reset()
            }).catch(err => {
              this.loading = false
            })
          } else {
            upParameter(this.laboratoryForm).then(res => {
              this.loading = false
              if (res.code !== 200) return
              this.$message.success('修改成功')
              this.refreshTable()
              this.reset()
            }).catch(err => {
              this.loading = false
            })
          }
        }
      })
    },
    reset() {
      this.resetForm('laboratoryForm')
      this.addDia = false
    },
    // 删除实验室
    delete(row) {
      this.$confirm('是否删除当前数据?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        delParameter({ id: row.id }).then(res => {
          this.$message.success('删除成功')
          this.refreshTable()
        })
      }).catch(() => { })
    },
    // 打开印章管理弹框
    fileManagement(row) {
      this.fileVisible = true;
      this.fileComponentTableLoading = true
      this.currentRow = row
      this.getFileComponentList()
    },
    getFileComponentList() {
      selectSeal({ id: this.currentRow.id, ...this.fileComponentPage }).then(res => {
        this.fileComponentTableLoading = false
        if (res.code === 200) {
          this.fileComponentData = res.data.records
          this.fileComponentPage.total = res.data.total
        }
      }).catch(err => {
        this.fileComponentTableLoading = false
      })
    },
    fileComponentPagination(page) {
      this.fileComponentPage.size = page.limit
      this.getFileComponentList()
    },
    // 打开更新印章弹框
    openUpload() {
      this.dataForm.type = '';
      this.dataForm.address = '';
      this.upFileVisible = true;
      this.getCertificationOperation()
    },
    // 查询印章类型
    getCertificationOperation() {
      const params = {
        current: -1,
        size: -1,
      }
      getCertificationDetail(params).then(res => {
        this.options[0].children = res.data.records.map(m => {
          m.value = m.name;
          m.label = m.name;
          return m
        });
      })
    },
    // 提交更新印章
    confirmConnect() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          addSeal({ labId: this.currentRow.id, ...this.dataForm }).then(res => {
            this.loading = false;
            this.getFileComponentList()
            this.upFileVisible = false;
          })
        }
      })
    },
    handleSuccess(response,) {
      if (response.code === 200) {
        this.dataForm.address = response.data.url
      }
    },
    beforeUpload(file, type) {
      if (file.size > 1024 * 1024 * 10) {
        this.$message.error('上传文件不超过10M');
        this.$refs.upload.clearFiles()
        return false;
      } else {
        return true;
      }
    },
    onError(err, file, fileList, type) {
      this.$message.error('上传失败')
      this.$refs.upload.clearFiles()
    },
  }
}
</script>
<style scoped>
.search {
  height: 46px;
  display: flex;
  justify-content: space-between;
}
 
.btns {
  text-align: right;
  margin-bottom: 10px;
}
 
::v-deep .el-dialog__body {
  padding-top: 8px !important;
}
 
.avatar-uploader ::v-deep .el-upload {
  border: 1px dashed #666666;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
 
.avatar-uploader ::v-deep .el-upload:hover {
  border-color: #409EFF;
}
 
.avatar-uploader-icon {
  font-size: 20px;
  color: #8c939d;
  width: 90px;
  height: 90px;
  line-height: 90px;
  text-align: center;
}
 
.avatar {
  width: 90px;
  height: 90px;
  display: block;
}
</style>