row.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. export default {
  30. data() {
  31. return {}
  32. },
  33. props: ['option', 'openKeys', 'checkedKeys'],
  34. computed: {
  35. hasChildren: function() {
  36. return this.option.children && this.option.children.length > 0;
  37. },
  38. open: function() {
  39. return this.hasChildren && this.openKeys.includes(this.option.key);
  40. },
  41. checked: function() {
  42. return this.checkedKeys.includes(this.option.key);
  43. },
  44. leftIcon: function() {
  45. let iconName = 'parent-open';
  46. if(this.hasChildren) {
  47. if(this.open) {
  48. iconName = 'parent-close';
  49. }
  50. } else {
  51. iconName = 'child'
  52. }
  53. return iconName;
  54. },
  55. rightIcon: function() {
  56. return this.checked ? 'check-checkbox' : 'check-no';
  57. }
  58. },
  59. methods: {
  60. rowClick: function() {
  61. if(!this.hasChildren) return;
  62. this.openKeysHandle(this.keysHandle(this.open, this.openKeys));
  63. },
  64. checkedHandle: function(e) {
  65. _stopPropagation(e);
  66. this.checkedKeysHandle(this.keysHandle(this.checked, this.checkedKeys));
  67. },
  68. keysHandle: function(condition, oldKeys) {
  69. let keys = [];
  70. if(condition) {
  71. keys = oldKeys.filter((key)=> key !== this.option.key);
  72. } else {
  73. keys = [...oldKeys, this.option.key];
  74. }
  75. return keys;
  76. },
  77. openKeysHandle: function(arr) {
  78. this.$emit('open-keys', arr);
  79. },
  80. checkedKeysHandle: function(arr) {
  81. this.$emit('checked-keys', arr);
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="less">
  87. .row {
  88. display: flex;
  89. flex-direction: column;
  90. align-items: center;
  91. padding-left: 25rpx;
  92. width: 100%;
  93. background-color: #fff;
  94. .content-wrap {
  95. display: flex;
  96. flex-direction: row;
  97. justify-content: space-between;
  98. align-items: center;
  99. border-bottom: 0.62rpx solid #DADEE6;
  100. width: 100%;
  101. height: 87.5rpx;
  102. font-size: 22.5rpx;
  103. line-height: 33.75rpx;
  104. color: #292C33;
  105. .left {
  106. display: flex;
  107. flex-direction: row;
  108. align-items: center;
  109. view {
  110. margin-right: 20rpx;
  111. height: 28rpx;
  112. image {
  113. width: 25rpx;
  114. height: 22.5rpx;
  115. }
  116. }
  117. }
  118. .right {
  119. display: flex;
  120. flex-direction: row;
  121. justify-content: center;
  122. align-items: center;
  123. width: 87.5rpx;
  124. height: 87.5rpx;
  125. image {
  126. width: 25rpx;
  127. height: 25rpx;
  128. }
  129. }
  130. }
  131. .children-wrap {
  132. width: 100%;
  133. padding-left: 77.5rpx;
  134. }
  135. }
  136. </style>