cuiqian2004
8 天以前 2db331628bbf94deee446d6e172e98f4db474a33
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
<template>
    <view class="uni-task-list">
        <!---->
        <scroll-view class="uni-panel-list" enable-flex scroll-y refresher-enabled="true"
            :refresher-triggered="triggered" :scroll-top="scrollTop" :refresher-threshold="100"
            @refresherpulling="onPulling"  @refresherrefresh="onRefresh"  @refresherrestore="onRestore" @refresherabort="onAbort" @scroll="scrollView"
            @scrolltolower="scrollEnd">
            <view v-if="emptyTip" class="uni-panel-center">
                <text style="color: gray;display: flex;justify-content: center;">{{emptyTip}}</text>
                <image mode="center" src="@/static/open-box.png"> </image>
            </view>
            <view class="uni-panel-item" v-for="(item, index) in listBody" :key="item.CN_G_ID">
                <taskItem :taskData="item" :pagesign="pagesign" @clickItem="triggerItem"></taskItem>
            </view>
            <view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
        </scroll-view>
    </view>
</template>
 
<script>
    import taskItem from "./task-item.vue"
    import TaskInit from "@/common/extend.js"
    import {
        showModal,
        showToast,
        showLoading,
        hideLoading
    } from "@/common/Page.js"
    import {
        queryList as taskQueryList,
        queryAuditList as taskQueryAuditList
    } from "@/api/gungho/task.js"
 
    export default {
        components: {
            taskItem,
        },
        name: "pageTaskList",
        props: {
            title: {
                type: String,
                default () {
                    return "";
                }
            },
 
            taskSql: {
                type: String,
                default () {
                    return "";
                }
            },
            taskOrder: {
                type: String,
                default () {
                    return "";
                }
            },
 
            taskType: {
                type: String,
                default () {
                    return "";
                }
            },
            taskStatus: {
                type: Array,
                default () {
                    return [];
                }
            },
 
        },
        data() {
            return {
                firstLoadData: true,
                listBody: [],
                sessionId: "",
                token: "",
                emptyTip: "",
                loadMoreText: "加载中...",
                showLoadMore: false,
                triggered: false,
                pagesign: "",
                scrollTop: 0,
                old: {
                    triggered: 0,
                    scrollTop: 0
                },
                isAuditList: false
            };
        },
        watch: {
            taskSql(value) {
                console.log(value)
                if (this.taskType == "需要我审核的") {
                    this.isAuditList = true;
                } else {
                    this.isAuditList = false;
                }
                this.loadData()
            },
        },
        methods: {
            loadData() {
                var _this = this;
                _this.errmsg = '';
                _this.pindex = 1;
                _this.psize = 15;
                _this.totalcount = 0;
                _this.ptotal = 0;
                _this.sessionId = "";
 
 
 
                showLoading("加载中,请稍后...")
                _this.showLoadMore = false;
                _this.pageGetList().then((resData) => {
 
                    _this.scrollTop = _this.old.scrollTop
                    _this.$nextTick(function() {
                        _this.scrollTop = 0
                    });
                    _this.listBody = resData;
 
                    _this.setData({
                        listBody: _this.listBody,
                    })
                    hideLoading()
                    if (_this.firstLoadData)
                        showToast('数据装载完毕', 'none')
                    else
                        showToast('列表已刷新', 'none')
                    _this.setData({
                        firstLoadData: false
                    })
                    _this.$forceUpdate();
                }).catch(() => {
                    hideLoading()
                    _this.setData({
                        listBody: [],
                        firstLoadData: false
                    })
                    _this.$forceUpdate();
                });
            },
            setData: function(obj) {
                let that = this;
                let keys = [];
                let val, data;
 
                Object.keys(obj).forEach(function(key) {
                    keys = key.split(".");
                    val = obj[key];
                    data = that.$data;
                    keys.forEach(function(key2, index) {
                        if (index + 1 == keys.length) {
                            that.$set(data, key2, val);
                        } else {
                            if (!data[key2]) {
                                that.$set(data, key2, {});
                            }
                        }
                        data = data[key2];
                    });
                });
            },
            triggerItem(item) {
                uni.navigateTo({
                    url: '/pages/task/detail?taskId=' + item.CN_G_ID +
                        '&taskType=' +
                        (this.isAuditList ? '12' : ""),
                    success(res) {
                        // console.log("navigateTo success",res);
                    },
                    fail(res) {
                        //console.log("navigateTo fail",res);
                    },
                })
            },
            pageGetList() {
                //console.log("tasklist pageGetList")
                var _this = this;
                return new Promise(async (resolve, reject) => {
                    try {
                        if (_this.taskSql == "") {
                            _this.emptyTip = 'sql没有完成'
                            _this.loadMoreText = ""
                            _this.showLoadMore = false;
                            resolve([])
                            return
                        }
                        _this.emptyTip = ''
                        const attrs =
                            "CN_S_NAME,CN_G_ID,CN_S_STATE,CN_S_PRJ_NAME,CN_G_FROM_OBJID,CN_N_QUADRANT,CN_S_CREATOR,CN_S_TAKEON_NAME,CN_T_CREATE,CN_D_PLAN_DUE,CN_N_DISCUS,CN_N_GAP_DAY"
                        let res = {}
                        if (this.isAuditList) {
                            res = await taskQueryAuditList({
                                page: _this.pindex,
                                size: _this.psize,
                                sql: _this.taskSql,
                                attrs,
                                order: _this.taskOrder,
                                type: "0",
 
                            })
                        } else {
                            res = await taskQueryList({
                                page: _this.pindex,
                                size: _this.psize,
                                sql: _this.taskSql,
                                attrs,
                                order: _this.taskOrder,
                                type: "0",
 
                            })
 
                        }
                        if (res) {
                            _this.totalcount = res.record_count
                            _this.ptotal = res.page_count
                            _this.query_id = res.query_id
 
                            let nRecords = res.rows.length
 
                            if (_this.pindex < res.page_count) {
                                _this.loadMoreText = "加载更多"
 
                            }
                            if (nRecords > 0) {
                                showToast('加载了' + nRecords + '条数据', 'none')
                                resolve(_this.getDefaultData(res.rows))
                            } else {
                                //_this.loadMoreText = "没有更多数据了!"
                                showToast('没有更多数据了', 'none')
                                resolve([])
                            }
                        } else {
                            //_this.loadMoreText = "没有更多数据了!"
                            showToast('没有更多数据了', 'none')
                            resolve([])
                        }
 
                    } catch (ex) {
                        console.log("tasklist pageGetList failed", ex)
                        _this.loadMoreText = "加载数据失败!"
                        reject(ex)
                        this.showError(ex)
                    }
                })
            },
            getTaskData(data) {
                if (data.CN_T_CREATE) {
                    data.CN_T_CREATE = TaskInit.dateUtils.format(data.CN_T_CREATE, "notime");
                }
                if (data.CN_D_PLAN_DUE) {
                    data.CN_D_PLAN_DUE = TaskInit.dateUtils.format(data.CN_D_PLAN_DUE,
                        "notime");
                }
                data.CN_S_NAME = (data.CN_S_NAME || data.CN_S_TITLE);
                data.Minute = data.Minute || "";
                if (data.Minute) {
                    console.log(data.Minute)
                    if (data.Minute < 0) { //超期
                        const minute = data.Minute * -1;
                        Math.ceil(minute / 60 / 24)
                        if (Math.ceil(minute / 60) == 0) {
                            data.Minute = "超期0小时";
                        } else if (Math.ceil(minute / 60) < 24) {
                            //                                console.log(Math.ceil(minute/60));
                            data.Minute = "超期" + Math.ceil(minute / 60) + "小时";
                        } else {
                            data.Minute = "超期" + Math.ceil(minute / 60 / 24) + "天";
                        }
                    } else { //将要超期
                        const minute = data.Minute;
                        if (Math.ceil(minute / 60) < 24) {
                            data.Minute = Math.ceil(minute / 60) + "小时后";
                        } else {
                            data.Minute = Math.ceil(minute / 60 / 24) + "天后";
                        }
                    }
                } else if (data.CN_N_GAP_DAY) {
                    if (data.CN_N_GAP_DAY > 0) {
                        data.Minute = "超期" + data.CN_N_GAP_DAY + "天";
                    }
                }
                data.CNSTATE = (TaskInit.taskstate[data.CN_S_STATE] || TaskInit.eventstate[ret
                    .data.Body[i].CN_S_E_TYPE]);
                // data.pagesql = this.taskSql;
 
                data.Minutechaoqi = data.Minute.indexOf('超期') > -1;
                data.Minutetoday = data.Minute.indexOf('今天') > -1;
                // console.log(JSON.stringify(ret.data.Body))
                return data
            },
 
            getDefaultData(arr) {
                let ret = {
                    data: {
                        Body: arr
                    }
                }
                //console.log("tasklist getDefaultData ",arr)
                for (let i = 0; i < ret.data.Body.length; i++) {
                    ret.data.Body[i] = this.getTaskData(ret.data.Body[i])
                }
                // console.log(JSON.stringify(ret.data.Body))
                return ret.data.Body
            },
            addPageData() {
                var _this = this;
                _this.pindex += 1;
                _this.pageGetList().then((resData) => {
                    console.log("tasklist scrollEnd", resData);
                    //let listData = _this.listBody + resData;
 
                    _this.listBody = _this.listBody.concat(resData);
                })
 
            },
            scrollView(e) { //nvue暂不支持滚动监听,可用bindingx代替
                //console.log("scrollView:" + e.scrollTop);
                this.old.scrollTop = e.detail.scrollTop
            },
            scrollEnd() {
                var _this = this;
            //    console.log("tasklist scrollEnd:", _this.ptotal, _this.pindex);
                _this.showLoadMore = true;
                if (_this.ptotal == _this.pindex) {
                    _this.loadMoreText = "没有更多数据了!"
                    return
                }
                _this.loadMoreText = "加载中..."
                setTimeout(() => {
                    _this.addPageData();
                }, 500)
 
            },
            onPulling(e) {
            //    console.log("onPulling", e);
                this.old.triggered = e.detail.triggered
            },
            onRefresh() {
                var _this = this;
                showLoading("加载中,请稍后...")
                _this.errmsg = '';
                _this.pindex = 1;
                _this.psize = 15;
                _this.totalcount = 0;
                _this.ptotal = 0;
                _this.showLoadMore = false;
                _this.pageGetList().then((resData) => {
                //    console.log("onRefresh", resData);
                    _this.listBody = resData;
                    _this.triggered = _this.old.triggered
                    hideLoading()
                    _this.$nextTick(function() {
                        _this.triggered = 'restore'; // 需要重置
                    });
 
                    _this.setData({
                        listBody: _this.listBody
                    })
                    _this.$forceUpdate();
 
                    showToast('列表已刷新', 'none')
                }).catch(() => {
                    hideLoading()
                    _this.setData({
                        listBody: []
                    })
                    _this.$forceUpdate();
                });
 
            },
            onRestore() {
            //    console.log("onRestore");
                this.triggered = 'restore'; // 需要重置
            },
            onAbort() {
            //    console.log("onAbort");
            },
            taskDataChange(data) {
                var _this = this
 
 
                var bChanged = false;
                let body = _this.listBody;
                if (data.change == '新建') {
                    const app = getApp()
                    let sLogin = app.globalData.userdata.user_login;
                    if (data.taskbody) {
                        data.taskbody = this.getTaskData(data.taskbody)
                        let bFlag = false
                        if (Array.isArray(_this.taskStatus)) {
                            if (_this.taskStatus.length > 0) {
                                for (let i = 0; i < _this.taskStatus.length; i++) {
                                    if (_this.taskStatus[i] == "待完成" || _this.taskStatus[i] == "未完成") {
                                        bFlag = true
                                        break;
                                    }
                                }
                            } else
                                bFlag = true
                        } else
                            bFlag = true
                        if (_this.taskType == "我创建的" || (data.taskbody.CN_S_TAKEON_ID == sLogin &&
                                _this.taskType == "我的任务" && bFlag)) {
                            body.unshift(data.taskbody);
                            _this.setData({
                                listBody: body,
                            })
                        }
                    }
                    return
                }
 
                for (let i = 0; i < body.length; i++) {
                    let item = body[i];
                    if (item.CN_G_ID == data.id) {
 
                        bChanged = true
                        let bRemove = false
                        let cnstate = ""
                        cnstate = data.change;
                        if (data.change == '删除') {
                            if (Array.isArray(_this.taskStatus)) {
                                if (_this.taskStatus.length > 0) {
                                    bRemove = true
                                    for (let i = 0; i < _this.taskStatus.length; i++) {
                                        if (_this.taskStatus[i] == "全部") {
                                            bRemove = false
                                            break;
                                        }
                                    }
                                }
                            }
 
                        } else {
                            if (_this.taskType == "我创建的") {
                                if (data.change == '未读') {
                                    cnstate = "未读"
                                } else if (data.change == '撤回' || data.change == '退回') {
                                    if (Array.isArray(_this.taskStatus)) {
                                        if (_this.taskStatus.length > 0) {
                                            bRemove = true
                                            for (let i = 0; i < _this.taskStatus.length; i++) {
                                                if (_this.taskStatus[i] == "全部") {
                                                    bRemove = false
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                } else if (data.change == '设置完成') {
                                    cnstate = "完成"
                                    if (Array.isArray(_this.taskStatus)) {
                                        if (_this.taskStatus.length > 0) {
                                            for (let i = 0; i < _this.taskStatus.length; i++) {
                                                bRemove = true
                                                if (_this.taskStatus[i] == "已完成" || _this.taskStatus[i] == "完成" || _this
                                                    .taskStatus[i] == "全部") {
                                                    bRemove = false
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            } else if (_this.taskType == "我的任务") {
                                if (data.change == '未读') {
                                    cnstate = "未读"
                                } else if (data.change == '转发') {
                                    bRemove = true
                                } else if (data.change == '退回' || data.change == '撤回' || data.change == '删除') {
                                    bRemove = false
                                    if (Array.isArray(_this.taskStatus)) {
                                        if (_this.taskStatus.length > 0) {
                                            bRemove = true
                                            for (let i = 0; i < _this.taskStatus.length; i++) {
                                                if (_this.taskStatus[i] == "全部") {
                                                    bRemove = false
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                } else if (data.change == '完成' || data.change == '设置完成') {
                                    cnstate = "完成"
                                    if (Array.isArray(_this.taskStatus)) {
                                        if (_this.taskStatus.length > 0) {
                                            for (let i = 0; i < _this.taskStatus.length; i++) {
                                                bRemove = true
                                                if (_this.taskStatus[i] == "已完成" || _this.taskStatus[i] == "完成" || _this
                                                    .taskStatus[i] == "全部") {
                                                    bRemove = false
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                } else if (data.change == '提交') {
                                    if (Array.isArray(_this.taskStatus)) {
                                        if (_this.taskStatus.length > 0) {
                                            for (let i = 0; i < _this.taskStatus.length; i++) {
                                                bRemove = true
                                                if (_this.taskStatus[i] == "已提交" || _this.taskStatus[i] == "提交" || _this
                                                    .taskStatus[i] == "全部") {
                                                    bRemove = false
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            } else if (_this.taskType == "需要我审核的") {
                                if (data.change == '同意' || data.change == '不同意') {
                                    bRemove = true
                                }
                            } else if (_this.taskType == "下属任务") {
                                if (data.change == '未读') {
                                    cnstate = "未读"
                                } else if (data.change == '转发') {
                                    bRemove = true
                                } else if (data.change == '退回' || data.change == '撤回' || data.change == '删除') {
                                    bRemove = false
                                    if (Array.isArray(_this.taskStatus)) {
                                        if (_this.taskStatus.length > 0) {
                                            bRemove = true
                                            for (let i = 0; i < _this.taskStatus.length; i++) {
                                                if (_this.taskStatus[i] == "全部") {
                                                    bRemove = false
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                } else if (data.change == '完成' || data.change == '设置完成') {
                                    cnstate = "完成"
                                    if (Array.isArray(_this.taskStatus)) {
                                        if (_this.taskStatus.length > 0) {
                                            for (let i = 0; i < _this.taskStatus.length; i++) {
                                                bRemove = true
                                                if (_this.taskStatus[i] == "已完成" || _this.taskStatus[i] == "完成" || _this
                                                    .taskStatus[i] == "全部") {
                                                    bRemove = false
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (bRemove) {
                            body.splice(i, 1);
                            break;
                        }
                        body[i].CN_S_STATE = cnstate;
                        body[i].CNSTATE = TaskInit.taskstate[cnstate];
                        console.log('taskDataChange break' + i)
                        break;
                    }
                }
                if (bChanged) {
                    _this.setData({
                        listBody: body
                    })
                }
            },
            showError(ex) {
                let tip = typeof ex === 'string' ? ex :(  ex.message || ex.err_msg || ex.errMsg || ex.err_info ||  "")
                
                showModal(tip, "提示", false)
            },
 
        },
        mounted() {
 
            var _this = this;
            if (_this.taskType == "需要我审核的") {
                this.isAuditList = true;
            } else {
                this.isAuditList = false;
            }
            // #ifdef MP-DINGTALK
            setTimeout(() => {
                _this.loadData();
            }, 200)
            // #endif
 
            uni.$on('taskDataChange', this.taskDataChange)
        },
        destroyed() {
            uni.$off('taskDataChange', this.taskDataChange)
        }
    }
</script>
 
<style lang="scss">
    .uni-task-list {
        padding: 0px 10rpx 4px;
        background-color: #e5eaee;
        width: 730rpx;
        height: 100%;
 
        .uni-panel-list {
            height: 100%;
            /* calc(100% - 54px); */
            width: 730rpx;
            flex-direction: column !important;
        }
 
        .uni-panel-center {
            display: flex;
            align-items: center;
            margin: 100px 10px 10px;
            width: calc(100% - 20px);
            flex-direction: column !important;
        }
 
        .uni-panel-body {
            height: 100%;
        }
 
        .uni-panel-item {
            margin: 8px 12px 8px 10px;
            border: solid 1px #ddd;
            background-color: white;
            border-radius: 5px;
            -webkit-box-shadow: 0 10px 6px -6px #ddd;
            -moz-box-shadow: 0 10px 6px -6px #ddd;
            box-shadow: 0 10px 6px -6px #ddd;
            //height: 64px;
        }
 
        .clearfix {
            content: " ";
            box-sizing: border-box;
        }
 
        /* loadmore */
        .uni-loadmore {
            height: 80rpx;
            line-height: 80rpx;
            text-align: center;
            padding-bottom: 30rpx;
        }
    }
</style>