radioTree.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <view>
  3. <!-- 内容 -->
  4. <form v-for="(item, index) in selectList" :key="index">
  5. <!-- 一级-->
  6. <view class="cu-form-group " :class="index==0 ? '' :'margin-top-sm'" >
  7. <text class="title ">{{item.name}}</text>
  8. <view>
  9. <text v-if="item.show==true" class="cuIcon-fold" @click="changeShow(index,item)"></text>
  10. <text v-else class="cuIcon-unfold" @click="changeShow(index,item)"></text>
  11. </view>
  12. </view>
  13. <!-- 二级 -->
  14. <view v-if="item.show && item.children" v-for="(items, indexs) in item.children" :key="indexs" class="cu-form-group" >
  15. <radio-group @change="RadioChange(index,items)">
  16. <radio :class="items.id==radioValue ?' checked':''" :value="items.id" :checked="items.id==radioValue ? true:false" class="round"></radio>
  17. <text v-if="items.name" class="title margin-left-sm">{{items.name}}</text>
  18. <text v-else class="title margin-left-sm">{{items.user_name}}</text>
  19. </radio-group>
  20. </view>
  21. </form>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. props: {
  27. selectList: {
  28. type: Array,
  29. default:[{
  30. name: '施工方',
  31. children: [{id:"1",name: '姓名1'}, {id:"2", name: '姓名2'}],
  32. },{
  33. name: '监理',
  34. children: [{id:"3",name: '姓名1'}, {id:"4", name: '姓名2'}],
  35. },{
  36. name: '业主',
  37. children: [{id:"5",name: '姓名1'}, {id:"6", name: '姓名2'}],
  38. }],
  39. },
  40. },
  41. data() {
  42. return {
  43. radioValue:0
  44. };
  45. },
  46. methods:{
  47. changeShow(index,item){//显示子节点
  48. if(item.show){
  49. this.$set(this.selectList[index], 'show', false)
  50. }else{
  51. this.$set(this.selectList[index], 'show', true)
  52. }
  53. },
  54. RadioChange(index,item){
  55. this.radioValue = item.id
  56. this.selectList[index].children.forEach(item => {
  57. if(item.id==this.radioValue){
  58. item.checked = true
  59. }else{
  60. item.checked = false
  61. }
  62. })
  63. //全局事件订阅只要注册的页面都可以收到回调值
  64. uni.$emit('num',1)
  65. },
  66. }
  67. }
  68. </script>
  69. <style>
  70. </style>