zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
<template>
  <div>
    <j-modal
      :title='title'
      :width='width'
      :visible='visible'
      switchFullscreen
      @ok='handleOk'
      :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
      @cancel='handleCancel'
      cancelText='关闭'>
 
      <a-spin :spinning='confirmLoading'>
        <j-form-container :disabled='disableSubmit'>
          <a-form-model ref='form' :model='model' :rules='validatorRules' slot='detail'>
            <a-row>
              <a-col :span='24'>
                <a-form-model-item label='选择产品' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='prodId'>
                  <j-search-select-tag @change='proChange($event)' placeholder='请选择产品' v-model='model.prodId'
                                       :dictOptions='proOptions' />
                </a-form-model-item>
              </a-col>
              <a-col :span='24'>
                <a-form-model-item label='批次类型' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='batchType'>
                  <j-dict-select-tag @change='batchTypeChange($event)' v-model='model.batchType' title='批次类型'
                                     dictCode='testing_batch_type' placeholder='请选择批次类型' />
                </a-form-model-item>
              </a-col>
              <a-col :span='24'>
                <a-form-model-item label='批次号' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='batchCode'>
                  <a-input v-model='model.batchCode' placeholder='请输入批次号'></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span='24'>
                <a-form-model-item label='型号通道' :labelCol='labelCol' :wrapperCol='wrapperCol'>
                  <div style='width: 100%;background-color: white;border: 1px dashed lightgray;padding: 0 10px'>
                    <a-list item-layout='horizontal' :data-source='channelInfoList'>
                      <a-list-item slot='renderItem' slot-scope='item, index'>
                        <div style='display: flex;align-items: center;'>
                          <span>{{ item.modelName }}</span>
                          <span><a-input-number :min='1' style='width: 60px;margin: 0 10px' v-model='item.sampleNum'></a-input-number></span>
                          <span>个</span>
                          <span style='margin-left: 20px'>通道:</span>
<!--                          <a-radio-group v-model='item.channelNum'>
                            <a-radio v-for='i in item.num' :value='i' :key='i'>
                              {{ i }}
                            </a-radio>
                          </a-radio-group>-->
 
                          <a-checkbox-group
                            v-model="item.channelNum"
                            :options="createOptions(item.num)"
                            @change="onCbChange(item,$event)"
                          />
                        </div>
                      </a-list-item>
                    </a-list>
                  </div>
                </a-form-model-item>
              </a-col>
 
            </a-row>
          </a-form-model>
        </j-form-container>
      </a-spin>
 
 
    </j-modal>
  </div>
</template>
 
<script>
import { queryProductList, queryProModelList } from '@api/lims'
import { postAction } from '@api/manage'
 
export default {
  name: 'LimsTestingBatchModal2',
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      proOptions: [],
      channelInfoList: [],
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        prodId: [{ required: true, message: '请选择产品!' }],
        batchType: [{ required: true, message: '请选择鉴定类型!' }],
        batchCode: [{ required: true, message: '批次号不能为空!' }]
 
      },
      url: {
        add: '/lims/testing/batch/add',
        edit: '/lims/testing/batch/edit',
        queryById: '/lims/testing/batch/queryById'
      }
    }
  },
  methods: {
    add() {
      this.visible = true
      this.initOptions()
 
    },
    edit(record) {
      this.visible = true
 
    },
    close() {
      this.$emit('close')
      this.model = {}
      this.channelInfoList = []
      this.proOptions = []
      this.visible = false
    },
    handleOk() {
      console.info('handleOk')
      this.submitForm()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    //生成checkbox选项
    createOptions(num){
      let array = []
      for (let i = 1; i <= num; i++) {
        array.push(i +'')
      }
      return array;
    },
    //选择checkbox
    onCbChange(item,checked){
      console.info(item)
      console.info(checked)
 
    },
 
    //选择批次类型
    batchTypeChange(value) {
      if (value) {
        this.generateBatchCode(value)
      }
 
    },
    //选择产品
    proChange(value) {
      console.info(value)
      this.queryProModel(value)
    },
    submitForm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          console.info('valid')
          //校验通道信息是否填写正确
          let flag = false
          console.info(this.channelInfoList)
          for (let i = 0; i <this.channelInfoList.length ; i++) {
            let item =  this.channelInfoList[i]
            if(item.channelNum){
              this.channelInfoList[i].channels =  item.channelNum.join(",")
              if(item.sampleNum && item.channels){
                flag  = true
              }
            }
 
          }
          console.info(flag)
          //校验通过
          if(flag){
            this.$message.success("校验通过")
            this.model.channelInfoList = this.channelInfoList
            this.handleAdd()
          }else{
            this.$message.warning("请检查通道信息是否填写正确")
          }
        }
      })
    },
    //添加
    handleAdd(){
      this.confirmLoading = true
      postAction(this.url.add,this.model).then(res=>{
        console.info(res)
        if(res.success){
          this.$message.success(res.message)
          this.close()
          this.submitCallback()
        }else {
          this.$message.error(res.message)
        }
      }).finally(() => {
        this.confirmLoading = false;
      })
 
    },
 
    //生成批次号
    generateBatchCode(value) {
      const date = new Date()
      const year = date.getFullYear()
      let month = date.getMonth() + 1
      let day = date.getDate()
      var hour = date.getHours() // 获取小时
      var minute = date.getMinutes() // 获取分钟
      var second = date.getSeconds() // 获取秒
      if (month < 10) month = '0' + month
      if (day < 10) day = '0' + day
      if (hour < 10) hour = '0' + hour
      if (minute < 10) minute = '0' + minute
      if (second < 10) second = '0' + second
 
      let batchCode = value + '' + year + month + day + hour + minute + second
 
      this.model.batchCode = batchCode
 
    },
    initOptions() {
      //产品列表
      queryProductList({ 'pageNo': 1, 'pageSize': 1000 }).then(res => {
        if (res.success) {
          let result = res.result.records
          this.proOptions = []
          if (result) {
            result.forEach(item => {
              this.proOptions.push({ 'text': item.name, 'value': item.id })
            })
          }
        }
 
      })
 
    },
    queryProModel(proId) {
      if(!proId){
 
        return false
      }
      //产品型号列表
      queryProModelList({ 'prodId': proId, 'pageNo': 1, 'pageSize': 1000 }).then(res => {
        console.info(res)
        if (res.success) {
          this.channelInfoList = []
          res.result.records.forEach(item => {
            let channel = { modelId:item.id,modelName:item.modelName, num: item.channelNum,modelCode:item.modelCode }
            this.channelInfoList.push(channel)
          })
        }
      })
    }
 
  }
}
</script>
 
<style scoped>
 
</style>