| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <template>
- <view>
- <mp-tree :checkList="checkList" v-if="tree.length>0" :props="prop"
- @sendValue="confirm" :parent="false" :isCheck="true" :trees="tree">
- <!-- 内容插槽 -->
- </mp-tree>
- </view>
- </template>
- <script>
- import mpTree from '@/components/mp-tree/tree.vue';
- export default {
- components: {
- mpTree
- },
- data() {
- return {
- tree: [],
- checkList: [],
- prop: {
- label: 'dictKey',
- children: 'children',
- multiple: true,
- checkStrictly: true
- },
- }
- },
- onLoad(options) {
- if (!this.$isEmpty(options.label)) {
- this.checkList=JSON.parse(options.label)
- }
- this.getLabel()
- },
- methods: {
- getLabel(){
- let params={
- code:'business_label'
- }
- this.$api.dict.dictionaryTree(params).then(res=>{
- this.tree=res.data
- console.log(this.tree,"....");
- })
- },
- //获取选中的值
- confirm(val, back) {
- let checkList=[]
- let labelKey=[]
- let parentIds=new Set()
- val.forEach(item=>{
- parentIds.add(item.parentId)
- labelKey.push(item.dictKey)
- let obj={
- id:item.id,
- dictKey:item.dictKey,
- dictValue:item.dictValue,
- hasChildren:item.hasChildren,
- parentId:item.parentId
- }
- checkList.push(obj)
- })
- //返回上一页的数据
- let labelData={
- //一级标签的ids,逗号分割
- labelParentIds:Array.from(parentIds).join(","),
- //二级标签的json数据
- labelJson:JSON.stringify(checkList),
- //二级标签key,逗号分割
- labelKey:labelKey.join(",")
- }
- console.log(labelData,"****");
- uni.$emit('labelData',labelData)
- this.$back()
- },
- }
- }
- </script>
- <style lang="scss">
- .box_sizing {
- -webkit-box-sizing: border-box;
- -moz-box-sizing: border-box;
- box-sizing: border-box;
- }
- .btn {
- position: fixed;
- bottom: 0;
- padding: 10px;
- background-color: #fff;
- width: 100%;
- .sureBtn {
- background-color: #0095F2;
- color: #fff;
- }
- }
- </style>
|