row.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="row">
  3. <view class="content-wrap" @click="rowClick">
  4. <view class="left">
  5. <view>
  6. <image class="left-icon"
  7. :style="{width: hasChildren ? '25rpx' : '20rpx'}"
  8. :src="`../../static/${leftIcon}.png`"></image>
  9. </view>
  10. <text>{{ option.label }}</text>
  11. </view>
  12. <view v-if="!hasChildren" class="right" @click="checkedHandle">
  13. <image :src="`../../static/${rightIcon}.png`"></image>
  14. </view>
  15. </view>
  16. <view class="children-wrap" v-if="open">
  17. <tm-trees-row v-for="(item,index) in option.children"
  18. :option="item"
  19. :openKeys="openKeys"
  20. :checkedKeys="checkedKeys"
  21. v-on:open-keys="openKeysHandle"
  22. v-on:checked-keys="checkedKeysHandle"
  23. :key="index"/>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {_stopPropagation} from "../../utils/compatible.js";
  29. import {arrFilter} from "../../utils/arrFilter.js";
  30. export default {
  31. data() {
  32. return {}
  33. },
  34. props: ['option', 'openKeys', 'checkedKeys'],
  35. computed: {
  36. hasChildren: function() {
  37. return this.option.children && this.option.children.length > 0;
  38. },
  39. open: function() {
  40. return this.hasChildren && this.openKeys.includes(this.option.key);
  41. },
  42. checked: function() {
  43. return this.checkedKeys.includes(this.option.key);
  44. },
  45. leftIcon: function() {
  46. let iconName = 'parent-open';
  47. if(this.hasChildren) {
  48. if(this.open) {
  49. iconName = 'parent-close';
  50. }
  51. } else {
  52. iconName = 'child'
  53. }
  54. return iconName;
  55. },
  56. rightIcon: function() {
  57. return this.checked ? 'check-checkbox' : 'check-no';
  58. }
  59. },
  60. methods: {
  61. rowClick: function() {
  62. if(!this.hasChildren) return;
  63. this.openKeysHandle(arrFilter(this.option.key, this.openKeys));
  64. },
  65. checkedHandle: function(e) {
  66. _stopPropagation(e);
  67. this.checkedKeysHandle(arrFilter(this.option.key, this.checkedKeys));
  68. },
  69. openKeysHandle: function(arr) {
  70. this.$emit('open-keys', arr);
  71. },
  72. checkedKeysHandle: function(arr) {
  73. this.$emit('checked-keys', arr);
  74. }
  75. }
  76. }
  77. </script>
  78. <style lang="less">
  79. .row {
  80. display: flex;
  81. flex-direction: column;
  82. align-items: center;
  83. padding-left: 25rpx;
  84. width: 100%;
  85. background-color: #fff;
  86. .content-wrap {
  87. display: flex;
  88. flex-direction: row;
  89. justify-content: space-between;
  90. align-items: center;
  91. border-bottom: 0.62rpx solid #DADEE6;
  92. width: 100%;
  93. height: 87.5rpx;
  94. font-size: 22.5rpx;
  95. line-height: 33.75rpx;
  96. color: #292C33;
  97. .left {
  98. display: flex;
  99. flex-direction: row;
  100. align-items: center;
  101. view {
  102. margin-right: 20rpx;
  103. height: 28rpx;
  104. image {
  105. width: 25rpx;
  106. height: 22.5rpx;
  107. }
  108. }
  109. }
  110. .right {
  111. display: flex;
  112. flex-direction: row;
  113. justify-content: center;
  114. align-items: center;
  115. width: 87.5rpx;
  116. height: 87.5rpx;
  117. image {
  118. width: 25rpx;
  119. height: 25rpx;
  120. }
  121. }
  122. }
  123. .children-wrap {
  124. width: 100%;
  125. padding-left: 77.5rpx;
  126. }
  127. }
  128. </style>