guoshilong
2022-10-14 d8e0af2ce345f3b40581ad05c596f965ae729c01
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
<template>
    <view class="container">
        <u-top-tips ref="uTips"></u-top-tips>
        <view class="tabs">
            <u-tabs-swiper ref="uTabs" :list="tabsList" :current="current" :is-scroll="false" swiperWidth="750"
                @change="tabsChange">
            </u-tabs-swiper>
        </view>
        <view class="swiper-item">
            <scroll-view scroll-y :style="{ height: useHeight, width: '100%' }" @scrolltolower="scrolltolower">
                <view class="onveMain">
                    <view class="once" v-for="(item, index) in taskinfoList" :key="index">
                        <view class="onve-left" @click="goToDetail(item.id)">
                            <!-- <view class="o-l-img">
                                <image src="" mode=""></image>
                            </view> -->
                            <view class="o-l-main">
                                <view class="o-l-m-up">
                                    {{item.title}}
                                </view>
                                <view class="o-l-m-center">
                                    <u-icon name="order" color="#d0d0d0" size="28"></u-icon>
                                    状态:{{item.state == 0?'待开始':item.state == 1?'正在进行':'已完成'}}
                                </view>
                                <view class="o-l-m-center">
                                    <u-icon name="volume" color="#d0d0d0" size="28"></u-icon>
                                    时间:{{item.startTime}}
                                </view>
                            </view>
                        </view>
                        <view class="onve-right">
                            <u-button class='greens' size="mini" v-if="current == 0" @click="startTask(item)">开始任务</u-button>
                            <u-button class='greens' size="mini" v-if="current == 1" @click="finishTask(item)">完成任务</u-button>
                            <u-button class='o-r-down' plain type="error" size="mini" v-if="current == 1" @click="goToEventsReported(item.id)">事件上报
                            </u-button>
                        </view>
                    </view>
 
                </view>
                <u-divider>没有更多了</u-divider>
            </scroll-view>
        </view>
 
    </view>
</template>
 
<script>
    import {
        getList,update
    } from "@/api/taskinfo/taskinfo";
    export default {
        data() {
            return {
                useHeight: "87vh",
                current: 0, // tabs组件的current值,表示当前活动的tab选项
                tabsList: [{
                    id: 0,
                    name: "待开始",
                }, {
                    id: 1,
                    name: "正在进行",
                }, {
                    id: 2,
                    name: "已完成",
                }],
                page: {
                    pageSize: 6,
                    currentPage: 1,
                    total: 0
                },
                query: {
                    state: 0,
                    toUserId: this.$store.state.userInfo.user_id //获取当前登录用户id
                },
                taskinfoList: null
            }
        },
        onShow() {
            this.getList()
        },
        created() {
            this.getList()
        },
        methods: {
            // tabs通知swiper切换
            tabsChange(index) {
                this.current = index;
                this.query.state = this.current;
                this.page.currentPage = 1
                this.getList();
            },
            getList() {
                // 获取任务列表API
                getList(this.page.currentPage, this.page.pageSize, this.query).then(res => {
                    const data = res.data;
                    this.page.total = data.total;
                    this.taskinfoList = data.records;
                })
            },
            // 下一页任务
            scrolltolower() {
                this.page.currentPage += 1
                // 获取任务列表API
                getList(this.page.currentPage, this.page.pageSize, this.query).then(res => {
                    const data = res.data;
                    this.page.total = data.total;
                    this.taskinfoList = this.taskinfoList.concat(data.records)
                })
            },
            // 跳转详情页
            goToDetail(id) {
                uni.navigateTo({
                    url: '/pages/taskinfo/detail?id=' + id
                })
            },
            //任务开始事件
            startTask(item){
                uni.showModal({
                    title:"提示",
                    content:"是否开始任务?",
                    success:(res)=> {
                        if(res.confirm){
                            item.state = '1'
                            item.routeRange =  '\'' + item.routeRange + '\''
                            update(item).then(res=>{
                                if(res.code == 200){
                                    this.page.currentPage = 1
                                    this.getList()
                                }
                            })
                        }
                    }
                })
            },
            //任务结束事件
            finishTask(item){
                uni.showModal({
                    title:"提示",
                    content:"是否结束任务?",
                    success:(res)=> {
                        if(res.confirm){
                            item.state = '2'
                            item.routeRange =  '\'' + item.routeRange + '\''
                            update(item).then(res=>{
                                if(res.code == 200){
                                    this.page.currentPage = 1
                                    this.getList()
                                }
                            })
                        }
                    }
                })
            },
            //事件上报
            goToEventsReported(id){
                uni.navigateTo({
                    url:"/pages/eventgm/eventsReported?id="+id
                })
            }
        }
    }
</script>
 
<style scoped lang="scss">
    page {
        height: 100% !important;
        width: 100% !important;
        overflow: hidden !important;
    }
 
    .swiper-item {
        flex: 1;
    }
 
    .onveMain {
        width: 100%;
        height: auto;
    }
 
    .once {
        width: calc(100% - 10px);
        height: 100px;
        border: 1px solid #d0d0d0;
        padding: 8px;
        box-sizing: border-box;
        margin: 5px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
 
        .onve-left {
            width: 75%;
            display: flex;
            align-items: center;
            justify-content: center;
 
            .o-l-img {
                width: 80px;
                height: 80px;
                background-color: #d0d0d0;
                margin-right: 5px;
                border-radius: 7px;
 
                image {
                    width: 100%;
                    height: 100%;
                    border-radius: 7px;
                }
            }
 
            .o-l-main {
                width: 100%;
                height: 80px;
                display: flex;
                // align-items: center;
                justify-content: center;
                flex-direction: column;
 
                .o-l-m-up {
                    height: 30px;
                    font-size: 16px;
                }
            }
        }
 
        .onve-right {
            width: 25%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
 
            .o-r-down {
                margin-top: 4px;
            }
        }
 
    }
 
    .orange {
        color: #FF7B15;
    }
 
    .green {
        color: #00e713;
    }
 
    .greens {
        color: #18a655 !important;
    }
 
    .blues {
        color: #2680F0 !important;
    }
 
    .Cation {
        display: inline-block;
        position: absolute;
        left: -35px;
 
        &::after {
            content: "";
        }
    }
 
    .notCation {
        color: #18a655;
    }
</style>