123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <template>
- <view :style="[getStyle]"
- class="ly-radio-group"
- >
- <view v-for="(item,index) in list" :key="index" :class="{'action':item[valueName] == value}"
- class="ly-radio-group-item" @click="changeHandle(item)">
- {{ item[labelName] }}
- </view>
- </view>
- </template>
- <script>
- export default {
- props: {
- list: {
- type: [Object, Array],
- default: []
- },
- labelName: {
- type: String,
- default: 'label'
- },
- valueName: {
- type: String,
- default: 'value'
- },
- value: {
- type: [String, Number],
- default: '',
- },
- change: {
- type: Function
- },
- height: {
- type: [Number, String],
- default: 70,
- },
- size: {
- type: [Number, String],
- default: 26,
- },
- color: {
- type: String,
- default: '#303133',
- },
- bgColor: {
- type: String,
- default: 'transparent',
- },
- bColor: {
- type: String,
- default: '#dcdfe6',
- },
- actionColor: {
- type: String,
- default: '#409eff',
- }
- },
- model: {
- prop: 'value',
- //这个事件名可以随意写,它实际上是规定了子组件要更新父组件值需要注册的方法
- event: 'input'
- },
- data() {
- return {}
- },
- computed: {
- getStyle() {
- let data = {
- '--color': this.color,
- '--bg-color': this.bgColor,
- '--b-color': this.bColor,
- '--action-color': this.actionColor,
- }
- return data
- },
- },
- methods: {
- changeHandle(item) {
- this.$emit('input', item[this.valueName])
- this.$emit('change', item)
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .ly-radio-group {
- display: inline-flex;
- width: 100%;
- &-item {
- border: 2rpx solid var(--b-color);
- border-left: 0;
- height: 70rpx;
- font-size: 26rpx;
- //padding: 0 20rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- color: var(--color);
- background: var(--bg-color);
- box-sizing: content-box;
- flex: 1;
- &:first-child {
- border-left: 2rpx solid var(--b-color);
- border-top-left-radius: 10rpx;
- border-bottom-left-radius: 10rpx;
- }
- &:last-child {
- border-top-right-radius: 10rpx;
- border-bottom-right-radius: 10rpx;
- }
- &.action {
- border-color: var(--action-color);
- background: var(--action-color);
- color: #FFFFFF;
- }
- }
- }
- </style>
|