Blame view

antis-ncc-admin/src/views/LqLaundryFlow/send-dialog.vue 7.53 KB
1138c09e   李宇   feat(LqLaundryFlo...
1
2
3
4
5
6
7
8
9
  <template>
  	<el-dialog title="创建送出记录" :visible.sync="visible" width="600px" :close-on-click-modal="false">
  		<el-form ref="form" :model="form" :rules="rules" label-width="120px">
  			<el-form-item label="门店" prop="storeId">
  				<el-select v-model="form.storeId" placeholder="请选择门店" filterable style="width: 100%" @change="handleStoreChange">
  					<el-option v-for="item in storeList" :key="item.id" :label="item.fullName" :value="item.id" />
  				</el-select>
  			</el-form-item>
  			<el-form-item label="产品类型" prop="productType">
6137a4e4   李宇   ```
10
  				<el-select v-model="form.productType" placeholder="请选择产品类型" clearable filterable style="width: 100%" @change="handleProductTypeChange">
1138c09e   李宇   feat(LqLaundryFlo...
11
12
13
14
15
  					<el-option v-for="item in productTypeOptions" :key="item.Value" :label="item.Name" :value="item.Name" />
  				</el-select>
  			</el-form-item>
  			<el-form-item label="清洗商" prop="laundrySupplierId">
  				<el-select v-model="form.laundrySupplierId" placeholder="请选择清洗商" filterable style="width: 100%" @change="handleSupplierChange">
6137a4e4   李宇   ```
16
  					<el-option v-for="item in filteredSupplierList" :key="item.id" :label="item.supplierName" :value="item.id" />
1138c09e   李宇   feat(LqLaundryFlo...
17
18
19
20
21
22
23
24
  				</el-select>
  			</el-form-item>
  			<el-form-item label="清洗单价" prop="laundryPrice">
  				<el-input v-model="form.laundryPrice" placeholder="自动填充" disabled />
  			</el-form-item>
  			<el-form-item label="送出数量" prop="quantity">
  				<el-input-number v-model="form.quantity" :min="1" :precision="0" style="width: 100%" />
  			</el-form-item>
2036dd49   李宇   最新
25
26
27
28
29
30
31
32
33
34
  			<el-form-item label="送出时间" prop="sendTime">
  				<el-date-picker
  					v-model="form.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>
1138c09e   李宇   feat(LqLaundryFlo...
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
  			<el-form-item label="备注">
  				<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入备注" />
  			</el-form-item>
  		</el-form>
  		<div slot="footer" class="dialog-footer">
  			<el-button @click="visible = false">取消</el-button>
  			<el-button type="primary" @click="submit" :loading="loading">确定</el-button>
  		</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,
  			form: {
  				storeId: '',
  				productType: '',
  				laundrySupplierId: '',
  				quantity: 1,
2036dd49   李宇   最新
61
  				sendTime: '',
1138c09e   李宇   feat(LqLaundryFlo...
62
63
64
65
66
67
68
69
70
71
  				remark: ''
  			},
  			rules: {
  				storeId: [{ required: true, message: '请选择门店', trigger: 'change' }],
  				productType: [{ required: true, message: '请选择产品类型', trigger: 'change' }],
  				laundrySupplierId: [{ required: true, message: '请选择清洗商', trigger: 'change' }],
  				quantity: [{ required: true, message: '请输入送出数量', trigger: 'blur' }]
  			},
  			storeList: [],
  			supplierList: [],
6137a4e4   李宇   ```
72
  			allSupplierList: [], // 保存所有清洗商列表
1138c09e   李宇   feat(LqLaundryFlo...
73
74
75
76
  			selectedSupplier: null,
  			productTypeOptions: []
  		}
  	},
6137a4e4   李宇   ```
77
78
79
80
81
82
83
84
85
  	computed: {
  		// 过滤后的清洗商列表(根据产品类型)
  		filteredSupplierList() {
  			if (!this.form.productType) {
  				return this.allSupplierList
  			}
  			return this.allSupplierList.filter(supplier => supplier.productType === this.form.productType)
  		}
  	},
1138c09e   李宇   feat(LqLaundryFlo...
86
87
88
89
90
91
92
93
94
  	mounted() {
  		this.initStoreList()
  		this.initSupplierList()
  		this.loadProductTypeOptions()
  	},
  	methods: {
  		// 初始化
  		init() {
  			this.visible = true
2036dd49   李宇   最新
95
96
97
98
99
100
101
102
103
104
  			// 格式化当前时间为 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')
  			const defaultSendTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  			
1138c09e   李宇   feat(LqLaundryFlo...
105
106
107
108
109
  			this.form = {
  				storeId: '',
  				productType: '',
  				laundrySupplierId: '',
  				quantity: 1,
2036dd49   李宇   最新
110
  				sendTime: defaultSendTime,
1138c09e   李宇   feat(LqLaundryFlo...
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
  				remark: ''
  			}
  			this.selectedSupplier = null
  			this.$nextTick(() => {
  				if (this.$refs.form) {
  					this.$refs.form.clearValidate()
  				}
  			})
  		},
  		// 初始化门店列表
  		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   李宇   ```
138
  					this.allSupplierList = res.data.list
1138c09e   李宇   feat(LqLaundryFlo...
139
140
141
  					this.supplierList = res.data.list
  				}
  			}).catch(() => {
6137a4e4   李宇   ```
142
  				this.allSupplierList = []
1138c09e   李宇   feat(LqLaundryFlo...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  				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() {
  			// 可以在这里添加逻辑
  		},
6137a4e4   李宇   ```
165
166
167
168
169
170
171
172
173
174
175
176
177
178
  		// 产品类型变化
  		handleProductTypeChange() {
  			// 如果已选择清洗商,检查是否支持新的产品类型
  			if (this.form.laundrySupplierId) {
  				const supplier = this.allSupplierList.find(item => item.id === this.form.laundrySupplierId)
  				if (supplier && this.form.productType && supplier.productType !== this.form.productType) {
  					// 如果当前清洗商不支持新的产品类型,清空选择
  					this.form.laundrySupplierId = ''
  					this.form.laundryPrice = 0
  					this.selectedSupplier = null
  					this.$message.warning('当前清洗商不支持该产品类型,请重新选择清洗商')
  				}
  			}
  		},
1138c09e   李宇   feat(LqLaundryFlo...
179
180
  		// 清洗商变化
  		handleSupplierChange(value) {
6137a4e4   李宇   ```
181
  			const supplier = this.filteredSupplierList.find(item => item.id === value)
1138c09e   李宇   feat(LqLaundryFlo...
182
183
184
  			if (supplier) {
  				this.selectedSupplier = supplier
  				this.$set(this.form, 'laundryPrice', supplier.laundryPrice || 0)
1138c09e   李宇   feat(LqLaundryFlo...
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
  			} else {
  				this.selectedSupplier = null
  				this.$set(this.form, 'laundryPrice', 0)
  			}
  		},
  		// 提交
  		submit() {
  			this.$refs.form.validate(valid => {
  				if (!valid) return
  
  				// 验证产品类型是否匹配
  				if (this.selectedSupplier && this.form.productType !== this.selectedSupplier.productType) {
  					this.$message.error(`清洗商【${this.selectedSupplier.supplierName}】不支持清洗产品类型【${this.form.productType}】`)
  					return
  				}
  
  				this.loading = true
  				request({
  					url: '/api/Extend/LqLaundryFlow/Send',
  					method: 'POST',
  					data: {
  						storeId: this.form.storeId,
  						productType: this.form.productType,
  						laundrySupplierId: this.form.laundrySupplierId,
  						quantity: this.form.quantity,
2036dd49   李宇   最新
210
  						sendTime: this.form.sendTime,
1138c09e   李宇   feat(LqLaundryFlo...
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
  						remark: this.form.remark
  					}
  				}).then(res => {
  					this.loading = false
  					if (res.code == 200) {
  						this.$message.success(res.msg || '创建成功')
  						this.visible = false
  						this.$emit('refresh')
  					} else {
  						this.$message.error(res.msg || '创建失败')
  					}
  				}).catch(() => {
  					this.loading = false
  				})
  			})
  		}
  	},
  	watch: {
  		visible(val) {
  			if (!val) {
  				this.$refs.form && this.$refs.form.resetFields()
  			}
  		}
  	}
  }
  </script>
  
  <style lang="scss" scoped>
  .dialog-footer {
  	text-align: right;
  }
  </style>