123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <template>
- <view class="box">
- <view class="input-box">
- <view class="input-box-left" :style="{'letter-spacing':labelWidth}">
- {{ label }}
- </view>
- <view class="input-box-right">
- <radio-group class="radio-data" @change="radioChange">
- <label class="radio-item" v-for="(radioItem,index) in radioArr">
- <radio :id="name+index" :value="radioItem.id" />
- <text class="iconfont icon-ok" v-if="inputValue===radioItem.id"></text>
- <text class="iconfont" v-else> </text>
- {{radioItem.name}}
- </label>
- </radio-group>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'en-radio',
- props: {
- type: {
- type: String,
- default: 'text'
- },
- label: {
- type: String,
- default: '标题'
- },
- radioData: {
- type: Array,
- default: []
- },
- radioKey:{
- type:String,
- default:'id'
- },
- radioValue:{
- type:String,
- default:'name'
- },
- disabled: {
- default: false
- },
- name: {
- type: String,
- default: 'text'
- },
- value: {
- default: '1'
- }
- },
- data() {
- return {
- inputValue: [],
- radioArr:[],
- labelWidth:0
- }
- },
- components: {},
- mounted() {
- this.setValue()
- this.setRadioData()
- this.setLabelWidth()
- },
- watch: {
- 'value': function () {
- if (this.inputValue !== this.value) {
- this.setValue()
- }
- },
- 'inputValue': function () {
- this.$emit('input', this.inputValue)
- }
- },
- methods: {
- radioChange(e){
- this.inputValue=e.detail.value
- console.log(this.inputValue)
- },
- setRadioData(){
- if(this.radioData.length<=0){
- return ;
- }
- this.radioData.forEach((item)=>{
- if(item[this.radioKey] && item[this.radioValue]){
- this.radioArr.push({
- 'id':item[this.radioKey]+'',
- 'name':item[this.radioValue]
- })
- }
- })
- },
- setValue(){
- this.inputValue = this.value+''
- },
- setLabelWidth(){
- let differenceNum=4- this.label.length;
- if(differenceNum===2){
- this.labelWidth='2em'
- }else if(differenceNum===1){
- this.labelWidth='0.5em'
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import url("../../../static/css/en-common.css");
- .box{
- .input-box {
- display: flex;
- align-items: center;
- .input-box-left {
- width: 210rpx;
- min-width: 210rpx;
- color: #333333;
- }
- .input-box-right{
- display: flex;
- align-items: center;
- .radio-data{
- display: flex;
- flex-wrap: wrap;
- .radio-item{
- margin: 6rpx 20rpx 0 6rpx;
- .iconfont{
- padding-right: 6rpx;
- }
- .icon-ok{
- color: var(--selected-color);
- }
- .icon-no{
- color: var(--unselected-color);
- }
- radio{
- display: none;
- }
- }
- }
- }
- }
- }
- </style>
|