index.vue 8.3 KB

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