Appointment.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="Appointment">
  3. <div class="main">
  4. <!-- <van-cell title="已预约" /> -->
  5. <van-cell v-for="(item, i) in mainList" :key="i" :title="item.userName">
  6. <template #label>
  7. <div>
  8. {{ item.orderTime }}
  9. </div>
  10. </template>
  11. <template #default>
  12. <div style="text-align: right">
  13. <van-button
  14. v-if="item.status !== 2 && item.self"
  15. @click="() => removequeue(item.id)"
  16. type="danger"
  17. size="mini"
  18. >
  19. 取消预约
  20. </van-button>
  21. <van-tag type="primary" v-if="item.status === 2">
  22. 已超时 请重新预约
  23. </van-tag>
  24. </div>
  25. </template>
  26. </van-cell>
  27. </div>
  28. <van-sidebar v-model="activeKey" @change="onChange">
  29. <van-sidebar-item v-for="(item, i) in dataList" :key="i" :title="item" />
  30. </van-sidebar>
  31. <div style="clear: both"></div>
  32. <div
  33. style="
  34. padding: 16px;
  35. position: fixed;
  36. width: calc(100% - 32px);
  37. bottom: 0;
  38. "
  39. >
  40. <van-button
  41. color="#e42417"
  42. round
  43. block
  44. :disabled="isDis"
  45. type="info"
  46. @click="toAppointment"
  47. native-type="submit"
  48. >
  49. 预约
  50. </van-button>
  51. <!-- @click="toAppointment" -->
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. // @ is an alias to /src
  57. import {
  58. Sidebar as vanSidebar,
  59. SidebarItem as vanSidebarItem,
  60. Cell as vanCell,
  61. Button as vanButton,
  62. Tag as vanTag,
  63. Dialog,
  64. Toast,
  65. } from "vant";
  66. import "vant/lib/sidebar/style/index";
  67. import "vant/lib/tag/style/index";
  68. import "vant/lib/button/style/index";
  69. import "vant/lib/cell/style/index";
  70. import "vant/lib/icon/style/index";
  71. import "vant/lib/toast/style/index";
  72. import "vant/lib/dialog/style/index";
  73. import "vant/lib/sidebar-item/style/index";
  74. import { orderList, cancel } from "../api/index";
  75. export default {
  76. name: "Appointment",
  77. data() {
  78. return {
  79. group: {},
  80. phone: "",
  81. name: "",
  82. isDis: false,
  83. activeKey: 0,
  84. dataList: [],
  85. mainList: [],
  86. };
  87. },
  88. mounted() {
  89. this.phone = this.$route.query.phone || "";
  90. this.name = this.$route.query.userName || "";
  91. localStorage.token = "";
  92. const that = this;
  93. orderList({
  94. userPhone: that.phone || "",
  95. }).then(res => {
  96. const li = res || [];
  97. let l = [];
  98. li.sort((a, b) => {
  99. return new Date(a.orderTime) - new Date(b.orderTime);
  100. });
  101. that.isDis = false;
  102. for (let i = 0; i < li.length; i++) {
  103. const v = li[i];
  104. // v.orderTime = v.orderTime.replace(/:00$/, "");
  105. if (v.status !== 2 && v.self) that.isDis = true;
  106. let key = v.orderTime.split(" ")[0];
  107. key = key.split("-");
  108. key.shift();
  109. if(key.length) key = key.join("月") + '日';
  110. else key = ""
  111. if (that.group[key]) {
  112. that.group[key].push(v);
  113. } else {
  114. l.push(key);
  115. that.group[key] = [v];
  116. }
  117. }
  118. that.dataList = l;
  119. that.onChange();
  120. });
  121. },
  122. computed: {},
  123. methods: {
  124. toAppointment() {
  125. this.$router.push({
  126. name: "Apply",
  127. params: { name: this.name, phone: this.phone },
  128. });
  129. },
  130. onChange() {
  131. this.mainList = this.group[this.dataList[this.activeKey]];
  132. },
  133. removequeue(id) {
  134. let that = this;
  135. Dialog.confirm({
  136. title: "取消预约",
  137. message: "确定要取消该预约?",
  138. confirmButtonColor: "#2a7ef4",
  139. }).then(() => {
  140. // on confirm
  141. cancel({
  142. id,
  143. }).then(() => {
  144. orderList({
  145. userPhone: that.phone || "",
  146. }).then(res => {
  147. Toast("已取消预约");
  148. const li = res || [];
  149. let l = [],
  150. group = {};
  151. that.isDis = false;
  152. li.sort((a, b) => {
  153. return new Date(a.orderTime) - new Date(b.orderTime);
  154. });
  155. for (let i = 0; i < li.length; i++) {
  156. const v = li[i];
  157. if (v.status !== 2 && v.self) that.isDis = true;
  158. v.orderTime = v.orderTime.replace(/:00$/, "");
  159. let key = v.orderTime.split(" ")[0];
  160. if (group[key]) {
  161. group[key].push(v);
  162. } else {
  163. l.push(key);
  164. group[key] = [v];
  165. }
  166. }
  167. that.dataList = l;
  168. that.group = group;
  169. that.onChange();
  170. });
  171. });
  172. });
  173. },
  174. },
  175. beforeUnmount: function () {
  176. localStorage.token = "";
  177. },
  178. components: {
  179. vanSidebar,
  180. vanCell,
  181. vanSidebarItem,
  182. vanButton,
  183. vanTag,
  184. },
  185. };
  186. </script>
  187. <style>
  188. .Appointment {
  189. height: 100%;
  190. box-sizing: border-box;
  191. background-color: #f7f8fa;
  192. padding-bottom: 76px;
  193. }
  194. .Appointment .van-sidebar {
  195. width: 100px;
  196. }
  197. .Appointment .main {
  198. width: calc(100% - 100px);
  199. height: 100%;
  200. overflow-y: scroll;
  201. background-color: #fff;
  202. box-sizing: border-box;
  203. padding: 5px;
  204. float: right;
  205. }
  206. .Appointment .van-sidebar-item--select::before {
  207. background-color: #e42417;
  208. }
  209. </style>