index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div v-loading="loading" class="venue-reservation">
  3. <BackBtn />
  4. <div class="venue-reservation-container">
  5. <div class="venue-reservation__title">
  6. {{ step === 0 ? "身份核验" : "场馆预约" }}
  7. </div>
  8. <div v-if="step === 1 && form1" class="ticket">
  9. <p>{{ form1.organ }} - {{ form1.division }}</p>
  10. <p>{{ form1.leader.name }} - {{ form1.leader.phone }}</p>
  11. </div>
  12. <Form1 v-if="step === 0" ref="form1Ref" :form-data="form1" />
  13. <Form2 v-else-if="step === 1" ref="form2Ref" :form1-data="form1" />
  14. <div class="venue-reservation__btns">
  15. <div
  16. v-if="step === 0"
  17. class="venue-reservation__btns__next"
  18. @click="next"
  19. >
  20. 下一步
  21. </div>
  22. <template v-else>
  23. <div class="venue-reservation__btns__pre" @click="previous">
  24. 上一步
  25. </div>
  26. <div
  27. :class="[
  28. 'venue-reservation__btns__next',
  29. form2Ref?.maxVisitorNum === 0 && 'disabled',
  30. ]"
  31. @click="next"
  32. style="color: #fff3c9"
  33. >
  34. 提交
  35. </div>
  36. </template>
  37. </div>
  38. </div>
  39. <Dialog v-model:visible="dialogVisible">
  40. <p v-if="dialogErrType">请准确填写</p>
  41. <p v-html="dialogText"></p>
  42. </Dialog>
  43. <Dialog v-if="form1" v-model:visible="checkVisible" class="check-dialog">
  44. <p class="title">请确认预约信息</p>
  45. <div class="check-dialog__info">
  46. <p>{{ form1.organ }} - {{ form1.division }}</p>
  47. <p v-for="(item, index) in visitList" :key="index">
  48. {{ item.name }} - {{ item.phone }} - {{ item.idcard }}
  49. </p>
  50. </div>
  51. <div class="venue-reservation__btns">
  52. <div class="venue-reservation__btns__pre" @click="checkVisible = false">
  53. 取消
  54. </div>
  55. <div
  56. class="venue-reservation__btns__next"
  57. style="color: #fff3c9"
  58. @click="submit2"
  59. >
  60. 确认
  61. </div>
  62. </div>
  63. </Dialog>
  64. </div>
  65. </template>
  66. <script lang="ts" setup>
  67. import { BackBtn } from "@/components";
  68. import Dialog from "./components/dialog.vue";
  69. import { onActivated, ref } from "vue";
  70. import "./index.scss";
  71. import Form1 from "./form-1.vue";
  72. import Form2 from "./form-2.vue";
  73. import { reservationVenueApi } from "@/api";
  74. import { DEFAULT_FORM1 } from "./constants";
  75. import encodeStr from "@/utils/pass";
  76. import { cloneDeep } from "lodash";
  77. let saveParams: any = null;
  78. const step = ref(0);
  79. const checkVisible = ref(false);
  80. const dialogVisible = ref(false);
  81. const dialogText = ref("");
  82. const dialogErrType = ref(false);
  83. const loading = ref(false);
  84. const form1 = ref<typeof DEFAULT_FORM1 | null>(null);
  85. const visitList = ref<(typeof DEFAULT_FORM1)["leader"][]>([]);
  86. const form1Ref = ref();
  87. const form2Ref = ref();
  88. onActivated(() => {
  89. clear();
  90. });
  91. const next = async () => {
  92. try {
  93. if (step.value === 0) {
  94. const params = await form1Ref.value.next();
  95. form1.value = params;
  96. step.value += 1;
  97. } else if (form2Ref.value?.maxVisitorNum > 0) {
  98. const { visitorList, ...form2Rest } = await form2Ref.value.submit();
  99. const { leader, ...form1Rest } = form1.value || {};
  100. const list = [leader, ...visitorList];
  101. visitList.value = visitorList;
  102. saveParams = {
  103. ...form1Rest,
  104. ...form2Rest,
  105. contact: list
  106. .map(
  107. (item: any) =>
  108. `${item.name}-${item.phone}${
  109. item.idcard ? "-" + encodeStr(item.idcard) : ""
  110. }`
  111. )
  112. .join(","),
  113. pcs: visitorList.length,
  114. };
  115. checkVisible.value = true;
  116. }
  117. } catch (err: any) {
  118. if (typeof err === "object" && err.msg) {
  119. dialogErrType.value = true;
  120. dialogText.value = err.msg;
  121. dialogVisible.value = true;
  122. }
  123. }
  124. };
  125. const clear = () => {
  126. step.value = 0;
  127. saveParams = null;
  128. form1.value = cloneDeep(DEFAULT_FORM1);
  129. visitList.value = [];
  130. };
  131. const submit2 = async () => {
  132. try {
  133. loading.value = true;
  134. checkVisible.value = false;
  135. await reservationVenueApi(saveParams);
  136. dialogErrType.value = false;
  137. dialogText.value = "预约已被接受<br/>请按照预约时间刷身份证原件入馆";
  138. dialogVisible.value = true;
  139. clear();
  140. } catch (err: any) {
  141. dialogText.value = err.msg;
  142. dialogVisible.value = true;
  143. } finally {
  144. loading.value = false;
  145. }
  146. };
  147. const previous = () => {
  148. step.value -= 1;
  149. };
  150. </script>