Blame view

store-pc/src/components/room-usage-dialog.vue 8.43 KB
c8f0ff5f   “wangming”   Refactor LqCooper...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  <template>
    <el-dialog
      :visible.sync="visibleProxy"
      :show-close="false"
      width="860px"
      :close-on-click-modal="false"
      custom-class="room-usage-dialog"
      append-to-body
    >
      <div class="inner">
        <div class="header">
          <div class="title">房态 · {{ date || '—' }}</div>
          <span class="close" @click="visibleProxy = false"><i class="el-icon-close"></i></span>
        </div>
  
b5df6609   “wangming”   ```
16
        <div class="body" v-loading="loading">
c8f0ff5f   “wangming”   Refactor LqCooper...
17
18
19
20
          <div class="legend">
            <span class="legend-item"><i class="dot dot--free"></i>空闲</span>
            <span class="legend-item"><i class="dot dot--busy"></i>占用</span>
            <span class="legend-item"><i class="dot dot--slot"></i>30分钟/格</span>
b5df6609   “wangming”   ```
21
22
            <span v-if="loadError" class="legend-tip legend-tip--err">{{ loadError }}</span>
            <span v-else-if="!normalizedRooms.length" class="legend-tip">当前门店暂无房间,请先在管理端配置</span>
c8f0ff5f   “wangming”   Refactor LqCooper...
23
24
          </div>
  
b5df6609   “wangming”   ```
25
          <div v-if="normalizedRooms.length" class="table">
c8f0ff5f   “wangming”   Refactor LqCooper...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
            <div class="thead">
              <div class="cell cell--room">房间</div>
              <div class="cell cell--grid">
                <div class="grid">
                  <div v-for="i in 48" :key="i" class="t">
                    {{ (i - 1) % 2 === 0 ? formatSlotTime(i - 1) : '' }}
                  </div>
                </div>
              </div>
            </div>
  
            <div v-for="r in normalizedRooms" :key="r.id" class="row">
              <div class="cell cell--room">
                <div class="room-name">{{ r.name }}</div>
b5df6609   “wangming”   ```
40
                <div class="room-sub">当日占用 {{ countBusySlots(r.id) }} 格</div>
c8f0ff5f   “wangming”   Refactor LqCooper...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
              </div>
              <div class="cell cell--grid">
                <div class="grid">
                  <div
                    v-for="i in 48"
                    :key="i"
                    :class="['slot', isBusy(r.id, i - 1) ? 'slot--busy' : 'slot--free']"
                    :title="slotTitle(r.id, i - 1)"
                  ></div>
                </div>
              </div>
            </div>
          </div>
        </div>
  
        <div class="footer">
          <el-button size="small" @click="visibleProxy = false">关 闭</el-button>
        </div>
      </div>
    </el-dialog>
  </template>
  
  <script>
b5df6609   “wangming”   ```
64
65
66
67
68
69
70
71
  import { getYyjlList } from '@/api/lqYyjl'
  import { getRoomsByStoreId } from '@/api/lqMdRoom'
  import {
    buildYysjTimestampRange,
    buildRoomBusyMap,
    parseDayRangeYmd
  } from '@/utils/appointmentHelper'
  
c8f0ff5f   “wangming”   Refactor LqCooper...
72
73
74
75
76
  export default {
    name: 'RoomUsageDialog',
    props: {
      visible: { type: Boolean, default: false },
      date: { type: String, default: '' },
b5df6609   “wangming”   ```
77
      storeId: { type: String, default: '' },
c8f0ff5f   “wangming”   Refactor LqCooper...
78
79
80
81
      rooms: { type: Array, default: () => [] }
    },
    data() {
      return {
b5df6609   “wangming”   ```
82
83
84
85
        loading: false,
        loadError: '',
        localRooms: [],
        roomBusy: {}
c8f0ff5f   “wangming”   Refactor LqCooper...
86
87
88
89
90
91
92
93
      }
    },
    computed: {
      visibleProxy: {
        get() { return this.visible },
        set(v) { this.$emit('update:visible', v) }
      },
      normalizedRooms() {
b5df6609   “wangming”   ```
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
        const src = (this.rooms && this.rooms.length) ? this.rooms : this.localRooms
        return (src || []).map(r => ({
          id: String(r.id),
          name: r.name || r.roomName || '房间'
        }))
      }
    },
    watch: {
      visible(v) {
        if (v) this.loadOccupancy()
      },
      date() {
        if (this.visible) this.loadOccupancy()
      },
      storeId() {
        if (this.visible) this.loadOccupancy()
c8f0ff5f   “wangming”   Refactor LqCooper...
110
111
112
      }
    },
    methods: {
b5df6609   “wangming”   ```
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
      resolveStoreId() {
        return this.storeId || (this.$store.getters.storeInfo || {}).storeId || ''
      },
      async loadOccupancy() {
        const storeId = this.resolveStoreId()
        const dayRange = parseDayRangeYmd(this.date)
        if (!storeId) {
          this.loadError = '未获取到当前门店'
          this.roomBusy = {}
          return
        }
        if (!dayRange) {
          this.loadError = '日期无效'
          this.roomBusy = {}
          return
        }
  
        this.loading = true
        this.loadError = ''
        try {
          if (!this.rooms || !this.rooms.length) {
            const roomRes = await getRoomsByStoreId(storeId)
            const list = (roomRes.data && roomRes.data.list) || []
            this.localRooms = list
              .filter(r => r.enabled !== 0 && r.enabled !== '0' && r.enabled !== false)
              .map(r => ({ id: r.id, name: r.roomName }))
          } else {
            this.localRooms = []
          }
  
          const yysj = buildYysjTimestampRange(dayRange.dayStart, dayRange.dayEnd)
          const res = await getYyjlList({
            djmd: storeId,
            currentPage: 1,
            pageSize: 500,
            sidx: 'yysj',
            sort: 'asc',
            yysj
          })
          const bookings = (res.data && res.data.list) || []
          this.roomBusy = buildRoomBusyMap(bookings)
        } catch (e) {
          this.roomBusy = {}
          this.loadError = '加载房态失败,请稍后重试'
        } finally {
          this.loading = false
        }
      },
c8f0ff5f   “wangming”   Refactor LqCooper...
161
162
163
164
165
      formatSlotTime(slotIndex) {
        const h = Math.floor(slotIndex / 2)
        const m = (slotIndex % 2) * 30
        return `${String(h).padStart(2, '0')}:${m === 0 ? '00' : '30'}`
      },
b5df6609   “wangming”   ```
166
167
168
      getBusyList(roomId) {
        return this.roomBusy[String(roomId)] || []
      },
c8f0ff5f   “wangming”   Refactor LqCooper...
169
      isBusy(roomId, slotIndex) {
b5df6609   “wangming”   ```
170
        return this.getBusyList(roomId).some(x => slotIndex >= x.startSlot && slotIndex < x.endSlot)
c8f0ff5f   “wangming”   Refactor LqCooper...
171
172
173
      },
      slotTitle(roomId, slotIndex) {
        const time = this.formatSlotTime(slotIndex)
b5df6609   “wangming”   ```
174
        const hit = this.getBusyList(roomId).find(x => slotIndex >= x.startSlot && slotIndex < x.endSlot)
c8f0ff5f   “wangming”   Refactor LqCooper...
175
176
177
178
        if (!hit) return `${time} 空闲`
        return `${time} ${hit.label}`
      },
      countBusySlots(roomId) {
b5df6609   “wangming”   ```
179
        return this.getBusyList(roomId).reduce((sum, x) => sum + Math.max(x.endSlot - x.startSlot, 0), 0)
c8f0ff5f   “wangming”   Refactor LqCooper...
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
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .inner {
    padding: 18px 22px 14px;
  }
  
  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(219, 234, 254, 0.96);
  }
  
  .title {
    font-size: 17px;
    font-weight: 600;
    color: #0f172a;
  }
  
  .close {
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: #64748b;
    transition: all 0.15s;
    &:hover { background: rgba(0, 0, 0, 0.06); color: #0f172a; }
  }
  
  .legend {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    font-size: 12px;
    color: #64748b;
    margin-bottom: 10px;
  }
  
  .legend-item { display: inline-flex; align-items: center; gap: 6px; }
  .legend-tip { margin-left: auto; color: #94a3b8; }
b5df6609   “wangming”   ```
232
  .legend-tip--err { color: #f56c6c; }
c8f0ff5f   “wangming”   Refactor LqCooper...
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
  
  .dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
  .dot--free { background: rgba(148, 163, 184, 0.35); }
  .dot--busy { background: rgba(239, 68, 68, 0.55); }
  .dot--slot { background: #e2e8f0; }
  
  .table {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
  }
  
  .thead, .row {
    display: grid;
    grid-template-columns: 140px 1fr;
  }
  
  .cell {
    padding: 10px 10px;
    border-right: 1px solid #f1f5f9;
    border-bottom: 1px solid #f1f5f9;
  }
  
  .cell--room {
    background: #f8fafc;
  }
  
  .room-name {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
  }
  
  .room-sub {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
  }
  
  .grid {
    display: grid;
    grid-template-columns: repeat(48, 1fr);
    gap: 0;
    min-height: 24px;
  }
  
  .t {
    font-size: 9px;
    color: #94a3b8;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
  }
  
  .slot {
    min-height: 18px;
    background: #f8fafc;
  }
  
  .slot--free {
    background: rgba(148, 163, 184, 0.18);
  }
  
  .slot--busy {
    background: rgba(239, 68, 68, 0.5);
  }
  
  .footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px solid #f1f5f9;
  }
  
  ::v-deep .room-usage-dialog {
    max-width: 860px;
    margin-top: 7vh !important;
    border-radius: 20px;
    padding: 0;
    background: radial-gradient(circle at 0 0, rgba(255, 255, 255, 0.96) 0, rgba(248, 250, 252, 0.98) 40%, rgba(241, 245, 249, 0.98) 100%);
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.18), 0 0 0 1px rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
  }
  ::v-deep .room-usage-dialog .el-dialog__header { display: none; }
  ::v-deep .room-usage-dialog .el-dialog__body { padding: 0; }
  ::v-deep .room-usage-dialog .el-button--default {
    border-radius: 999px;
    padding: 0 18px;
    height: 30px;
    line-height: 30px;
    background: rgba(239, 246, 255, 0.9);
    color: #2563eb;
    border-color: rgba(37, 99, 235, 0.18);
    font-size: 12px;
  }
  </style>