Blame view

antis-ncc-admin/src/views/LqLaundryFlow/send-dialog.vue 9.18 KB
1138c09e   李宇   feat(LqLaundryFlo...
1
  <template>
7d45b4d1   李宇   最新
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
  	<el-dialog title="创建送出记录" :visible.sync="visible" width="800px" :close-on-click-modal="false">
  		<el-form ref="form" :model="{ items }" label-width="110px">
  			<div
  				v-for="(item, index) in items"
  				:key="index"
  				class="form-block"
  			>
  				<div class="form-block-header">
  					<span class="form-block-title">记录 {{ index + 1 }}</span>
  					<el-button
  						v-if="items.length > 1"
  						type="text"
  						icon="el-icon-minus"
  						@click="removeItem(index)"
  					>
  						删除
  					</el-button>
  				</div>
  				<el-row :gutter="12">
  					<el-col :span="12">
  						<el-form-item :label="'门店'" :prop="`items.${index}.storeId`">
  							<el-select v-model="item.storeId" placeholder="请选择门店" filterable style="width: 100%">
  								<el-option
  									v-for="s in storeList"
  									:key="s.id"
  									:label="s.fullName"
  									:value="s.id"
  								/>
  							</el-select>
  						</el-form-item>
  					</el-col>
  					<el-col :span="12">
  						<el-form-item :label="'产品类型'" :prop="`items.${index}.productType`">
  							<el-select
  								v-model="item.productType"
  								placeholder="请选择产品类型"
  								clearable
  								filterable
  								style="width: 100%"
  							>
  								<el-option
  									v-for="p in productTypeOptions"
  									:key="p.Value"
  									:label="p.Name"
  									:value="p.Name"
  								/>
  							</el-select>
  						</el-form-item>
  					</el-col>
  				</el-row>
  				<el-row :gutter="12">
  					<el-col :span="12">
  						<el-form-item :label="'清洗商'" :prop="`items.${index}.laundrySupplierId`">
  							<el-select
  								v-model="item.laundrySupplierId"
  								placeholder="请选择清洗商"
  								filterable
  								style="width: 100%"
  								@change="val => handleSupplierChange(index, val)"
  							>
  								<el-option
  									v-for="sp in filteredSupplierList(item.productType)"
  									:key="sp.id"
  									:label="sp.supplierName"
  									:value="sp.id"
  								/>
  							</el-select>
  						</el-form-item>
  					</el-col>
  					<el-col :span="12">
  						<el-form-item label="清洗单价">
  							<el-input v-model="item.laundryPrice" placeholder="自动填充" disabled />
  						</el-form-item>
  					</el-col>
  				</el-row>
  				<el-row :gutter="12">
  					<el-col :span="12">
  						<el-form-item :label="'送出数量'" :prop="`items.${index}.quantity`">
  							<el-input-number v-model="item.quantity" :min="1" :precision="0" style="width: 100%" />
  						</el-form-item>
  					</el-col>
  					<el-col :span="12">
  						<el-form-item :label="'送出时间'" :prop="`items.${index}.sendTime`">
  							<el-date-picker
  								v-model="item.sendTime"
  								type="datetime"
  								value-format="yyyy-MM-dd HH:mm:ss"
  								format="yyyy-MM-dd HH:mm:ss"
  								placeholder="请选择送出时间"
  								style="width: 100%"
  							/>
  						</el-form-item>
  					</el-col>
  				</el-row>
  				<el-form-item label="备注">
  					<el-input v-model="item.remark" type="textarea" :rows="2" placeholder="请输入备注" />
  				</el-form-item>
  				<el-divider v-if="index !== items.length - 1" />
  			</div>
  			<el-form-item>
  				<el-button type="dashed" icon="el-icon-plus" @click="addItem">
  					新增一条记录
  				</el-button>
1138c09e   李宇   feat(LqLaundryFlo...
105
106
107
108
  			</el-form-item>
  		</el-form>
  		<div slot="footer" class="dialog-footer">
  			<el-button @click="visible = false">取消</el-button>
7d45b4d1   李宇   最新
109
110
111
  			<el-button type="primary" @click="submit" :loading="loading">
  				{{ items.length > 1 ? `批量提交(${items.length} 条)` : '确定' }}
  			</el-button>
1138c09e   李宇   feat(LqLaundryFlo...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  		</div>
  	</el-dialog>
  </template>
  
  <script>
  import request from '@/utils/request'
  import { getStoreSelector } from '@/api/extend/store'
  
  export default {
  	name: 'SendDialog',
  	data() {
  		return {
  			visible: false,
  			loading: false,
7d45b4d1   李宇   最新
126
  			items: [],
1138c09e   李宇   feat(LqLaundryFlo...
127
128
  			storeList: [],
  			supplierList: [],
6137a4e4   李宇   ```
129
  			allSupplierList: [], // 保存所有清洗商列表
7d45b4d1   李宇   最新
130
131
  			productTypeOptions: [],
  			defaultSendTime: ''
1138c09e   李宇   feat(LqLaundryFlo...
132
133
  		}
  	},
6137a4e4   李宇   ```
134
  	computed: {
6137a4e4   李宇   ```
135
  	},
1138c09e   李宇   feat(LqLaundryFlo...
136
137
138
139
140
141
  	mounted() {
  		this.initStoreList()
  		this.initSupplierList()
  		this.loadProductTypeOptions()
  	},
  	methods: {
7d45b4d1   李宇   最新
142
143
144
145
146
147
148
149
150
151
152
  		createEmptyItem() {
  			return {
  				storeId: '',
  				productType: '',
  				laundrySupplierId: '',
  				laundryPrice: 0,
  				quantity: 1,
  				sendTime: this.defaultSendTime,
  				remark: ''
  			}
  		},
1138c09e   李宇   feat(LqLaundryFlo...
153
154
155
  		// 初始化
  		init() {
  			this.visible = true
2036dd49   李宇   最新
156
157
158
159
160
161
162
163
  			// 格式化当前时间为 yyyy-MM-dd HH:mm:ss
  			const now = new Date()
  			const year = now.getFullYear()
  			const month = String(now.getMonth() + 1).padStart(2, '0')
  			const day = String(now.getDate()).padStart(2, '0')
  			const hours = String(now.getHours()).padStart(2, '0')
  			const minutes = String(now.getMinutes()).padStart(2, '0')
  			const seconds = String(now.getSeconds()).padStart(2, '0')
7d45b4d1   李宇   最新
164
165
166
  			this.defaultSendTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  
  			this.items = [this.createEmptyItem()]
1138c09e   李宇   feat(LqLaundryFlo...
167
168
  			this.$nextTick(() => {
  				if (this.$refs.form) {
7d45b4d1   李宇   最新
169
  					this.$refs.form.clearValidate && this.$refs.form.clearValidate()
1138c09e   李宇   feat(LqLaundryFlo...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  				}
  			})
  		},
  		// 初始化门店列表
  		initStoreList() {
  			getStoreSelector().then(res => {
  				if (res.code == 200 && res.data && res.data.list) {
  					this.storeList = res.data.list
  				}
  			}).catch(() => {
  				this.storeList = []
  			})
  		},
  		// 初始化清洗商列表
  		initSupplierList() {
  			request({
  				url: '/api/Extend/LqLaundrySupplier/GetList',
  				method: 'GET',
  				data: { currentPage: 1, pageSize: 1000, isEffective: 1 }
  			}).then(res => {
  				if (res.code == 200 && res.data && res.data.list) {
6137a4e4   李宇   ```
191
  					this.allSupplierList = res.data.list
1138c09e   李宇   feat(LqLaundryFlo...
192
193
194
  					this.supplierList = res.data.list
  				}
  			}).catch(() => {
6137a4e4   李宇   ```
195
  				this.allSupplierList = []
1138c09e   李宇   feat(LqLaundryFlo...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
  				this.supplierList = []
  			})
  		},
  		// 加载产品类型选项
  		loadProductTypeOptions() {
  			request({
  				url: '/api/Extend/LqStoreConsumableInventory/consumable-product-type',
  				method: 'GET'
  			}).then(res => {
  				if (res.code == 200 && res.data && Array.isArray(res.data)) {
  					this.productTypeOptions = res.data
  				} else {
  					this.productTypeOptions = []
  				}
  			}).catch(() => {
  				this.productTypeOptions = []
  			})
  		},
  		// 门店变化
  		handleStoreChange() {
  			// 可以在这里添加逻辑
  		},
7d45b4d1   李宇   最新
218
219
220
221
222
223
  		// 产品类型变化(当前实现中,不需要额外处理)
  		handleProductTypeChange() {},
  		// 按产品类型过滤清洗商
  		filteredSupplierList(productType) {
  			if (!productType) return this.allSupplierList
  			return this.allSupplierList.filter(supplier => supplier.productType === productType)
6137a4e4   李宇   ```
224
  		},
1138c09e   李宇   feat(LqLaundryFlo...
225
  		// 清洗商变化
7d45b4d1   李宇   最新
226
227
  		handleSupplierChange(index, value) {
  			const supplier = this.allSupplierList.find(item => item.id === value)
1138c09e   李宇   feat(LqLaundryFlo...
228
  			if (supplier) {
7d45b4d1   李宇   最新
229
  				this.$set(this.items[index], 'laundryPrice', supplier.laundryPrice || 0)
1138c09e   李宇   feat(LqLaundryFlo...
230
  			} else {
7d45b4d1   李宇   最新
231
  				this.$set(this.items[index], 'laundryPrice', 0)
1138c09e   李宇   feat(LqLaundryFlo...
232
233
  			}
  		},
7d45b4d1   李宇   最新
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
  		// 新增一条记录
  		addItem() {
  			this.items.push(this.createEmptyItem())
  		},
  		// 删除一条记录
  		removeItem(index) {
  			if (this.items.length === 1) return
  			this.items.splice(index, 1)
  		},
  		// 前端校验
  		validateItems() {
  			if (!this.items.length) {
  				this.$message.error('请至少填写一条记录')
  				return false
  			}
  			for (let i = 0; i < this.items.length; i++) {
  				const item = this.items[i]
  				if (!item.storeId) {
  					this.$message.error(`第 ${i + 1} 条:请选择门店`)
  					return false
1138c09e   李宇   feat(LqLaundryFlo...
254
  				}
7d45b4d1   李宇   最新
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
  				if (!item.productType) {
  					this.$message.error(`第 ${i + 1} 条:请选择产品类型`)
  					return false
  				}
  				if (!item.laundrySupplierId) {
  					this.$message.error(`第 ${i + 1} 条:请选择清洗商`)
  					return false
  				}
  				if (!item.quantity || item.quantity <= 0) {
  					this.$message.error(`第 ${i + 1} 条:请输入有效的送出数量`)
  					return false
  				}
  				// 产品类型与清洗商匹配校验
  				const supplier = this.allSupplierList.find(x => x.id === item.laundrySupplierId)
  				if (supplier && supplier.productType && supplier.productType !== item.productType) {
  					this.$message.error(`第 ${i + 1} 条:清洗商【${supplier.supplierName}】不支持清洗产品类型【${item.productType}】`)
  					return false
  				}
  			}
  			return true
  		},
  		// 提交(支持单条或批量)
  		async submit() {
  			if (!this.validateItems()) return
  			if (this.loading) return
  			this.loading = true
  			try {
  				const payloadItems = this.items.map(x => ({
  					storeId: x.storeId,
  					productType: x.productType,
  					laundrySupplierId: x.laundrySupplierId,
  					quantity: x.quantity,
  					sendTime: x.sendTime,
  					remark: x.remark
  				}))
  				const res = await request({
  					url: '/api/Extend/LqLaundryFlow/BatchSend',
1138c09e   李宇   feat(LqLaundryFlo...
292
  					method: 'POST',
7d45b4d1   李宇   最新
293
  					data: { items: payloadItems }
1138c09e   李宇   feat(LqLaundryFlo...
294
  				})
7d45b4d1   李宇   最新
295
296
297
298
299
300
301
302
303
304
  				if (res.code == 200) {
  					this.$message.success(res.msg || res.message || '创建成功')
  					this.visible = false
  					this.$emit('refresh')
  				} else {
  					this.$message.error(res.msg || res.message || '创建失败')
  				}
  			} finally {
  				this.loading = false
  			}
1138c09e   李宇   feat(LqLaundryFlo...
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  		}
  	},
  	watch: {
  		visible(val) {
  			if (!val) {
  				this.$refs.form && this.$refs.form.resetFields()
  			}
  		}
  	}
  }
  </script>
  
  <style lang="scss" scoped>
  .dialog-footer {
  	text-align: right;
  }
7d45b4d1   李宇   最新
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
  
  .form-block {
  	padding: 8px 0 0;
  	max-height: 300px;
  	overflow-y: scroll;
  }
  
  .form-block-header {
  	display: flex;
  	justify-content: space-between;
  	align-items: center;
  	margin-bottom: 4px;
  }
  
  .form-block-title {
  	font-weight: 600;
  	font-size: 13px;
  	color: #606266;
  }
1138c09e   李宇   feat(LqLaundryFlo...
340
  </style>