cuiqian2004
9 天以前 f57571f987f3d25730123f488fccdfa3158ec5b1
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
<template>
    <view class="uni-task-kanban">
        <dragSortList ref="dragSorts" :listData="lists" :countPage="4" :longTouch="true" :feedbackGenerator="false"
            :listHeight="listHeight" :rowHeight="54" listBackgroundColor="#e8ebec" @clickItem="onclick" @change="change"
            @confirm="confirm" @add="onAdd">
        </dragSortList>
    </view>
</template>
<script>
    import dragSortList from "./dragsortlist/dragSortList.vue"
    import {
        getKanbanLaneTask,
        updPlanType as updTaskPlanType
    } from "@/api/gungho/task.js"
 
 
    import TaskInit from "@/common/extend.js"
    import {
        showModal,
        showToast
    } from "@/common/Page.js"
    export default {
        components: {
            dragSortList,
        },
        name: "pageTaskKanban",
        props: {
            listHeight: {
                value: Number,
                default: 0
            },
        },
        data() {
            return {
                lists: []
            }
        },
        mounted() {
            this.initList()
            /* var _this = this
             getListPanel().then((res)=>{
                
                let lsts = _this.getDefaultData(res)
                _this.setData({
                    list:lsts
                })
                console.log("getListPanel res:",lsts)
            }).catch((rej)=>{
                console.log("getListPanel fail:",rej)
            }) */
        },
        methods: {
            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];
                    });
                });
            },
            initList() {
                var _this = this
                console.log("taskkanban initList:")
                getKanbanLaneTask({}).then((res) => {
 
                    let lsts = _this.getDefaultData(res)
                    _this.setData({
                        lists: lsts
                    })
                    console.log("taskkanban initList getListPanel res:", lsts)
                }).catch((rej) => {
                    this.showError(rej)
                    console.log("taskkanban initList getListPanel fail:", rej)
                })
            },
            getDefaultData(arr) {
                //console.log("tasklist getDefaultData ",arr)
                let lists = [
                    [],
                    [],
                    [],
                    []
                ]
                for (let i = 0; i < arr.length; i++) {
                    if (arr[i].CN_T_CREATE) {
                        arr[i].CN_T_CREATE = TaskInit.dateUtils.format(arr[i].CN_T_CREATE, "notime");
                    }
                    if (arr[i].CN_D_PLAN_DUE) {
                        arr[i].CN_D_PLAN_DUE = TaskInit.dateUtils.format(arr[i].CN_D_PLAN_DUE, "notime");
                    }
                    arr[i].CN_S_NAME = (arr[i].CN_S_NAME || arr[i].CN_S_TITLE);
                    arr[i].Minute = arr[i].Minute || "";
                    if (arr[i].Minute) {
                        console.log(arr[i].Minute)
                        if (arr[i].Minute < 0) { //超期
                            const minute = arr[i].Minute * -1;
                            Math.ceil(minute / 60 / 24)
                            if (Math.ceil(minute / 60) == 0) {
                                arr[i].Minute = "超期0小时";
                            } else if (Math.ceil(minute / 60) < 24) {
                                //                                console.log(Math.ceil(minute/60));
                                arr[i].Minute = "超期" + Math.ceil(minute / 60) + "小时";
                            } else {
                                arr[i].Minute = "超期" + Math.ceil(minute / 60 / 24) + "天";
                            }
                        } else { //将要超期
                            const minute = arr[i].Minute;
                            if (Math.ceil(minute / 60) < 24) {
                                arr[i].Minute = Math.ceil(minute / 60) + "小时后";
                            } else {
                                arr[i].Minute = Math.ceil(minute / 60 / 24) + "天后";
                            }
                        }
                    } else if (arr[i].CN_N_GAP_DAY) {
                        if (arr[i].CN_N_GAP_DAY > 0) {
                            arr[i].Minute = "超期" + arr[i].CN_N_GAP_DAY + "天";
                        }
                    }
                    arr[i].CNSTATE = (TaskInit.taskstate[arr[i].CN_S_STATE] || TaskInit.eventstate[arr[i].CN_S_E_TYPE]);
 
                    arr[i].id = arr[i].CN_G_ID
                    arr[i].Minutechaoqi = arr[i].Minute.indexOf('超期') > -1;
                    arr[i].Minutetoday = arr[i].Minute.indexOf('今天') > -1;
                    let nType = arr[i].CN_N_PLAN_TYPE
                    if (nType < 0 || nType > 3) {
                        nType = 0
                    }
                    lists[nType].push(arr[i]);
                }
                // console.log(lists)
                return lists
            },
            onAdd(e) {
                const app = getApp()
                console.log('=== onAdd ===', e);
                uni.navigateTo({
                    url: '/pages/task/create?plantype=' + e.page
                })
            },
            onclick(e) {
                console.log('=== onclick start ===');
                //console.log('被点击行: ', JSON.stringify(e));
                //console.log('=== onclick end ===');
                uni.navigateTo({
                    url: '/pages/task/detail?taskId=' + e.CN_G_ID ,
                    success(res) {
                        // console.log("navigateTo success",res);
                    },
                    fail(res) {
                        //console.log("navigateTo fail",res);
                    },
                })
            },
            change(e) {
                console.log('=== change start ===');
                console.log('被拖拽行: ', e.moveRow);
                console.log('原始下标: ', e.page, e.index);
                console.log('被拖拽到: ', e.pageMoveTo, e.moveTo);
                console.log('=== change end ===');
            },
 
            confirm(e) {
                console.log('=== confirm start ===');
                console.log('被拖拽行: ', e.moveRow);
                console.log('原始下标: ', e.page, e.index)
                console.log('被拖拽到: ', e.pageMoveTo, e.moveTo);
                console.log('排序后的list: ', e.list);
                if (e.page != e.pageMoveTo) {
 
                    updTaskPlanType({
                        id: e.moveRow.CN_G_ID,
                        state: e.State,
                        type: e.pageMoveTo
                    }).then((res) => {
                        console.log('updTaskPlanType sucess', res);
                    }).catch((rej) => {
                        this.showError(rej)
                        console.log('updTaskPlanType fail', rej);
                    })
                }
                if (e.page != e.pageMoveTo || e.index != e.moveTo) {
 
                }
                // 如果需要删除列表行,必须要排序后,同步一下排序后的list到页面list
                // 因为排序后页面的list和组件内的list已经不一样,不同步list,直接删除页面的list中项目,达不到实际效果。
                console.log('=== confirm end ===');
            },
            showError(ex) {
                let tip = typeof ex === 'string' ? ex :(  ex.message || ex.err_msg || ex.errMsg || ex.err_info ||  "")
                
                showModal(tip, "提示", false)
            },
        }
    }
</script>
<style lang="scss" scoped>
    .uni-task-kanban {
        background-color: #e8ebec;
        width: 750rpx;
    }
</style>