|
|
@@ -1,753 +0,0 @@
|
|
1
|
|
-<template>
|
|
2
|
|
- <view class="w-100">
|
|
3
|
|
- <view class="bg-f1 h-100vh">
|
|
4
|
|
- <view class="pt-f left-0 w-100 p-0-32 bg-white z1000" :style="'height: 132rpx;top:0'">
|
|
5
|
|
- <view>
|
|
6
|
|
- <view class="fz-34 fw-b pt-20">
|
|
7
|
|
- {{initInfo.film_name}}
|
|
8
|
|
- </view>
|
|
9
|
|
- <view class="mt-10 fz-28 color-666">
|
|
10
|
|
- {{initInfo.show_des}}
|
|
11
|
|
- </view>
|
|
12
|
|
- </view>
|
|
13
|
|
- </view>
|
|
14
|
|
- <movable-area :style="'height:'+(seatRow*40+350)+'rpx;width: 100vw;top:'+(rpxNum*132)+'px'" class="pt-f left-0">
|
|
15
|
|
- <movable-view :style="'width: 100vw;height:'+(seatRow*40+350)+'rpx;'" :inertia="true" :scale="true" :scale-min="0.95"
|
|
16
|
|
- :scale-max="2" direction="all" @change="onMove" @scale="onScale">
|
|
17
|
|
- <view class="Stage dp-f jc-c ai-c fz-22 color-333">
|
|
18
|
|
- {{initInfo.hall_name}}
|
|
19
|
|
- </view>
|
|
20
|
|
- <view style="width: 100rpx;height: 30rpx;" class="m-0-a mt-48 dp-f jc-c ai-c fz-20 color-999 b-1 br-5">银幕中央</view>
|
|
21
|
|
-
|
|
22
|
|
- <view class="pt-f pa-v-2 b-d-1" :style="'height:'+seatRow*(20+seatSize*pxNum)+'rpx;top:165rpx;width:0'"></view>
|
|
23
|
|
-
|
|
24
|
|
- <view v-for="(item,index) in seatArray" :key="index" class="dp-f jc-c mt-20" :style="'width:'+boxWidth+'px;height:'+seatSize+'px'">
|
|
25
|
|
- <view v-for="(seat,col) in item" :key="col" class="dp-ib" :style="'width:'+seatSize+'px;height:'+seatSize+'px'"
|
|
26
|
|
- @click="handleChooseSeat(index,col)">
|
|
27
|
|
- <image v-if="seat.type===0" class="w-100 h-100" src="../../static/unselected.png" mode="aspectFit"></image>
|
|
28
|
|
- <image v-else-if="seat.type===1" class="w-100 h-100" src="../../static/selected.png" mode="aspectFit"></image>
|
|
29
|
|
- <image v-else-if="seat.type===2" class="w-100 h-100" src="../../static/bought.png" mode="aspectFit"></image>
|
|
30
|
|
- </view>
|
|
31
|
|
- </view>
|
|
32
|
|
-
|
|
33
|
|
- <view class="pt-f bg-line br-15 over-h" :style="'left: '+(10-moveX/scale)+'px;top:109rpx;width:30rpx;'">
|
|
34
|
|
- <view class="w-100 dp-f ai-c jc-c fz-22 color-fff" :style="'height:'+seatSize+'px;margin-top:20rpx;'" v-for="(m,mindex) in mArr"
|
|
35
|
|
- :key="mindex">{{m}}</view>
|
|
36
|
|
- <view :style="'height: 20rpx;'"></view>
|
|
37
|
|
- </view>
|
|
38
|
|
-
|
|
39
|
|
- </movable-view>
|
|
40
|
|
- </movable-area>
|
|
41
|
|
- <view class="pt-f bottom-bar left-0 dp-f fd-cr z1000">
|
|
42
|
|
- <view class="bg-white p-all-32">
|
|
43
|
|
- <!-- <view class="dp-f ai-c jc-c fz-28 color-333 mb-20" v-if="SelectNum===0">
|
|
44
|
|
- 推荐选座
|
|
45
|
|
- <view style="width: 106rpx;height: 60rpx;" class="b-1 br-5 dp-f ai-c jc-c fz-28 ml-20" v-for="(n,numindex) in 4"
|
|
46
|
|
- :key="n" @click="smartChoose(numindex+1)">
|
|
47
|
|
- {{numindex+1}}人
|
|
48
|
|
- </view>
|
|
49
|
|
- </view> -->
|
|
50
|
|
- <view class="dp-f ai-c fw-w fz-28 color-333 mb-20" v-if="SelectNum>0">
|
|
51
|
|
- <text>已选</text>
|
|
52
|
|
- <view class="p-all-10 b-1 br-5 dp-f ai-c jc-c fz-28 ml-20" v-for="(optItem,optindex) in optArr" :key="optindex">
|
|
53
|
|
- {{optItem.RowNum+'排'+optItem.ColumnNum+'座'}}
|
|
54
|
|
- </view>
|
|
55
|
|
- </view>
|
|
56
|
|
- <view style="width: 686rpx;height: 90rpx;" class="dp-f jc-c ai-c br-10 fz-34 color-fff" :class="SelectNum>0?'bg-red-1':'bg-unbtn'"
|
|
57
|
|
- @click="buySeat">
|
|
58
|
|
- {{SelectNum>0?('¥ '+aPrice+' 确认座位'):'请选座位'}}
|
|
59
|
|
- </view>
|
|
60
|
|
- </view>
|
|
61
|
|
- <view class="dp-f jc-c ai-c mb-20 fz-28" v-if="showTis">
|
|
62
|
|
- <view class="dp-f jc-c ai-c m-0-10">
|
|
63
|
|
- <image :style="'width:'+seatSize+'px;height:'+seatSize+'px'" src="/static/unselected.png" mode="aspectFit"></image><span
|
|
64
|
|
- class="ml-10">可选</span>
|
|
65
|
|
- </view>
|
|
66
|
|
- <view class="dp-f jc-c ai-c m-0-10">
|
|
67
|
|
- <image :style="'width:'+seatSize+'px;height:'+seatSize+'px'" src="/static/bought.png" mode="aspectFit"></image><span
|
|
68
|
|
- class="ml-10">不可选</span>
|
|
69
|
|
- </view>
|
|
70
|
|
- <view class="dp-f jc-c ai-c m-0-10">
|
|
71
|
|
- <image :style="'width:'+seatSize+'px;height:'+seatSize+'px'" src="/static/selected.png" mode="aspectFit"></image><span
|
|
72
|
|
- class="ml-10">选中</span>
|
|
73
|
|
- </view>
|
|
74
|
|
- </view>
|
|
75
|
|
- </view>
|
|
76
|
|
- </view>
|
|
77
|
|
- </view>
|
|
78
|
|
-</template>
|
|
79
|
|
-<script>
|
|
80
|
|
-
|
|
81
|
|
- import {
|
|
82
|
|
- seatData
|
|
83
|
|
- } from '@/utils/seat-data.js'
|
|
84
|
|
-
|
|
85
|
|
- import {
|
|
86
|
|
- apiGetSchedSeatList,
|
|
87
|
|
- } from '~/apis/movies'
|
|
88
|
|
- export default {
|
|
89
|
|
- data() {
|
|
90
|
|
- return {
|
|
91
|
|
- scaleMin:1,//h5端为解决1无法缩小问题,设为0.95
|
|
92
|
|
- boxWidth: 400, //屏幕宽度px
|
|
93
|
|
- space: ' ', //空格
|
|
94
|
|
- seatArray: [], //影院座位的二维数组,-1为非座位,0为未购座位,1为已选座位(绿色),2为已购座位(红色),一维行,二维列
|
|
95
|
|
- seatRow: 0, //影院座位行数
|
|
96
|
|
- seatCol: 0, //影院座位列数
|
|
97
|
|
- seatSize: 0, //座位尺寸
|
|
98
|
|
- SelectNum: 0, //选择座位数
|
|
99
|
|
- moveX: 0, //水平移动偏移量
|
|
100
|
|
- scale: 1, //放大倍数
|
|
101
|
|
- minRow: 0, //从第几行开始排座位
|
|
102
|
|
- minCol: 0, //从第几列开始排座位
|
|
103
|
|
- showTis: true, //显示选座提示
|
|
104
|
|
- seatList: [], //接口获取的原始位置
|
|
105
|
|
- mArr: [], //排数提示
|
|
106
|
|
- optArr: [], //选中的座位数组。
|
|
107
|
|
- isWXAPP:false,
|
|
108
|
|
- relation_id:'',
|
|
109
|
|
- sched_sign:'',
|
|
110
|
|
- initInfo:'',
|
|
111
|
|
- orgSeatList:[]
|
|
112
|
|
- };
|
|
113
|
|
- },
|
|
114
|
|
- computed: {
|
|
115
|
|
- aPrice() {
|
|
116
|
|
- return this.SelectNum * 36
|
|
117
|
|
- },
|
|
118
|
|
- rpxNum() {
|
|
119
|
|
- return this.boxWidth / 750
|
|
120
|
|
- },
|
|
121
|
|
- pxNum() {
|
|
122
|
|
- return 750 / this.boxWidth
|
|
123
|
|
- },
|
|
124
|
|
- },
|
|
125
|
|
-
|
|
126
|
|
- onLoad(e) {
|
|
127
|
|
- //relation_id=${item.relation_id}&sched_sign=${item.sched_sign}`
|
|
128
|
|
- console.log("===onLoad",e);
|
|
129
|
|
-
|
|
130
|
|
- if(e.info){
|
|
131
|
|
- this.initInfo = JSON.parse(decodeURIComponent(e.info))
|
|
132
|
|
- }
|
|
133
|
|
- //获取宽度
|
|
134
|
|
- let _this =this
|
|
135
|
|
- uni.getSystemInfo({
|
|
136
|
|
- success: function(e) {
|
|
137
|
|
- _this.boxWidth = e.screenWidth
|
|
138
|
|
- //#ifdef H5
|
|
139
|
|
- _this.scaleMin = 0.95
|
|
140
|
|
- //#endif
|
|
141
|
|
- }
|
|
142
|
|
- })
|
|
143
|
|
- this.initData()
|
|
144
|
|
- //this.getSeatList()
|
|
145
|
|
- },
|
|
146
|
|
- methods: {
|
|
147
|
|
-
|
|
148
|
|
- completeSeats(originalData) {
|
|
149
|
|
- // 1. 确定最大行号和列号
|
|
150
|
|
- let maxRow = 0, maxColumn = 0;
|
|
151
|
|
- originalData.forEach(rowArray => {
|
|
152
|
|
- rowArray.forEach(seat => {
|
|
153
|
|
- maxRow = Math.max(maxRow, parseInt(seat.rowNo));
|
|
154
|
|
- maxColumn = Math.max(maxColumn, parseInt(seat.columnNo));
|
|
155
|
|
- });
|
|
156
|
|
- });
|
|
157
|
|
- this.seatRow = maxRow//数组长度
|
|
158
|
|
- this.seatCol = maxColumn//子数组中长度最大的
|
|
159
|
|
- // 2. 按行号整理原始数据
|
|
160
|
|
- const rowMap = new Map();
|
|
161
|
|
- originalData.forEach(rowArray => {
|
|
162
|
|
- if (rowArray.length === 0) return;
|
|
163
|
|
- const rowNo = rowArray[0].rowNo;
|
|
164
|
|
- rowMap.set(rowNo, rowArray);
|
|
165
|
|
- });
|
|
166
|
|
-
|
|
167
|
|
- // 3. 生成完整的行和列
|
|
168
|
|
- const result = [];
|
|
169
|
|
- for (let row = 1; row <= maxRow; row++) {
|
|
170
|
|
- const rowNo = row.toString();
|
|
171
|
|
- const currentRow = rowMap.get(rowNo) || [];
|
|
172
|
|
- const columnMap = new Map(currentRow.map(seat => [seat.columnNo, seat]));
|
|
173
|
|
-
|
|
174
|
|
- // 生成当前排的完整列数据
|
|
175
|
|
- const completedColumns = Array.from({ length: maxColumn }, (_, colIdx) => {
|
|
176
|
|
- const columnNo = (colIdx + 1).toString();
|
|
177
|
|
- return columnMap.has(columnNo)
|
|
178
|
|
- ? columnMap.get(columnNo)
|
|
179
|
|
- : {
|
|
180
|
|
- supplier_id: null,
|
|
181
|
|
- seatNo: `${rowNo}排${columnNo.padStart(2, '0')}座`,
|
|
182
|
|
- rowNo,
|
|
183
|
|
- columnNo ,
|
|
184
|
|
- status:-1
|
|
185
|
|
- };
|
|
186
|
|
- });
|
|
187
|
|
- result.push(completedColumns);
|
|
188
|
|
- }
|
|
189
|
|
-
|
|
190
|
|
- return result;
|
|
191
|
|
- },
|
|
192
|
|
- initData() {
|
|
193
|
|
-
|
|
194
|
|
-
|
|
195
|
|
- let arr = seatData
|
|
196
|
|
- //假数据说明:SeatCode座位编号,RowNum-行号,ColumnNum-纵号,YCoord-Y坐标,XCoord-X坐标,Status-状态
|
|
197
|
|
- let row = 0
|
|
198
|
|
- let col = 0
|
|
199
|
|
- let minCol = parseInt(arr[0].XCoord)
|
|
200
|
|
- let minRow = parseInt(arr[0].YCoord)
|
|
201
|
|
- for (let i of arr) {
|
|
202
|
|
- minRow = parseInt(i.YCoord) < minRow ? parseInt(i.YCoord) : minRow
|
|
203
|
|
- minCol = parseInt(i.XCoord) < minCol ? parseInt(i.XCoord) : minCol
|
|
204
|
|
- row = parseInt(i.YCoord) > row ? parseInt(i.YCoord) : row
|
|
205
|
|
- col = parseInt(i.XCoord) > col ? parseInt(i.XCoord) : col
|
|
206
|
|
- }
|
|
207
|
|
- this.seatList = arr
|
|
208
|
|
- this.seatRow = row - minRow + 1
|
|
209
|
|
- this.seatCol = col - minCol + 3
|
|
210
|
|
- this.minRow = minRow
|
|
211
|
|
- this.minCol = minCol - 1
|
|
212
|
|
- console.log("===this.seatRow--initData",this.seatList);
|
|
213
|
|
- console.log("===this.seatRow",this.seatRow);
|
|
214
|
|
- console.log("===this.seatCol",this.seatCol);
|
|
215
|
|
- console.log("===minRow",this.minRow);
|
|
216
|
|
- console.log("===minCol",this.minCol);
|
|
217
|
|
- this.initSeatArray()
|
|
218
|
|
- },
|
|
219
|
|
-
|
|
220
|
|
- getSeatList(){
|
|
221
|
|
- uni.showLoading()
|
|
222
|
|
- let params = `relation_id=${this.initInfo.relation_id}&sched_sign=${this.initInfo.sched_sign}`
|
|
223
|
|
- apiGetSchedSeatList(params).then(res => {
|
|
224
|
|
- console.log("===getSeatList",res);
|
|
225
|
|
- this.orgSeatList = res
|
|
226
|
|
-
|
|
227
|
|
- let _arr = this.completeSeats(this.orgSeatList)
|
|
228
|
|
- console.log("===getSeatList",_arr);
|
|
229
|
|
-
|
|
230
|
|
- //this.initSeatArray()
|
|
231
|
|
- uni.hideLoading()
|
|
232
|
|
- })
|
|
233
|
|
- },
|
|
234
|
|
- //初始座位数组
|
|
235
|
|
- initSeatArray: function() {
|
|
236
|
|
-
|
|
237
|
|
-
|
|
238
|
|
-
|
|
239
|
|
- let seatArray = Array(this.seatRow).fill(0).map(() => Array(this.seatCol).fill({
|
|
240
|
|
- type: -1,
|
|
241
|
|
- SeatCode: '',
|
|
242
|
|
- RowNum: '',
|
|
243
|
|
- ColumnNum: ''
|
|
244
|
|
- }));
|
|
245
|
|
- console.log("===this.seatArray",seatArray);
|
|
246
|
|
- this.seatArray = seatArray
|
|
247
|
|
- console.log("===this.seatArray",this.seatArray);
|
|
248
|
|
- this.seatSize = this.boxWidth > 0 ?
|
|
249
|
|
- parseInt(parseInt(this.boxWidth, 10) / (this.seatCol + 1), 10) :
|
|
250
|
|
- parseInt(parseInt(414, 10) / (this.seatCol + 1), 10)
|
|
251
|
|
- this.initNonSeatPlace();
|
|
252
|
|
- },
|
|
253
|
|
-
|
|
254
|
|
- //初始化是座位的地方
|
|
255
|
|
- initNonSeatPlace: function() {
|
|
256
|
|
- let seat = this.seatList.slice()
|
|
257
|
|
- let arr = this.seatArray.slice()
|
|
258
|
|
- for (let num in seat) {
|
|
259
|
|
- let status = 2 //-1为非座位,0为未购座位,1为已选座位(绿色),2为已购座位(红色)
|
|
260
|
|
- if (seat[num].Status === 0) {
|
|
261
|
|
- status = 0
|
|
262
|
|
- } else if (seat[num].Status === -1) {
|
|
263
|
|
- status = -1
|
|
264
|
|
- }
|
|
265
|
|
- arr[parseInt(seat[num].YCoord) - this.minRow][parseInt(seat[num].XCoord) - this.minCol] = {
|
|
266
|
|
- type: status,
|
|
267
|
|
- SeatCode: seat[num].SeatCode,
|
|
268
|
|
- RowNum: seat[num].RowNum,
|
|
269
|
|
- ColumnNum: seat[num].ColumnNum
|
|
270
|
|
- }
|
|
271
|
|
- }
|
|
272
|
|
- this.seatArray = arr.slice()
|
|
273
|
|
- console.log("===this.seatArray==slice",this.seatArray);
|
|
274
|
|
- let mArr = []
|
|
275
|
|
- for (let i in arr) {
|
|
276
|
|
- let m = ''
|
|
277
|
|
- for (let n of arr[i]) {
|
|
278
|
|
- if (n.SeatCode) {
|
|
279
|
|
- m = n.RowNum
|
|
280
|
|
- }
|
|
281
|
|
- }
|
|
282
|
|
- if (m) {
|
|
283
|
|
- mArr.push(m)
|
|
284
|
|
- } else {
|
|
285
|
|
- mArr.push('')
|
|
286
|
|
- }
|
|
287
|
|
- }
|
|
288
|
|
- this.mArr = mArr
|
|
289
|
|
- },
|
|
290
|
|
- //放大缩小事件
|
|
291
|
|
- onScale: function(e) {
|
|
292
|
|
- this.showTis = false
|
|
293
|
|
- // this.moveX=-e.detail.x
|
|
294
|
|
- let w = this.boxWidth * 0.5
|
|
295
|
|
- let s = 1 - e.detail.scale
|
|
296
|
|
- this.moveX = w * s
|
|
297
|
|
- this.scale = e.detail.scale
|
|
298
|
|
- if (s > 0 || s === 0) {
|
|
299
|
|
- this.showTis = true
|
|
300
|
|
- }
|
|
301
|
|
- },
|
|
302
|
|
- //移动事件
|
|
303
|
|
- onMove: function(e) {
|
|
304
|
|
- this.showTis = false
|
|
305
|
|
- this.moveX = e.detail.x
|
|
306
|
|
- },
|
|
307
|
|
- //重置座位
|
|
308
|
|
- resetSeat: function() {
|
|
309
|
|
- this.SelectNum = 0
|
|
310
|
|
- this.optArr = []
|
|
311
|
|
- //将所有已选座位的值变为0
|
|
312
|
|
- let oldArray = this.seatArray.slice();
|
|
313
|
|
- for (let i = 0; i < this.seatRow; i++) {
|
|
314
|
|
- for (let j = 0; j < this.seatCol; j++) {
|
|
315
|
|
- if (oldArray[i][j].type === 1) {
|
|
316
|
|
- oldArray[i][j].type = 0
|
|
317
|
|
- }
|
|
318
|
|
- }
|
|
319
|
|
- }
|
|
320
|
|
- this.seatArray = oldArray;
|
|
321
|
|
- },
|
|
322
|
|
- //选定且购买座位
|
|
323
|
|
- buySeat: function() {
|
|
324
|
|
- console.log("===SelectNum",this.SelectNum);
|
|
325
|
|
- if (this.SelectNum === 0) {
|
|
326
|
|
- return
|
|
327
|
|
- }
|
|
328
|
|
- let oldArray = [];
|
|
329
|
|
- for (let i = 0; i < this.seatRow; i++) {
|
|
330
|
|
- for (let j = 0; j < this.seatCol; j++) {
|
|
331
|
|
- if (this.seatArray[i][j].type === 1) {
|
|
332
|
|
- oldArray.push(this.seatArray[i][j].SeatCode)
|
|
333
|
|
- }
|
|
334
|
|
- }
|
|
335
|
|
- }
|
|
336
|
|
-
|
|
337
|
|
- console.log("===oldArray",oldArray);
|
|
338
|
|
- // uni.navigateTo({
|
|
339
|
|
- // url:'/subPages/pages/movies/moviesOrder'
|
|
340
|
|
- // })
|
|
341
|
|
- },
|
|
342
|
|
- //处理座位选择逻辑
|
|
343
|
|
- handleChooseSeat: function(row, col) {
|
|
344
|
|
-
|
|
345
|
|
-
|
|
346
|
|
- let seatValue = this.seatArray[row][col].type;
|
|
347
|
|
- let newArray = this.seatArray;
|
|
348
|
|
- //如果是已购座位,直接返回
|
|
349
|
|
- if (seatValue === 2 || seatValue === -1) return
|
|
350
|
|
- //如果是已选座位点击后变未选
|
|
351
|
|
- if (seatValue === 1) {
|
|
352
|
|
- if(col % 2 ==0){ //偶数
|
|
353
|
|
- newArray[row][col].type = 0
|
|
354
|
|
- newArray[row][col-1].type = 0
|
|
355
|
|
- }else {
|
|
356
|
|
- newArray[row][col].type = 0
|
|
357
|
|
- newArray[row][col+1].type = 0
|
|
358
|
|
- }
|
|
359
|
|
- this.SelectNum--
|
|
360
|
|
- this.getOptArr(newArray[row][col], 0)
|
|
361
|
|
- } else if (seatValue === 0) {
|
|
362
|
|
- console.log("===SelectNum",this.SelectNum);
|
|
363
|
|
- if(this.SelectNum==4){
|
|
364
|
|
- uni.showToast({
|
|
365
|
|
- title:'每次最多只能选择4个座位',
|
|
366
|
|
- icon:'none'
|
|
367
|
|
- })
|
|
368
|
|
- return
|
|
369
|
|
- }
|
|
370
|
|
-
|
|
371
|
|
- if(col % 2 ==0){ //偶数
|
|
372
|
|
- newArray[row][col].type = 1
|
|
373
|
|
- newArray[row][col-1].type = 1
|
|
374
|
|
- }else {
|
|
375
|
|
- newArray[row][col].type = 1
|
|
376
|
|
- newArray[row][col+1].type = 1
|
|
377
|
|
- }
|
|
378
|
|
- this.SelectNum++
|
|
379
|
|
- this.getOptArr(newArray[row][col], 1)
|
|
380
|
|
-
|
|
381
|
|
-
|
|
382
|
|
- }
|
|
383
|
|
- //必须整体更新二维数组,Vue无法检测到数组某一项更新,必须slice复制一个数组才行
|
|
384
|
|
- this.seatArray = newArray.slice();
|
|
385
|
|
-
|
|
386
|
|
- },
|
|
387
|
|
- //处理已选座位数组
|
|
388
|
|
- getOptArr: function(item, type) {
|
|
389
|
|
- let optArr = this.optArr
|
|
390
|
|
- if (type === 1) {
|
|
391
|
|
- optArr.push(item)
|
|
392
|
|
- console.log("===optArr",optArr);
|
|
393
|
|
- } else if (type === 0) {
|
|
394
|
|
- let arr = []
|
|
395
|
|
- optArr.forEach(v => {
|
|
396
|
|
- if (v.SeatCode !== item.SeatCode) {
|
|
397
|
|
- arr.push(v)
|
|
398
|
|
- }
|
|
399
|
|
- })
|
|
400
|
|
- optArr = arr
|
|
401
|
|
- }
|
|
402
|
|
- this.optArr = optArr.slice()
|
|
403
|
|
- },
|
|
404
|
|
- //推荐选座,参数是推荐座位数目,
|
|
405
|
|
- smartChoose: function(num) {
|
|
406
|
|
- console.log('num===', num)
|
|
407
|
|
- // 先重置
|
|
408
|
|
- this.resetSeat()
|
|
409
|
|
- //找到影院座位水平垂直中间位置的后一排
|
|
410
|
|
- let rowStart = parseInt((this.seatRow - 1) / 2, 10) + 1;
|
|
411
|
|
- //先从中间排往后排搜索
|
|
412
|
|
- let backResult = this.searchSeatByDirection(rowStart, this.seatRow - 1, num);
|
|
413
|
|
- if (backResult.length > 0) {
|
|
414
|
|
- this.chooseSeat(backResult);
|
|
415
|
|
- this.SelectNum += num
|
|
416
|
|
- return
|
|
417
|
|
- }
|
|
418
|
|
- //再从中间排往前排搜索
|
|
419
|
|
- let forwardResult = this.searchSeatByDirection(rowStart - 1, 0, num);
|
|
420
|
|
- if (forwardResult.length > 0) {
|
|
421
|
|
- this.chooseSeat(forwardResult);
|
|
422
|
|
- this.SelectNum += num
|
|
423
|
|
- return
|
|
424
|
|
- }
|
|
425
|
|
- //提示用户无合法位置可选
|
|
426
|
|
- alert('无合法位置可选!')
|
|
427
|
|
-
|
|
428
|
|
- },
|
|
429
|
|
-
|
|
430
|
|
- //搜索函数,参数:fromRow起始行,toRow终止行,num推荐座位数
|
|
431
|
|
- searchSeatByDirection: function(fromRow, toRow, num) {
|
|
432
|
|
- /*
|
|
433
|
|
- * 推荐座位规则
|
|
434
|
|
- * (1)初始状态从座位行数的一半处的后一排的中间开始向左右分别搜索,取离中间最近的,如果满足条件,
|
|
435
|
|
- * 记录下该结果离座位中轴线的距离,后排搜索完成后取距离最小的那个结果座位最终结果,优先向后排进行搜索,
|
|
436
|
|
- * 后排都没有才往前排搜,前排逻辑同上
|
|
437
|
|
- *
|
|
438
|
|
- * (2)只考虑并排且连续的座位,不能不在一排或者一排中间有分隔
|
|
439
|
|
- *
|
|
440
|
|
- * */
|
|
441
|
|
-
|
|
442
|
|
- /*
|
|
443
|
|
- * 保存当前方向搜索结果的数组,元素是对象,result是结果数组,offset代表与中轴线的偏移距离
|
|
444
|
|
- * {
|
|
445
|
|
- * result:Array([x,y])
|
|
446
|
|
- * offset:Number
|
|
447
|
|
- * }
|
|
448
|
|
- *
|
|
449
|
|
- */
|
|
450
|
|
- let currentDirectionSearchResult = [];
|
|
451
|
|
-
|
|
452
|
|
- let largeRow = fromRow > toRow ? fromRow : toRow,
|
|
453
|
|
- smallRow = fromRow > toRow ? toRow : fromRow;
|
|
454
|
|
-
|
|
455
|
|
- for (let i = smallRow; i <= largeRow; i++) {
|
|
456
|
|
- //每一排的搜索,找出该排里中轴线最近的一组座位
|
|
457
|
|
- let tempRowResult = [],
|
|
458
|
|
- minDistanceToMidLine = Infinity;
|
|
459
|
|
- for (let j = 0; j <= this.seatCol - num; j++) {
|
|
460
|
|
- //如果有合法位置
|
|
461
|
|
- if (this.checkRowSeatContinusAndEmpty(i, j, j + num - 1)) {
|
|
462
|
|
- //计算该组位置距离中轴线的距离:该组位置的中间位置到中轴线的距离
|
|
463
|
|
- let resultMidPos = parseInt((j + num / 2), 10);
|
|
464
|
|
- let distance = Math.abs(parseInt(this.seatCol / 2) - resultMidPos);
|
|
465
|
|
- //如果距离较短则更新
|
|
466
|
|
- if (distance < minDistanceToMidLine) {
|
|
467
|
|
- minDistanceToMidLine = distance;
|
|
468
|
|
- //该行的最终结果
|
|
469
|
|
- tempRowResult = this.generateRowResult(i, j, j + num - 1)
|
|
470
|
|
- }
|
|
471
|
|
- }
|
|
472
|
|
- }
|
|
473
|
|
- //保存该行的最终结果
|
|
474
|
|
- currentDirectionSearchResult.push({
|
|
475
|
|
- result: tempRowResult,
|
|
476
|
|
- offset: minDistanceToMidLine
|
|
477
|
|
- })
|
|
478
|
|
- }
|
|
479
|
|
-
|
|
480
|
|
- //处理后排的搜索结果:找到距离中轴线最短的一个
|
|
481
|
|
- //注意这里的逻辑需要区分前后排,对于后排是从前往后,前排则是从后往前找
|
|
482
|
|
- let isBackDir = fromRow < toRow;
|
|
483
|
|
- let finalReuslt = [],
|
|
484
|
|
- minDistanceToMid = Infinity;
|
|
485
|
|
- if (isBackDir) {
|
|
486
|
|
- //后排情况,从前往后
|
|
487
|
|
- currentDirectionSearchResult.forEach((item) => {
|
|
488
|
|
- if (item.offset < minDistanceToMid) {
|
|
489
|
|
- finalReuslt = item.result;
|
|
490
|
|
- minDistanceToMid = item.offset;
|
|
491
|
|
- }
|
|
492
|
|
- });
|
|
493
|
|
- } else {
|
|
494
|
|
- //前排情况,从后往前找
|
|
495
|
|
- currentDirectionSearchResult.reverse().forEach((item) => {
|
|
496
|
|
- if (item.offset < minDistanceToMid) {
|
|
497
|
|
- finalReuslt = item.result;
|
|
498
|
|
- minDistanceToMid = item.offset;
|
|
499
|
|
- }
|
|
500
|
|
- })
|
|
501
|
|
- }
|
|
502
|
|
-
|
|
503
|
|
- //直接返回结果
|
|
504
|
|
- return finalReuslt
|
|
505
|
|
- },
|
|
506
|
|
-
|
|
507
|
|
- /*辅助函数,判断每一行座位从i列到j列是否全部空余且连续
|
|
508
|
|
- *
|
|
509
|
|
- */
|
|
510
|
|
- checkRowSeatContinusAndEmpty: function(rowNum, startPos, endPos) {
|
|
511
|
|
- let isValid = true;
|
|
512
|
|
- for (let i = startPos; i <= endPos; i++) {
|
|
513
|
|
- if (this.seatArray[rowNum][i].type !== 0) {
|
|
514
|
|
- isValid = false;
|
|
515
|
|
- break;
|
|
516
|
|
- }
|
|
517
|
|
- }
|
|
518
|
|
- return isValid
|
|
519
|
|
- },
|
|
520
|
|
- //辅助函数:返回每一行的某个合理位置的座位数组
|
|
521
|
|
- generateRowResult: function(row, startPos, endPos) {
|
|
522
|
|
- let result = [];
|
|
523
|
|
- for (let i = startPos; i <= endPos; i++) {
|
|
524
|
|
- result.push([row, i])
|
|
525
|
|
- }
|
|
526
|
|
- return result
|
|
527
|
|
- },
|
|
528
|
|
- //辅助函数:智能推荐的选座操作
|
|
529
|
|
- chooseSeat: function(result) {
|
|
530
|
|
- let opt = this.optArr
|
|
531
|
|
- let oldArray = this.seatArray.slice();
|
|
532
|
|
- for (let i = 0; i < result.length; i++) {
|
|
533
|
|
- //选定座位
|
|
534
|
|
- oldArray[result[i][0]][result[i][1]].type = 1
|
|
535
|
|
- this.optArr.push(oldArray[result[i][0]][result[i][1]])
|
|
536
|
|
- }
|
|
537
|
|
- this.seatArray = oldArray;
|
|
538
|
|
- },
|
|
539
|
|
- }
|
|
540
|
|
- }
|
|
541
|
|
-</script>
|
|
542
|
|
-
|
|
543
|
|
-<style lang="scss" scoped>
|
|
544
|
|
- .p-all-10{
|
|
545
|
|
- padding: 10rpx;
|
|
546
|
|
- }
|
|
547
|
|
- .ml-10 {
|
|
548
|
|
- margin-left: 10rpx;
|
|
549
|
|
- }
|
|
550
|
|
-
|
|
551
|
|
- .m-0-10 {
|
|
552
|
|
- margin: 0 10rpx;
|
|
553
|
|
- }
|
|
554
|
|
-
|
|
555
|
|
- .bg-unbtn {
|
|
556
|
|
- background-color: #f9abb3;
|
|
557
|
|
- }
|
|
558
|
|
-
|
|
559
|
|
- .bg-red-1 {
|
|
560
|
|
- background-color: #F45664;
|
|
561
|
|
- }
|
|
562
|
|
-
|
|
563
|
|
- .br-10 {
|
|
564
|
|
- border-radius: 10rpx;
|
|
565
|
|
- }
|
|
566
|
|
-
|
|
567
|
|
- .ml-20 {
|
|
568
|
|
- margin-left: 20rpx;
|
|
569
|
|
- }
|
|
570
|
|
-
|
|
571
|
|
- .mb-20 {
|
|
572
|
|
- margin-bottom: 20rpx;
|
|
573
|
|
- }
|
|
574
|
|
-
|
|
575
|
|
- .p-all-32 {
|
|
576
|
|
- padding: 32rpx;
|
|
577
|
|
- }
|
|
578
|
|
-
|
|
579
|
|
- .fd-cr {
|
|
580
|
|
- flex-direction: column-reverse;
|
|
581
|
|
- /* 主轴方向从下到上,默认从左到右 */
|
|
582
|
|
- }
|
|
583
|
|
-
|
|
584
|
|
- .bottom-bar {
|
|
585
|
|
- bottom: var(--window-bottom);
|
|
586
|
|
- }
|
|
587
|
|
-
|
|
588
|
|
- .color-fff {
|
|
589
|
|
- color: #fff
|
|
590
|
|
- }
|
|
591
|
|
-
|
|
592
|
|
- .br-15 {
|
|
593
|
|
- border-radius: 15rpx;
|
|
594
|
|
- }
|
|
595
|
|
-
|
|
596
|
|
- .over-h {
|
|
597
|
|
- overflow: hidden;
|
|
598
|
|
- }
|
|
599
|
|
-
|
|
600
|
|
- .dp-ib {
|
|
601
|
|
- display: inline-block;
|
|
602
|
|
- }
|
|
603
|
|
-
|
|
604
|
|
- .mt-20 {
|
|
605
|
|
- margin-top: 20rpx;
|
|
606
|
|
- }
|
|
607
|
|
-
|
|
608
|
|
- .pa-v-2 {
|
|
609
|
|
- /* 定位垂直对齐 */
|
|
610
|
|
- left: 50%;
|
|
611
|
|
- transform: translateX(-50%)
|
|
612
|
|
- }
|
|
613
|
|
-
|
|
614
|
|
- .b-d-1 {
|
|
615
|
|
- border: 1px dashed #e5e5e5;
|
|
616
|
|
- }
|
|
617
|
|
-
|
|
618
|
|
- .w-100 {
|
|
619
|
|
- width: 100%;
|
|
620
|
|
- }
|
|
621
|
|
-
|
|
622
|
|
- .h-100 {
|
|
623
|
|
- height: 100%;
|
|
624
|
|
- }
|
|
625
|
|
-
|
|
626
|
|
- .bg-f1 {
|
|
627
|
|
- background-color: #f1f1f1;
|
|
628
|
|
- }
|
|
629
|
|
-
|
|
630
|
|
- .h-100vh {
|
|
631
|
|
- height: 100vh;
|
|
632
|
|
- }
|
|
633
|
|
-
|
|
634
|
|
- .pt-f {
|
|
635
|
|
- position: fixed;
|
|
636
|
|
- }
|
|
637
|
|
-
|
|
638
|
|
- .left-0 {
|
|
639
|
|
- left: 0;
|
|
640
|
|
- }
|
|
641
|
|
-
|
|
642
|
|
- .p-0-32 {
|
|
643
|
|
- padding: 0 32rpx;
|
|
644
|
|
- }
|
|
645
|
|
-
|
|
646
|
|
- .pt-20 {
|
|
647
|
|
- padding-top: 20rpx;
|
|
648
|
|
- }
|
|
649
|
|
-
|
|
650
|
|
- .bg-white {
|
|
651
|
|
- background-color: #fff;
|
|
652
|
|
- }
|
|
653
|
|
-
|
|
654
|
|
- .z1000 {
|
|
655
|
|
- z-index: 1000;
|
|
656
|
|
- }
|
|
657
|
|
-
|
|
658
|
|
- .fz-34 {
|
|
659
|
|
- font-size: 34rpx;
|
|
660
|
|
- }
|
|
661
|
|
-
|
|
662
|
|
- .fw-b {
|
|
663
|
|
- font-weight: bold;
|
|
664
|
|
- }
|
|
665
|
|
-
|
|
666
|
|
- .mt-10 {
|
|
667
|
|
- margin-top: 10rpx;
|
|
668
|
|
- }
|
|
669
|
|
-
|
|
670
|
|
- .fz-28 {
|
|
671
|
|
- font-size: 28rpx;
|
|
672
|
|
- }
|
|
673
|
|
-
|
|
674
|
|
- .color-666 {
|
|
675
|
|
- color: #666666
|
|
676
|
|
- }
|
|
677
|
|
-
|
|
678
|
|
- .dp-f {
|
|
679
|
|
- display: flex;
|
|
680
|
|
- }
|
|
681
|
|
-
|
|
682
|
|
- .jc-c {
|
|
683
|
|
- justify-content: center;
|
|
684
|
|
- }
|
|
685
|
|
-
|
|
686
|
|
- .ai-c {
|
|
687
|
|
- align-items: center;
|
|
688
|
|
- }
|
|
689
|
|
-
|
|
690
|
|
- .fz-22 {
|
|
691
|
|
- font-size: 22rpx;
|
|
692
|
|
- }
|
|
693
|
|
-
|
|
694
|
|
- .color-333 {
|
|
695
|
|
- color: #333333
|
|
696
|
|
- }
|
|
697
|
|
-
|
|
698
|
|
- .m-0-a {
|
|
699
|
|
- margin: 0 auto;
|
|
700
|
|
- }
|
|
701
|
|
-
|
|
702
|
|
- .mt-48 {
|
|
703
|
|
- margin-top: 48rpx;
|
|
704
|
|
- }
|
|
705
|
|
-
|
|
706
|
|
- .fz-20 {
|
|
707
|
|
- font-size: 20rpx;
|
|
708
|
|
- }
|
|
709
|
|
-
|
|
710
|
|
- .color-999 {
|
|
711
|
|
- color: #999999
|
|
712
|
|
- }
|
|
713
|
|
-
|
|
714
|
|
- .b-1 {
|
|
715
|
|
- border: 1px solid #CCCCCC;
|
|
716
|
|
- }
|
|
717
|
|
-
|
|
718
|
|
- .br-5 {
|
|
719
|
|
- border-radius: 5rpx;
|
|
720
|
|
- }
|
|
721
|
|
-
|
|
722
|
|
- .Stage {
|
|
723
|
|
- background-color: #dddddd;
|
|
724
|
|
- width: 380rpx;
|
|
725
|
|
- height: 34rpx;
|
|
726
|
|
- transform: perspective(34rpx) rotateX(-10deg);
|
|
727
|
|
- margin: 0 auto;
|
|
728
|
|
- }
|
|
729
|
|
-
|
|
730
|
|
- .bg-line {
|
|
731
|
|
- background-color: rgba(0, 0, 0, 0.3);
|
|
732
|
|
- }
|
|
733
|
|
-
|
|
734
|
|
- .sel-seat {
|
|
735
|
|
- background: url('/static/selected.png') center center no-repeat;
|
|
736
|
|
- background-size: 100% 100%;
|
|
737
|
|
- }
|
|
738
|
|
-
|
|
739
|
|
- .unsel-seat {
|
|
740
|
|
- background: url('/static/unselected.png') center center no-repeat;
|
|
741
|
|
- background-size: 100% 100%;
|
|
742
|
|
- }
|
|
743
|
|
-
|
|
744
|
|
- .bought-seat {
|
|
745
|
|
- background: url('/static/bought.png') center center no-repeat;
|
|
746
|
|
- background-size: 100% 100%;
|
|
747
|
|
- }
|
|
748
|
|
-</style>
|
|
749
|
|
-<route lang="yaml">
|
|
750
|
|
-style:
|
|
751
|
|
- navigationBarTitleText: 选择座位
|
|
752
|
|
- enablePullDownRefresh: true
|
|
753
|
|
-</route>
|