assay-detail-table.vue
11.5 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
<template>
<!-- 化验明细:样品/数量/样号/送样编号 + 成份%(成分项按码单分厂区分,逐行填写) -->
<view class="sub-table">
<view class="sub-header">
<image class="sub-bar" src="/static/images/title.png" />
<text class="sub-title">化验明细</text>
<view class="add-btn" @click="addRow">
<text class="add-btn_text">+ 新增行</text>
</view>
</view>
<view class="sub-body">
<view v-if="!rows.length" class="empty-tip">暂无明细,请选择过磅品种后加载</view>
<view v-for="(row, idx) in rows" :key="'line-' + idx" class="card">
<view class="card-index">第 {{ idx + 1 }} 行</view>
<view class="card-delete" @click="delRow(idx)"><text>删除</text></view>
<view class="row">
<text class="label">送样编号</text>
<picker
class="picker-box"
mode="selector"
:range="getRowCodeLabels(row)"
@change="onSendCodeChange($event, idx)"
>
<view class="picker-value" :class="{ placeholder: !row.assayApplyCode }">
{{ row.assayApplyCode || '请选择送样编号' }}
</view>
</picker>
</view>
<view class="row">
<text class="label">样品</text>
<text class="value">{{ row.productName || '-' }}</text>
</view>
<view class="row">
<text class="label">数量</text>
<text class="value">{{ row.quantity === null || row.quantity === undefined || row.quantity === '' ? '-' : row.quantity }}</text>
</view>
<!-- 成份%(按分厂区分的成分项,逐行填写) -->
<view class="component-title">成份%</view>
<view class="component-grid">
<view v-for="key in componentKeys" :key="key" class="component-item">
<text class="component-label">{{ componentLabels[key] || key }}</text>
<input
class="component-input"
type="digit"
:value="row[key] === null || row[key] === undefined ? '' : String(row[key])"
placeholder="未填"
placeholder-class="component-placeholder"
@input="onComponentInput($event, idx, key)"
/>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import { COMPONENT_LABELS, ALL_COMPONENT_KEYS, getComponentKeys } from './component-config.js'
export default {
name: 'AssayDetailTable',
props: {
// 化验明细数据源(applyOptions 返回),供送样编号下拉与固定值使用
options: {
type: Array,
default: () => []
},
// 码单分厂名称,决定成份%项集合
workshopName: {
type: String,
default: ''
}
},
data() {
return {
componentLabels: COMPONENT_LABELS,
// 化验明细行数据
rows: []
}
},
computed: {
// 当前分厂对应的成分项 key 列表
componentKeys() {
return getComponentKeys(this.workshopName)
}
},
methods: {
// 构造行对象(初始化全部成分字段,保证响应式)
buildRow(item, index) {
const row = {
productName: (item && item.productName) || '',
productId: (item && item.productId) || '',
quantity: item ? item.quantity : '',
testCode: String(index + 1),
assayApplyCode: (item && item.assayApplyCode) || '',
assayApplyId: (item && item.assayApplyId) || ''
}
ALL_COMPONENT_KEYS.forEach(key => {
row[key] = (item && item[key] !== undefined && item[key] !== null) ? item[key] : null
})
return row
},
// 按化验明细数据源填充表格(每条明细一行,样号从1开始编号)
loadRows(options) {
this.rows = (options || []).map((item, index) => this.buildRow(item, index))
},
// 回显表格数据(修改时使用),样号按行序重新编号
setRows(list) {
this.rows = (list || []).map((item, index) => this.buildRow(item, index))
},
// 获取提交用明细行(含各行成分值,未填/分厂未包含的成分为 null)
getLines() {
return (this.rows || [])
.filter(row => row.assayApplyId)
.map(row => {
const line = { assayApplyId: row.assayApplyId }
ALL_COMPONENT_KEYS.forEach(key => {
const val = row[key]
line[key] = (val === undefined || val === null || val === '') ? null : Number(val)
})
return line
})
},
// 送样编号下拉标签(化验明细数据中所有的送样编号,排除已被其他行选中的,避免重复选择)
getRowCodeLabels(row) {
return this.getRowCodeOptions(row).map(it => it.label)
},
getRowCodeOptions(row) {
const selectedIds = (this.rows || [])
.filter(r => r !== row && r.assayApplyId)
.map(r => r.assayApplyId)
return (this.options || [])
.filter(item => item.assayApplyCode && !selectedIds.includes(item.assayApplyId))
.map(item => ({ label: item.assayApplyCode, value: item.assayApplyId }))
},
// 送样编号下拉变化:带出该送样编号对应的固定数据(成分值保留当前行已填写内容)
onSendCodeChange(e, index) {
const row = this.rows[index]
if (!row) return
const opt = this.getRowCodeOptions(row)[Number(e.detail.value)]
if (!opt) return
const item = (this.options || []).find(i => i.assayApplyId === opt.value) || {}
row.productId = item.productId || ''
row.assayApplyCode = item.assayApplyCode || ''
row.assayApplyId = item.assayApplyId || ''
row.productName = item.productName || ''
row.quantity = item.quantity !== undefined && item.quantity !== null ? item.quantity : ''
},
// 成份值输入:仅允许数字与小数点,空值重置为 null
onComponentInput(e, index, key) {
const row = this.rows[index]
if (!row) return
let value = String((e && e.detail && e.detail.value) == null ? '' : e.detail.value)
value = value.replace(/[^\d.]/g, '')
const parts = value.split('.')
if (parts.length > 2) {
value = parts[0] + '.' + parts.slice(1).join('')
}
row[key] = value === '' ? null : value
},
// 新增化验明细行:样品/数量为固定数据,样号按行序从1开始编号,成分值默认空
addRow() {
const fixed = (this.options || [])[0] || {}
this.rows.push(this.buildRow(fixed, this.rows.length))
},
// 删除指定化验明细行,删除后样号重新从1开始编号
delRow(index) {
if (index < 0 || index >= this.rows.length) return
this.rows.splice(index, 1)
this.rows.forEach((row, i) => {
row.testCode = String(i + 1)
})
}
}
}
</script>
<style lang="scss" scoped>
.sub-table {
background: #fff;
margin-bottom: 20rpx;
}
.sub-header {
display: flex;
align-items: center;
padding: 16rpx 24rpx 16rpx 32rpx;
.sub-bar { width: 6rpx; height: 32rpx; margin-right: 14rpx; }
.sub-title { font-size: 30rpx; font-weight: 600; color: rgba(0, 0, 0, 0.9); flex: 1; line-height: 42rpx; }
.add-btn {
height: 52rpx;
line-height: 52rpx;
padding: 0 24rpx;
border-radius: 8rpx;
background: $theme-primary;
.add-btn_text { font-size: 26rpx; color: #fff; }
}
}
.sub-body {
padding: 0 32rpx 24rpx;
.empty-tip {
text-align: center;
padding: 60rpx 0;
color: rgba(0, 0, 0, 0.4);
font-size: 28rpx;
}
.card {
position: relative;
background: #fafafa;
border-radius: 12rpx;
padding: 32rpx 28rpx 20rpx;
margin-bottom: 24rpx;
.card-index {
position: absolute;
top: 0;
right: 0;
background: rgba(24, 144, 255, 0.08);
color: $theme-primary;
font-size: 22rpx;
line-height: 36rpx;
padding: 0 16rpx;
border-bottom-left-radius: 12rpx;
border-top-right-radius: 12rpx;
}
.card-delete {
position: absolute;
top: 8rpx;
left: 12rpx;
padding: 4rpx 12rpx;
text { font-size: 24rpx; color: #d54941; }
}
.row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14rpx 0;
border-bottom: 1rpx dashed #f2f2f2;
&:last-of-type { border-bottom: none; }
.label {
flex-shrink: 0;
width: 220rpx;
font-size: 28rpx;
color: rgba(0, 0, 0, 0.6);
line-height: 40rpx;
}
.picker-box { flex: 1; }
.picker-value {
font-size: 28rpx;
color: rgba(0, 0, 0, 0.9);
line-height: 40rpx;
text-align: right;
&.placeholder { color: rgba(0, 0, 0, 0.4); }
}
.value {
flex: 1;
text-align: right;
font-size: 28rpx;
color: rgba(0, 0, 0, 0.9);
line-height: 40rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.component-title {
font-size: 28rpx;
font-weight: 600;
color: rgba(0, 0, 0, 0.9);
margin: 16rpx 0 4rpx;
}
.component-grid {
display: flex;
flex-wrap: wrap;
.component-item {
width: 33.33%;
box-sizing: border-box;
padding: 12rpx 8rpx 0 0;
.component-label {
display: block;
font-size: 24rpx;
color: rgba(0, 0, 0, 0.6);
line-height: 36rpx;
}
.component-input {
width: 100%;
height: 60rpx;
line-height: 60rpx;
margin-top: 6rpx;
padding: 0 16rpx;
border: 1rpx solid #e7e7e7;
border-radius: 8rpx;
font-size: 26rpx;
color: rgba(0, 0, 0, 0.9);
background: #fff;
box-sizing: border-box;
}
.component-placeholder { color: rgba(0, 0, 0, 0.3); }
}
}
}
}
</style>