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
import { selectTypeMapping } from '@/config';
import { mapGetters, mapActions } from 'vuex';
const getterList = selectTypeMapping.map(types => `optionList${types.value}`);
const actionsList = selectTypeMapping.map(
types => `fetchOptionList${types.value}`
);
export default {
data() {
return {
baseDataOptionsLabel: [], // 页面需要声明需要使用的基础数据 例如: ['赠送类型']
};
},
created() {
this.baseDataOptionsLabel.map(this.getOptionsValue).map(value => {
if (!this[`optionList${value}`].length) {
this[`fetchOptionList${value}`]();
}
});
},
computed: {
...mapGetters(getterList),
},
methods: {
...mapActions(actionsList),
changeHandle(val) {
this.$emit('input', val);
},
getOptionsList(label) {
let optionValue = this.getOptionsValue(label);
if (optionValue) {
let options = this.$store.getters['optionList' + optionValue];
if (options && options.length) {
return Promise.resolve(options);
} else {
return this.$store.dispatch('fetchOptionList' + optionValue);
}
} else {
return Promise.resolve([]);
}
},
getOptionsValue(label) {
let item = selectTypeMapping.find(item => item.label === label);
return item ? item.value : null;
},
getOptionsName(label, val) {
let optionValue = this.getOptionsValue(label);
if (optionValue) {
let item = this[`optionList${optionValue}`].find(
({ value }) => val === value
);
return item ? item.name : '';
}
return '';
},
formatterMoneyToDouble(val) {
return val ? Number(val).toFixed(2) : Number(0).toFixed(2);
},
},
};