| | |
| | | mode="selector" |
| | | range-key="name" |
| | | :range="options2" |
| | | :value="current" |
| | | @change="evt=>handleChange(evt.detail.value)" |
| | | > |
| | | <view class="content"> |
| | |
| | | > |
| | | {{label}}: |
| | | </view> |
| | | <view :class="selected ? 'value':'empty'"> |
| | | {{selected ? options2[selectIndex].name : ('请选择' + label)}} |
| | | <view :class="selected ? 'filled':'empty'"> |
| | | {{selected ? options2[current].name : ('请选择' + label)}} |
| | | </view> |
| | | <view class='at-icon at-icon-chevron-down' /> |
| | | <view class="at-icon at-icon-chevron-down" /> |
| | | </view> |
| | | </picker> |
| | | </view> |
| | |
| | | props: { |
| | | type: String, |
| | | label: String, |
| | | options: Array, |
| | | options: { |
| | | type: Array, |
| | | default: [], |
| | | }, |
| | | value: null, |
| | | onChange: Function, |
| | | }, |
| | | data() { |
| | | return { |
| | | selectIndex: 0, |
| | | selected: false, |
| | | }; |
| | | return {}; |
| | | }, |
| | | computed: { |
| | | options2() { |
| | | return [{ name: '- 取消选择 -' }, ...this.options]; |
| | | }, |
| | | current() { |
| | | for (let i = 0, item; (item = this.options2[i]); i++) { |
| | | if (this.value === item.value) { |
| | | return i; |
| | | } |
| | | } |
| | | return 0; |
| | | }, |
| | | selected() { |
| | | if (typeof this.value === 'undefined') { |
| | | return false; |
| | | } |
| | | for (let item of this.options) { |
| | | if (this.value === item.value) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | }, |
| | | }, |
| | | methods: { |
| | | handleChange(index) { |
| | | this.selectIndex = Number(index); |
| | | if (this.selectIndex > 0) { |
| | | this.selected = true; |
| | | this.onChange(this.options2[this.selectIndex].value); |
| | | const selectIndex = Number(index); |
| | | if (selectIndex > 0) { |
| | | this.onChange(this.options2[selectIndex].value); |
| | | } else { |
| | | this.selected = false; |
| | | this.onChange(); |
| | | } |
| | | }, |