cuiqian2004
8 天以前 30311cd24ee3b1567ffafac002494bb67feda657
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
<template>
    <view class="pages-map-task">
        <view class="task-div" v-if="selectedType !='set'">
            <view class="header">
                <view class="item">
                    <view class="title">{{accumulated_duration}}<text class="text">min</text></view>
                    <view class="text">累计时长</view>
                </view>
                <view class="item">
                    <view class="title">{{accumulated_mileage}}<text class="text">m</text></view>
                    <view class="text">累计里程</view>
                </view>
                <view class="item">
                    <view class="title">{{cumulative_number}}</view>
                    <view class="text">累计次数</view>
                </view>
            </view>
            <view class="list">
                <view class="task-header" v-if="fixedList.length > 0">固定任务</view>
                <view class="task-list" v-if="fixedList.length > 0">
                    <TaskLogItemView class="item" v-for="(item,index) in fixedList" :key="index" :taskData="item"
                        @click-item="clickTask">
 
                    </TaskLogItemView>
                </view>
                <view class="task-header" v-if="tempList.length > 0">临时任务</view>
                <view class="task-list" v-if="tempList.length > 0">
                    <TaskLogItemView class="item" v-for="(item,index) in tempList" :key="index" :taskData="item"
                        @click-item="clickTask">
 
                    </TaskLogItemView>
                </view>
            </view>
        </view>
        <view class="task-set" v-else>
            <view class="list-header" v-if="fixedSetList.length > 0">固定任务</view>
            <view class="set-list">
                <TaskItemView class="list-item" v-for="(item,index) in fixedSetList" :key="index" :taskData="item"
                    :deleteX="deleteX[0][index]" @click-item="clickSetTask" @click-delete="clickDelSetTask"
                    @touchstart="touchStart($event,0, index)" @touchmove="touchMove($event,0, index)"
                    @touchend="touchEnd($event, 0,index)">
 
                </TaskItemView>
            </view>
            <view class="list-header" v-if="tempSetList.length > 0">临时任务</view>
            <view class="set-list">
                <TaskItemView class="list-item" v-for="(item,index) in tempSetList" :key="index" :taskData="item"
                    :deleteX="deleteX[1][index]" @click-item="clickSetTask" @click-delete="clickDelSetTask"
                    @touchstart="touchStart($event, 1,index)" @touchmove="touchMove($event,1, index)"
                    @touchend="touchEnd($event, 1,index)">
 
                </TaskItemView>
            </view>
        </view>
        <view class="bottom">
            <view class="button" :class="selectedType =='set'?'':'selected'" @click="clickTaskList">
                <uni-icons class="icon" :color="selectedType !='set'?'#1ABC9C':'#ccc'" type="bars"
                    size="36"></uni-icons>任务记录
            </view>
            <view class="button" :color="selectedType =='set'?'#1ABC9C':'#ccc'"
                :class="selectedType =='set'?'selected':''" @click="clickTaskSet">
                <uni-icons class="icon" :color="selectedType =='set'?'#1ABC9C':'#ccc'" type="gear-filled"
                    size="36"></uni-icons>任务设置
            </view>
        </view>
    </view>
</template>
 
<script>
    import {
        showToast,
        showModal
    } from "@/comm/utils.js"
    import TaskLogItemView from "./infos/task-log-item.vue"
    import TaskItemView from "./infos/task-item.vue"
    export default {
        name: "PagesMapTask",
        components: {
            TaskLogItemView,
            TaskItemView
        },
        data() {
            return {
                selectedType: "list",
                accumulated_duration: 167991,
                accumulated_mileage: 7532556,
                cumulative_number: 6000,
                taskList: [{
                        name: "1号站点到2号站点",
                        date: "5-18",
                        accumulated_duration: 5693,
                        accumulated_mileage: 6421,
                        cumulative_number: 55,
                        type: 0,
                    }, {
                        name: "2号站点到1号站点",
                        date: "5-08",
                        accumulated_duration: 888,
                        accumulated_mileage: 642,
                        cumulative_number: 31,
                        type: 0,
                    }, {
                        name: "1号站点到2号站点",
                        date: "4-28",
                        accumulated_duration: 998,
                        accumulated_mileage: 2421,
                        cumulative_number: 85,
                        type: 0,
                    }, {
                        name: "2号站点到1号站点",
                        date: "4-28",
                        accumulated_duration: 688,
                        accumulated_mileage: 1421,
                        cumulative_number: 65,
                        type: 0,
                    },
                    {
                        name: "1号站点到2号站点",
                        date: "5-18",
                        accumulated_duration: 5693,
                        accumulated_mileage: 6421,
                        cumulative_number: 55,
                        type: 1,
                    }, {
                        name: "2号站点到1号站点",
                        date: "5-08",
                        accumulated_duration: 888,
                        accumulated_mileage: 642,
                        cumulative_number: 31,
                        type: 1,
                    }, {
                        name: "1号站点到2号站点",
                        date: "4-28",
                        accumulated_duration: 998,
                        accumulated_mileage: 2421,
                        cumulative_number: 85,
                        type: 1,
                    }, {
                        name: "2号站点到1号站点",
                        date: "4-28",
                        accumulated_duration: 688,
                        accumulated_mileage: 1421,
                        cumulative_number: 65,
                        type: 1,
                    }
                ],
                setList: [{
                    id: "1",
                    name: "2号站点到1号站点",
                    status: 1,
                    type: 0,
                    attribute: 0,
                    start_point: "2号站点",
                    end_point: "1号站点",
                    start_time: "15:00",
                    end_time: "21:00",
                    button_no: "1",
                    button_color: "#aa00ff"
                }, {
                    id: "2",
                    name: "1号站点到2号站点",
                    status: 0,
                    type: 0,
                    attribute: 0,
                    start_point: "2号站点",
                    end_point: "1号站点",
                    start_time: "15:00",
                    end_time: "21:00",
                    button_no: "2",
                    button_color: "#55aaff"
                }, {
                    id: "3",
                    name: "2号站点到1号站点",
                    status: 0,
                    type: 1,
                    attribute: 0,
                    start_point: "2号站点",
                    end_point: "1号站点",
                    start_time: "15:00",
                    end_time: "21:00",
                    button_no: "3",
                    button_color: "#ffaa7f"
 
                }],
 
                startX: 0, // 触摸起始点
                deleteX: [
                    [],
                    []
                ], // 每个项目的偏移量
            }
        },
        computed: {
            fixedList() {
                return this.taskList.filter((a) => a.type != 1)
            },
            tempList() {
                return this.taskList.filter((a) => a.type == 1)
            },
            fixedSetList() {
                return this.setList.filter((a) => a.type != 1)
            },
            tempSetList() {
                return this.setList.filter((a) => a.type == 1)
            },
        },
 
        methods: {
            setData(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];
                    });
                });
            },
            clickTask(item) {
                uni.navigateTo({
                    url: "/pages/task/index"
                })
            },
            clickSetTask(item) {
                uni.navigateTo({
                    url: `/pages/task/set?param=${JSON.stringify(item)}`
                })
            },
            clickDelSetTask(item) {
                showModal("确认删除任务设置", "警告").then((res) => {
                    if (res) {
                        const list = this.setList
                        const index = list.findIndex((a) => {
                            a.id == item.id
                        })
                        if (index < 0)
                            return
                        list.splice(index, 1)
                        this.setData({
                            setList: list
                        })
                    }
                })
            },
 
            clickTaskList() {
                this.selectedType = "list"
            },
            clickTaskSet() {
                this.selectedType = "set"
            },
            touchStart(event, root, index) {
                this.startX = event.touches[0].pageX;
                const old = this.deleteX[root][index]
                if (old) {
                    this.deleteX = [
                        [],
                        []
                    ]
                    this.deleteX[root][index] = old; // 重置偏移量
                } else
                {
                    this.deleteX = [
                        [],
                        []
                    ]
                    this.deleteX[root][index] = 0; // 重置偏移量
                }
                
            },
            touchMove(event, root, index) {
                const moveX = event.touches[0].pageX - this.startX;
                if (moveX < 0) {
                    this.deleteX[root][index] = moveX; // 左滑时更新偏移量
                }
                else if (moveX > 0) {
                    this.deleteX[root][index] =0
                }
            },
            touchEnd(event, root, index) {
                if (this.deleteX[root][index] < -50) { // 如果滑动距离超过一定阈值,显示删除按钮
                    this.deleteX[root][index] = -80; // 设置固定偏移量
                } else {
                    this.deleteX[root][index] = 0; // 否则恢复原位
                }
            },
 
 
        }
    }
</script>
 
<style lang="scss">
    .pages-map-task {
        display: flex;
        width: 750rpx;
        height: 100vh;
        flex-direction: column;
 
        .task-div {
            display: flex;
            width: 100%;
            flex: 1;
            flex-direction: column;
            overflow: auto;
        }
 
        .header {
            width: 100%;
            padding: 10px;
            height: 30px;
            display: flex;
            flex-direction: row;
 
            .item {
                padding: 0 10px;
                display: flex;
                width: 100%;
                flex-direction: column;
                flex: 1;
 
                .title {
                    font-size: 20px;
                    font-weight: 700;
                }
 
                .text {
                    font-size: 14px;
                    color: #888;
                }
            }
        }
 
        .list {
            width: calc(100% - 40px);
            margin: 10px;
            padding: 0 10px;
            display: flex;
            flex-direction: column;
            flex: 1;
            overflow: auto;
 
        }
 
        .task-header {
            width: 100%;
            padding: 10px;
            font-size: 15px;
        }
 
        .task-list {
            border: 1px solid #ccc;
            border-radius: 5px;
            padding: 0 10px;
 
            .item {
 
                border-bottom: 1px solid #ddd;
            }
        }
 
        .task-set {
            display: flex;
            width: calc(100% - 20px);
            padding: 0 10px;
            flex: 1;
            flex-direction: column;
            overflow-y: auto;
            overflow-x: hidden;
 
            .list-header {
                margin: 10px;
                border-bottom: 1px solid #ddd;
            }
 
            .set-list {
                // border: 1px solid #ccc;
                border-radius: 10px;
 
                background-color: #fff;
 
                .list-item {
 
                    border-bottom: 1px solid #ddd;
                }
            }
 
        }
 
        .bottom {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: row;
            font-size: 14px !important;
            color: #ccc;
 
            .button {
                margin: 10px 20px;
                width: 100px !important;
                height: 100px !important;
                border: 0;
                display: flex;
                flex-direction: column;
                background-color: #00000000;
 
                .icon {
                    margin: 10px !important;
                    width: 28px;
                    height: 28px;
 
                }
            }
 
            .selected {
                color: #1ABC9C;
 
                .icon {
                    margin: 10px !important;
                    width: 28px;
                    height: 28px;
 
                }
            }
 
 
        }
 
    }
</style>