app-check-box.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view>
  3. <view class="app-view" v-if="type === 'all'" @click="selectAll">
  4. <view class="app-item"
  5. :style="{'width': `${size ? size : 32}rpx`}"
  6. :class="[
  7. {'app-radius': shape === 'round'}
  8. ]"
  9. ></view>
  10. <view class="app-mask"
  11. v-show="value.boolean"
  12. :style="{'width': `${size ? size : 32}rpx`}"
  13. :class="[
  14. {'app-radius': shape === 'round'},
  15. `${theme}-background`
  16. ]"
  17. ></view>
  18. </view>
  19. <view class="app-view" @click="handleCheckBox" v-if="type !== 'all'">
  20. <view class="app-item"
  21. :style="{'width': `${size ? size : 32}rpx`}"
  22. :class="[
  23. {'app-radius': shape === 'round'}
  24. ]"
  25. ></view>
  26. <view class="app-mask"
  27. v-show="value.boolean"
  28. :style="{'width': `${size ? size : 32}rpx`}"
  29. :class="[
  30. {'app-radius': shape === 'round'},
  31. `${theme}-background`
  32. ]"
  33. ></view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. name: 'app-check-box',
  40. props: {
  41. selectData: Array,
  42. shape: String,
  43. theme: String,
  44. size: String,
  45. type: String,
  46. item: Object,
  47. value: {
  48. default: {
  49. type: 'all',
  50. boolean: false
  51. },
  52. },
  53. isShow: Boolean,
  54. },
  55. data() {
  56. return {
  57. showHidden: this.value,
  58. allBoolean: this.value,
  59. }
  60. },
  61. methods: {
  62. handleCheckBox() {
  63. this.showHidden = !this.showHidden;
  64. this.$emit('input', this.showHidden);
  65. },
  66. selectAll() {
  67. this.allBoolean = !this.allBoolean;
  68. this.$emit('input', this.allBoolean);
  69. }
  70. },
  71. watch: {
  72. selectData: {
  73. handler: function() {
  74. // let num = 0;
  75. // let add = this.selectData.length;
  76. // for (let i = 0; i < this.selectData.length; i++) {
  77. // if (this.selectData[i].boolean === true) {
  78. // num++;
  79. // } else {
  80. // add--;
  81. // }
  82. // }
  83. // if (add < this.selectData.length) {
  84. // this.allBoolean = false;
  85. // this.$emit('input', this.allBoolean);
  86. // }
  87. // if (num === this.selectData.length) {
  88. // this.allBoolean = true;
  89. // this.$emit('input', this.allBoolean);
  90. // }
  91. },
  92. deep: true,
  93. immediate: true,
  94. },
  95. isShow: {
  96. handler: function(response) {
  97. // for (let i = 0;i < this.selectData.length; i++) {
  98. // this.selectData[i].boolean = response;
  99. // }
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped lang="scss">
  106. .app-view {
  107. position: relative;
  108. }
  109. .app-item {
  110. width: #{32rpx};
  111. height: #{32rpx};
  112. border: #{1rpx} solid $uni-general-color-three;
  113. }
  114. .app-radius {
  115. border-radius: 50%;
  116. }
  117. .app-mask {
  118. width: #{32rpx};
  119. height: #{32rpx};
  120. position: absolute;
  121. top: 0;
  122. left: 0;
  123. }
  124. </style>