index.vue 7.3 KB

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