gx
queenwuli
2021-01-25 c4246ca910f28014efaace64ebf92f47a673a9cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<template>
    <!-- 添加标签 -->
    <view>
        <search-bar @confirm="search" placeholder="搜索标签名称" class="ml-10 mr-10"></search-bar>
        <view class="content">
            <view class="title">
                <text>常用标签</text>
            </view>
            <view class="list" v-for="(item,index) in list" @click="lableChange(item)">
                <text class="iconfont" 
                    :class="item.isCheck?'icontubiao-duoxuandianji':'iconcheckbox-full'" 
                    :style="{color: item.color}"></text>
                <view class="ml-10 name">{{item.label}}</view>
            </view>
            <view class="title">
                <text>我的标签</text>
            </view>
            
            <uni-swipe-action>
                <uni-swipe-action-item :right-options="options"  @click="bindClick($event, item.id)" v-for="(item,index) in myList">
                    <view class="list" @click="lableChange(item)">
                        <text class="iconfont"
                            :class="item.isCheck?'icontubiao-duoxuandianji':'iconcheckbox-full'" 
                            :style="{color: item.color}"></text>
                        <view class="ml-10 name">{{item.label}}</view>
                    </view>
                </uni-swipe-action-item>
            </uni-swipe-action>
        </view>
        <button class="sticky-footer blue-btn" @click="confirm">确认</button>
    </view>
</template>
 
<script>
    import searchBar from '../../components/searchBar/index.vue';
    import {uniSwipeAction} from '../../components/uni-swipe-action/uni-swipe-action.vue'
    import {uniSwipeActionItem} from '../../components/uni-swipe-action-item/uni-swipe-action-item.vue'
    export default {
        components:{
            searchBar
        },
        data(){
            return{
                queryKey: '',
                list:[],
                myList:[],
                selectId: '',
                options:[{
                        text: '删除',
                        style: {
                            backgroundColor: '#dd524d'
                        }
                    }
                 ]
            }
        },
        onShow() {
            this.loadList()
        },
        onLoad(options) {
            if(options.selectId){
                this.selectId = options.selectId
            }
        },
        onNavigationBarButtonTap(e){
            if(e.index==0){
                uni.navigateTo({
                    url:"./createLabel"
                })
            }
        },
        methods:{
            loadList(){
                let selectedArr = this.selectId?this.selectId.split(','):[];
                this.$httpUtils.request('/api/label/findLabelList', {
                    label: this.queryKey
                }, 'POST').then((res) => {
                    if(res.status == 200){
                        this.list = res.mapInfo.allLabel.map((item) => {
                            if(this.selectId && selectedArr.includes(item.id.toString())){
                                return Object.assign(item, {isCheck: true})
                            }
                            return Object.assign(item, {isCheck: false})
                        });
                        this.myList = res.mapInfo.myLabel.map((item) => {
                            if(this.selectId && selectedArr.includes(item.id.toString())){
                                return Object.assign(item, {isCheck: true})
                            }
                            return Object.assign(item, {isCheck: false})
                        });
                    }
                })
            },
            search(val){
                this.queryKey = val;
                this.loadList();
            },
            lableChange(item){
                item.isCheck = !item.isCheck;
            },
            confirm(){
                let result = this.list.concat(this.myList);
                let selectItems = result.filter((item) => {
                    return item.isCheck
                });
                let pages = getCurrentPages();
                let prevPage = pages[ pages.length - 2 ]; 
                if(selectItems.length){
                    prevPage.$vm.setLabel && prevPage.$vm.setLabel(selectItems);
                }
                uni.navigateBack()
            },
            bindClick(e, id){
                uni.showModal({
                    title: '提示',
                    content: '确定删除该标签吗?',
                    success: (res) => {
                        if (res.confirm) {
                            this.$httpUtils.request('/api/label/delById/'+id).then((res) => {
                                if(res.status == 200){
                                    this.loadList()
                                }
                                this.$toast.info(res.info);
                            })
                        }
                    }
                });
            }
        }
    }
</script>
 
<style>
    .content{
        margin-bottom: 60px;
    }
    .title{
        background: #F2F2F2;
        padding: 10px;
        font-size: 15px;
    }
    .list{
        width: 100%;
        display: flex;
        align-items: center;
        padding-left: 10px;
    }
    .list .iconfont{
        font-size: 18px;
    }
    .list .name{
        width: 100%;
        padding: 10px 5px;
        border-bottom: 1px solid #EDEAF4;
        font-size: 14px;
    }
    .sticky-footer{
        bottom: 10px;
    }
</style>