zhangwencui
2026-01-16 00b5cbce9f587931c7dc5455df707b0acc753e69
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
<template>
  <view class="meeting-list">
    <PageHeader title="会议列表"
                @back="goBack" />
    <!-- 查询表单 -->
    <view class="search-section">
      <view class="search-bar">
        <view class="search-input">
          <up-input class="search-text"
                    placeholder="查询日期"
                    @click.stop="showDatePicker"
                    v-model="queryForm.meetingDate"
                    clearable />
        </view>
        <view class="filter-button"
              @click="clearDate">
          <u-icon name="close-circle-fill"
                  size="24"
                  color="#999"></u-icon>
        </view>
      </view>
    </view>
    <!-- 日期选择器 -->
    <up-datetime-picker v-model="datePickerValue"
                        mode="date"
                        :show="showDatePickerDialog"
                        @confirm="handleDateConfirm"
                        @cancel="showDatePickerDialog = false"
                        format="YYYY-MM-DD"
                        value-format="YYYY-MM-DD" />
    <!-- 会议室使用情况 -->
    <view class="table-container">
      <scroll-view scroll-x="true"
                   style="width: 100%;">
        <view class="time-table">
          <!-- 表头 -->
          <view class="table-header">
            <view class="header-cell room-header">会议室</view>
            <view v-for="timeSlot in timeSlots"
                  :key="timeSlot.value"
                  class="header-cell time-header">
              {{ timeSlot.label }}
            </view>
          </view>
          <!-- 表格内容 -->
          <view class="table-body">
            <view v-for="room in roomUsage"
                  :key="room.id"
                  class="table-row">
              <view class="cell room-cell">{{ room.name }}</view>
              <view class="cells-container">
                <template v-for="(cell, index) in generateMeetingCells(room)"
                          :key="index">
                  <view class="cell content-cell"
                        :class="[cell.type, `status-${cell.meeting?.status || '0'}`]"
                        :style="{ width: `${cell.span * 120}rpx` }"
                        @click="viewMeetingDetails(cell)">
                    <view v-if="cell.type === 'meeting'"
                          class="meeting-content">
                      <view class="meeting-title">{{ cell.meeting.title }}</view>
                      <view class="meeting-time">{{ cell.startTime }}-{{ cell.endTime }}</view>
                    </view>
                    <view v-else
                          class="free-content">
                      空闲
                    </view>
                  </view>
                </template>
              </view>
            </view>
          </view>
        </view>
      </scroll-view>
    </view>
    <!-- 会议详情对话框 -->
    <u-popup :show="detailDialogVisible"
             mode="center"
             customStyle="width: 80%;"
             :round="10">
      <view class="dialog-content">
        <view class="dialog-header">
          <text class="dialog-title">会议详情</text>
          <up-icon name="close"
                   @click="detailDialogVisible = false"
                   class="close-icon"></up-icon>
        </view>
        <view v-if="currentMeeting"
              class="dialog-body">
          <view class="detail-item">
            <text class="detail-label">会议主题</text>
            <text class="detail-value">{{ currentMeeting.title }}</text>
          </view>
          <view class="detail-item">
            <text class="detail-label">会议室</text>
            <text class="detail-value">{{ currentMeeting.room }}</text>
          </view>
          <view class="detail-item">
            <text class="detail-label">会议时间</text>
            <text class="detail-value">{{ currentMeeting.time }}</text>
          </view>
          <view class="detail-item">
            <text class="detail-label">主持人</text>
            <text class="detail-value">{{ currentMeeting.host }}</text>
          </view>
          <view class="detail-item">
            <text class="detail-label">参会人数</text>
            <text class="detail-value">{{ currentMeeting.participants }}人</text>
          </view>
          <view class="detail-item">
            <text class="detail-label">会议说明</text>
            <text class="detail-value">{{ currentMeeting.description }}</text>
          </view>
        </view>
        <view class="dialog-footer">
          <u-button @click="detailDialogVisible = false">关闭</u-button>
        </view>
      </view>
    </u-popup>
  </view>
</template>
 
<script setup>
  import { ref, reactive, onMounted } from "vue";
  import PageHeader from "@/components/PageHeader.vue";
  import { getMeetingUseList } from "@/api/managementMeetings/meeting.js";
  import dayjs from "dayjs";
 
  // 查询表单
  const queryForm = reactive({
    meetingDate: dayjs().format("YYYY-MM-DD"),
  });
 
  const loading = ref(false);
  const timeSlots = ref([]);
  const roomUsage = ref([]);
  const currentMeeting = ref(null);
  const detailDialogVisible = ref(false);
  const showDatePickerDialog = ref(false);
  const datePickerValue = ref(Date.now());
 
  // 返回上一页
  const goBack = () => {
    uni.navigateBack();
  };
 
  // 清空日期
  const clearDate = () => {
    datePickerValue.value = Date.now();
    queryForm.meetingDate = dayjs().format("YYYY-MM-DD");
    getList();
  };
 
  // 显示日期选择器
  const showDatePicker = () => {
    if (queryForm.meetingDate) {
      datePickerValue.value = new Date(queryForm.meetingDate).getTime();
    } else {
      datePickerValue.value = Date.now();
    }
    console.log(datePickerValue.value, "datePickerValue.value");
    showDatePickerDialog.value = true;
  };
 
  // 处理日期选择确认
  const handleDateConfirm = value => {
    // dayjs().format("YYYY-MM-DD")
    console.log(value, "value");
 
    queryForm.meetingDate = dayjs(value.value).format("YYYY-MM-DD");
    showDatePickerDialog.value = false;
    getList();
  };
 
  // 获取列表数据
  const getList = () => {
    handleSearch();
  };
 
  // 初始化时间槽(以半小时为间隔,从8:00到18:00)
  const initTimeSlots = () => {
    const slots = [];
    for (let hour = 8; hour < 18; hour++) {
      // 每个小时添加两个时间段:整点和半点
      slots.push({
        label: `${hour.toString().padStart(2, "0")}:00`,
        value: `${hour.toString().padStart(2, "0")}:00`,
      });
 
      if (hour < 17) {
        // 到17:30为止
        slots.push({
          label: `${hour.toString().padStart(2, "0")}:30`,
          value: `${hour.toString().padStart(2, "0")}:30`,
        });
      }
    }
    timeSlots.value = slots;
    console.log(timeSlots.value, "timeSlots.value");
  };
 
  // 生成会议室的时间单元格
  const generateMeetingCells = room => {
    const cells = [];
    const meetings = room.meetings || [];
    const occupiedSlots = new Set();
 
    // 处理每个会议
    for (const meeting of meetings) {
      const startIdx = timeSlots.value.findIndex(
        slot => slot.value === meeting.startTime
      );
      let endIdx = timeSlots.value.findIndex(
        slot => slot.value === meeting.endTime
      );
      if (endIdx === -1) {
        endIdx = timeSlots.value.length;
      }
 
      if (startIdx !== -1) {
        // 标记被占用的时间段
        for (let i = startIdx; i < endIdx; i++) {
          if (timeSlots.value[i]) {
            occupiedSlots.add(timeSlots.value[i].value);
          }
        }
 
        // 创建会议单元格
        cells.push({
          type: "meeting",
          meeting: meeting,
          span: endIdx - startIdx,
          startTime: meeting.startTime,
          endTime: meeting.endTime,
        });
      }
    }
 
    // 处理空闲时间段
    for (let i = 0; i < timeSlots.value.length; i++) {
      const slot = timeSlots.value[i];
      if (!occupiedSlots.has(slot.value)) {
        // 查找连续的空闲时间段
        let span = 1;
        while (
          i + span < timeSlots.value.length &&
          !occupiedSlots.has(timeSlots.value[i + span].value)
        ) {
          occupiedSlots.add(timeSlots.value[i + span].value);
          span++;
        }
 
        cells.push({
          type: "free",
          span: span,
          time: slot.value,
        });
      }
    }
 
    // 按时间排序
    cells.sort((a, b) => {
      const timeA = a.startTime || a.time;
      const timeB = b.startTime || b.time;
      return (
        timeSlots.value.findIndex(s => s.value === timeA) -
        timeSlots.value.findIndex(s => s.value === timeB)
      );
    });
 
    return cells;
  };
 
  // 查看会议详情
  const viewMeetingDetails = cell => {
    console.log(cell, "cell");
 
    if (cell && cell.type === "meeting") {
      currentMeeting.value = cell.meeting;
      detailDialogVisible.value = true;
    } else {
      uni.showToast({
        title: "该时间段会议室空闲",
        icon: "info",
      });
    }
  };
 
  // 查询按钮操作
  const handleSearch = async () => {
    loading.value = true;
    try {
      const resp = await getMeetingUseList({ ...queryForm });
      roomUsage.value = resp.data;
    } catch (error) {
      uni.showToast({
        title: "获取数据失败",
        icon: "error",
      });
    } finally {
      loading.value = false;
    }
  };
 
  // 重置搜索表单
  const resetSearch = () => {
    queryForm.meetingDate = dayjs().format("YYYY-MM-DD");
  };
 
  // 页面加载时获取数据
  onMounted(() => {
    // 初始化时间槽
    initTimeSlots();
 
    // 默认查询今天的数据
    handleSearch();
  });
</script>
 
<style scoped lang="scss">
  @import "../../../styles/sales-common.scss";
  .meeting-list {
    min-height: 100vh;
    background: #f8f9fa;
    padding: 16rpx;
  }
 
  .search-section {
    background: #fff;
    padding: 16rpx;
    border-radius: 8rpx;
    margin-bottom: 16rpx;
    box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  }
 
  .search-bar {
    display: flex;
    align-items: center;
    gap: 12rpx;
  }
 
  .search-input {
    flex: 1;
  }
 
  .filter-button {
    padding: 12rpx 16rpx;
    background: #f5f7fa;
    border-radius: 4rpx;
  }
 
  .form-buttons {
    display: flex;
    gap: 12rpx;
    margin-top: 16rpx;
    justify-content: center;
  }
 
  .table-container {
    margin-top: 16rpx;
    overflow-x: auto;
  }
 
  .time-table {
    width: 100%;
  }
 
  .table-header {
    display: flex;
    border: 1rpx solid #e4e7ed;
    background: #f5f7fa;
  }
 
  .header-cell {
    padding: 12rpx 8rpx;
    text-align: center;
    font-weight: bold;
    border-right: 1rpx solid #e4e7ed;
  }
 
  .room-header {
    width: 120rpx;
    flex-shrink: 0;
  }
 
  .time-header {
    width: 120rpx;
    flex-shrink: 0;
  }
 
  .table-body {
    border: 1rpx solid #e4e7ed;
    border-top: none;
  }
 
  .table-row {
    display: flex;
    border-top: 1rpx solid #e4e7ed;
  }
 
  .table-row:first-child {
    border-top: none;
  }
 
  .cell {
    padding: 16rpx 8rpx;
    text-align: center;
    border-right: 1rpx solid #e4e7ed;
    display: flex;
    align-items: center;
    justify-content: center;
    word-break: break-word;
    line-height: 1.2;
  }
 
  .room-cell {
    width: 120rpx;
    font-weight: bold;
    flex-shrink: 0;
    background: #f9fafc;
  }
 
  .cells-container {
    display: flex;
  }
 
  .content-cell {
    min-height: 120rpx;
    cursor: pointer;
    transition: all 0.3s;
    flex-direction: column;
    justify-content: center;
  }
 
  .content-cell:active {
    opacity: 0.8;
  }
 
  .free {
    color: #f56c6c;
  }
 
  .meeting {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
 
  .status-1 {
    background-color: #fef0f0;
    color: #d14646;
  }
 
  .status-0 {
    background-color: #ecf5ff;
    color: #409eff;
  }
 
  .meeting-content {
    width: 100%;
  }
 
  .meeting-title {
    font-weight: bold;
    margin-bottom: 8rpx;
    font-size: 24rpx;
  }
 
  .meeting-time {
    font-size: 20rpx;
    opacity: 0.8;
  }
 
  .free-content {
    color: #909399;
  }
 
  /* 对话框样式 */
  .dialog-content {
    padding: 24rpx;
  }
 
  .dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24rpx;
    padding-bottom: 16rpx;
    border-bottom: 1rpx solid #e4e7ed;
  }
 
  .dialog-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #303133;
  }
 
  .close-icon {
    font-size: 32rpx;
    color: #909399;
  }
 
  .dialog-body {
    margin-bottom: 24rpx;
  }
 
  .detail-item {
    display: flex;
    margin-bottom: 16rpx;
    padding: 8rpx 0;
    border-bottom: 1rpx solid #f0f0f0;
  }
 
  .detail-label {
    width: 140rpx;
    font-weight: bold;
    color: #606266;
  }
 
  .detail-value {
    flex: 1;
    color: #303133;
  }
 
  .dialog-footer {
    display: flex;
    justify-content: center;
    margin-top: 16rpx;
  }
</style>