Browse Source

Merge remote-tracking branch 'origin/master'

liying 7 years ago
parent
commit
a8663db968

+ 1 - 0
src/main/resources/static/js/movieDetail.js

@@ -76,6 +76,7 @@ $(document).ready(function(){
         $('#movie-director').text(movie.director);
         $('#movie-starring').text(movie.starring);
         $('#movie-writer').text(movie.screenWriter);
+        $('#movie-length').text(movie.length);
     }
 
     // user界面才有

+ 62 - 41
src/main/resources/static/js/userMovieBuy.js

@@ -1,54 +1,61 @@
+var selectedSeats = []
+var scheduleId;
+
 $(document).ready(function () {
-    var scheduleId = parseInt(window.location.href.split('?')[1].split('&')[1].split('=')[1]);
+    scheduleId = parseInt(window.location.href.split('?')[1].split('&')[1].split('=')[1]);
 
-    getCinemaHalls();
+    getInfo();
 
-    function getCinemaHalls() {
-        // TODO:修改
-        var halls = [];
+    function getInfo() {
         getRequest(
-            '/hall/all',
+            '/ticket/get/occupiedSeats?scheduleId=' + scheduleId,
             function (res) {
-                halls = res.content;
-                renderHall(halls);
+                if (res.success) {
+                    renderSchedule(res.content.scheduleItem, res.content.seats);
+                }
             },
             function (error) {
                 alert(JSON.stringify(error));
             }
         );
     }
+});
 
-    function renderHall(halls) {
-        $('#hall-card').empty();
-        var hallDomStr = "";
+function renderSchedule(schedule, seats) {
+    $('#schedule-hall-name').text(schedule.hallName);
+    $('#schedule-time').text(schedule.startTime.substring(5, 7) + "月" + schedule.startTime.substring(8, 10) + "日 " + schedule.startTime.substring(11, 16) + "场");
 
-        var hall = halls[0]
+    var hallDomStr = "";
+    var seat = "";
+    for (var i = 0; i < seats.length; i++) {
+        var temp = ""
+        for (var j = 0; j < seats[i].length; j++) {
+            var id = "seat" + i + j
 
-        var seat = "";
-        for (var i = 0; i < hall.row; i++) {
-            var temp = ""
-            for (var j = 0; j < hall.column; j++) {
-                var id = "seat" + i + j
+            if (seats[i][j] == 0) {
+                // 未选
                 temp += "<button class='cinema-hall-seat-choose' id='" + id + "' onclick='seatClick(\"" + id + "\"," + i + "," + j + ")'></button>";
+            } else {
+                // 已选中
+                selectedSeats[selectedSeats.length] = [i, j]
+                temp += "<button class='cinema-hall-seat' id='" + id + "' onclick='seatClick(\"" + id + "\"," + i + "," + j + ")'></button>";
             }
-            seat += "<div>" + temp + "</div>";
         }
-        var hallDom =
-            "<div class='cinema-hall'>" +
-            "<div>" +
-            "<span class='cinema-hall-name'>" + hall.name + "</span>" +
-            "<span class='cinema-hall-size'>" + hall.column + '*' + hall.row + "</span>" +
-            "</div>" +
-            "<div class='cinema-seat'>" + seat +
-            "</div>" +
-            "</div>";
-        hallDomStr += hallDom;
-
-        $('#hall-card').append(hallDomStr);
+        seat += "<div>" + temp + "</div>";
     }
-});
+    var hallDom =
+        "<div class='cinema-hall'>" +
+        "<div>" +
+        "<span class='cinema-hall-name'>" + schedule.hallName + "</span>" +
+        "<span class='cinema-hall-size'>" + seats.length + '*' + seats[0].length + "</span>" +
+        "</div>" +
+        "<div class='cinema-seat'>" + seat +
+        "</div>" +
+        "</div>";
+    hallDomStr += hallDom;
 
-var selectedSeat = []
+    $('#hall-card').html(hallDomStr);
+}
 
 function seatClick(id, i, j) {
     let seat = $('#' + id);
@@ -56,27 +63,27 @@ function seatClick(id, i, j) {
         seat.removeClass("cinema-hall-seat-choose");
         seat.addClass("cinema-hall-seat");
 
-        selectedSeat[selectedSeat.length] = [i, j]
+        selectedSeats[selectedSeats.length] = [i, j]
     } else {
         seat.removeClass("cinema-hall-seat");
         seat.addClass("cinema-hall-seat-choose");
 
-        selectedSeat = selectedSeat.filter(function (value) {
+        selectedSeats = selectedSeats.filter(function (value) {
             return value[0] != i || value[1] != j;
         })
     }
 
-    selectedSeat.sort(function (x, y) {
+    selectedSeats.sort(function (x, y) {
         var res = x[0] - y[0];
         return res === 0 ? x[1] - y[1] : res;
     });
 
     let seatDetailStr = "";
-    if (selectedSeat.length == 0) {
+    if (selectedSeats.length == 0) {
         seatDetailStr += "还未选择座位"
         $('#order-confirm-btn').attr("disabled", "disabled")
     } else {
-        for (let seatLoc of selectedSeat) {
+        for (let seatLoc of selectedSeats) {
             seatDetailStr += "<span>" + (seatLoc[0] + 1) + "排" + (seatLoc[1] + 1) + "座</span>";
         }
         $('#order-confirm-btn').removeAttr("disabled");
@@ -85,12 +92,26 @@ function seatClick(id, i, j) {
 }
 
 function orderConfirmClick() {
-    $('#seat-state').css("display","none");
-    $('#order-state').css("display","");
+    var seats = [];
+    for (let seat of selectedSeats) {
+        seats.push({rowIndex: seat[0], columnIndex: seat[1]});
+    }
+
+    // 锁座位
+    postRequest(
+        '/ticket/lockSeat',
+        {userId: sessionStorage.getItem('id'), scheduleId: scheduleId, seats: seats},
+        function (res) {
+            $('#seat-state').css("display", "none");
+            $('#order-state').css("display", "");
+        },
+        function (error) {
+            alert(error);
+        });
 }
 
 function payConfirmClick() {
-    $('#order-state').css("display","none");
-    $('#success-state').css("display","");
+    $('#order-state').css("display", "none");
+    $('#success-state').css("display", "");
     $('#buyModal').modal('hide')
 }

+ 6 - 4
src/main/resources/templates/userMovieBuy.html

@@ -41,6 +41,7 @@
         </ul>
     </div>
 </div>
+
 <div class="content-container">
     <div class="card col-md-12">
         <div class="col-md-10 col-md-offset-1" id="seat-state">
@@ -61,18 +62,19 @@
                         </div>
                         <div class="info">
                             <div id="movie-name"></div>
-                            <div>版本:国语版3D</div>
-                            <div>片长:137分钟</div>
+                            <div>语言:<span id="movie-language"></span></div>
+                            <div>类型:<span id="movie-type"></span></div>
+                            <div>片长:<span id="movie-length"></span>分钟</div>
                         </div>
                     </div>
                     <hr/>
                     <div class="line">
                         <div class="name">影厅:</div>
-                        <div>1号厅</div>
+                        <div id="schedule-hall-name"></div>
                     </div>
                     <div class="line">
                         <div class="name">场次:</div>
-                        <div>4月17日 14:00场</div>
+                        <div id="schedule-time"></div>
                     </div>
                     <div class="line">
                         <div class="name">座位:</div>