Application.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="filterInfo">
  3. <div class="title" @click="showMore = !showMore">
  4. <h4>应用领域</h4>
  5. <van-icon :custom-class="showMore ? 'showMore' : ''" name="arrow-down" color="#CBCFDB" :size="18" />
  6. </div>
  7. <div class="list" :class="{ showLess: !showMore }">
  8. <block v-for="item in list" :key="item.id">
  9. <van-button
  10. :custom-class="chooseList.includes(item.id) ? 'chooseActive' : 'choose'"
  11. type="default"
  12. :color="chooseList.includes(item.id) ? '#FFF4E5' : '#F5F7FA'"
  13. @click="choose(item.id)"
  14. >
  15. {{ getName(item) }}
  16. <img
  17. v-if="chooseList.includes(item.id)"
  18. src="../../static/imgs/icon_list_xuanzhong.png"
  19. class="chooseImg"
  20. alt=""
  21. />
  22. </van-button>
  23. </block>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. value: {
  31. type: String,
  32. default: ''
  33. }
  34. },
  35. computed: {
  36. valueList() {
  37. if (this.value) {
  38. return this.value.split(',').map(item => {
  39. Number(item);
  40. });
  41. } else {
  42. return [];
  43. }
  44. }
  45. },
  46. data() {
  47. return {
  48. list: [],
  49. showMore: false,
  50. chooseList: []
  51. };
  52. },
  53. mounted() {
  54. this.$http.get('/productTag/application').then(res => {
  55. this.list = res;
  56. });
  57. },
  58. methods: {
  59. choose(id) {
  60. const list = [...this.chooseList];
  61. if (list.includes(id)) {
  62. const index = list.indexOf(id);
  63. list.splice(index, 1);
  64. } else {
  65. list.push(id);
  66. }
  67. this.chooseList = list;
  68. this.$emit('input', list.join(','));
  69. }
  70. },
  71. watch: {
  72. value() {
  73. if (this.value && this.chooseList.length === 0) {
  74. this.$nextTick(() => {
  75. this.chooseList = [...this.valueList];
  76. });
  77. } else if (!this.value && this.chooseList.length !== 0) {
  78. this.chooseList = [];
  79. }
  80. }
  81. }
  82. };
  83. </script>
  84. <style lang="less">
  85. .filterInfo {
  86. .title {
  87. display: flex;
  88. align-items: center;
  89. justify-content: space-between;
  90. .van-icon {
  91. transition: transform ease-in-out 0.3s;
  92. &.showMore {
  93. transform: rotate(180deg);
  94. }
  95. }
  96. }
  97. .list {
  98. display: flex;
  99. justify-content: space-between;
  100. flex-wrap: wrap;
  101. overflow: hidden;
  102. transition: max-height ease-in-out 0.3s;
  103. max-height: 800px;
  104. &.showLess {
  105. max-height: 34px;
  106. }
  107. }
  108. .van-button {
  109. width: 106px;
  110. box-sizing: border-box;
  111. height: 34px;
  112. margin-bottom: 10px;
  113. &.choose {
  114. color: #565b66 !important;
  115. }
  116. &.chooseActive {
  117. color: @warn!important;
  118. }
  119. .chooseImg {
  120. position: absolute;
  121. width: 16px;
  122. height: 16px;
  123. right: 0;
  124. bottom: 0;
  125. }
  126. }
  127. }
  128. </style>