index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <script setup lang="ts">
  2. import CouponArrivalPopup from './components/couponArrivalPopup.vue'
  3. import indexHome from './components/index.vue'
  4. import cart from './components/cart.vue'
  5. import classfiy from './components/classfiy.vue'
  6. import my from './components/my.vue'
  7. definePage({
  8. name: 'xsb-homeTabbar',
  9. islogin: false,
  10. style: {
  11. navigationStyle: 'custom',
  12. navigationBarTitleText: '星闪豹首页',
  13. backgroundColorBottom: '#fff',
  14. disableScroll: true,
  15. },
  16. })
  17. const sysXsbStore = useSysXsbStore()
  18. const {
  19. opcity,
  20. backTop,
  21. SelectShopInfo,
  22. allShopHasPermission,
  23. xsbShopList,
  24. isClassfiyPageOpen,
  25. } = storeToRefs(sysXsbStore)
  26. const { userInfo } = storeToRefs(useUserStore())
  27. const commonCategoryData = ref<Api.xsbCategories[]>([])
  28. const { data: goodsList, isLastPage, page, error, reload, refresh } = usePagination((pageNum, pageSize) =>
  29. Apis.xsb.getSearchProductList({ data: { pageNum, pageSize, salesNum: 'DESC', shopId: Number(SelectShopInfo.value?.shopId) || 1, channelId: userInfo.value.channelId || 1 } }), {
  30. data: resp => resp.data?.list,
  31. initialData: [],
  32. initialPage: 1,
  33. initialPageSize: 10,
  34. append: true,
  35. immediate: false,
  36. })
  37. const tabbarItems = ref([
  38. { name: 'xsb-home', value: null, active: true, title: '首页', icon1: '' },
  39. { name: 'xsb-classfiy', value: null, active: false, title: '分类', icon1: '' },
  40. { name: 'xsb-cart', value: null, active: false, title: '购物车', icon1: '' },
  41. { name: 'xsb-my', value: null, active: false, title: '我的', icon1: '' },
  42. ])
  43. const tabbarName = ref('xsb-home')
  44. const swiperList = ref<Api.xsbAdvertInfo[]>([])
  45. const hotText = ref<Api.xsbSearchTerm[]>([])
  46. const recommendText = ref<Api.xsbSearchTerm[]>([])
  47. const isShow = ref(true)
  48. function handleTabbarChange({ value }: { value: string }) {
  49. setTabbarItemActive(value)
  50. tabbarName.value = value
  51. }
  52. watch(() => isClassfiyPageOpen.value, () => {
  53. if (isClassfiyPageOpen.value) {
  54. handleChange('xsb-classfiy')
  55. isClassfiyPageOpen.value = false
  56. }
  57. })
  58. function setTabbarItemActive(name: string) {
  59. tabbarItems.value.forEach((item) => {
  60. if (item.name === name) {
  61. item.active = true
  62. }
  63. else {
  64. item.active = false
  65. }
  66. })
  67. }
  68. function handleClick() {
  69. backTop.value = true
  70. }
  71. onLoad((options: any) => {
  72. opcity.value = 0
  73. if (options.name) {
  74. handleTabbarChange({ value: options.name })
  75. }
  76. })
  77. const loading = ref(true)
  78. async function getCategories() {
  79. const res = await Apis.xsb.categories({ data: { shopId: unref(SelectShopInfo).shopId, channelId: unref(userInfo).channelId || 1 } })
  80. commonCategoryData.value = res.data
  81. }
  82. async function getCurrentImg() {
  83. const res = await Apis.xsb.appAdvertInfo({})
  84. swiperList.value = res.data
  85. }
  86. async function getSearchData(type: number) {
  87. const { data } = await Apis.xsb.SearchTerm({ data: { type } })
  88. return data
  89. }
  90. function handleCouponArrivalUse() {
  91. handleChange('xsb-classfiy')
  92. }
  93. onMounted(async () => {
  94. allShopHasPermission.value = false
  95. await useSysXsbStore().getAllShopList()
  96. hotText.value = await getSearchData(2)
  97. recommendText.value = await getSearchData(3)
  98. getCurrentImg()
  99. // reload()
  100. getCategories()
  101. loading.value = false
  102. queryPopupConfig()
  103. })
  104. onShow(() => {
  105. refresh()
  106. })
  107. watch(() => SelectShopInfo.value.shopId, () => {
  108. getCategories()
  109. refresh()
  110. })
  111. onShareAppMessage(() => {
  112. return {
  113. title: '市民请集合',
  114. }
  115. })
  116. function handleScrollBottom() {
  117. if (error.value) {
  118. reload()
  119. return
  120. }
  121. if (!isLastPage.value) {
  122. page.value++
  123. }
  124. }
  125. function handleChange(name: string) {
  126. tabbarItems.value = tabbarItems.value.map((it) => {
  127. if (it.name === name) {
  128. it.active = true
  129. }
  130. else {
  131. it.active = false
  132. }
  133. return it
  134. })
  135. tabbarName.value = name
  136. }
  137. function beforeleave() {
  138. if (tabbarName.value === 'xsb-classfiy') {
  139. isShow.value = false
  140. handleChange('xsb-home')
  141. nextTick(() => {
  142. isShow.value = true
  143. })
  144. }
  145. }
  146. const curtainInfo = ref({
  147. enabled: false,
  148. imageUrl: '',
  149. })
  150. async function queryPopupConfig() {
  151. try {
  152. const res = await Apis.xsb.popupConfig({})
  153. curtainInfo.value = res.data
  154. }
  155. catch (error) {
  156. console.error('获取弹窗配置失败:', error)
  157. curtainInfo.value = { enabled: false, imageUrl: '' }
  158. }
  159. }
  160. </script>
  161. <template>
  162. <view class="page-xsb">
  163. <indexHome
  164. v-if="tabbarName == 'xsb-home'" :category-list="commonCategoryData" :swiper="swiperList"
  165. :hot-text="hotText" :recommend-text="recommendText" :loading="loading" :goods-list="goodsList"
  166. :last-page="isLastPage" :error="error" @change-nav="handleChange('xsb-classfiy')"
  167. @scroll-bottom="handleScrollBottom"
  168. />
  169. <cart v-if="tabbarName == 'xsb-cart'" @change-tab="handleChange('xsb-home')" />
  170. <classfiy v-if="tabbarName == 'xsb-classfiy'" :category-list="commonCategoryData" :hot-text="hotText" />
  171. <my v-if="tabbarName == 'xsb-my'" />
  172. <view v-if="tabbarName == 'xsb-classfiy'">
  173. <page-container :show="isShow" :overlay="false" @beforeleave="beforeleave" />
  174. </view>
  175. <wd-tabbar
  176. v-model="tabbarName" safe-area-inset-bottom placeholder fixed :bordered="false" custom-class="custom-tab"
  177. :custom-style="`box-shadow:${tabbarName == 'xsb-cart' || tabbarName == 'xsb-classfiy' ? '' : ' 0rpx -6rpx 12rpx 2rpx rgba(0, 0, 0, 0.09)'}`"
  178. :z-index="99999" @change="handleTabbarChange"
  179. >
  180. <wd-tabbar-item
  181. v-for="(item, index) in tabbarItems" :key="index" :name="item.name"
  182. :value="useSysXsbStore().getTabbarItemValue(item.name)" :title="index == 0 && item.active ? '' : item.title"
  183. @change="handleTabbarChange"
  184. >
  185. <template #icon="{ active }">
  186. <template v-if="index == 0 && !active">
  187. <i class="iconfont text-44rpx">&#xe629;</i>
  188. </template>
  189. <template v-else-if="index == 0 && active">
  190. <i v-if="opcity == 1" class="iconfont text-76rpx text-[var(--them-color)]" @click="handleClick">&#xe62b;</i>
  191. <i v-else class="iconfont text-76rpx text-[var(--them-color)]">&#xe648;</i>
  192. </template>
  193. <template v-else-if="index != 0">
  194. <text :class="[active ? 'text-[var(--them-color)]' : '']" class="iconfont text-44rpx">
  195. {{ item.icon1 }}
  196. </text>
  197. </template>
  198. </template>
  199. </wd-tabbar-item>
  200. </wd-tabbar>
  201. <wd-popup v-model="allShopHasPermission" custom-style="border-radius:32rpx;" :close-on-click-modal="false" :z-index="99999">
  202. <view class="p28rpx">
  203. <view class="text-center text-24rpx text-#AAAAAA">
  204. 你没有该门店的商品数据查看权限,请切
  205. 换其他门店
  206. </view>
  207. <view class="mt30rpx w420rpx">
  208. <view v-for="item in xsbShopList" :key="item.shopId" class="mb20rpx flex items-center text-28rpx" :class="[item.isPermiss ? 'text-[var(--them-color)] font-semibold' : 'text-#AAAAAA ']">
  209. {{ item.shopName }}
  210. <view v-if="!item.isPermiss" class="ml20rpx rounded-22rpx bg-#aaa px16rpx text-24rpx text-white">
  211. 无权限
  212. </view>
  213. </view>
  214. </view>
  215. </view>
  216. </wd-popup>
  217. <wd-overlay :show="curtainInfo.enabled" :z-index="99999" @click="curtainInfo.enabled = false">
  218. <view class="h-full flex items-center justify-center">
  219. <image class="h-784rpx w-750rpx" :src="curtainInfo.imageUrl" />
  220. </view>
  221. </wd-overlay>
  222. <CouponArrivalPopup
  223. @use="handleCouponArrivalUse"
  224. />
  225. </view>
  226. </template>
  227. <style scoped lang="scss">
  228. .page-xsb {
  229. :deep() {
  230. .login-btn {
  231. min-width: 0 !important;
  232. width: 180rpx;
  233. }
  234. .cell-title {
  235. padding-left: 20rpx;
  236. }
  237. .item-cell {
  238. .card {
  239. padding: 0 !important;
  240. }
  241. .cell-group {
  242. overflow: hidden;
  243. border-radius: 12rpx;
  244. }
  245. .wd-cell__right {
  246. width: 60rpx !important;
  247. flex: unset !important;
  248. }
  249. }
  250. .wd-swiper-nav__item--dots-bar.is-active{
  251. background-color: var(--them-color) !important;
  252. }
  253. }
  254. }
  255. </style>