Appointment.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. >已超时 请重新预约</van-tag
  23. >
  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 {
  75. orderList,
  76. cancel,
  77. // getAPPUser,
  78. // getAPPToken,
  79. // getAPPUserDetail,
  80. } from "../api/index";
  81. // import { urlSearchData } from "../utils/tool";
  82. export default {
  83. name: "Appointment",
  84. data() {
  85. return {
  86. group: {},
  87. phone: "",
  88. name: "",
  89. isDis: false,
  90. activeKey: 0,
  91. dataList: [],
  92. mainList: [],
  93. };
  94. },
  95. mounted() {
  96. this.phone = this.$route.query.phone || "";
  97. this.name = this.$route.query.userName || "";
  98. localStorage.token = "";
  99. // let search = urlSearchData();
  100. const that = this;
  101. orderList({
  102. userPhone: that.phone || "",
  103. }).then(res => {
  104. const li = res || [];
  105. let l = [];
  106. li.sort((a, b) => {
  107. return new Date(a.orderTime) - new Date(b.orderTime);
  108. });
  109. that.isDis = false;
  110. for (let i = 0; i < li.length; i++) {
  111. const v = li[i];
  112. // v.orderTime = v.orderTime.replace(/:00$/, "");
  113. if (v.status !== 2 && v.self) that.isDis = true;
  114. let key = v.orderTime.split(" ")[0];
  115. if (that.group[key]) {
  116. that.group[key].push(v);
  117. } else {
  118. l.push(key);
  119. that.group[key] = [v];
  120. }
  121. }
  122. that.dataList = l;
  123. that.onChange();
  124. });
  125. // getAPPUser({
  126. // ticket: search.ticket,
  127. // }).then(r => {
  128. // getAPPToken("rest/63bada00-7d01-4acc-ab2b-df8061eeeb8f").then(res => {
  129. // const t = JSON.parse(res || "{}");
  130. // localStorage.token = t.id;
  131. // getAPPUserDetail({
  132. // loginName: r,
  133. // }).then(detail => {
  134. // const obj = JSON.parse(detail || "{}");
  135. // console.log(obj);
  136. // that.phone = obj.telNumber;
  137. // that.name = obj.name;
  138. // orderList({
  139. // userPhone: that.phone || "",
  140. // }).then(res => {
  141. // const li = res || [];
  142. // let l = [];
  143. // li.sort((a, b) => {
  144. // return new Date(a.orderTime) - new Date(b.orderTime);
  145. // });
  146. // for (let i = 0; i < li.length; i++) {
  147. // const v = li[i];
  148. // v.orderTime = v.orderTime.replace(/:00$/, "");
  149. // let key = v.orderTime.split(" ")[0];
  150. // if (that.group[key]) {
  151. // that.group[key].push(v);
  152. // } else {
  153. // l.push(key);
  154. // that.group[key] = [v];
  155. // }
  156. // }
  157. // that.dataList = l;
  158. // that.onChange();
  159. // });
  160. // });
  161. // });
  162. // });
  163. },
  164. computed: {},
  165. methods: {
  166. toAppointment() {
  167. this.$router.replace({
  168. name: "Apply",
  169. params: { name: this.name, phone: this.phone },
  170. });
  171. },
  172. onChange() {
  173. this.mainList = this.group[this.dataList[this.activeKey]];
  174. },
  175. removequeue(id) {
  176. let that = this;
  177. Dialog.confirm({
  178. title: "取消预约",
  179. message: "确定要取消该预约?",
  180. confirmButtonColor: "#2a7ef4",
  181. }).then(() => {
  182. // on confirm
  183. cancel({
  184. id,
  185. }).then(() => {
  186. orderList({
  187. userPhone: that.phone || "",
  188. }).then(res => {
  189. Toast("已取消预约");
  190. const li = res || [];
  191. let l = [],
  192. group = {};
  193. that.isDis = false;
  194. li.sort((a, b) => {
  195. return new Date(a.orderTime) - new Date(b.orderTime);
  196. });
  197. for (let i = 0; i < li.length; i++) {
  198. const v = li[i];
  199. if (v.status !== 2 && v.self) that.isDis = true;
  200. v.orderTime = v.orderTime.replace(/:00$/, "");
  201. let key = v.orderTime.split(" ")[0];
  202. if (group[key]) {
  203. group[key].push(v);
  204. } else {
  205. l.push(key);
  206. group[key] = [v];
  207. }
  208. }
  209. that.dataList = l;
  210. that.group = group;
  211. that.onChange();
  212. });
  213. });
  214. });
  215. },
  216. },
  217. beforeUnmount: function () {
  218. localStorage.token = "";
  219. },
  220. components: {
  221. vanSidebar,
  222. vanCell,
  223. vanSidebarItem,
  224. vanButton,
  225. vanTag,
  226. },
  227. };
  228. </script>
  229. <style>
  230. .Appointment {
  231. height: 100%;
  232. box-sizing: border-box;
  233. background-color: #f7f8fa;
  234. padding-bottom: 76px;
  235. }
  236. .Appointment .van-sidebar {
  237. width: 100px;
  238. }
  239. .Appointment .main {
  240. width: calc(100% - 100px);
  241. height: 100%;
  242. overflow-y: scroll;
  243. background-color: #fff;
  244. box-sizing: border-box;
  245. padding: 5px;
  246. float: right;
  247. }
  248. .Appointment .van-sidebar-item--select::before {
  249. background-color: #e42417;
  250. }
  251. </style>