en-radio.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view class="box">
  3. <view class="input-box">
  4. <view class="input-box-left">
  5. {{ label }}
  6. </view>
  7. <view class="input-box-right">
  8. <radio-group class="radio-data" @change="radioChange">
  9. <label class="radio-item" v-for="(radioItem,index) in radioArr">
  10. <radio :id="name+index" :value="radioItem.id" />
  11. <text class="iconfont icon-ok" v-if="inputValue===radioItem.id">&#xe608;</text>
  12. <text class="iconfont" v-else> &#xead9;</text>
  13. {{radioItem.name}}
  14. </label>
  15. </radio-group>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'en-radio',
  23. props: {
  24. type: {
  25. type: String,
  26. default: 'text'
  27. },
  28. label: {
  29. type: String,
  30. default: '标题'
  31. },
  32. radioData: {
  33. type: Array,
  34. default: []
  35. },
  36. radioKey:{
  37. type:String,
  38. default:'id'
  39. },
  40. radioValue:{
  41. type:String,
  42. default:'name'
  43. },
  44. disabled: {
  45. default: false
  46. },
  47. name: {
  48. type: String,
  49. default: 'text'
  50. },
  51. value: {
  52. default: '1'
  53. }
  54. },
  55. data() {
  56. return {
  57. inputValue: [],
  58. radioArr:[],
  59. }
  60. },
  61. components: {},
  62. mounted() {
  63. this.setValue()
  64. this.setRadioData()
  65. },
  66. watch: {
  67. 'value': function () {
  68. if (this.inputValue !== this.value) {
  69. this.setValue()
  70. }
  71. },
  72. 'inputValue': function () {
  73. this.$emit('input', this.inputValue)
  74. }
  75. },
  76. methods: {
  77. radioChange(e){
  78. this.inputValue=e.detail.value
  79. console.log(this.inputValue)
  80. },
  81. setRadioData(){
  82. if(this.radioData.length<=0){
  83. return ;
  84. }
  85. this.radioData.forEach((item)=>{
  86. if(item[this.radioKey] && item[this.radioValue]){
  87. this.radioArr.push({
  88. 'id':item[this.radioKey]+'',
  89. 'name':item[this.radioValue]
  90. })
  91. }
  92. })
  93. },
  94. setValue(){
  95. this.inputValue = this.value
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. @import url("../static/css/en-common.css");
  102. .box{
  103. .input-box {
  104. display: flex;
  105. align-items: center;
  106. .input-box-left {
  107. width: 210rpx;
  108. min-width: 210rpx;
  109. color: #333333;
  110. }
  111. .input-box-right{
  112. display: flex;
  113. align-items: center;
  114. .radio-data{
  115. display: flex;
  116. flex-wrap: wrap;
  117. .radio-item{
  118. margin: 6rpx 20rpx 0 6rpx;
  119. .iconfont{
  120. color: #333333;
  121. padding-right: 6rpx;
  122. }
  123. .icon-ok{
  124. color: #3169FA;
  125. }
  126. radio{
  127. display: none;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. </style>