Blame view

antis-ncc-admin/src/views/lqInventory/usage-multi-form.vue 10.5 KB
1138c09e   李宇   feat(LqLaundryFlo...
1
2
3
  <template>
  	<el-dialog title="添加使用记录" :close-on-click-modal="false" :visible.sync="visible"
  		class="NCC-dialog NCC-dialog_center" lock-scroll width="900px">
97151af6   李宇   feat(lqInventory)...
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
  		<el-form ref="elForm" :model="dataForm" size="small" label-width="120px" label-position="right" :rules="rules">
  			<!-- 审批信息 -->
  			<el-row :gutter="15">
  				<el-col :span="12">
  					<el-form-item label="审批人" prop="approverId">
  						<el-select v-model="dataForm.approverId" placeholder="请选择审批人(财务老师或库管)" clearable filterable
  							:style='{"width":"100%"}' @change="onApproverChange">
  							<el-option v-for="approver in approverOptions" :key="approver.id" :label="approver.label"
  								:value="approver.id" />
  						</el-select>
  					</el-form-item>
  				</el-col>
  				<el-col :span="12">
  					<el-form-item label="申请门店" prop="applicationStoreId">
  						<el-select v-model="dataForm.applicationStoreId" placeholder="请选择申请门店" clearable filterable
  							:style='{"width":"100%"}'>
  							<el-option v-for="store in storeOptions" :key="store.id" :label="store.dm"
  								:value="store.id" />
  						</el-select>
  					</el-form-item>
  				</el-col>
  				<el-col :span="24">
  					<el-form-item label="备注" prop="remarks">
  						<el-input v-model="dataForm.remarks" type="textarea" :rows="2" placeholder="请输入备注(可选)"
  							:style='{"width":"100%"}' maxlength="500" show-word-limit />
  					</el-form-item>
  				</el-col>
  			</el-row>
  			<el-divider></el-divider>
  			<!-- 使用记录列表 -->
1138c09e   李宇   feat(LqLaundryFlo...
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
  			<div class="usage-items-container">
  				<div v-for="(item, index) in dataForm.usageItems" :key="index" class="usage-item-row">
  					<el-row :gutter="15">
  						<el-col :span="12">
  							<el-form-item label="产品" :prop="`usageItems.${index}.productId`"
  								:rules="rules.productId">
  								<el-select v-model="item.productId" placeholder="请选择产品" clearable filterable
  									:style='{"width":"100%"}' @change="onProductChange(item, index)">
  									<el-option v-for="product in productOptions" :key="product.id"
  										:label="product.productName" :value="product.id" />
  								</el-select>
  							</el-form-item>
  						</el-col>
  						<el-col :span="12">
  							<el-form-item label="门店" :prop="`usageItems.${index}.storeId`"
  								:rules="rules.storeId">
  								<el-select v-model="item.storeId" placeholder="请选择门店" clearable filterable
  									:style='{"width":"100%"}'>
  									<el-option v-for="store in storeOptions" :key="store.id" :label="store.dm"
  										:value="store.id" />
  								</el-select>
  							</el-form-item>
  						</el-col>
  						<el-col :span="12">
  							<el-form-item label="使用数量"
  								:prop="`usageItems.${index}.usageQuantity`" :rules="rules.usageQuantity">
  								<el-input-number v-model="item.usageQuantity" placeholder="数量" :min="1" :precision="0"
  									:style='{"width":"100%"}' />
  							</el-form-item>
  						</el-col>
  						<el-col :span="12">
  							<el-form-item label="使用时间"
  								:prop="`usageItems.${index}.usageTime`" :rules="rules.usageTime">
  								<el-date-picker v-model="item.usageTime" type="datetime" placeholder="使用时间"
  									value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss"
  									:style='{"width":"100%"}' />
  							</el-form-item>
  						</el-col>
  						<el-col :span="24" v-if="dataForm.usageItems.length > 1">
  							<div class="item-actions">
  								<el-button type="text" icon="el-icon-delete" @click="removeItem(index)"
  									class="delete-btn">删除</el-button>
  							</div>
  						</el-col>
  					</el-row>
  					<el-divider v-if="index < dataForm.usageItems.length - 1"></el-divider>
  				</div>
  			</div>
  			<div class="add-item-btn">
  				<el-button type="text" icon="el-icon-plus" @click="addItem()">添加一条记录</el-button>
  			</div>
  		</el-form>
  		<span slot="footer" class="dialog-footer">
  			<el-button @click="visible = false">取 消</el-button>
  			<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">确 定</el-button>
  		</span>
  	</el-dialog>
  </template>
  
  <script>
  import request from '@/utils/request'
  
  export default {
97151af6   李宇   feat(lqInventory)...
97
  		data() {
1138c09e   李宇   feat(LqLaundryFlo...
98
99
100
101
  		return {
  			visible: false,
  			btnLoading: false,
  			dataForm: {
97151af6   李宇   feat(lqInventory)...
102
103
104
  				approverId: '',
  				applicationStoreId: '',
  				remarks: '',
1138c09e   李宇   feat(LqLaundryFlo...
105
106
107
108
109
110
111
112
113
114
115
116
  				usageItems: [
  					{
  						productId: '',
  						storeId: '',
  						usageTime: '',
  						usageQuantity: 1,
  						relatedConsumeId: ''
  					}
  				]
  			},
  			productOptions: [],
  			storeOptions: [],
97151af6   李宇   feat(lqInventory)...
117
  			approverOptions: [],
1138c09e   李宇   feat(LqLaundryFlo...
118
  			rules: {
97151af6   李宇   feat(lqInventory)...
119
120
121
122
123
124
  				approverId: [
  					{ required: true, message: '请选择审批人', trigger: 'change' }
  				],
  				applicationStoreId: [
  					{ required: true, message: '请选择申请门店', trigger: 'change' }
  				],
1138c09e   李宇   feat(LqLaundryFlo...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  				productId: [
  					{ required: true, message: '请选择产品', trigger: 'change' }
  				],
  				storeId: [
  					{ required: true, message: '请选择门店', trigger: 'change' }
  				],
  				usageQuantity: [
  					{ required: true, message: '请输入使用数量', trigger: 'blur' }
  				],
  				usageTime: [
  					{ required: true, message: '请选择使用时间', trigger: 'change' }
  				]
  			}
  		}
  	},
  		methods: {
  		init() {
  			this.visible = true
  			this.dataForm = {
97151af6   李宇   feat(lqInventory)...
144
145
146
  				approverId: '',
  				applicationStoreId: '',
  				remarks: '',
1138c09e   李宇   feat(LqLaundryFlo...
147
148
149
150
151
152
153
154
155
156
157
158
  				usageItems: [
  					{
  						productId: '',
  						storeId: '',
  						usageTime: '',
  						usageQuantity: 1,
  						relatedConsumeId: ''
  					}
  				]
  			}
  			this.initProductOptions()
  			this.initStoreOptions()
97151af6   李宇   feat(lqInventory)...
159
  			this.initApproverOptions()
1138c09e   李宇   feat(LqLaundryFlo...
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
  		},
  		initProductOptions() {
  			request({
  				url: '/api/Extend/LqProduct/GetList',
  				method: 'GET',
  				data: {
  					currentPage: 1,
  					pageSize: 1000,
  					onShelfStatus: 1  // 只获取上架的产品
  				}
  			}).then(res => {
  				if (res.code == 200 && res.data && res.data.list) {
  					// 过滤出上架的产品
  					this.productOptions = res.data.list.filter(product => product.onShelfStatus === 1)
  				}
  			}).catch(() => {
  				this.productOptions = []
  			})
  		},
  		initStoreOptions() {
  			request({
  				url: '/api/Extend/LqMdxx',
  				method: 'GET',
  				data: {
  					currentPage: 1,
  					pageSize: 1000
  				}
  			}).then(res => {
  				if (res.data && res.data.list) {
  					this.storeOptions = res.data.list
  				}
  			}).catch(() => {
  				this.storeOptions = []
  			})
  		},
97151af6   李宇   feat(lqInventory)...
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
  		initApproverOptions() {
  			// 获取财务老师和库管列表
  			Promise.all([
  				request({
  					url: '/api/Extend/user',
  					method: 'GET',
  					data: {
  						page: 1,
  						pageSize: 1000,
  						gw: '主管'
  					}
  				}),
  				// request({
  				// 	url: '/api/Extend/user',
  				// 	method: 'GET',
  				// 	data: {
  				// 		page: 1,
  				// 		pageSize: 1000,
  				// 		gw: '经理'
  				// 	}
  				// })
  			]).then(([financeRes, storekeeperRes]) => {
  				this.approverOptions = []
  				// 添加财务老师
  				if (financeRes.code == 200 && financeRes.data && financeRes.data.list) {
  					financeRes.data.list.forEach(item => {
  						this.approverOptions.push({
  							id: item.id,
  							label: `${item.realName || item.name || item.userName}(主管)`
  						})
  					})
  				}
  				// // 添加库管
  				// if (storekeeperRes.code == 200 && storekeeperRes.data && storekeeperRes.data.list) {
  				// 	storekeeperRes.data.list.forEach(item => {
  				// 		this.approverOptions.push({
  				// 			id: item.id,
  				// 			label: `${item.realName || item.name || item.userName}(库管)`
  				// 		})
  				// 	})
  				// }
  			}).catch(() => {
  				this.approverOptions = []
  			})
  		},
  		onApproverChange() {
  			// 审批人选择变化时的处理
  		},
1138c09e   李宇   feat(LqLaundryFlo...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
  		onProductChange(item, index) {
  			// 产品选择变化时的处理
  		},
  		addItem() {
  			this.dataForm.usageItems.push({
  				productId: '',
  				storeId: '',
  				usageTime: '',
  				usageQuantity: 1,
  				relatedConsumeId: ''
  			})
  		},
  		removeItem(index) {
  			if (this.dataForm.usageItems.length > 1) {
  				this.dataForm.usageItems.splice(index, 1)
  			} else {
  				this.$message({
  					type: 'warning',
  					message: '至少保留一条记录'
  				})
  			}
  		},
  		dataFormSubmit() {
97151af6   李宇   feat(lqInventory)...
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
  			// 验证审批信息
  			if (!this.dataForm.approverId) {
  				this.$message({
  					type: 'error',
  					message: '请选择审批人'
  				})
  				return false
  			}
  			if (!this.dataForm.applicationStoreId) {
  				this.$message({
  					type: 'error',
  					message: '请选择申请门店'
  				})
  				return false
  			}
  
1138c09e   李宇   feat(LqLaundryFlo...
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
  			// 验证所有表单项
  			let isValid = true
  			this.dataForm.usageItems.forEach((item, index) => {
  				if (!item.productId) {
  					this.$message({
  						type: 'error',
  						message: `第${index + 1}条记录:请选择产品`
  					})
  					isValid = false
  				}
  				if (!item.storeId) {
  					this.$message({
  						type: 'error',
  						message: `第${index + 1}条记录:请选择门店`
  					})
  					isValid = false
  				}
  				if (!item.usageQuantity || item.usageQuantity <= 0) {
  					this.$message({
  						type: 'error',
  						message: `第${index + 1}条记录:请输入使用数量`
  					})
  					isValid = false
  				}
  				if (!item.usageTime) {
  					this.$message({
  						type: 'error',
  						message: `第${index + 1}条记录:请选择使用时间`
  					})
  					isValid = false
  				}
  			})
  
  			if (!isValid) {
  				return false
  			}
  
  			this.btnLoading = true
  			// 转换日期时间为ISO格式
  			const usageItems = this.dataForm.usageItems.map(item => {
  				let usageTime = item.usageTime
  				// 如果日期时间不是ISO格式,转换为ISO格式
  				if (usageTime && !usageTime.includes('T')) {
  					const date = new Date(usageTime)
  					usageTime = date.toISOString()
  				}
  				return {
  					productId: item.productId,
  					storeId: item.storeId,
  					usageTime: usageTime,
  					usageQuantity: item.usageQuantity,
  					relatedConsumeId: item.relatedConsumeId || ''
  				}
  			})
  			request({
  				url: '/api/Extend/LqInventoryUsage/BatchCreate',
  				method: 'POST',
  				data: {
97151af6   李宇   feat(lqInventory)...
340
341
342
  					approverId: this.dataForm.approverId,
  					applicationStoreId: this.dataForm.applicationStoreId,
  					remarks: this.dataForm.remarks || '',
1138c09e   李宇   feat(LqLaundryFlo...
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
  					usageItems: usageItems
  				}
  			}).then(res => {
  				this.btnLoading = false
  				this.$message({
  					type: 'success',
  					message: res.msg || '添加成功',
  					onClose: () => {
  						this.visible = false
  						this.$emit('refresh')
  					}
  				})
  			}).catch(() => {
  				this.btnLoading = false
  			})
  		}
  	}
  }
  </script>
  
  <style lang="scss" scoped>
  .usage-items-container {
  	padding: 10px 0;
  }
  
  .usage-item-row {
  	margin-bottom: 10px;
  }
  
  .item-actions {
  	display: flex;
  	justify-content: flex-end;
  	margin-top: 10px;
  
  	.delete-btn {
  		color: #F56C6C;
  
  		&:hover {
  			color: #f78989;
  		}
  	}
  }
  
  .add-item-btn {
  	margin-top: 10px;
  	text-align: center;
  	padding: 10px 0;
  	border-top: 1px dashed #dcdfe6;
  }
  </style>