enum-data.vue 1.4 KB
Newer Older
Y
yurj26 已提交
1
<script lang="uts">
雪洛's avatar
雪洛 已提交
2 3
  import { PropType } from 'vue'
  import { ItemType } from './enum-data'
4

D
DCloud_LXH 已提交
5
  export default {
6
    emits: ['change'],
D
DCloud_LXH 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    props: {
      title: {
        type: String,
        default: ''
      },
      items: {
        type: Array as PropType<Array<ItemType>>,
        required: true
      }
    },
    data() {
      return {
        current: 0
      }
    },
    methods: {
      // @ts-ignore
      _change(e : RadioGroupChangeEvent) {
        const selected = this.items.find((item: ItemType) : boolean => {
雪洛's avatar
雪洛 已提交
26
          return item.name == e.detail.value
D
DCloud_LXH 已提交
27
        })
雪洛's avatar
雪洛 已提交
28
        if (selected != null) {
D
DCloud_LXH 已提交
29 30 31 32 33 34 35 36 37 38
          this.current = selected.value
          this.$emit('change', this.current)
          uni.showToast({
            icon: 'none',
            title: '当前选中:' + selected.name,
          })
        }
      }
    }
  }
39 40 41
</script>

<template>
D
DCloud_LXH 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54
  <view class="uni-padding-wrap">
    <view class="uni-title uni-common-mt">
      <text class="uni-title-text"> {{title}} </text>
    </view>
  </view>
  <view class="uni-list uni-common-pl">
    <radio-group @change="_change" class="radio-group">
      <radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item.name"
        :class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.name" :checked="index === current">
        {{ item.name }}
      </radio>
    </radio-group>
  </view>
55 56
</template>

D
DCloud_LXH 已提交
57
<style></style>