Apply.vue 4.3 KB

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