adminScheduleManage.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. var colors = [
  2. '#FF6666',
  3. '#FFFF33',
  4. '#FF9933',
  5. '#66cccc',
  6. '#FFCCCC',
  7. '#3399FF',
  8. '#9966FF',
  9. ];
  10. function formatDate(date){
  11. var year = date.getFullYear();
  12. var month = date.getMonth()+1+'';
  13. var day = date.getDate()+'';
  14. month.length===1 && (month = '0'+month)
  15. day.length===1 && (day = '0'+day)
  16. return year+'-'+month+'-'+day;
  17. }
  18. function formatTime(date){
  19. return date.getHours()+":"+date.getMinutes();
  20. }
  21. $(document).ready(function() {
  22. var hallId,
  23. scheduleDate = formatDate(new Date());
  24. initSelectAndDate();
  25. function getSchedules() {
  26. var schedules = [];
  27. postRequest(
  28. '/schedule/search',
  29. {
  30. hallId: hallId,
  31. startDate: scheduleDate
  32. },
  33. function (res) {
  34. schedules = res.content;
  35. console.log(schedules);
  36. renderScheduleTable(schedules);
  37. },
  38. function (error) {
  39. alert(JSON.stringify(error));
  40. }
  41. );
  42. }
  43. function renderScheduleTable(schedules){
  44. $('.schedule-date-container').empty();
  45. $(".schedule-time-line").siblings().remove();
  46. schedules.forEach(function (scheduleOfDate) {
  47. $('.schedule-date-container').append("<div class='schedule-date'>"+formatDate(new Date(scheduleOfDate.date))+"</div>");
  48. var scheduleDateDom = $(" <ul class='schedule-item-line'></ul>");
  49. $(".schedule-container").append(scheduleDateDom);
  50. scheduleOfDate.scheduleItemList.forEach(function (schedule,index) {
  51. var scheduleStyle = mapScheduleStyle(schedule);
  52. scheduleDateDom.append(
  53. "<li class='schedule-item' style='background:"+scheduleStyle.color+";top:"+scheduleStyle.top+";height:"+scheduleStyle.height+"'>"+
  54. "<span>"+schedule.movieName+"</span>"+
  55. "<span class='error-text'>¥"+schedule.fare+"</span>"+
  56. "<span>"+formatTime(new Date(schedule.startTime))+"-"+formatTime(new Date(schedule.endTime))+"</span>"+
  57. "</li>");
  58. })
  59. })
  60. }
  61. function mapScheduleStyle(schedule) {
  62. var start = new Date(schedule.startTime).getHours()+new Date(schedule.startTime).getMinutes()/60,
  63. end = new Date(schedule.endTime).getHours()+new Date(schedule.endTime).getMinutes()/60 ;
  64. return {
  65. color: colors[schedule.movieId%colors.length],
  66. top: 40*start+'px',
  67. height: 40*(end-start)+'px'
  68. }
  69. }
  70. function initSelectAndDate() {
  71. $('#schedule-date-input').val(scheduleDate);
  72. getCinemaHalls();
  73. getAllMovies();
  74. // 过滤条件变化后重新查询
  75. $('#hall-select').change (function () {
  76. hallId=$(this).children('option:selected').val();
  77. getSchedules();
  78. });
  79. $('#schedule-date-input').change(function () {
  80. scheduleDate = $('#schedule-date-input').val();
  81. getSchedules();
  82. });
  83. }
  84. function getCinemaHalls() {
  85. var halls = [];
  86. getRequest(
  87. '/hall/all',
  88. function (res) {
  89. halls = res.content;
  90. hallId = halls[0].id;
  91. halls.forEach(function (hall) {
  92. $('#hall-select').append("<option value="+ hall.id +">"+hall.name+"</option>");
  93. $('#schedule-hall-input').append("<option value="+ hall.id +">"+hall.name+"</option>");
  94. });
  95. getSchedules();
  96. },
  97. function (error) {
  98. alert(JSON.stringify(error));
  99. }
  100. );
  101. }
  102. function getAllMovies() {
  103. getRequest(
  104. '/movie/all',
  105. function (res) {
  106. var movieList = res.content;
  107. movieList.forEach(function (movie) {
  108. $('#schedule-movie-input').append("<option value="+ movie.id +">"+movie.name+"</option>");
  109. });
  110. },
  111. function (error) {
  112. alert(error);
  113. }
  114. );
  115. }
  116. $('#schedule-form-btn').click(function () {
  117. var form = {
  118. hallId: $("#schedule-hall-input").children('option:selected').val(),
  119. movieId : $("#schedule-movie-input").children('option:selected').val(),
  120. startTime: $("#schedule-start-date-input").val(),
  121. endTime: $("#schedule-end-date-input").val(),
  122. fare: $("#schedule-price-input").val()
  123. };
  124. //todo 需要做一下表单验证?
  125. postRequest(
  126. '/schedule/add',
  127. form,
  128. function (res) {
  129. getSchedules();
  130. $("#scheduleModal").modal('hide');
  131. },
  132. function (error) {
  133. alert(JSON.stringify(error));
  134. }
  135. );
  136. })
  137. });