group-add.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <div class="w-full h-[100vh]">
  3. <ChatHeaderBar title="添加成员" />
  4. <ChatSearch v-model:searchString="searchString" @search="search" placeholder="请输入关键词" />
  5. <div class="h-118"></div>
  6. <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  7. <Empty v-if="!addDataList?.length && !loading" title="暂无数据" top="100" />
  8. <van-list
  9. v-else-if="addDataList.length"
  10. v-model:loading="loading"
  11. error-text="获取失败"
  12. finished-text="-- 没有更多了 --"
  13. :finished="finished"
  14. :immediate-check="false"
  15. @load="getLoadList"
  16. >
  17. <van-checkbox-group v-model="checked">
  18. <van-index-bar highlight-color="#FD9A00" index-list :sticky="false">
  19. <template v-for="(item, index) in addDataList" :key="item?.id">
  20. <van-index-anchor index="A" />
  21. <van-cell
  22. v-for="(item, index) in addDataList"
  23. :key="item?.id"
  24. center
  25. clickable
  26. @click="toggle(index)"
  27. disabled
  28. >
  29. <template #icon>
  30. <div class="flex justify-start">
  31. <van-checkbox
  32. checked-color="#FD9A00"
  33. :name="item.id"
  34. :ref="(el) => (checkboxRefs[index] = el)"
  35. @click.stop
  36. />
  37. <div class="w-40 h-40 ml-13 mr-12 rounded-full overflow-hidden">
  38. <img class="w-full h-full shrink-0 object-cover" :src="item?.img" alt="" />
  39. </div>
  40. </div>
  41. </template>
  42. <template #title>
  43. <div class="flex items-center">
  44. <h1 class="text-xl text-black-3">{{ item?.visaTitle }}</h1>
  45. <van-tag style="margin-left: 5px" color="#F7F8FA" text-color="#666666">
  46. 相互关注
  47. </van-tag>
  48. </div>
  49. </template>
  50. </van-cell>
  51. </template>
  52. </van-index-bar>
  53. </van-checkbox-group>
  54. </van-list>
  55. </van-pull-refresh>
  56. </div>
  57. </template>
  58. <script setup>
  59. import { pinyin } from 'pinyin-pro'
  60. definePageMeta({
  61. layout: false
  62. })
  63. onMounted(() => {
  64. getList()
  65. })
  66. const refreshing = ref(false)
  67. const loading = ref(false)
  68. const finished = ref(false)
  69. const checked = ref([])
  70. const searchString = ref('')
  71. const checkboxRefs = ref([])
  72. // 字母的数组
  73. const letterList = ref([])
  74. const toggle = (index) => {
  75. checkboxRefs.value[index].toggle()
  76. }
  77. const queryParams = reactive({
  78. pageNum: 1,
  79. pageSize: 10,
  80. searchString: ''
  81. })
  82. const addDataList = ref([])
  83. useSeoMeta({
  84. title: '添加成员'
  85. })
  86. const search = () => {
  87. addDataList.value = []
  88. queryParams.pageNum = 1
  89. queryParams.searchString = searchString.value
  90. getList()
  91. }
  92. // 刷新
  93. const onRefresh = () => {
  94. queryParams.pageNum = 1
  95. addDataList.value = []
  96. getList()
  97. }
  98. // 触底加载
  99. const getLoadList = () => {
  100. queryParams.pageNum++
  101. finished.value = true
  102. getList()
  103. }
  104. // 获取数据
  105. const getList = async () => {
  106. try {
  107. let url = `/website/tourism/visa/list/page`
  108. loading.value = true
  109. let {
  110. data: { dataList, totalCount }
  111. } = await request(url, {
  112. query: {
  113. ...queryParams
  114. }
  115. })
  116. let arr = []
  117. if (Array.isArray(dataList) && dataList?.length) {
  118. addDataList.value = addDataList.value.concat(dataList)
  119. arr = addDataList.value
  120. arr = arr.map((item, index) => {
  121. let letter = pinyin(item?.visaTitle, { pattern: 'first', toneType: 'none' })
  122. console.log(letter, '123')
  123. item.letter = letter
  124. return item
  125. })
  126. console.log(arr, 'addDataList.value .value')
  127. } else {
  128. addDataList.value = []
  129. }
  130. loading.value = false
  131. refreshing.value = false
  132. if (addDataList.value.length >= totalCount) {
  133. finished.value = true
  134. } else {
  135. finished.value = false
  136. }
  137. } catch (err) {
  138. } finally {
  139. refreshing.value = false
  140. loading.value = false
  141. }
  142. }
  143. // // 数据转化
  144. // const changeInitials = (list) => {
  145. // console.log(list)
  146. // let letter = []
  147. // let listArr = []
  148. // listArr = list.map((item, index) => {
  149. // item.letter = pinyin(item?.visaTitle, { pattern: 'first', toneType: 'none' })
  150. // .map((pinyin) => pinyin[0].toUpperCase()) // 获取拼音的首字母并转换为大写
  151. // .join('')
  152. // letter.push(item.letter)
  153. // return item
  154. // })
  155. // console.log(list, '21')
  156. // console.log(listArr, '444')
  157. // return {
  158. // letter,
  159. // listArr
  160. // }
  161. // }
  162. </script>
  163. <style lang="scss" scoped></style>