add.vue
17 KB
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
<template>
<view class="page">
<scroll-view class="scroll" scroll-y>
<!-- 基础信息 -->
<uni-list>
<!-- 码单编号(弹窗选择) -->
<uni-list-item class="select-item" :class="form.weighingTicketCode ? 'is-filled' : 'is-empty'" clickable
@click="openTicketSheet" :rightText="form.weighingTicketCode || '请选择码单'" showArrow>
<template v-slot:body>
<view class="item-title"><text class="required">*</text><text>码单编号</text></view>
</template>
</uni-list-item>
<!-- 日期(选择码单后带出) -->
<uni-list-item class="select-item" :class="form.reportDate ? 'is-filled' : 'is-empty'">
<template v-slot:body>
<view class="item-title"><text class="required">*</text><text>日期</text></view>
</template>
<template v-slot:footer>
<view class="picker-value" :class="{ placeholder: !form.reportDate }">
{{ form.reportDate || '选择码单后带出' }}
</view>
</template>
</uni-list-item>
<!-- 客户名称(选择码单后带出) -->
<uni-list-item class="select-item" :class="form.supplierName ? 'is-filled' : 'is-empty'">
<template v-slot:body>
<view class="item-title"><text class="required">*</text><text>客户名称</text></view>
</template>
<template v-slot:footer>
<view class="picker-value" :class="{ placeholder: !form.supplierName }">
{{ form.supplierName || '选择码单后带出' }}
</view>
</template>
</uni-list-item>
<!-- 计划编号 -->
<uni-list-item class="select-item" :class="form.procurementPlanId ? 'is-filled' : 'is-empty'">
<template v-slot:body>
<view class="item-title"><text class="required">*</text><text>计划编号</text></view>
</template>
<template v-slot:footer>
<picker mode="selector" :range="planLabels" @change="onPlanChange" :disabled="!planOptions.length">
<view class="picker-value" :class="{ placeholder: !form.procurementPlanId }">
{{ getPlanLabel() || '请选择计划编号' }}
</view>
</picker>
</template>
</uni-list-item>
<!-- 过磅品种 -->
<uni-list-item class="select-item" :class="form.productId ? 'is-filled' : 'is-empty'">
<template v-slot:body>
<view class="item-title"><text class="required">*</text><text>过磅品种</text></view>
</template>
<template v-slot:footer>
<picker mode="selector" :range="productLabels" @change="onProductChange" :disabled="!productOptions.length">
<view class="picker-value" :class="{ placeholder: !form.productId }">
{{ getProductLabel() || '请选择过磅品种' }}
</view>
</picker>
</template>
</uni-list-item>
</uni-list>
<!-- 化验明细:样品/数量/样号/送样编号 + 成份%(成分项按码单分厂区分) -->
<AssayDetailTable ref="detailTable" :options="applyDetailOptions" :workshop-code="ticketWorkshopCode" :workshop-name="ticketWorkshopName" />
</scroll-view>
<view class="footer">
<button class="btn submit" type="primary" @click="onSubmit">保存</button>
</view>
<RelateSelectSheet :visible.sync="ticketSheet.visible" title="选择码单" :multiple="false"
:fetchFn="ticketSheet.fetchFn" :display-fields="ticketSheet.displayFields"
row-key="id" :selectedKeys.sync="ticketSheet.selectedKeys" @confirm="onTicketConfirm" />
</view>
</template>
<script>
import RelateSelectSheet from '@/components/relate-select/index.vue'
import AssayDetailTable from './assay-detail-table.vue'
import {
assayReportTicketPageApi,
assayReportPlanOptionsApi,
assayReportProductOptionsApi,
assayReportApplyOptionsApi,
assayReportCreateApi
} from '@/api/procure-manage/assayReport.js'
export default {
name: 'AddMaterialTest',
components: { RelateSelectSheet, AssayDetailTable },
data() {
return {
form: {
weighingTicketId: '',
weighingTicketCode: '',
reportDate: '',
supplierName: '',
procurementPlanId: '',
productId: ''
},
// 选中的码单行对象,供回显与分厂成分联动使用
selectedTicketRow: null,
// 计划编号下拉选项(所选码单下的计划)
planOptions: [],
// 过磅品种下拉选项(所选计划下的品种)
productOptions: [],
// 化验明细数据源(applyOptions 返回),供明细子组件送样编号下拉与固定值使用
applyDetailOptions: [],
ticketSheet: {
visible: false,
fetchFn: null,
displayFields: [
{ label: '码单编号', field: 'code' },
{ label: '供应商', field: 'supplierName' },
{ label: '分厂', field: 'workshopName' },
{ label: '创建人', field: 'createBy' },
{ label: '完成时间', field: 'completeTime' }
],
selectedKeys: []
}
}
},
computed: {
// 码单分厂编码/名称,决定化验明细成份项集合
ticketWorkshopCode() {
return (this.selectedTicketRow && this.selectedTicketRow.workshopCode) || ''
},
ticketWorkshopName() {
return (this.selectedTicketRow && this.selectedTicketRow.workshopName) || ''
},
planLabels() {
return (this.planOptions || []).map(it => it.label)
},
productLabels() {
return (this.productOptions || []).map(it => it.label)
}
},
created() {
this.ticketSheet.fetchFn = this.fetchTickets.bind(this)
},
methods: {
// 码单选择弹窗数据源(可选过磅码单分页,合并筛选条件)
fetchTickets({ pageIndex, pageSize, extra }) {
const keyword = (extra && extra.keyword) || ''
const params = {
pageIndex,
pageSize,
code: keyword || undefined
}
return assayReportTicketPageApi(params).then(res => {
const _data = (res && res.data) || {}
const records = _data.datas || _data.list || _data.records || []
const totalCount = _data.totalCount || _data.count || 0
const hasNext = _data.hasNext || false
return { records, totalCount, hasNext }
}).catch(() => ({ records: [], totalCount: 0, hasNext: false }))
},
openTicketSheet() {
this.ticketSheet.selectedKeys = this.form.weighingTicketId ? [this.form.weighingTicketId] : []
this.ticketSheet.visible = true
},
// 码单选择回调:带出日期/客户名称,联动刷新计划编号下拉、按分厂刷新成分表格
onTicketConfirm({ items }) {
const row = (items || [])[0]
if (!row) {
this.selectedTicketRow = null
this.form.weighingTicketId = ''
this.form.weighingTicketCode = ''
this.form.reportDate = ''
this.form.supplierName = ''
this.resetDownStream()
return
}
this.selectedTicketRow = row
this.form.weighingTicketId = row.id || ''
this.form.weighingTicketCode = row.code || ''
// 选择码单后带出日期与客户名称
this.form.reportDate = String(row.completeTime || '').slice(0, 10)
this.form.supplierName = row.supplierName || ''
// 切换码单后重置计划编号、品种及化验明细(成分项随分厂名变化由明细子组件自动刷新)
this.resetDownStream()
this.loadPlanOptions(row.id)
},
resetDownStream() {
this.form.procurementPlanId = ''
this.form.productId = ''
this.planOptions = []
this.productOptions = []
this.applyDetailOptions = []
const detailTable = this.$refs.detailTable
detailTable && detailTable.setRows && detailTable.setRows([])
},
// 根据所选码单加载计划编号下拉选项
loadPlanOptions(ticketId) {
assayReportPlanOptionsApi(ticketId)
.then(res => {
const list = (res && res.data) || []
this.planOptions = (list || []).map(item => ({
label: item.planCode,
value: item.planId
}))
})
.catch(() => {
this.planOptions = []
})
},
getPlanLabel() {
const found = (this.planOptions || []).find(it => it.value === this.form.procurementPlanId)
return found ? found.label : ''
},
// 计划编号改选后:重置品种并按所选计划刷新过磅品种下拉
onPlanChange(e) {
const opt = (this.planOptions || [])[Number(e.detail.value)]
if (!opt) return
this.form.procurementPlanId = opt.value
this.form.productId = ''
this.productOptions = []
this.applyDetailOptions = []
const detailTable = this.$refs.detailTable
detailTable && detailTable.setRows && detailTable.setRows([])
assayReportProductOptionsApi({
ticketId: this.form.weighingTicketId || undefined,
planId: opt.value
})
.then(res => {
const list = (res && res.data) || []
this.productOptions = (list || []).map(item => ({
label: item.productName,
value: item.productId
}))
})
.catch(() => {
this.productOptions = []
})
},
getProductLabel() {
const found = (this.productOptions || []).find(it => it.value === this.form.productId)
return found ? found.label : ''
},
// 过磅品种改选后:按码单/计划/品种加载化验明细并填充表格
onProductChange(e) {
const opt = (this.productOptions || [])[Number(e.detail.value)]
if (!opt) return
this.form.productId = opt.value
this.applyDetailOptions = []
const detailTable = this.$refs.detailTable
detailTable && detailTable.setRows && detailTable.setRows([])
this.loadApplyDetail()
},
// 加载化验明细数据
loadApplyDetail() {
assayReportApplyOptionsApi({
ticketId: this.form.weighingTicketId || undefined,
planId: this.form.procurementPlanId || undefined,
productId: this.form.productId || undefined
})
.then(res => {
const list = (res && res.data) || []
this.applyDetailOptions = (list || []).map(item => ({
assayApplyId: item.assayApplyId || item.id || '',
assayApplyLineId: item.assayApplyLineId || '',
assayApplyCode: item.assayApplyCode || '',
sampleCode: item.sampleCode || '',
productName: item.productName || '',
category: item.category || '',
productId: item.productId || '',
quantity: item.quantity
}))
// 默认按化验明细填充表格,样号从1开始编号
const detailTable = this.$refs.detailTable
detailTable && detailTable.loadRows && detailTable.loadRows(this.applyDetailOptions)
})
.catch(() => {
this.applyDetailOptions = []
})
},
validate() {
const f = this.form
if (!f.weighingTicketId) return this.tip('请选择码单编号')
if (!f.reportDate) return this.tip('日期不能为空')
if (!f.procurementPlanId) return this.tip('请选择计划编号')
if (!f.productId) return this.tip('请选择过磅品种')
return true
},
tip(msg) {
uni.showToast({ title: msg, icon: 'none' })
return false
},
async onSubmit() {
if (!this.validate()) return
const confirmRes = await new Promise(resolve => {
uni.showModal({ title: '提示', content: '确定保存原料化验报告单吗?', confirmText: '确定', cancelText: '取消', success: resolve })
})
if (!(confirmRes && confirmRes.confirm)) return
const detailTable = this.$refs.detailTable
const lines = (detailTable && detailTable.getLines && detailTable.getLines()) || []
uni.showLoading({ title: '提交中...', mask: true })
assayReportCreateApi({
weighingTicketId: this.form.weighingTicketId,
reportDate: this.form.reportDate,
procurementPlanId: this.form.procurementPlanId,
productId: this.form.productId,
lines
})
.then(() => {
uni.hideLoading()
uni.showToast({ title: '保存成功', icon: 'none' })
try { uni.setStorageSync('MATERIAL_TEST_LIST_NEED_REFRESH', '1') } catch (e) {}
setTimeout(() => { uni.navigateBack() }, 400)
})
.catch(e => {
uni.hideLoading()
uni.showToast({ title: (e && (e.msg || e.message)) || '保存失败', icon: 'none' })
})
}
}
}
</script>
<style lang="scss" scoped>
.page {
display: flex;
flex-direction: column;
height: 100%;
}
.scroll {
flex: 1;
padding: 12rpx 0 200rpx !important;
}
.footer {
z-index: 2;
position: fixed;
left: 0;
right: 0;
bottom: 0;
padding: 32rpx;
padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
background: #fff;
box-shadow: 0 -8rpx 24rpx rgba(0, 0, 0, 0.06);
.btn {
height: 80rpx;
line-height: 80rpx;
border-radius: 12rpx;
font-size: 32rpx;
}
.submit {
background: $theme-primary;
color: #fff;
}
}
::v-deep .uni-list {
.uni-easyinput {
display: flex;
.uni-input-input {
color: rgba(0, 0, 0, 0.9);
}
}
.uni-input-placeholder {
z-index: 1;
}
.uni-input-input {
background-color: #ffffff;
}
background: transparent;
&-item {
&__extra-text {
font-size: 32rpx;
}
&__content-title {
font-size: 32rpx;
color: rgba(0, 0, 0, 0.9);
}
&__container {
padding: 32rpx;
.item-title,
.uni-list-item__content {
flex: none;
min-height: 48rpx;
line-height: 48rpx;
font-size: 32rpx;
position: relative;
width: 240rpx;
margin-right: 32rpx;
color: rgba(0, 0, 0, 0.9);
.required {
color: red;
position: absolute;
top: 50%;
transform: translateY(-50%);
left: -16rpx;
}
}
}
&.select-item {
&.is-empty {
.uni-list-item__extra-text {
color: rgba(0, 0, 0, 0.4) !important;
}
}
&.is-filled {
.uni-list-item__extra-text {
color: rgba(0, 0, 0, 0.9) !important;
}
}
}
}
}
.picker-value {
font-size: 32rpx;
color: rgba(0, 0, 0, 0.9);
line-height: 48rpx;
text-align: right;
min-height: 48rpx;
&.placeholder {
color: rgba(0, 0, 0, 0.4);
}
}
</style>