chooseLable.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view>
  3. <mp-tree v-slot:default="{item}" :checkList="checkList" v-if="tree.length>0" :props="prop"
  4. @sendValue="confirm" :parent="false" :isCheck="true" :trees="tree">
  5. <!-- 内容插槽 -->
  6. <view>
  7. <view class="content-item">
  8. <view class="word">{{item.dictKey}}</view>
  9. </view>
  10. </view>
  11. </mp-tree>
  12. </view>
  13. </template>
  14. <script>
  15. import mpTree from '@/components/mp-tree/tree.vue';
  16. export default {
  17. components: {
  18. mpTree
  19. },
  20. data() {
  21. return {
  22. tree: [],
  23. checkList: [],
  24. prop: {
  25. label: 'dictKey',
  26. children: 'children',
  27. multiple: true,
  28. checkStrictly: true
  29. },
  30. }
  31. },
  32. onLoad(options) {
  33. if (!this.$isEmpty(options.label)) {
  34. this.checkList=JSON.parse(options.label)
  35. }
  36. this.getLabel()
  37. },
  38. methods: {
  39. getLabel(){
  40. let params={
  41. code:'business_label'
  42. }
  43. this.$api.dict.dictionaryTree(params).then(res=>{
  44. this.tree=res.data
  45. })
  46. },
  47. //获取选中的值
  48. confirm(val, back) {
  49. let checkList=[]
  50. let labelKey=[]
  51. let parentIds=new Set()
  52. val.forEach(item=>{
  53. parentIds.add(item.parentId)
  54. labelKey.push(item.dictKey)
  55. let obj={
  56. id:item.id,
  57. dictKey:item.dictKey,
  58. dictValue:item.dictValue,
  59. hasChildren:item.hasChildren,
  60. parentId:item.parentId
  61. }
  62. checkList.push(obj)
  63. })
  64. //返回上一页的数据
  65. let labelData={
  66. //一级标签的ids,逗号分割
  67. labelParentIds:Array.from(parentIds).join(","),
  68. //二级标签的json数据
  69. labelJson:JSON.stringify(checkList),
  70. //二级标签key,逗号分割
  71. labelKey:labelKey.join(",")
  72. }
  73. console.log(labelData,"****");
  74. uni.$emit('labelData',labelData)
  75. this.$back()
  76. },
  77. }
  78. }
  79. </script>
  80. <style lang="scss">
  81. .box_sizing {
  82. -webkit-box-sizing: border-box;
  83. -moz-box-sizing: border-box;
  84. box-sizing: border-box;
  85. }
  86. .btn {
  87. position: fixed;
  88. bottom: 0;
  89. padding: 10px;
  90. background-color: #fff;
  91. width: 100%;
  92. .sureBtn {
  93. background-color: #0095F2;
  94. color: #fff;
  95. }
  96. }
  97. .content-item {
  98. display: flex;
  99. position: relative;
  100. align-items: center;
  101. .person {
  102. height: 64rpx;
  103. min-width: 64rpx;
  104. border-radius: 50%;
  105. border: 1rpx solid rgba(0, 149, 235, 0.15);
  106. background-color: rgba(0, 149, 235, 0.1);
  107. margin-left: 0px;
  108. color: #0095F2;
  109. line-height: 64rpx;
  110. font-size: 22rpx;
  111. text-align: center;
  112. margin-left: 20rpx;
  113. }
  114. .word {
  115. margin-left: 20rpx;
  116. font-size: 30rpx;
  117. color: #5b5757;
  118. width: 500rpx;
  119. word-break: break-all;
  120. }
  121. }
  122. </style>