Apply.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="apply">
  3. <van-nav-bar title="预定" :left-arrow="back" @click-left="$router.go(-1)" />
  4. <van-form @submit="onSubmit">
  5. <van-field
  6. v-model="username"
  7. label="用户名"
  8. placeholder="用户名"
  9. :rules="[{ required: true, message: '请填写用户名' }]"
  10. />
  11. <van-field label="套餐">
  12. <template #input>
  13. <van-radio-group v-model="radio" direction="horizontal">
  14. <van-radio v-for="(item, i) in goodsLi" :key="i" :name="item.id">{{
  15. item.name
  16. }}</van-radio>
  17. </van-radio-group>
  18. </template>
  19. </van-field>
  20. <van-field
  21. v-model="userphone"
  22. type="tel"
  23. label="联系电话"
  24. placeholder="联系电话"
  25. :rules="[{ required: true, message: '请填写联系电话' }]"
  26. />
  27. <van-field
  28. @click="() => (dateInput = true)"
  29. v-model="selectTime"
  30. label="预定时间"
  31. placeholder="预定时间"
  32. readonly
  33. :rules="[{ required: true, message: '请选择预定时间' }]"
  34. />
  35. <div style="margin: 16px">
  36. <van-button
  37. color="#2a7ef4"
  38. round
  39. block
  40. type="info"
  41. native-type="submit"
  42. >
  43. 提交
  44. </van-button>
  45. </div>
  46. </van-form>
  47. <div style="margin: 16px">
  48. <!-- <div style="margin: 16px" v-if="!back"> -->
  49. <van-button round block type="default" @click="toAppointment">
  50. 查看预约
  51. </van-button>
  52. </div>
  53. <!-- #2a7ef4 -->
  54. <van-popup v-model="dateInput" position="bottom">
  55. <van-picker
  56. title="选择预约时间"
  57. @cancel="dateInput = false"
  58. @confirm="onConfirm"
  59. value-key="startTime"
  60. show-toolbar
  61. :columns="tagList"
  62. />
  63. </van-popup>
  64. </div>
  65. </template>
  66. <script>
  67. // @ is an alias to /src
  68. import {
  69. NavBar as vanNavBar,
  70. Form as vanForm,
  71. Field as vanField,
  72. Button as vanButton,
  73. Popup as vanPopup,
  74. RadioGroup as vanRadioGroup,
  75. Radio as vanRadio,
  76. Picker as vanPicker,
  77. } from "vant";
  78. import "vant/lib/nav-bar/style/index";
  79. import "vant/lib/form/style/index";
  80. import "vant/lib/field/style/index";
  81. import "vant/lib/button/style/index";
  82. import "vant/lib/popup/style/index";
  83. import "vant/lib/picker/style/index";
  84. import { goodsList, apply, applyrang } from "../api/index";
  85. export default {
  86. name: "Apply",
  87. data() {
  88. return {
  89. username: "",
  90. userphone: "",
  91. date: "",
  92. currentDate: "",
  93. dateInput: false,
  94. minDate: new Date(Date.now()),
  95. maxDate: new Date(Date.now() + 86400000),
  96. radio: "",
  97. back: true,
  98. finished: false,
  99. loading: false,
  100. goodsLi: [],
  101. tagList: [],
  102. };
  103. },
  104. mounted() {
  105. this.userphone = this.$route.query.phone || "";
  106. this.username = this.$route.query.userName || "";
  107. this.back = !location.href.split("?")[1];
  108. goodsList().then(res => {
  109. this.goodsLi = res || [];
  110. this.radio = (this.goodsLi[0] || {}).id;
  111. });
  112. applyrang().then(res => {
  113. let l = res || [],
  114. nl = [],
  115. o = {};
  116. for (let i = 0; i < l.length; i++) {
  117. const v = l[i];
  118. let keys = v.startTime.split(" "),
  119. key = keys[0],
  120. val = keys[1];
  121. v.startTime = val;
  122. if (o[key] >= 0) {
  123. nl[o[key]].children.push(v);
  124. } else {
  125. o[key] = nl.length;
  126. nl[o[key]] = {
  127. startTime: key,
  128. children: [v],
  129. };
  130. }
  131. }
  132. this.tagList = nl;
  133. });
  134. },
  135. computed: {
  136. selectTime() {
  137. return this.date;
  138. },
  139. },
  140. methods: {
  141. filter(type, options) {
  142. if (type === "minute") {
  143. return options.filter(option => option % 5 === 0);
  144. }
  145. return options;
  146. },
  147. toAppointment() {
  148. this.$router.push({ name: "Appointment", query: { phone: this.userphone } });
  149. },
  150. onSubmit() {
  151. apply({
  152. userName: this.username,
  153. userPhone: this.userphone,
  154. goodsId: this.radio,
  155. orderTime: this.date,
  156. }).then(() => {
  157. this.toAppointment();
  158. });
  159. },
  160. onConfirm(date) {
  161. this.dateInput = false;
  162. this.date = date.join(" ");
  163. },
  164. },
  165. beforeUnmount: function () {},
  166. components: {
  167. vanNavBar,
  168. vanForm,
  169. vanField,
  170. vanPopup,
  171. vanButton,
  172. vanRadioGroup,
  173. vanRadio,
  174. vanPicker,
  175. },
  176. };
  177. </script>
  178. <style>
  179. .apply {
  180. height: 100%;
  181. max-width: 990px;
  182. margin: 0 auto;
  183. background-color: #fff;
  184. }
  185. .apply .van-tag {
  186. white-space: nowrap;
  187. overflow: hidden;
  188. text-overflow: ellipsis;
  189. }
  190. </style>