Form.vue
12.4 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
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
<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">
<el-form-item label="分类" prop="reimbursementCategoryId">
<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)"
:value="item.id">
<span style="float: left">{{ item.level1Name }} - {{ item.typeName }}</span>
<!-- <span style="float: right; color: #8492a6; font-size: 13px">({{ item.level2Code }})</span> -->
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="单价" prop="unitPrice">
<el-input v-model="dataForm.unitPrice" placeholder="请输入" clearable :style='{"width":"100%"}' @input="calculateAmount">
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="数量" prop="quantity">
<el-input v-model="dataForm.quantity" placeholder="请输入" clearable :style='{"width":"100%"}' @input="calculateAmount">
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="总金额" prop="amount">
<el-input v-model="dataForm.amount" placeholder="自动计算" readonly :style='{"width":"100%"}' >
</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>
<!-- <el-col :span="24">
<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>
</el-col> -->
<el-col :span="24">
<el-form-item label="创建人" prop="createUser">
<user-select v-model="dataForm.createUser" placeholder="请选择" clearable @change="handleCreateUserChange">
</user-select>
</el-form-item>
</el-col>
<el-col :span="24">
<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>
</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'
import { getUserInfo } from '@/api/permission/user'
export default {
components: {},
props: [],
data() {
return {
loading: false,
visible: false,
isDetail: false,
categoryLoading: false,
categoryOptions: [],
storeOptions: [],
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() {
this.loadStoreOptions();
},
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) {
const selectedCategory = this.categoryOptions.find(item => item.id === value);
if (selectedCategory) {
// value已经是level2Code,直接赋值
this.dataForm.reimbursementCategoryId = value;
this.dataForm.reimbursementCategoryName = selectedCategory.typeName;
}
} else {
this.dataForm.reimbursementCategoryId = undefined;
this.dataForm.reimbursementCategoryName = undefined;
}
},
// 自动计算总金额:单价 * 数量
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 = [];
});
},
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);
}
// 加载数据后重新计算总金额,确保数据一致性
this.calculateAmount();
})
} else {
// 新增模式:设置默认值
// 创建时间:当前时间(时间戳)
this.dataForm.createTime = new Date().getTime();
// 购买时间:默认今日(时间戳,设置为今天的00:00:00)
const today = new Date();
today.setHours(0, 0, 0, 0);
this.dataForm.purchaseTime = today.getTime();
// 审批状态:默认"未审批"
this.dataForm.approveStatus = '未审批';
// 创建人:获取当前用户信息
UserSettingInfo().then(response => {
if (response.data && response.data.id) {
this.dataForm.createUser = response.data.id;
// 自动填充创建人门店
this.handleCreateUserChange(response.data.id);
}
}).catch(() => {
// 如果API调用失败,尝试从store获取
const userInfo = this.$store.getters.userInfo;
if (userInfo) {
const userId = userInfo.userId || userInfo.id;
this.dataForm.createUser = userId;
// 自动填充创建人门店
this.handleCreateUserChange(userId);
}
});
}
})
},
// 加载已选择的分类选项(用于编辑时显示)
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>