Applyreal.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="apply">
  3. <van-nav-bar title="预定" />
  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. }}({{ item.price }}元)</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. <div style="margin: 16px">
  28. <van-button
  29. color="#2a7ef4"
  30. round
  31. block
  32. type="info"
  33. native-type="submit"
  34. >
  35. 提交
  36. </van-button>
  37. </div>
  38. </van-form>
  39. <!-- #2a7ef4 -->
  40. </div>
  41. </template>
  42. <script>
  43. // @ is an alias to /src
  44. import {
  45. NavBar as vanNavBar,
  46. Form as vanForm,
  47. Field as vanField,
  48. Button as vanButton,
  49. RadioGroup as vanRadioGroup,
  50. Radio as vanRadio,
  51. Toast
  52. } from "vant";
  53. import "vant/lib/nav-bar/style/index";
  54. import "vant/lib/form/style/index";
  55. import "vant/lib/toast/style/index";
  56. import "vant/lib/field/style/index";
  57. import "vant/lib/button/style/index";
  58. import { goodsList, applyreal } from "../api/index";
  59. export default {
  60. name: "Applyreal",
  61. data() {
  62. return {
  63. username: "",
  64. userphone: "",
  65. radio: "",
  66. finished: false,
  67. loading: false,
  68. goodsLi: [],
  69. };
  70. },
  71. mounted() {
  72. goodsList().then(res => {
  73. this.goodsLi = res || [];
  74. this.radio = (this.goodsLi[0] || {}).id;
  75. });
  76. },
  77. computed: {},
  78. methods: {
  79. filter(type, options) {
  80. if (type === "minute") {
  81. return options.filter(option => option % 5 === 0);
  82. }
  83. return options;
  84. },
  85. onSubmit() {
  86. applyreal({
  87. userName: this.username,
  88. userPhone: this.userphone,
  89. goodsId: this.radio,
  90. }).then(() => {
  91. Toast("预约成功")
  92. });
  93. },
  94. },
  95. beforeUnmount: function () {},
  96. components: {
  97. vanNavBar,
  98. vanForm,
  99. vanField,
  100. vanButton,
  101. vanRadioGroup,
  102. vanRadio,
  103. },
  104. };
  105. </script>
  106. <style>
  107. .apply {
  108. height: 100%;
  109. max-width: 990px;
  110. margin: 0 auto;
  111. background-color: #fff;
  112. }
  113. .apply .van-tag {
  114. white-space: nowrap;
  115. overflow: hidden;
  116. text-overflow: ellipsis;
  117. }
  118. .apply .van-radio{
  119. margin-bottom: 14px
  120. }
  121. </style>