| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <template>
- <view>
- <mp-tree v-slot:default="{item}" :checkList="checkList" v-if="tree.length>0" :props="prop"
- @sendValue="confirm" :parent="false" :isCheck="true" :trees="tree">
- <!-- 内容插槽 -->
- <view>
- <view class="content-item">
- <view class="word">{{item.dictKey}}</view>
- </view>
- </view>
- </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
- })
- },
- //获取选中的值
- 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;
- }
- }
- .content-item {
- display: flex;
- position: relative;
- align-items: center;
- .person {
- height: 64rpx;
- min-width: 64rpx;
- border-radius: 50%;
- border: 1rpx solid rgba(0, 149, 235, 0.15);
- background-color: rgba(0, 149, 235, 0.1);
- margin-left: 0px;
- color: #0095F2;
- line-height: 64rpx;
- font-size: 22rpx;
- text-align: center;
- margin-left: 20rpx;
- }
- .word {
- margin-left: 20rpx;
- font-size: 30rpx;
- color: #5b5757;
- width: 500rpx;
- word-break: break-all;
- }
- }
- </style>
|