helpCenter.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <route lang="json5" type="page">
  2. {
  3. layout: 'default',
  4. style: {
  5. navigationBarTitleText: '%helpCenter.title%',
  6. navigationBarBackgroundColor: '#fff',
  7. },
  8. }
  9. </route>
  10. <script lang="ts" setup>
  11. // eslint-disable-next-line unused-imports/no-unused-imports
  12. import { onPageScroll } from '@dcloudio/uni-app'
  13. import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
  14. import { qaGroupList, qaList } from '@/api/qa'
  15. import i18n from '@/locale/index'
  16. import { toPage } from '@/utils/page'
  17. defineOptions({
  18. name: 'HelpCenter',
  19. })
  20. const systemInfo = uni.getSystemInfoSync()
  21. const safeAreaInsets = systemInfo.safeAreaInsets
  22. const paging = ref<any>(null)
  23. useZPaging(paging)
  24. const dataList = ref<any[]>([])
  25. const groupList = ref<any[]>([])
  26. const tab = ref<string>('')
  27. const locale = computed(() => i18n.global.locale)
  28. const shouldUseEn = computed(() => locale.value !== 'bn')
  29. watch(locale, () => {
  30. paging.value?.reload()
  31. })
  32. function getGroupName(item: any) {
  33. return shouldUseEn.value ? (item.enName || '') : (item.bnName || '')
  34. }
  35. function getQaTitle(item: any) {
  36. return shouldUseEn.value ? (item.enTitle || '') : (item.bnTitle || '')
  37. }
  38. async function loadGroups() {
  39. const res = await qaGroupList()
  40. if (res.code === '200') {
  41. const list = (res.data || []) as any[]
  42. groupList.value = list
  43. if (!tab.value && list.length)
  44. tab.value = String(list[0].id)
  45. }
  46. }
  47. async function queryList(pageNo: number, pageSize: number) {
  48. if (!tab.value) {
  49. paging.value?.complete([])
  50. return
  51. }
  52. try {
  53. const res = await qaList({
  54. page: pageNo,
  55. size: pageSize,
  56. groupId: Number(tab.value),
  57. })
  58. if (res.code === '200') {
  59. paging.value.complete(res.data?.list || [])
  60. }
  61. else {
  62. paging.value.complete(false)
  63. }
  64. }
  65. catch {
  66. paging.value.complete(false)
  67. }
  68. }
  69. function handleTabClick() {
  70. paging.value?.reload()
  71. }
  72. function handleItemClick(item: any) {
  73. toPage({ url: '/pages/mine/helpCenterDetail', params: { id: item.id } })
  74. }
  75. onShow(async () => {
  76. if (!groupList.value.length) {
  77. await loadGroups()
  78. }
  79. else {
  80. paging.value?.reload()
  81. }
  82. })
  83. </script>
  84. <template>
  85. <z-paging v-if="tab" ref="paging" v-model="dataList" :show-loading-more-no-more-view="false" use-page-scroll @query="queryList">
  86. <template #top>
  87. <view class="bg-white" :style="{ paddingTop: `${safeAreaInsets?.top}px` }">
  88. <wd-tabs v-if="groupList.length && tab" v-model="tab" :auto-line-width="true" custom-class="bg-transparent!" slidable="always" @click="handleTabClick">
  89. <wd-tab v-for="g in groupList" :key="g.id" :name="String(g.id)" :title="getGroupName(g)" />
  90. </wd-tabs>
  91. </view>
  92. </template>
  93. <view class="pt-20rpx">
  94. <view v-for="item in dataList" :key="item.id" class="mb-20rpx bg-white px-22rpx py-20rpx" @click="handleItemClick(item)">
  95. <view class="flex items-center justify-between">
  96. <view class="flex-1 pr-16rpx text-28rpx line-height-[2]">
  97. {{ getQaTitle(item) }}
  98. </view>
  99. <wd-icon name="chevron-right" class="opacity-50" size="28rpx" />
  100. </view>
  101. </view>
  102. </view>
  103. </z-paging>
  104. </template>
  105. <style lang="scss" scoped>
  106. </style>