school.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.schoolName" closable size="large"></u-tag>
  19. </view>
  20. </view>
  21. <!-- 底部提交按钮 -->
  22. <view class="fixed-bottom">
  23. <u-button size="large" 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. // 获取学校列表
  36. const getSchoolList = () => {
  37. uni.$u.http.get('/app/appConf/getPadSchoolBroadcast').then(res => {
  38. if (res.code == 200) {
  39. schoolList.value = res.data
  40. }
  41. })
  42. }
  43. getSchoolList()
  44. // 保存学校
  45. const handleSubmit = () => {
  46. if (schoolList.value.length === 0) {
  47. uni.$u.toast('请至少添加一所学校')
  48. return
  49. }
  50. uni.$u.http.post('/app/appConf/setPadSchoolBroadcast', schoolList.value).then(res => {
  51. if (res.code == 200) {
  52. uni.showToast({
  53. title: '设置成功',
  54. icon: 'success'
  55. })
  56. }
  57. })
  58. }
  59. // 添加学校
  60. const handleAddSchool = () => {
  61. if (!schoolName.value.trim()) {
  62. uni.$u.toast('请输入学校名称')
  63. return
  64. }
  65. schoolList.value.push({
  66. schoolName: schoolName.value,
  67. id: ''
  68. })
  69. schoolName.value = ''
  70. }
  71. // 移除学校
  72. const handleRemoveSchool = (index) => {
  73. schoolList.value.splice(index, 1)
  74. }
  75. </script>
  76. <style lang="scss" scoped>
  77. .school-add {
  78. height: 100%;
  79. padding: 30rpx;
  80. box-sizing: border-box;
  81. display: flex;
  82. flex-direction: column;
  83. .input-section {
  84. background: #FFFFFF;
  85. border-radius: 8rpx;
  86. padding: 20rpx;
  87. margin-bottom: 20rpx;
  88. .input-header {
  89. display: flex;
  90. align-items: center;
  91. .required {
  92. color: #FF4D4F;
  93. font-size: 28rpx;
  94. margin-right: 4rpx;
  95. }
  96. .label {
  97. font-size: 28rpx;
  98. color: #333333;
  99. white-space: nowrap;
  100. }
  101. .input {
  102. flex: 1;
  103. }
  104. }
  105. }
  106. .school-list {
  107. display: flex;
  108. flex-wrap: wrap;
  109. gap: 10rpx;
  110. }
  111. .submit-btn {
  112. padding: 40rpx 0rpx;
  113. padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
  114. position: fixed;
  115. width: calc(100% - 60rpx);
  116. bottom: 0;
  117. }
  118. }
  119. </style>