tm-checked-group.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="tm-radio-group">
  3. <component :is="currentComponet" :list="list" :defaultValue="defaultValue" :label="label" :setting="setting"
  4. :openkeys="openPkeys" @change="toggleSelect" @changeOpenPKey="changeOpenPKey" />
  5. </view>
  6. </template>
  7. <script>
  8. /**
  9. * 单选列表组合/下拉式单选列表组合
  10. * 芦荟
  11. * 2021.2.2
  12. * props:看下面,有注释说明
  13. */
  14. import radioGroup from './check-group.vue'
  15. import radioSelectGroup from './check-select-group.vue'
  16. export default {
  17. props: {
  18. // 渲染的数据
  19. list: {
  20. type: Array,
  21. default: () => {
  22. return []
  23. }
  24. },
  25. // 选中的数据
  26. defaultValue: {
  27. type: Array,
  28. default: []
  29. },
  30. // 单选列表组合名字
  31. label: {
  32. type: String,
  33. default: ''
  34. },
  35. // 单选组配置
  36. setting: {
  37. type: Object,
  38. default: () => {
  39. return {
  40. pName: 'pName', // 父级显示的文字
  41. child: 'child', // 子数据list
  42. value: 'value', // 设置当前选中的值(默认取value)
  43. name: 'name' // 当前显示的文字(默认取name)
  44. }
  45. }
  46. },
  47. /**
  48. * 单选列表组合 或 下拉式单选列表组合
  49. * default:单选列表组合(如指派改善任务) 默认值
  50. * select: 下拉式单选列表组合(如人员架构)
  51. */
  52. type: {
  53. type: String,
  54. default: 'default'
  55. },
  56. // 默认展开的父级下标(注意: 数组存父级元素下标)
  57. openkeys: {
  58. type: Array,
  59. default: () => {
  60. return []
  61. }
  62. },
  63. },
  64. computed: {
  65. // 当前显示的组件
  66. currentComponet() {
  67. return this.type === 'default' ? 'radio-group' : 'radio-select-group'
  68. }
  69. },
  70. data() {
  71. return {
  72. // 展开的父级下标
  73. openPkeys: this.openkeys
  74. }
  75. },
  76. methods: {
  77. /**
  78. * 返回的参数
  79. * data :
  80. * -- radio-group => {checkedList,parentIndex}
  81. * -- radio-select-group => {checkedList,parentIndex,parent}
  82. */
  83. toggleSelect(data) {
  84. this.$emit('change',data);
  85. },
  86. // 更改父级展开的下标
  87. changeOpenPKey(type, key) {
  88. this.openPkeys = type === 'open' ?
  89. [...this.openPkeys, key] :
  90. this.openPkeys.filter(openKey => openKey != key);
  91. }
  92. },
  93. components: {
  94. radioGroup,
  95. radioSelectGroup
  96. }
  97. }
  98. </script>
  99. <style lang="less">
  100. .tm-radio-group {
  101. .label-view {
  102. height: 47.5rpx;
  103. line-height: 45rpx;
  104. padding-left: 25rpx;
  105. >text {
  106. font-size: 22.5rpx;
  107. color: #666F80;
  108. }
  109. }
  110. .radio-group {
  111. padding-left: 25rpx;
  112. background-color: #fff;
  113. .radio-item {
  114. display: flex;
  115. align-items: center;
  116. justify-content: space-between;
  117. height: 87.5rpx;
  118. border-bottom: 0.62rpx solid #DADEE6;
  119. padding-right: 25rpx;
  120. .text {
  121. font-size: 22.5rpx;
  122. color: #292C33;
  123. }
  124. .icon {
  125. width: 25rpx;
  126. height: 25rpx;
  127. }
  128. }
  129. }
  130. }
  131. </style>