wzp
2022-02-22 46083a2914a62c1835612fb0872d7fdc76d7bb9d
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<template>
    <!-- mescroll-body本质是原生page的滚动,无法像mescroll-uni那样用flex布局嵌在某个view中使用局部区域滚动, 但是可以通过fixed定位其他元素来实现"局部区域滚动"-->
    <view>
        <!-- 顶部 fixed定位 -->
        <view class="top-warp"> 
            <view class="">
                <cu-custom bgColor="bg-gradual-blue" :isBack="true">
                    <block slot="backText">返回</block>
                    <block slot="content">资产借用</block>
                </cu-custom>
            </view>
            
        </view>
        <view class="search-box">
            <view class="item">
                <u-search placeholder="请输入关键字搜索" v-model="keyword" :clearabled="true" :show-action="false"
                    @search="onSearch">
                </u-search>
            </view>
        </view>
        
        
        
        <!-- mescroll-body跟随page滚动, 不可fixed定位, 可设置 top, bottom, topbar, bottombar, safearea的偏移量-->
        <mescroll-body ref="mescrollRef" top="176" bottom="300" @init="mescrollInit" @down="downCallback" @up="upCallback">
            <view class="cu-list menu-avatar ">
                <view class="cu-item" v-for="(item,index) in assetsList" :key="index">
                    <view class="cu-avatar radius lg bg-white"
                        style="background-image:url(../../static/device.png)">
                    </view>
                    <view class="content">
                        <view>
                            <view class="text-cut text-bold text-xl">{{item.name}}</view>
                            <view class="cu-tag radius bg-orange sm">可领用:{{item.quantity}}</view>
                            <view class="numbox">
                                <u-number-box v-model="valueList[index]" :min="0" :max="item.quantity"
                                    :showMinus="valueList[index] > 0">
                                    <view slot="minus" class="minus">
                                        <u-icon name="minus" size="12"></u-icon>
                                    </view>
                                    <input slot="input" style="width: 38px;text-align: center; " class="input"
                                        :value="valueList[index]?valueList[index]:0"></input>
                                    <view slot="plus" class="plus">
                                        <u-icon name="plus" color="#FFFFFF" size="12"></u-icon>
                                    </view>
                                </u-number-box>
                            </view>
                        </view>
                        <view class="text-gray text-sm flex">
                            <view class="text-cut">规格:{{item.model?item.model:'无'}} 编码:{{item.serialNumber}}</view>
                        </view>
                    </view>
                </view>
            </view>
        </mescroll-body>
        
        <!-- 底部 fixed定位 -->
        <view class="bottom-warp">
            <view class="margin-top">
                <view class="margin-left border-title">
                    申请理由
                </view>
                <view class="flex justify-center align-center" style="margin-top: 10rpx;">
                    <view class="" style="width: 95%; ">
                        <u--textarea height="50" v-model="reason" placeholder="请输入内容" placeholderStyle="font-size: 15rpx;">
                        </u--textarea>
                    </view>
            
                </view>
            </view>
            
            <view class="padding-left padding-top  border-title " style="padding-bottom: 10rpx;">
                <view class="action">
                    申请人信息
                </view>
            </view>
            <view class="flex justify-center">
                <view class="u-border radius" style="width: 95%; padding:20rpx 0 20rpx 20rpx;">
                    <view class="">
                        申请人: {{applicant}}
                    </view>
 
                    <view class="" style="margin-top: 5rpx;">
                        申请时间: {{applicationTime}}
                    </view>
                </view>
            </view>
            
            <view class="margin-top" style="margin-bottom: 30rpx;">
                <u-button style="width: 40%;" type="primary" text="提交申请" @click="submit" :disabled="isDisabled"></u-button>
            </view>
            
            <u-toast ref="uToast"></u-toast>
        </view>
    </view>
</template>
 
 
<script>
    import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
 
    
    export default {
        mixins: [MescrollMixin], // 使用mixin
        data() {
            return {
                keyword: '',
                value: 0,
                reason: '',
                total:0,
                assetsList: [],
                listFlag: false,
                
                valueList: [],
                applicant: "", //申请人
                
                applicationTime: '', //申请时间
                templateId: '', //模板ID
                isDisabled: false,
                
                
                page: 1,
                pageSize: 10,
                status: 'loadmore',
                user:null
            }
        },
        onLoad() {
            this.user =uni.getStorageSync('user');
            this.applicant = this.user.userName;
            this.applicationTime = this.$dayjs().format("YYYY-MM-DD HH:mm:ss")
        },
        onShow() {
            this.initTemplateData();
        },
        methods: {
            /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
            onSearch(e) {
                console.log("搜索:" + this.keyword)
                this.page = 1;
                let page ={};
                page.num =1;
                this.upCallback(page);
            },
            
            upCallback(page) {
                
                let pageNum = page.num; //页码,默认从1开始
                let pageSize = 10; //页长,默认每页10条
                
                console.log(pageNum)
                this.$http.get('/assets/approval/search', {
                        params: {
                            pageNum: pageNum,
                            pageSize: pageSize,
                            keyStr: this.keyword,
                            state: "1"
                        }
                    })
                    .then(res => {
                        if (res.data.code === 0) {
                            let data = res.data.rows;
                            console.log(res.data.total)
                            if (page.num == 1) this.assetsList = []; //如果是第一页,需手动置空列表
                            this.assetsList = this.assetsList.concat(data); //追加新数据
                            console.log(this.assetsList.length)
                            this.mescroll.endBySize(this.assetsList.length, res.data.total);
                        }
                        else{
                            this.mescroll.endBySize(0, 0);
                        }
                        
                    })
                    .catch(err => {
                        this.mescroll.endErr();
                        console.log('异常', err);
                    });
            },
 
            //获取借用的模板
            initTemplateData() {
                this.$http.get('/assets/approval/getTemplate')
                    .then(res => {
                        // debugger;
                        if (res.data.code === 0) {
                            let data = res.data.data;
                            //获取领用的模板ID
                            for (let i = 0; i < data.length; i++) {
                                if (data[i].type === 2) {
                                    this.templateId = data[i].templateId;
                                    break;
                                }
                            }
                            console.log('模板ID=' + this.templateId)
                        }
            
            
                    }).catch(err => {
            
                        console.log(err.data)
                    })
            },
            
            submit() {
                this.isDisabled = true;
                if (this.reason.length <= 0) {
                    this.isDisabled = false;
                    this.$refs.uToast.show({
                        type: 'error',
                        message: "请填写申请理由"
                    });
                    return;
                }
                if (this.valueList.length <= 0) {
                    this.isDisabled = false;
                    this.$refs.uToast.show({
                        type: 'error',
                        message: "请选择一个或多个领用资产!"
                    });
            
                    return;
                }
            
                this.submitApply();
            },
            
            submitApply() {
                let assets = [];
                for (let i = 0; i < this.valueList.length; i++) {
                    if (this.valueList[i] > 0) {
                        let item = this.assetsList[i];
                        assets.push({
                            "id": item.id,
                            "name": item.name,
                            "serialNumber": item.serialNumber,
                            "quantity": this.valueList[i]
                        })
                    }
                }
            
                // console.log(assets);
                let data = {
                    "assets": assets,
                    "templateId": this.templateId,
                    "reason": this.reason
                }
            
                this.$http.post('/assets/approval/submit', data)
                    .then(res => {
                        // debugger;
                        if (res.data.code === 0) {
                            console.log("成功了");
                            this.reason="";
                            this.$refs.uToast.show({
                                type: 'success',
                                message: "提交成功"
                            });
                        } else {
                            this.$refs.uToast.show({
                                type: 'error',
                                message: res.data.msg
                            });
                        }
                        this.isDisabled = false;
            
                    }).catch(err => {
                        this.isDisabled = false;
                        console.log(err.data)
                    })
            }
        }
    }
</script>
 
 
<style lang="scss">
    /* 顶部 fixed定位*/
    .top-warp{
        z-index: 200;
        position: fixed;
        top: var(--window-top);
        left: 0;
        width: 100%;
        height: 88rpx;
        padding-top: 10rpx;
        font-size: 28rpx;
        text-align: center;
        background-color: #CFE0DA;
    }
    
    // 设置padding
    .mescroll-body,
    /deep/.mescroll-body{
        padding-left: 0rpx;
    }
    
    /* 底部 fixed定位*/
    .bottom-warp{
        z-index: 200;
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100%;
        background-color: #FFFFFF;
    }
    
    .itembox {
        /* 父容器设置宽度, 并超出部分不显示 */
        width: 100%;
        height: 100%;
        overflow: scroll;
    
        .item {
            /* 子容器比父容器的宽度多 17 px, 经测正好是滚动条的默认宽度 */
            // width: 5517px;
            // height: 100%;
            // line-height: 30px;
            text-align: center;
            overflow-y: scroll;
        }
    
    }
    
    .content-box {
        position: relative;
        // border: 1rpx red solid;
        height: 50vh;
    }
    
    .search-box {
        background-color: #FFFFFF;
        // margin-top: 88rpx;
        z-index: 200;
        top:88rpx;
        width: 100%;
        position: fixed;
        padding: 10rpx 30rpx 0rpx 30rpx;
        // border: 1rpx red solid;
    }
    
    
    .numbox {
        margin-left: 20rpx;
    }
    
    .minus {
    
        width: 15px;
        height: 15px;
        border-width: 1px;
        border-color: #E6E6E6;
        border-top-left-radius: 50px;
        border-top-right-radius: 50px;
        border-bottom-left-radius: 50px;
        border-bottom-right-radius: 50px;
        @include flex;
        justify-content: center;
        align-items: center;
    }
    
    .input {
        padding: 0 5px;
    }
    
    .plus {
        width: 15px;
        height: 15px;
        background-color: #53C21D; //#FF0000;
        border-radius: 50%;
        /* #ifndef APP-NVUE */
        display: flex;
        /* #endif */
        justify-content: center;
        align-items: center;
    }
</style>