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
| /**
| * CSelect
| * @author Tevin
| */
|
| <template>
| <view class="c-select">
| <picker
| mode="selector"
| :range="options"
| :value="current"
| range-key="name"
| @change="evt=>handleChange(evt.detail)"
| >
| <AtInput
| ref="input"
| :name="itemRes.name"
| :title="itemRes.label"
| :required="itemRes.required"
| :error="itemRes.error"
| :placeholder="placeholder"
| :value="selected"
| >
| <view class="at-icon at-icon-chevron-right" />
| </AtInput>
| </picker>
| </view>
| </template>
|
| <script>
| import { AtInput } from 'taro-ui-vue';
| import './cSelect.scss';
|
| export default {
| name: 'CSelect',
| components: {
| AtInput,
| },
| props: {
| options: Array,
| placeholder: String,
| itemRes: Object,
| },
| data() {
| return {};
| },
| computed: {
| optionKey() {
| return typeof (this.options[0] || {}).value === 'undefined' ? 'id' : 'value';
| },
| current() {
| const curVal = this.itemRes.formData[this.itemRes.name];
| for (let i = 0, item; (item = this.options[i]); i++) {
| if (curVal === item[this.optionKey]) {
| return i;
| }
| }
| return -1;
| },
| selected() {
| const curVal = this.itemRes.formData[this.itemRes.name];
| for (let i = 0, item; (item = this.options[i]); i++) {
| if (curVal === item[this.optionKey]) {
| return item.name;
| }
| }
| return '';
| },
| },
| methods: {
| handleChange(evt) {
| const item = this.options[evt.value];
| this.itemRes.onChange(item[this.optionKey]);
| },
| },
| mounted() {},
| };
| </script>
|
|