chooseLable.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view>
  3. <mp-tree :checkList="checkList" v-if="tree.length>0" :props="prop"
  4. @sendValue="confirm" :parent="false" :isCheck="true" :trees="tree">
  5. <!-- 内容插槽 -->
  6. </mp-tree>
  7. </view>
  8. </template>
  9. <script>
  10. import mpTree from '@/components/mp-tree/tree.vue';
  11. export default {
  12. components: {
  13. mpTree
  14. },
  15. data() {
  16. return {
  17. tree: [],
  18. checkList: [],
  19. prop: {
  20. label: 'dictKey',
  21. children: 'children',
  22. multiple: true,
  23. checkStrictly: true
  24. },
  25. }
  26. },
  27. onLoad(options) {
  28. if (!this.$isEmpty(options.label)) {
  29. this.checkList=JSON.parse(options.label)
  30. }
  31. this.getLabel()
  32. },
  33. methods: {
  34. getLabel(){
  35. let params={
  36. code:'business_label'
  37. }
  38. this.$api.dict.dictionaryTree(params).then(res=>{
  39. this.tree=res.data
  40. console.log(this.tree,"....");
  41. })
  42. },
  43. //获取选中的值
  44. confirm(val, back) {
  45. let checkList=[]
  46. let labelKey=[]
  47. let parentIds=new Set()
  48. val.forEach(item=>{
  49. parentIds.add(item.parentId)
  50. labelKey.push(item.dictKey)
  51. let obj={
  52. id:item.id,
  53. dictKey:item.dictKey,
  54. dictValue:item.dictValue,
  55. hasChildren:item.hasChildren,
  56. parentId:item.parentId
  57. }
  58. checkList.push(obj)
  59. })
  60. //返回上一页的数据
  61. let labelData={
  62. //一级标签的ids,逗号分割
  63. labelParentIds:Array.from(parentIds).join(","),
  64. //二级标签的json数据
  65. labelJson:JSON.stringify(checkList),
  66. //二级标签key,逗号分割
  67. labelKey:labelKey.join(",")
  68. }
  69. console.log(labelData,"****");
  70. uni.$emit('labelData',labelData)
  71. this.$back()
  72. },
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. .box_sizing {
  78. -webkit-box-sizing: border-box;
  79. -moz-box-sizing: border-box;
  80. box-sizing: border-box;
  81. }
  82. .btn {
  83. position: fixed;
  84. bottom: 0;
  85. padding: 10px;
  86. background-color: #fff;
  87. width: 100%;
  88. .sureBtn {
  89. background-color: #0095F2;
  90. color: #fff;
  91. }
  92. }
  93. </style>