b2c391f9
hexiaodong
hxd20251113
|
1
2
3
4
5
|
<template>
<el-dialog :title="!dataForm.id ? '新建' : isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll width="600px">
<el-row :gutter="15" class="" >
<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
<el-col :span="24">
|
50f29afc
李宇
build(antis-ncc-a...
|
6
|
<el-form-item label="分类" prop="reimbursementCategoryId">
|
b2c391f9
hexiaodong
hxd20251113
|
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<el-select
v-model="dataForm.reimbursementCategoryId"
filterable
remote
reserve-keyword
placeholder="请输入一级名称或二级名称搜索"
:remote-method="searchReimbursementCategory"
:loading="categoryLoading"
@change="handleCategoryChange"
clearable
:style='{"width":"100%"}'>
<el-option
v-for="item in categoryOptions"
:key="item.id"
:label="getCategoryLabel(item)"
|
50f29afc
李宇
build(antis-ncc-a...
|
22
|
:value="item.id">
|
b2c391f9
hexiaodong
hxd20251113
|
23
|
<span style="float: left">{{ item.level1Name }} - {{ item.typeName }}</span>
|
50f29afc
李宇
build(antis-ncc-a...
|
24
|
<!-- <span style="float: right; color: #8492a6; font-size: 13px">({{ item.level2Code }})</span> -->
|
b2c391f9
hexiaodong
hxd20251113
|
25
26
27
28
29
30
|
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="单价" prop="unitPrice">
|
50f29afc
李宇
build(antis-ncc-a...
|
31
|
<el-input v-model="dataForm.unitPrice" placeholder="请输入" clearable :style='{"width":"100%"}' @input="calculateAmount">
|
b2c391f9
hexiaodong
hxd20251113
|
32
33
34
35
36
|
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="数量" prop="quantity">
|
50f29afc
李宇
build(antis-ncc-a...
|
37
|
<el-input v-model="dataForm.quantity" placeholder="请输入" clearable :style='{"width":"100%"}' @input="calculateAmount">
|
b2c391f9
hexiaodong
hxd20251113
|
38
39
40
41
42
|
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="总金额" prop="amount">
|
50f29afc
李宇
build(antis-ncc-a...
|
43
|
<el-input v-model="dataForm.amount" placeholder="自动计算" readonly :style='{"width":"100%"}' >
|
b2c391f9
hexiaodong
hxd20251113
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="备注说明" prop="memo">
<el-input v-model="dataForm.memo" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="附件" prop="attachment">
<NCC-UploadFz v-model="dataForm.attachment" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
</NCC-UploadFz>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="购买时间" prop="purchaseTime">
<el-date-picker v-model="dataForm.purchaseTime" placeholder="请选择" clearable :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
</el-date-picker>
</el-form-item>
</el-col>
|
50f29afc
李宇
build(antis-ncc-a...
|
65
|
<!-- <el-col :span="24">
|
b2c391f9
hexiaodong
hxd20251113
|
66
67
68
69
|
<el-form-item label="创建时间" prop="createTime">
<el-date-picker v-model="dataForm.createTime" placeholder="请选择" clearable :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
</el-date-picker>
</el-form-item>
|
50f29afc
李宇
build(antis-ncc-a...
|
70
|
</el-col> -->
|
b2c391f9
hexiaodong
hxd20251113
|
71
72
|
<el-col :span="24">
<el-form-item label="创建人" prop="createUser">
|
50f29afc
李宇
build(antis-ncc-a...
|
73
|
<user-select v-model="dataForm.createUser" placeholder="请选择" clearable @change="handleCreateUserChange">
|
b2c391f9
hexiaodong
hxd20251113
|
74
75
76
77
|
</user-select>
</el-form-item>
</el-col>
<el-col :span="24">
|
50f29afc
李宇
build(antis-ncc-a...
|
78
79
80
81
82
83
84
85
86
|
<el-form-item label="门店" prop="createUserStoreId">
<el-select v-model="dataForm.createUserStoreId" placeholder="自动填充" disabled :style='{"width":"100%"}' clearable>
<el-option
v-for="store in storeOptions"
:key="store.id"
:label="store.dm"
:value="store.id">
</el-option>
</el-select>
|
b2c391f9
hexiaodong
hxd20251113
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
</el-form-item>
</el-col>
</el-form>
</el-row>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import request from '@/utils/request'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import { previewDataInterface } from '@/api/systemData/dataInterface'
import { UserSettingInfo } from '@/api/permission/userSetting'
|
50f29afc
李宇
build(antis-ncc-a...
|
102
|
import { getUserInfo } from '@/api/permission/user'
|
b2c391f9
hexiaodong
hxd20251113
|
103
104
105
106
107
108
109
110
111
112
|
export default {
components: {},
props: [],
data() {
return {
loading: false,
visible: false,
isDetail: false,
categoryLoading: false,
categoryOptions: [],
|
50f29afc
李宇
build(antis-ncc-a...
|
113
|
storeOptions: [],
|
b2c391f9
hexiaodong
hxd20251113
|
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
|
dataForm: {
id:undefined,
reimbursementCategoryId:undefined,
reimbursementCategoryName:undefined,
unitPrice:undefined,
quantity:undefined,
amount:undefined,
memo:undefined,
attachment:[],
purchaseTime:undefined,
createTime:undefined,
createUser:undefined,
createUserStoreId:undefined,
approveStatus:undefined,
approveUser:undefined,
approveTime:undefined,
applicationId:undefined,
},
rules: {
},
}
},
computed: {},
watch: {},
created() {
|
50f29afc
李宇
build(antis-ncc-a...
|
139
|
this.loadStoreOptions();
|
b2c391f9
hexiaodong
hxd20251113
|
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
|
},
mounted() {
},
methods: {
goBack() {
this.$emit('refresh')
},
// 获取分类标签显示
getCategoryLabel(item) {
if (!item) return '';
return `${item.level1Name || ''} - ${item.typeName || ''} (${item.level2Code || ''})`;
},
// 搜索报销分类(支持OR逻辑:一级名称、二级名称或二级编号)
searchReimbursementCategory(query) {
if (query !== '') {
this.categoryLoading = true;
// 由于后端是AND逻辑,我们需要分别查询然后合并结果
Promise.all([
request({
url: '/api/Extend/LqReimbursementCategory/Actions/GetNoPagingList',
method: 'GET',
data: { level1Name: query }
}),
request({
url: '/api/Extend/LqReimbursementCategory/Actions/GetNoPagingList',
method: 'GET',
data: { typeName: query }
}),
request({
url: '/api/Extend/LqReimbursementCategory/Actions/GetNoPagingList',
method: 'GET',
data: { level2Code: query }
})
]).then(results => {
// 合并结果并去重
const allResults = [];
results.forEach(result => {
if (result.data && Array.isArray(result.data)) {
allResults.push(...result.data);
}
});
// 根据id去重
const uniqueResults = [];
const seenIds = new Set();
allResults.forEach(item => {
if (!seenIds.has(item.id)) {
seenIds.add(item.id);
uniqueResults.push(item);
}
});
this.categoryOptions = uniqueResults;
this.categoryLoading = false;
}).catch(() => {
this.categoryLoading = false;
});
} else {
this.categoryOptions = [];
}
},
// 选择分类后自动填充
handleCategoryChange(value) {
if (value) {
|
50f29afc
李宇
build(antis-ncc-a...
|
202
|
const selectedCategory = this.categoryOptions.find(item => item.id === value);
|
b2c391f9
hexiaodong
hxd20251113
|
203
204
205
206
207
208
209
210
211
212
|
if (selectedCategory) {
// value已经是level2Code,直接赋值
this.dataForm.reimbursementCategoryId = value;
this.dataForm.reimbursementCategoryName = selectedCategory.typeName;
}
} else {
this.dataForm.reimbursementCategoryId = undefined;
this.dataForm.reimbursementCategoryName = undefined;
}
},
|
50f29afc
李宇
build(antis-ncc-a...
|
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
|
// 自动计算总金额:单价 * 数量
calculateAmount() {
const unitPrice = parseFloat(this.dataForm.unitPrice) || 0;
const quantity = parseFloat(this.dataForm.quantity) || 0;
this.dataForm.amount = (unitPrice * quantity).toFixed(2);
},
// 创建人改变时,自动填充创建人门店
handleCreateUserChange(userId) {
if (userId) {
// 获取用户信息
request({
url: '/api/permission/Users/' + userId,
method: 'GET',
}).then(res => {
this.dataForm.createUserStoreId = res.data.mdid || '';
});
} else {
// 清空创建人时,也清空门店
this.dataForm.createUserStoreId = '';
}
},
// 加载门店列表
loadStoreOptions() {
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 = [];
});
},
|
b2c391f9
hexiaodong
hxd20251113
|
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
init(id, isDetail) {
this.dataForm.id = id || 0;
this.visible = true;
this.isDetail = isDetail || false;
this.categoryOptions = [];
this.$nextTick(() => {
this.$refs['elForm'].resetFields();
if (this.dataForm.id) {
// 编辑模式:加载已有数据
request({
url: '/api/Extend/LqPurchaseRecords/' + this.dataForm.id,
method: 'get'
}).then(res =>{
this.dataForm = res.data;
if(!this.dataForm.attachment)this.dataForm.attachment=[];
// 如果有已选择的分类,加载对应的选项
if (this.dataForm.reimbursementCategoryId) {
this.loadCategoryOption(this.dataForm.reimbursementCategoryId);
}
|
50f29afc
李宇
build(antis-ncc-a...
|
270
271
|
// 加载数据后重新计算总金额,确保数据一致性
this.calculateAmount();
|
b2c391f9
hexiaodong
hxd20251113
|
272
273
274
275
276
|
})
} else {
// 新增模式:设置默认值
// 创建时间:当前时间(时间戳)
this.dataForm.createTime = new Date().getTime();
|
50f29afc
李宇
build(antis-ncc-a...
|
277
278
279
280
|
// 购买时间:默认今日(时间戳,设置为今天的00:00:00)
const today = new Date();
today.setHours(0, 0, 0, 0);
this.dataForm.purchaseTime = today.getTime();
|
b2c391f9
hexiaodong
hxd20251113
|
281
282
283
284
285
286
|
// 审批状态:默认"未审批"
this.dataForm.approveStatus = '未审批';
// 创建人:获取当前用户信息
UserSettingInfo().then(response => {
if (response.data && response.data.id) {
this.dataForm.createUser = response.data.id;
|
50f29afc
李宇
build(antis-ncc-a...
|
287
288
|
// 自动填充创建人门店
this.handleCreateUserChange(response.data.id);
|
b2c391f9
hexiaodong
hxd20251113
|
289
290
291
292
293
|
}
}).catch(() => {
// 如果API调用失败,尝试从store获取
const userInfo = this.$store.getters.userInfo;
if (userInfo) {
|
50f29afc
李宇
build(antis-ncc-a...
|
294
295
296
297
|
const userId = userInfo.userId || userInfo.id;
this.dataForm.createUser = userId;
// 自动填充创建人门店
this.handleCreateUserChange(userId);
|
b2c391f9
hexiaodong
hxd20251113
|
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
|
}
});
}
})
},
// 加载已选择的分类选项(用于编辑时显示)
loadCategoryOption(level2Code) {
request({
url: '/api/Extend/LqReimbursementCategory/Actions/GetNoPagingList',
method: 'GET',
data: {
level2Code: level2Code
}
}).then(res => {
if (res.data && res.data.length > 0) {
this.categoryOptions = res.data;
}
});
},
dataFormSubmit() {
this.$refs['elForm'].validate((valid) => {
if (valid) {
if (!this.dataForm.id) {
request({
url: `/api/Extend/LqPurchaseRecords`,
method: 'post',
data: this.dataForm,
}).then((res) => {
this.$message({
message: res.msg,
type: 'success',
duration: 1000,
onClose: () => {
this.visible = false,
this.$emit('refresh', true)
}
})
})
} else {
request({
url: '/api/Extend/LqPurchaseRecords/' + this.dataForm.id,
method: 'PUT',
data: this.dataForm
}).then((res) => {
this.$message({
message: res.msg,
type: 'success',
duration: 1000,
onClose: () => {
this.visible = false
this.$emit('refresh', true)
}
})
})
}
}
})
},
}
}
</script>
|