hanbaoshan
2020-04-15 72e13f676e7a78d5491819f0f68f6fd6c440d2aa
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
161
162
163
164
165
166
167
168
169
170
171
172
173
<template>
    <view class="content">
        <uniNavBar title="我的车辆" status-bar="true" class="header-bar" background-color="#fff" left-icon="back" :right-text="isShowEdit?'完成':'编辑'" color="#000" @clickLeft="goBack" @clickRight="edit">
        </uniNavBar>
        <!-- <div class="gap"></div> -->
        <view>
            <uni-swipe-action ref="swipeBar">
                <uni-swipe-action-item :disabled="isShowEdit" :options="options" @click="onClick($event,i)" @change="change" v-for="(i,index) in myCarList" :key="index">
                    <view class='cont'>
                        <uni-icons class="del" v-show="isShowEdit" @click="delItem(i)" type="minus-filled" size="20" color="#ff0000"></uni-icons>
                        <text>{{i}}</text>
                    </view>
                </uni-swipe-action-item>
            </uni-swipe-action>
        </view>
 
        <button class="add" type="default" @click="toAddCar">
            <uni-icons class="plus" type="plus" size="20" color="#fff"></uni-icons>
            添加车辆
        </button>
    </view>
</template>
 
<script>
    import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue';
    import uniSwipeActionItem from '@/components/uni-swipe-action-item/uni-swipe-action-item.vue';
    const {userId} = JSON.parse(uni.getStorageSync('user'));
    console.log(JSON.parse(uni.getStorageSync('user')))
    export default {
        components: {
            uniSwipeAction,uniSwipeActionItem
        },
        data() {
            return {
                options:[{
                    text: '删除',
                    style: {
                        backgroundColor: '#ff0000'
                    }
                }],
                isShowEdit: false,
                isEditable: true,
                myCarList:[]
            }
        },
        mounted(){
            //this.getCarList();
            console.log(JSON.parse(uni.getStorageSync('user')))
            this.getCarList();
        },
        onShow(){
            console.log(JSON.parse(uni.getStorageSync('user')))
            this.getCarList();
        },
        onBackPress(e){
            console.log(e);
            uni.navigateTo({
                url:'/pages/mine/mine'
            })
            return true
        },
        methods: {
            async getCarList(){
                console.log(JSON.parse(uni.getStorageSync('user')));
                let {userId} = JSON.parse(uni.getStorageSync('user'));
                console.log(userId)
                let res = await this.$api.syncRequest({
                    url: '/basic/api/user/myPlateNos?userId='+userId
                });
                if(res.data.success){
                    this.myCarList = res.data.data;
                    
                }
            },
            updateStorage(){
                let user = JSON.parse(uni.getStorageSync('user'));
                user.plateNos = this.myCarList;
                debugger
                //localStorage.setItem('user',JSON.stringify(user));
                uni.setStorageSync('user',JSON.stringify(user))
            },
            goBack(){
                uni.navigateBack({
                    delta: 1,
                    animationType: 'pop-out',
                    animationDuration: 200
                });
            },
            edit(){
                if(this.isEditable){
                    this.isShowEdit = !this.isShowEdit;
                    console.log(this.$refs['swipeBar'])
                }
            },
            onClick(e,i){
                debugger
                console.log('当前点击的是第'+e.index+'个按钮,点击内容是'+e.content.text);
                if(e.index==0){
                    this.delItem(i)
                }
            },
            delItem(plateNo){
                debugger
                this.$api.syncRequest({
                    url:`/basic/api/user/delPlateNo?userId=${userId}&&plateNo=${plateNo}`,
                    method: 'DELETE'
                }).then(res=>{
                    if(res.data.success){
                        uni.showToast({
                            icon: 'none',
                            title: '车辆已删除'
                        });
                        this.getCarList();
                        this.updateStorage();
                    }
                })
            },
            change(open){
              console.log('当前开启状态:'+ open);
        
              if(open){
                  this.isEditable = false
              }else{
                  this.isEditable = true
              }
            },
            toAddCar(){
                uni.navigateTo({
                    url: '/pages/addCar/addCar'
                });
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    uni-page-wrapper,uni-page-body{
        height: 100%;
    }
    .content{
        height: 100%;
        background-color: #fbfbfb;
        .header-bar{
            height: 200rpx;        
        }
        
        /deep/.uni-swipe_box{
            line-height: 90rpx;
            padding-left: 30rpx;
            box-sizing: border-box;
            border-bottom: 1rpx solid #F1F1F1;
            &:focus{
                background-color: #F1F1F1;
            }
            .cont{
                .del{
                    vertical-align: top;
                    padding: 0 10rpx 0;
                }
                font-size: 36rpx;
            }
        }
        .add{
            margin: 120rpx 30rpx 0;
            background-color: #0bbf71;
            color: #fff;
            .plus{
                padding-right:20rpx;
                font-weight: bold;
            }
        }
    }
</style>