reservation.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <view class="reservation-index form-box">
  3. <uni-forms label-position="top" :modelValue="formData">
  4. <uni-forms-item label="姓名" name="name">
  5. <uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" disabled />
  6. </uni-forms-item>
  7. <uni-forms-item label="联系方式" name="phone">
  8. <uni-easyinput type="tel" v-model="formData.phone" placeholder="请输入姓名" disabled />
  9. </uni-forms-item>
  10. <uni-forms-item label="预约时间" name="date">
  11. <view class="select-box" @click="open">
  12. <text class="select-text" v-if="formData.date">{{formData.date}}</text>
  13. <text class="select-label" v-else>请选择日期</text>
  14. <uni-icons class="form-icon" type="down" size="12" color="#8c8c8c"></uni-icons>
  15. </view>
  16. </uni-forms-item>
  17. </uni-forms>
  18. <uv-datetime-picker ref="dateTimePicker" v-model="nowTime" mode="datetime" @confirm="confirm"
  19. :minDate="nowTime">
  20. </uv-datetime-picker>
  21. <view class="hui-button-box">
  22. <view class="hui-button-view">
  23. <view class="hui-button" @click="submit">提交预约</view>
  24. </view>
  25. <uv-safe-bottom></uv-safe-bottom>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. insertReservation
  32. } from '@/request/api/house.js'
  33. export default {
  34. data() {
  35. return {
  36. formData: {
  37. name: '',
  38. phone: '',
  39. date: ''
  40. },
  41. houseId: '',
  42. projectId: '',
  43. chargePersonId: '',
  44. nowTime: Number(new Date())
  45. }
  46. },
  47. onLoad(body) {
  48. if (body.houseId) this.houseId = body.houseId;
  49. if (body.projectId) this.projectId = body.projectId;
  50. if (body.chargePersonId) this.chargePersonId = body.chargePersonId;
  51. },
  52. onShow() {
  53. this.formData.date = this.$dayjs().format('YYYY-MM-DD HH:mm');
  54. this.formData['name'] = this.$store.getters.user.userName;
  55. this.formData['phone'] = this.$store.getters.user.phone;
  56. },
  57. methods: {
  58. open() {
  59. this.$refs.dateTimePicker.open();
  60. },
  61. confirm(e) {
  62. let date = this.$dayjs(e.value).format('YYYY-MM-DD HH:mm');
  63. this.formData.date = date;
  64. },
  65. submit() {
  66. insertReservation({
  67. userId: this.$store.getters.user.userId,
  68. projectItemTargetRoomId: this.houseId,
  69. date: this.formData.date,
  70. projectId: this.projectId,
  71. chargePersonId: parseInt(this.chargePersonId)
  72. }).then(res => {
  73. if (res.code == 200) {
  74. this.$toast('预约成功');
  75. setTimeout(() => {
  76. this.$navigateBack();
  77. }, 1000);
  78. }
  79. })
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. .reservation-index {
  86. padding: 30rpx;
  87. }
  88. </style>