school.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="school-add">
  3. <!-- 输入区域 -->
  4. <view class="input-section">
  5. <view class="input-header">
  6. <text class="required">*</text>
  7. <text class="label">学校名称:</text>
  8. <u-input v-model="schoolName" placeholder="请输入一个学校名称" border="false" class="input">
  9. <template #suffix>
  10. <u-icon name="plus" size="24" color="#666" @click="handleAddSchool"></u-icon>
  11. </template>
  12. </u-input>
  13. </view>
  14. </view>
  15. <!-- 学校列表 -->
  16. <view class="school-list">
  17. <view class="school-item" v-for="(item, index) in schoolList" :key="index">
  18. <u-tag :text="item.name" closable></u-tag>
  19. </view>
  20. </view>
  21. <!-- 底部提交按钮 -->
  22. <view class="submit-btn">
  23. <u-button type="success" block @click="handleSubmit">提交</u-button>
  24. </view>
  25. </view>
  26. </template>
  27. <script setup>
  28. import {
  29. ref
  30. } from 'vue'
  31. // 学校名称输入
  32. const schoolName = ref('')
  33. // 学校列表
  34. const schoolList = ref([{
  35. name: '河南大学'
  36. }, {
  37. name: '清华大学'
  38. }, {
  39. name: '北京大学'
  40. }])
  41. // 添加学校
  42. const handleAddSchool = () => {
  43. if (!schoolName.value.trim()) {
  44. uni.$u.toast('请输入学校名称')
  45. return
  46. }
  47. schoolList.value.push({
  48. name: schoolName.value
  49. })
  50. schoolName.value = ''
  51. }
  52. // 移除学校
  53. const handleRemoveSchool = (index) => {
  54. schoolList.value.splice(index, 1)
  55. }
  56. // 提交
  57. const handleSubmit = () => {
  58. if (schoolList.value.length === 0) {
  59. uni.$u.toast('请至少添加一所学校')
  60. return
  61. }
  62. // 这里处理提交逻辑
  63. console.log('提交的学校列表:', schoolList.value)
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .school-add {
  68. height: 100%;
  69. padding: 30rpx;
  70. box-sizing: border-box;
  71. display: flex;
  72. flex-direction: column;
  73. .input-section {
  74. background: #FFFFFF;
  75. border-radius: 8rpx;
  76. padding: 20rpx;
  77. margin-bottom: 20rpx;
  78. .input-header {
  79. display: flex;
  80. align-items: center;
  81. .required {
  82. color: #FF4D4F;
  83. font-size: 28rpx;
  84. margin-right: 4rpx;
  85. }
  86. .label {
  87. font-size: 28rpx;
  88. color: #333333;
  89. white-space: nowrap;
  90. }
  91. .input {
  92. flex: 1;
  93. }
  94. }
  95. }
  96. .school-list {
  97. display: flex;
  98. flex-wrap: wrap;
  99. gap: 10rpx;
  100. }
  101. .submit-btn {
  102. padding: 40rpx 0rpx;
  103. padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
  104. position: fixed;
  105. width: calc(100% - 60rpx);
  106. bottom: 0;
  107. }
  108. }
  109. </style>