绿满眶商城微信小程序-uniapp
zxl
4 天以前 3d43cd90f46f76316dbde60cb96cfbdc43152e90
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<template>
    <view class="container">
        <!-- 标题 -->
        <view class="header">
            <text class="title">用户列表</text>
        </view>
        <view>
            <button class="add-btn" @click="navigateToAdd()" :disabled="!isShopkeeper">新增用户</button>
        </view>
        <!-- 搜索框 -->
        <view class="search-box">
            <u-search v-model="query.realName" placeholder="搜索姓名" :showAction="false" @change="searchClerk()"></u-search>
        </view>
 
        <!-- 用户列表 -->
        <scroll-view scroll-y class="clerk-list" @scrolltolower="loadMore" v-if="clerkList.length > 0">
            <view class="clerk-item" v-for="(clerk, index) in clerkList" :key="clerk.id" >
 
                <view class="clerk-info">
                    <text class="realName">{{ clerk.realName ? clerk.realName: '未设置人名' }}</text>
                    <text class="mobile">{{ clerk.mobile }}</text>
                </view>
                <!-- 操作按钮区域 -->
                <view class="action-buttons">
                    <u-button type="primary" size="mini" @click.stop="restPassword(clerk.memberId)" class="edit-btn" :disabled="!checkPermission(clerk)">重置密码</u-button>
                    <u-button type="primary" size="mini" @click.stop="navigateToDetail(clerk.id)" class="edit-btn" :disabled="!checkPermission(clerk)">修改</u-button>
                    <u-button type="error" size="mini" @click.stop="deleteUser(clerk.id)" 
                        class="delete-btn" :disabled="!checkPermission(clerk)">删除</u-button>
                </view> 
 
            </view>
 
            <!-- 加载更多提示 -->
            
            <view class="load-more">
              <u-loadmore 
                v-if="clerkList.length > 0"
                :status="loading ? 'loading' : noMore ? 'nomore' : 'loadmore'"
                :load-text="{
                  loadmore: '上拉加载更多',
                  loading: '正在加载',
                  nomore: '没有更多了'
                }"
              />
            </view>
            <view style="height:150rpx">
                                  
            </view>
        </scroll-view>
 
 
    </view>
</template>
 
<script>
    import {
        getPage,
        del,
        add,
        update,
        restPassword,
        checkClerkPermission
    } from "@/api/userPermissions.js"
    import UIcon from '@/uview-components/uview-ui/components/u-icon/u-icon.vue';
    import UButton from '@/uview-components/uview-ui/components/u-button/u-button.vue';
    import UForm from '@/uview-components/uview-ui/components/u-form/u-form.vue';
    import UFormItem from '@/uview-components/uview-ui/components/u-form-item/u-form-item.vue';
    import UInput from '@/uview-components/uview-ui/components/u-input/u-input.vue';
    import USearch from '@/uview-components/uview-ui/components/u-search/u-search.vue';
    import UPopup from '@/uview-components/uview-ui/components/u-popup/u-popup.vue';
    import ULoading from '@/uview-components/uview-ui/components/u-loading/u-loading.vue';
    import ULoadmore from '@/uview-components/uview-ui/components/u-loadmore/u-loadmore.vue';
 
    import storage from "@/utils/storage.js"; //缓存
    import {
        getUserInfo
    } from "@/api/members";
    
    export default {
        components: {
            UIcon,
            UButton,
            UForm,
            UFormItem,
            UInput,
            USearch,
            UPopup,
            ULoading,
            ULoadmore,
        },
        data() {
            return {
                total:0,
                clerkList: [], // 用户列表数据
                loading: false, // 加载状态
                noMore: false, // 是否没有更多数据
                query: {
                    realName: '',
                    pageNumber: 1,
                    pageSize: 15,
                },
                isSuper:false,
                isShopkeeper:false,
                clerkId:'',//登录账号id
            }
        },
        onShow() {
            this.getPage()
        },
        onLoad() {
            this.getPage()
            //获得用户权限
            checkClerkPermission().then(res=>{
                this.isSuper = res.data.data.isSuper;
                this.isShopkeeper = res.data.data.isShopkeeper;
                this.clerkId = res.data.data.clerkId;
            })
            
        },
    
        methods: {
            //检查权限
            checkPermission(clerk){
                if(this.isShopkeeper){
                    return true;
                }
                if(this.clerkId === clerk.id){
                    return true;
                }else{
                    if(this.isSuper && !clerk.isSuper){
                        return true;
                    }
                    return false;
                }
                    
            },
            restPassword(id){
                restPassword(id).then(res=>{
                    if(res.statusCode === 200){
                        uni.showToast({
                            title: res.data.msg, // 提示文字
                            icon: 'none', // 图标类型(success/loading/none)
                            mask: true // 是否显示透明蒙层(防止触摸穿透)
                        });
                    }
                })
            },
            async getPage() {
                //
                uni.showLoading({
                    title: '加载中'
                });
                getPage(this.query).then(res => {
                    uni.hideLoading();
                    if (res.statusCode === 200) {
                        const newData = res.data.data;
                        // 更新总数据量
                        this.total = res.data.total || 0;
                        // 追加或替换数据
                        this.clerkList = this.query.pageNumber === 1 ?
                            newData :
                            [...this.clerkList, ...newData];
                            
                        // 判断是否还有更多数据
                        this.noMore = newData.length < this.query.pageSize ||
                            this.clerkList.length >= this.total;
                        
                    }
                })
 
 
            },
 
            // 搜索用户
            searchClerk() {
                this.query.pageNumber = 1
                this.noMore = false
                this.clerkList = []
                this.getPage()
            },
 
            // 加载更多
            loadMore() {
                if (!this.noMore) {
                    this.query.pageNumber++
                    this.getPage()
                }
            },
            // 跳转到新增用户
            navigateToAdd() {
                uni.navigateTo({
                    url: `/pages/userPermissions/addStoreMember`
                })
            },
            // 跳转到用户详情
            navigateToDetail(id) {
                uni.navigateTo({
                    url: `/pages/userPermissions/addStoreMember?id=${id}`
                })
            },
            deleteUser(id){
                del(id).then(res =>{
                    if (res.statusCode === 200) {
                        this.getPage();
                    }
                })
            },
            
            
        }
    }
</script>
 
<style lang="scss" scoped>
    .action-buttons {
      display: flex;
      margin-left: 20rpx;
    }
    
    .edit-btn {
      margin-right: 10rpx;
    }
    .container {
        padding: 20rpx;
        height: 100vh;
        display: flex;
        flex-direction: column;
        background-color: #f5f5f5;
    }
 
    .header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 20rpx 0;
        margin-bottom: 20rpx;
 
        .title {
            font-size: 36rpx;
            font-weight: bold;
            color: #333;
        }
 
 
    }
 
    .add-btn {
        width: 50%;
        background-color: #2979ff;
        color: white;
        border-radius: 40rpx;
        padding: 0 50rpx;
        height: 60rpx;
        line-height: 60rpx;
        font-size: 26rpx;
        box-shadow: 0 2rpx 10rpx rgba(41, 121, 255, 0.3);
        margin-bottom: 20rpx;
    }
 
    .search-box {
        margin-bottom: 20rpx;
    }
 
    .clerk-list {
        flex: 1;
        overflow: hidden;
    }
 
    .clerk-item {
        display: flex;
        align-items: center;
        padding: 20rpx;
        margin-bottom: 20rpx;
        background-color: #fff;
        border-radius: 12rpx;
        box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
 
        .avatar {
            width: 80rpx;
            height: 80rpx;
            border-radius: 50%;
            margin-right: 20rpx;
        }
 
        .clerk-info {
            flex: 1;
            display: flex;
            flex-direction: column;
 
            .realName {
                font-size: 32rpx;
                color: #333;
                margin-bottom: 8rpx;
            }
 
            .mobile {
                font-size: 24rpx;
                color: #999;
            }
        }
    }
    .load-more {
                padding: 20rpx 0;
                text-align: center;
                color: #999;
                font-size: 26rpx;
                background-color: #f7f8fa;
            }
 
</style>