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
<!-- author cuibo -->
<template>
<c-select v-model="model" v-bind="$attrs" placeholder="请选择币种" filterable v-bind:disabled="isDisable" @change="handleChange"
popper-class="m-currency-dropdown">
<el-option v-for="item in codes" :key="item.value" :label="item.label" :value="item.value" :disabled="disabledList.indexOf(item.value)!== -1">
</el-option>
</c-select>
</template>
<script>
import QueryRequest from "../../model/QueryRequest";
import Currency from "../../model/Currency";
import Select from "../Select"
export default {
components: {
'c-select': Select
},
props: {
value: {
type: [String, Array, Number],
default: undefined
},
disabledList: {
type: Array,
default: function () {
return []
}
},
disabled: {
type: Boolean,
default: false
},
isOften: {
type: Boolean,
default: true
},
},
computed: {
model: {
get() {
return this.value;
},
set(newVal) {
this.$emit("input", newVal);
}
},
isDisable: {
get() {
return this.disabled
}
},
},
data: function() {
return {
codes: [],
list: [],
currencyMap: {}
}
},
created() {
this.handleSearch();
},
methods: {
listCurs(){
return Promise.resolve(null)
},
handleSearch() {
var params = new QueryRequest().data;
params.current = 0;
params.size = 0;
params.data = new Currency().data;
// console.log('this.isOften', this.isOften)
let key = 'curCache'
if (this.isOften === true) {
//查询条件——是常用币种
params.data.isOften = 'Y'
key = key + 'Y'
} else {
params.data = {};
}
let promise;
if (!window[key] || new Date() - window[key].lastTime > 30000) //30s内不超时
{
promise = listCurs(params)
window[key] = {
lastTime: new Date() - 0,
promise
}
} else {
promise = window[key].promise
}
promise
.then(res => {
if (res.code === SUCCESS) {
this.list = res.data;
console.log('list', this.list)
for (var i = 0; i < this.list.length; i++) {
this.codes.push({
value: this.list[i].currCode,
label: this.list[i].currSymbol + '-' + this.list[i].currCnName
});
//利用map遍历list
this.currencyMap[this.list[i].currCode] = JSON.parse(JSON.stringify(this.list[i]))
}
}
})
.catch(error => {
console.log(error);
});
},
handleChange(value) {
//根据value在currencyMap中找到list中的币种对象 返回
this.$emit('update-currency', this.currencyMap[value])
}
}
}
</script>