index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="px32rpx py-20rpx">
  3. <view class="bg-white rounded-32rpx py28rpx">
  4. <view class="px24rpx box-border">
  5. <view class="text-32rpx font-semibold">选择约课学生</view>
  6. <view class="mt28rpx">
  7. <view
  8. v-if="selectedTags.length"
  9. class="flex flex-wrap gap-10rpx mb20rpx"
  10. >
  11. <view
  12. v-for="item in selectedTags"
  13. :key="item.id"
  14. class="bg-[rgba(0,0,0,0.1)] text-[rgb(0,0,0,0.9)] text-24rpx px20rpx py10rpx rounded-full flex items-center cursor-pointer"
  15. @click="removeTag(item)"
  16. >
  17. {{ item.fullName }}
  18. <text class="ml10rpx font-bold">×</text>
  19. </view>
  20. </view>
  21. <view class="flex items-center mt28rpx">
  22. <view class="text-28rpx">学生姓名:</view>
  23. <wd-input
  24. v-model="inputValue"
  25. type="text"
  26. placeholder="请输入姓名"
  27. no-border
  28. @focus="inputFocus"
  29. />
  30. </view>
  31. </view>
  32. </view>
  33. <scroll-view scroll-y class="max-h-600rpx">
  34. <view
  35. v-if="data.length"
  36. class="mt10rpx py10rpx rounded-xl px24rpx"
  37. v-for="item in data"
  38. @click="selectStudent(item)"
  39. :key="item.id"
  40. hover-class="hover:bg-gray-100"
  41. >
  42. <view class="text-28rpx">
  43. {{ item.fullName }}
  44. </view>
  45. <view class="mt12rpx text-[rgb(0,0,0,0.3)] text-24rpx"
  46. >{{ item.phone }}
  47. </view>
  48. </view>
  49. </scroll-view>
  50. </view>
  51. </view>
  52. <fixdbtn block size="large" @click="handleSubmit">提交</fixdbtn>
  53. </template>
  54. <script setup lang="ts">
  55. import type { FamilyMembers } from "@/api/globals";
  56. import router from "@/router";
  57. import { useWatcher } from "alova/client";
  58. const inputValue = ref("");
  59. const selectedTags = ref<FamilyMembers[]>([]);
  60. const { data } = useWatcher(
  61. () =>
  62. Apis.app.getFamilyMembersByName({
  63. params: { name: inputValue.value, courseId: coursePriceRulesId.value },
  64. }),
  65. [inputValue],
  66. { debounce: 500, immediate: false, initialData: [] },
  67. );
  68. const { send: setFormData } = useRequest(
  69. (data) => Apis.app.temporaryCourse({ data }),
  70. {
  71. immediate: false,
  72. },
  73. );
  74. const isFirst = ref(true);
  75. const coursePriceRulesId = ref();
  76. onLoad((query: any) => {
  77. coursePriceRulesId.value = query.id;
  78. });
  79. // 选择学生
  80. const selectStudent = (item: FamilyMembers) => {
  81. if (!selectedTags.value.some((it) => it.id == item.id)) {
  82. selectedTags.value.push(item);
  83. }
  84. inputValue.value = "";
  85. };
  86. function inputFocus() {
  87. if (!isFirst.value) return;
  88. inputValue.value = "1";
  89. inputValue.value = "";
  90. isFirst.value = false;
  91. }
  92. // 删除 tag
  93. const removeTag = (item: FamilyMembers) => {
  94. selectedTags.value = selectedTags.value.filter((tag) => tag.id !== item.id);
  95. };
  96. async function handleSubmit() {
  97. if (selectedTags.value.length == 0)
  98. return uni.showToast({ title: "请选择约课的学生" });
  99. console.log(selectedTags.value, "提交核销数据");
  100. const formData = {
  101. coursePriceRulesId: coursePriceRulesId.value,
  102. userIds: selectedTags.value.map((it) => it.id),
  103. };
  104. await setFormData(formData);
  105. uni.showToast({ title: "预约成功", icon: "success" });
  106. setTimeout(() => {
  107. router.back();
  108. }, 1500);
  109. }
  110. </script>
  111. <style scoped>
  112. .absolute {
  113. position: absolute;
  114. }
  115. .z-10 {
  116. z-index: 10;
  117. }
  118. </style>
  119. <route lang="json">
  120. {
  121. "name": "ReservationClass",
  122. "style": {
  123. "navigationBarTitleText": "选择课程"
  124. }
  125. }
  126. </route>