index.vue 8.0 KB

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