transactionManagement.vue
10.8 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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<script lang="ts" setup name="transactionManagement" >
import { ref,onBeforeMount } from 'vue';
import { ElMessage, ElMessageBox } from "element-plus"
import { useRoute } from "vue-router"
import useUserStore from "@/store/modules/user";
import TableTools from "@/components/Tools/table_tools.vue";
import Table from "./components/Table/index.vue"
import {
getTradeList,
deleteTradeAll,
createTrade,
tradeUpdate,
getDocumentList
} from "@/api/modules/dataTransaction";
const route = useRoute()
const userStore = useUserStore();
const searchItemList = ref([
{
type: "input",
label: "",
field: "daName",
default: "",
placeholder: "资产名称",
clearable: true,
},
]);
const page = ref({
limit: 50,
rows:0,
curr: 1,
sizes: [
{ label: "10", value: 10 },
{ label: "50", value: 50 },
{ label: "100", value: 100 },
{ label: "150", value: 150 },
{ label: "200", value: 200 },
],
daName: '',
});
const BASE_ID = "BASE_ID"
const { proxy } = getCurrentInstance() as any;
const tableRef = ref()
const tableInfo = ref({
id: 'entry-asset-table',
loading:false,
isEdit:false,
currentId:"0",
flag:"create",
data:[] as any,
})
const companyOption = ref<any>([])
const assetsOption = ref<any>([])
const colums = [
{
type:"index",
label:"序号",
align:"center",
width:"56"
},
{
prop:"companyName",
label:"公司名称",
width:"220",
selectKey:"tenantName",
componentType:"select",
componentDisabled:false,
selectOption:() => companyOption.value
},
{
prop:"daName",
label:"资产名称",
width:"180",
componentType:"select",
componentDisabled:false,
selectKey:"daName",
selectOption:() => assetsOption.value
},
{
prop:"daCode",
label:"资产编号",
width:"180"
},
{
prop:"registerTime",
label:"登记时间",
width:"130",
componentType:"dateTime",
},
{
prop:"effectiveDate",
label:"有效期",
width:"130",
componentType:"dateTime",
},
{
prop:"issuingEntityName",
label:"发证主体",
width:"250"
},
{
prop:"tradeTime",
label:"交易时间",
width:"130",
componentType:"dateTime",
componentDisabled:false
},
{
prop:"tradeObject",
label:"交易对象",
width:"180",
componentDisabled:false
},
]
const columnInfo = ref({
guid:"",
companyGuid: "",
companyName:"",
registerGuid: "",
daName: "",
registerTime: "",
daCode: "",
effectiveDate: "",
issuingEntityName:"",
issuingEntityGuid: "",
tradeTime:"",
tradeObject:""
})
const tableSelectInfo = ref({
selectValue:"",
companyGuid:""
})
const toSearch = (val: any, clear: boolean = false) => {
page.value.curr = 1;
if (clear) {
searchItemList.value.map((item) => (item.default = ""));
page.value.daName = '';
} else {
page.value.daName = val.daName;
}
getTableData();
};
// 查资产
const getAssetsList = async () => {
const res = await getDocumentList({
daName:tableSelectInfo.value.selectValue,
companyGuid:tableSelectInfo.value.companyGuid,
type:2})
assetsOption.value =res.data || []
return Promise.resolve()
}
const documentList = async () => {
const res:any = await getDocumentList({
daName:tableSelectInfo.value.selectValue,
isCompany: true,
type:2})
if(res?.code === proxy.$passCode) {
companyOption.value = res.data || []
}
}
const getTableData = () => {
tableInfo.value.loading = true;
getTradeList({
pageSize: page.value.limit,
pageIndex: page.value.curr,
daName: page.value.daName,
}).then((res: any) => {
tableInfo.value.loading = false;
if (res?.code == proxy.$passCode) {
const data = res.data || {};
tableInfo.value.data = data.records || [];
page.value.curr = data.pageIndex;
page.value.rows = data.totalRows || 0;
}
})
}
const createOneData = async () => {
if(companyOption.value.length>0) {
findTab(true)
assetsOption.value = []
tableInfo.value.flag = "create"
tableInfo.value.data.unshift({
guid:BASE_ID,
companyGuid: "",
companyName:"",
registerGuid: "",
daName: "",
registerTime: "",
daCode: "",
effectiveDate: "",
issuingEntityName:"",
issuingEntityGuid: "",
tradeTime:"",
tradeObject:""
})
tableInfo.value.currentId = BASE_ID
tableInfo.value.isEdit = true
} else {
ElMessage.warning("没有可添加的数据!")
}
}
const columnDel =async (row) => {
ElMessageBox.confirm(
'是否确定删除所选数据?',
'提示',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
const guids = [row.guid]
deleteTradeAll(row.guid).then((res:any)=>{
if(res?.code===proxy.$passCode){
ElMessage.success("删除成功")
getTableData()
columnCancel()
documentList()
findTab(false)
tableRef.value.columnInfo = {}
} else {
ElMessage.error(res?.msg)
}
}).catch((res)=>{
tableRef.value.columnInfo = {}
})
}).catch(()=>{
tableRef.value.columnInfo = {}
})
}
const columnSave = async (row) => {
if(!row.companyName) {
ElMessage.warning("公司名称不能为空")
return
} else if(!row.daName) {
ElMessage.warning("资产名称不能为空")
return
} else if(!row.tradeTime) {
ElMessage.warning("交易时间不能为空")
return
} else if(!row.tradeObject) {
ElMessage.warning("交易对象不能为空")
return
}
let res:any
switch(tableInfo.value.flag) {
case "create":res = await createTrade(row);break
case "edit":res = await tradeUpdate(row);break
}
if(res?.code===proxy.$passCode) {
ElMessage.success(`${tableInfo.value.flag==='create' ? '新增' : '修改'}成功`);
getTableData()
columnInfoReset()
findTab(false)
tableRef.value.columnInfo = {}
}else {
ElMessage.error(res?.msg);
//columnCancel()
}
documentList()
//columnInfoReset()
}
const columnInfoReset = () => {
tableInfo.value.currentId = "0"
tableInfo.value.isEdit = false
columnInfo.value = {
guid:BASE_ID,
companyGuid: "",
companyName:"",
registerGuid: "",
daName: "",
registerTime: "",
daCode: "",
effectiveDate: "",
issuingEntityName:"",
issuingEntityGuid: "",
tradeTime:"",
tradeObject:""
}
}
const columnEdit = (row) => {
tableInfo.value.currentId = row.guid
tableInfo.value.isEdit = true
tableInfo.value.flag = "edit"
columnInfo.value = {...row}
findTab(true)
tableSelectInfo.value.companyGuid = row.companyGuid
assetsOption.value = []
addAssetsOption(null,row,true)
// addCompanyOption(row)
//tableRef.value.columnInfo.intableMoney = tableRef.value.columnInfo.intableMoney.toFixed(2)
}
const columnCancel = () => {
tableInfo.value.isEdit = false
if(tableInfo.value.flag==="edit") {
tableInfo.value.currentId = "0"
} else {
tableInfo.value.data.shift()
columnInfoReset()
}
findTab(false)
}
const pageChange = (info) => {
page.value.curr = info.curr
page.value.limit = info.limit
getTableData()
}
const handelSelect = (row,key,row1) => {
if(key==="companyName") {
tableSelectInfo.value.companyGuid = row.tenantGuid
addAssetsOption(row,row1)
columnInfo.value.companyName = row.tenantName
tableRef.value.columnInfo.companyName = row.tenantName
if(row.tenantGuid!==row1.companyGuid) {
tableRef.value.columnInfo.daName = ""
tableRef.value.columnInfo.daCode = ""
tableRef.value.columnInfo.issuingEntityName = ""
tableRef.value.columnInfo.issuingEntityGuid = ""
tableRef.value.columnInfo.registerGuid = ""
tableRef.value.columnInfo.registerTime = ""
tableRef.value.columnInfo.effectiveDate = ""
}
} else {
if(tableInfo.value.flag==="create") {
columnInfo.value = {
guid:row.guid,
companyName:row.tenantName,
daName:row.daName,
registerTime:row.registerTime,
daCode:row.daCode,
effectiveDate:row.effectiveDate,
issuingEntityName:row.issuingEntityName,
issuingEntityGuid:row.issuingEntityGuid,
companyGuid:row.tenantGuid,
registerGuid:row.registerGuid,
tradeTime:row.tradeTime,
tradeObject:row.tradeObject
}
// 新增不用传guid 所以删掉,但是往输入框添加数据 通过guid判断
const {guid,...obj} = columnInfo.value
tableRef.value.columnInfo = obj
} else {
columnInfo.value.daName = row.daName
columnInfo.value.daCode = row.daCode
columnInfo.value.registerTime = row.registerTime
columnInfo.value.effectiveDate = row.effectiveDate
columnInfo.value.issuingEntityName = row.issuingEntityName;
columnInfo.value.registerGuid = row.registerGuid;
tableRef.value.columnInfo = {...columnInfo.value}
}
}
}
const findTab = (flag) => {
const tab:any = userStore.tabbar.find((tab:any)=>tab.fullPath===route.path)
tab.meta.editPage = flag
}
const addAssetsOption = (values,row,flag=false) => {
getAssetsList();
}
const addCompanyOption = (row) => {
let flag = true
documentList().then(()=>{
const obj = {
tenantName:row.companyName,
tenantGuid:row.companyGuid
}
const arr = companyOption.value
arr.forEach((item)=>{
if(item.tenantGuid===row.companyGuid){
flag = false
}
})
if(flag) {
arr.unshift(obj)
companyOption.value = arr
}
})
}
onBeforeMount(()=> {
// getTableData()
documentList()
})
</script>
<template>
<div class="container_wrap">
<div class="table_tool_wrap">
<TableTools :searchItems="searchItemList" :searchId="'entry-data-search'" @search="toSearch" />
<div class="tools_btns">
<el-button type="primary" @click="createOneData" :disabled="tableInfo.isEdit">新建</el-button>
</div>
</div>
<div class="table_panel_wrap">
<Table
ref="tableRef"
:tableInfo="tableInfo"
:page="page"
:colums="colums"
v-model="columnInfo"
@pageChange="pageChange"
@columnSave="columnSave"
@columnDel="columnDel"
@columnEdit="columnEdit"
@columnCancel="columnCancel"
@handelSelect="handelSelect"
></Table>
</div>
</div>
</template>
<style scoped lang="scss">
.container_wrap {
padding: 0 16px;
}
</style>