tagpop.nvue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="tagpopcon" >
  3. <view class="tagpopcon-title" :style="{width:width+'px'}">选择标签</view>
  4. <list class="tagpop-box" :show-scrollbar="true" :style="{height:height+'px'}" :scrollable="true">
  5. <cell v-for="(item,index) in tags" :key="index" >
  6. <view class="tag-group">
  7. <view class="tag-label">{{ item.label }}</view>
  8. <image class="close_icon" src="/static/close_icon.png" @click="closePopup"></image>
  9. <view class="child-label-box">
  10. <u-tag class="child-label" v-for="(it,idx) in item.children" :key="idx" :text="it.label"
  11. :color="it.checked?'#2583EB':'#666'" :bgColor="it.checked?'#ffe8dc':'#fff'"
  12. :borderColor="it.checked?'#ffe8dc':'#eee'" @click="handleChooseTag(index,idx)"></u-tag>
  13. </view>
  14. </view>
  15. </cell>
  16. </list>
  17. </view>
  18. </template>
  19. <script>
  20. import { getTag } from "@/api/expert.js"
  21. export default {
  22. data() {
  23. return {
  24. height: 0,
  25. width: 350,
  26. tags:[]
  27. }
  28. },
  29. onLoad(){
  30. this.height = uni.getSystemInfoSync().screenHeight / 2 - uni.getSystemInfoSync().statusBarHeight
  31. this.width = uni.getSystemInfoSync().screenWidth
  32. this.getTags()
  33. },
  34. methods: {
  35. getTags() {
  36. getTag().then(res => {
  37. if (res.code == 200) {
  38. this.tags = res.data || []
  39. this.tags = this.addCheckedProperty(this.tags)
  40. uni.$emit('chooseTag',this.tags)
  41. }
  42. })
  43. },
  44. addCheckedProperty(tags) {
  45. return tags.map(tag => {
  46. // 为当前对象添加checked属性
  47. const updatedTag = {
  48. ...tag,
  49. checked: false
  50. };
  51. // 如果有子对象,递归处理
  52. if (updatedTag.children) {
  53. updatedTag.children = this.addCheckedProperty(updatedTag.children);
  54. }
  55. return updatedTag;
  56. });
  57. },
  58. handleChooseTag(index, idx) {
  59. this.tags[index].children[idx].checked = !this.tags[index].children[idx].checked
  60. uni.$emit('chooseTag',this.tags)
  61. },
  62. closePopup() {
  63. const subNVue = uni.getSubNVueById('tagpop');
  64. subNVue.hide('slide-out-bottom');
  65. },
  66. }
  67. }
  68. </script>
  69. <style scoped lang="scss">
  70. .tagpopcon {
  71. background-color: #fff;
  72. border-radius: 16rpx 16rpx 0 0;
  73. padding: 24rpx;
  74. position: relative;
  75. &-title {
  76. text-align: center;
  77. position: fixed;
  78. top: 0;
  79. left: 0;
  80. height: 44px;
  81. display: flex;
  82. align-items: center;
  83. flex-direction: row;
  84. justify-content: center;
  85. background-color: #fff;
  86. border-bottom: 1rpx solid #eee;
  87. }
  88. .close_icon {
  89. position: fixed;
  90. top: 10px;
  91. right: 10px;
  92. width: 22px;
  93. height: 22px;
  94. }
  95. .tagpop-box {
  96. padding-top: 44px;
  97. }
  98. .tag-label {
  99. font-size: 16px;
  100. font-weight: bold;
  101. margin-bottom: 5px;
  102. // background-color: #f7f7f7;
  103. }
  104. .child-label-box {
  105. display: flex;
  106. flex-direction: row;
  107. align-items: center;
  108. flex-wrap: wrap;
  109. }
  110. .child-label {
  111. margin: 0 16rpx 16rpx 0;
  112. }
  113. }
  114. </style>