tm-radio-group.vue 3.3 KB

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