addressBook.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="container">
  3. <!-- 背景图片区域 -->
  4. <img class="img_bg" src="../../static/images/center-bg.png" />
  5. <!-- input组件区域 -->
  6. <headerInput @changeInputValue="changeInputValue" />
  7. <!-- 学校名称区域 -->
  8. <view class="school" v-if="!keyWord">万载三中</view>
  9. <!-- 年级树形展示区域 -->
  10. <template v-if="!keyWord">
  11. <view class="tree" v-for="(item, index) in list" :key="item.id" @click="handleClick(index)">
  12. <uni-collapse :ref="setItemRef">
  13. <uni-collapse-item titleBorder="show">
  14. <template v-slot:title>
  15. <view class="tree_item">{{ item.title }}</view>
  16. </template>
  17. <view class="tree_item border" v-for="ele in item.children" :key="ele.id" @click="goPage('/pages/grade/grade')">
  18. {{ ele.title }}
  19. <img class="item_img" src="../../static/images/right.png" />
  20. </view>
  21. </uni-collapse-item>
  22. </uni-collapse>
  23. </view>
  24. </template>
  25. <!-- 搜索结果展示区域 -->
  26. <listView :list="searchList" v-if="keyWord" />
  27. </view>
  28. </template>
  29. <script setup>
  30. import { ref, nextTick } from 'vue'
  31. import { onLoad } from '@dcloudio/uni-app'
  32. import headerInput from '@/components/headerInput.vue'
  33. import listView from '@/components/listView.vue'
  34. // 搜索框关键词数据
  35. const keyWord = ref('')
  36. // 年级结构数据
  37. const list = ref([
  38. {
  39. id: 1,
  40. title: '一年级(103)',
  41. children: [
  42. {
  43. id: '1-1',
  44. title: '1班(30)'
  45. },
  46. {
  47. id: '1-2',
  48. title: '2班(36)'
  49. },
  50. {
  51. id: '1-3',
  52. title: '3班(37)'
  53. }
  54. ]
  55. },
  56. {
  57. id: 2,
  58. title: '二年级(110)',
  59. children: [
  60. {
  61. id: '2-1',
  62. title: '1班(37)'
  63. },
  64. {
  65. id: '2-2',
  66. title: '2班(36)'
  67. },
  68. {
  69. id: '2-3',
  70. title: '3班(37)'
  71. }
  72. ]
  73. }
  74. ])
  75. // 搜索结果列表
  76. const searchList = ref([
  77. {
  78. id: 1,
  79. name: '李商隐',
  80. number: 6262662
  81. },
  82. {
  83. id: 2,
  84. name: '张三',
  85. number: 6266662
  86. },
  87. {
  88. id: 3,
  89. name: '李四',
  90. number: 6862662
  91. },
  92. {
  93. id: 4,
  94. name: '王五',
  95. number: 8262662
  96. }
  97. ])
  98. // 折叠面板ref数组
  99. const collapseRefs = ref([])
  100. onLoad(() => {})
  101. // 生成ref数组回调
  102. const setItemRef = (el) => {
  103. collapseRefs.value.push(el)
  104. }
  105. // 点击每一个年级回调
  106. const handleClick = (index) => {
  107. nextTick(() => {
  108. collapseRefs.value[index].resize()
  109. })
  110. }
  111. // 点击每一个班级回调
  112. const goPage = (url) => {
  113. uni.navigateTo({
  114. url
  115. })
  116. }
  117. // 输入框组件自定义事件
  118. const changeInputValue = (data) => {
  119. keyWord.value = data
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .container {
  124. display: flex;
  125. flex-direction: column;
  126. position: relative;
  127. padding: 0 20rpx;
  128. min-height: 100vh;
  129. background-color: #f1f6fe;
  130. // 背景图片区域样式
  131. .img_bg {
  132. position: absolute;
  133. top: -70rpx;
  134. right: -32rpx;
  135. width: 589rpx;
  136. height: 320rpx;
  137. pointer-events: none;
  138. }
  139. // 学校名称区域样式
  140. .school {
  141. margin-top: 38rpx;
  142. color: #808080;
  143. font-size: 28rpx;
  144. }
  145. // 年级树形展示区域样式
  146. .tree {
  147. margin-top: 20rpx;
  148. width: 710rpx;
  149. border-radius: 8rpx;
  150. background-color: #fff;
  151. z-index: 1;
  152. .tree_item {
  153. display: flex;
  154. justify-content: space-between;
  155. align-items: center;
  156. padding: 0 24rpx 0 30rpx;
  157. box-sizing: border-box;
  158. width: 100%;
  159. height: 100rpx;
  160. font-size: 28rpx;
  161. font-weight: bold;
  162. .item_img {
  163. width: 31rpx;
  164. height: 31rpx;
  165. }
  166. }
  167. .border {
  168. font-weight: 400;
  169. border-bottom: 1rpx solid #e6e6e6;
  170. }
  171. }
  172. }
  173. </style>