detail-navbar.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <!-- 商品详情:商品/评价/详情的 nav -->
  2. <template>
  3. <su-fixed alway :bgStyles="{ background: '#fff' }" :val="0" noNav opacity :placeholder="false">
  4. <su-status-bar />
  5. <view class="ui-bar ss-flex ss-col-center ss-row-between ss-p-x-20"
  6. :style="[{ height: sys_navBar - sys_statusBar + 'px' }]">
  7. <!-- 左 -->
  8. <view class="icon-box ss-flex">
  9. <view class="icon-button icon-button-left ss-flex ss-row-center" @tap="onClickLeft">
  10. <text class="sicon-back" v-if="hasHistory" />
  11. <text class="sicon-home" v-else />
  12. </view>
  13. <view class="line"></view>
  14. <view class="icon-button icon-button-right ss-flex ss-row-center" @tap="onClickRight">
  15. <text class="sicon-more" />
  16. </view>
  17. </view>
  18. <!-- 中 -->
  19. <view class="detail-tab-card ss-flex-1" :style="[{ opacity: state.tabOpacityVal }]">
  20. <view class="tab-box ss-flex ss-col-center ss-row-around">
  21. <view class="tab-item ss-flex-1 ss-flex ss-row-center ss-col-center" v-for="item in state.tabList"
  22. :key="item.value" @tap="onTab(item)">
  23. <view class="tab-title" :class="state.curTab === item.value ? 'cur-tab-title' : ''">
  24. {{ item.label }}
  25. </view>
  26. <view v-show="state.curTab === item.value" class="tab-line"></view>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 右 -->
  31. <view class="ui-tabbar-box " :style="[{ opacity: state.tabOpacityVal }]">
  32. <view class="ui-tabbar ss-flex ss-col-center ss-row-between">
  33. <view class="ss-flex ss-col-center ss-row-between" >
  34. <view v-if="collectIcon"
  35. class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center"
  36. @tap="onFavorite">
  37. <block v-if="modelValue.favorite">
  38. <image class="item-icon"
  39. :src="sheep.$url.static('/static/images/collect_1.gif')" mode="aspectFit" />
  40. <!-- <view class="item-title">已收藏</view> -->
  41. </block>
  42. <block v-else>
  43. <image class="item-icon"
  44. :src="sheep.$url.static('/static/images/collect_0.png')" mode="aspectFit" />
  45. <!-- <view class="item-title">收藏</view> -->
  46. </block>
  47. </view>
  48. <view v-if="shareIcon" class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center"
  49. @tap="showShareModal(modelValue.id)">
  50. <image class="item-icon" :src="sheep.$url.static('/static/images/share.png')"
  51. mode="aspectFit" />
  52. <!-- <view class="item-title">分享</view> -->
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- #ifdef MP -->
  58. <view :style="[capsuleStyle]"></view>
  59. <!-- #endif -->
  60. </view>
  61. </su-fixed>
  62. </template>
  63. <script setup>
  64. import {
  65. reactive,
  66. computed
  67. } from 'vue';
  68. import {
  69. onPageScroll
  70. } from '@dcloudio/uni-app';
  71. import sheep from '@/sheep';
  72. import throttle from '@/sheep/helper/throttle.js';
  73. import {
  74. showMenuTools,
  75. closeMenuTools
  76. } from '@/sheep/hooks/useModal';
  77. import {
  78. showShareModal
  79. } from '@/sheep/hooks/useModal';
  80. import { t } from '@/locale'
  81. import { showAuthModal } from '@/sheep/hooks/useModal';
  82. import FavoriteApi from '@/sheep/api/product/favorite';
  83. const isLogin = computed(() => sheep.$store('user').isLogin);
  84. const sys_statusBar = sheep.$platform.device.statusBarHeight;
  85. const sys_navBar = sheep.$platform.navbar;
  86. const capsuleStyle = {
  87. width: sheep.$platform.capsule.width + 'px',
  88. height: sheep.$platform.capsule.height + 'px',
  89. };
  90. const state = reactive({
  91. tabOpacityVal: 0,
  92. curTab: 'goods',
  93. tabList: [{
  94. label: t('common.product'),
  95. value: 'goods',
  96. to: 'detail-swiper-selector',
  97. },
  98. {
  99. label: t('common.review'),
  100. value: 'comment',
  101. to: 'detail-comment-selector',
  102. },
  103. {
  104. label: t('common.detail'),
  105. value: 'detail',
  106. to: 'detail-content-selector',
  107. },
  108. ],
  109. });
  110. // 接收参数
  111. const props = defineProps({
  112. modelValue: {
  113. type: Object,
  114. default () {},
  115. },
  116. collectIcon: {
  117. type: Boolean,
  118. default: true,
  119. },
  120. shareIcon: {
  121. type: Boolean,
  122. default: true,
  123. },
  124. });
  125. const emits = defineEmits(['clickLeft']);
  126. const hasHistory = sheep.$router.hasHistory();
  127. function onClickLeft() {
  128. if (hasHistory) {
  129. sheep.$router.back();
  130. } else {
  131. sheep.$router.go('/pages/index/index');
  132. }
  133. emits('clickLeft');
  134. }
  135. function onClickRight() {
  136. showMenuTools();
  137. }
  138. let commentCard = {
  139. top: 0,
  140. bottom: 0,
  141. };
  142. function getCommentCardNode() {
  143. return new Promise((res, rej) => {
  144. uni.createSelectorQuery()
  145. .select('.detail-comment-selector')
  146. .boundingClientRect((data) => {
  147. if (data) {
  148. commentCard.top = data.top;
  149. commentCard.bottom = data.top + data.height;
  150. res(data);
  151. } else {
  152. res(null);
  153. }
  154. })
  155. .exec();
  156. });
  157. }
  158. function onTab(tab) {
  159. let scrollTop = 0;
  160. if (tab.value === 'comment') {
  161. scrollTop = commentCard.top - sys_navBar + 1;
  162. } else if (tab.value === 'detail') {
  163. scrollTop = commentCard.bottom - sys_navBar + 1;
  164. }
  165. uni.pageScrollTo({
  166. scrollTop,
  167. duration: 200,
  168. });
  169. }
  170. // console.log(props.modelValue)
  171. async function onFavorite() {
  172. if(!isLogin.value){
  173. showAuthModal();
  174. return;
  175. }
  176. // 情况一:取消收藏
  177. if (props.modelValue.favorite) {
  178. const {
  179. code
  180. } = await FavoriteApi.deleteFavorite(props.modelValue.id);
  181. if (code !== 0) {
  182. return
  183. }
  184. sheep.$helper.toast(t('common.unfavorite'));
  185. props.modelValue.favorite = false;
  186. // 情况二:添加收藏
  187. } else {
  188. // 收藏
  189. const {
  190. code
  191. } = await FavoriteApi.createFavorite(props.modelValue.id);
  192. // 调用收藏加身价的接口
  193. await FavoriteApi.createCollectBefore(props.modelValue.id)
  194. if (code !== 0) {
  195. return
  196. }
  197. sheep.$helper.toast(t('common.favorite_success'));
  198. props.modelValue.favorite = true;
  199. }
  200. }
  201. onPageScroll((e) => {
  202. state.tabOpacityVal = e.scrollTop > sheep.$platform.navbar ? 1 : e.scrollTop * 0.01;
  203. if (commentCard.top === 0) {
  204. throttle(() => {
  205. getCommentCardNode();
  206. }, 50);
  207. }
  208. if (e.scrollTop < commentCard.top - sys_navBar) {
  209. state.curTab = 'goods';
  210. } else if (
  211. e.scrollTop >= commentCard.top - sys_navBar &&
  212. e.scrollTop <= commentCard.bottom - sys_navBar
  213. ) {
  214. state.curTab = 'comment';
  215. } else {
  216. state.curTab = 'detail';
  217. }
  218. });
  219. </script>
  220. <style lang="scss" scoped>
  221. .ui-tabbar-box {
  222. // box-shadow: 0px -6px 10px 0px rgba(51, 51, 51, 0.2);
  223. }
  224. .ui-tabbar {
  225. display: flex;
  226. height: 100%;
  227. background: #fff;
  228. .detail-tabbar-item {
  229. width: 80rpx;
  230. .item-icon {
  231. width: 40rpx;
  232. height: 40rpx;
  233. }
  234. .item-title {
  235. font-size: 20rpx;
  236. font-weight: 500;
  237. line-height: 20rpx;
  238. margin-top: 12rpx;
  239. }
  240. }
  241. }
  242. .icon-box {
  243. box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
  244. border-radius: 30rpx;
  245. width: 134rpx;
  246. height: 56rpx;
  247. margin-left: 8rpx;
  248. border: 1px solid rgba(#fff, 0.4);
  249. .line {
  250. width: 2rpx;
  251. height: 24rpx;
  252. background: #e5e5e7;
  253. }
  254. .sicon-back {
  255. font-size: 32rpx;
  256. color: #000;
  257. }
  258. .sicon-home {
  259. font-size: 32rpx;
  260. color: #000;
  261. }
  262. .sicon-more {
  263. font-size: 32rpx;
  264. color: #000;
  265. }
  266. .icon-button {
  267. width: 67rpx;
  268. height: 56rpx;
  269. &-left:hover {
  270. background: rgba(0, 0, 0, 0.16);
  271. border-radius: 30rpx 0px 0px 30rpx;
  272. }
  273. &-right:hover {
  274. background: rgba(0, 0, 0, 0.16);
  275. border-radius: 0px 30rpx 30rpx 0px;
  276. }
  277. }
  278. }
  279. .left-box {
  280. position: relative;
  281. width: 60rpx;
  282. height: 60rpx;
  283. display: flex;
  284. justify-content: center;
  285. align-items: center;
  286. .circle {
  287. position: absolute;
  288. left: 0;
  289. top: 0;
  290. width: 60rpx;
  291. height: 60rpx;
  292. background: rgba(#fff, 0.6);
  293. border: 1rpx solid #ebebeb;
  294. border-radius: 50%;
  295. box-sizing: border-box;
  296. z-index: -1;
  297. }
  298. }
  299. .right {
  300. position: relative;
  301. width: 60rpx;
  302. height: 60rpx;
  303. display: flex;
  304. justify-content: center;
  305. align-items: center;
  306. .circle {
  307. position: absolute;
  308. left: 0;
  309. top: 0;
  310. width: 60rpx;
  311. height: 60rpx;
  312. background: rgba(#ffffff, 0.6);
  313. border: 1rpx solid #ebebeb;
  314. box-sizing: border-box;
  315. border-radius: 50%;
  316. z-index: -1;
  317. }
  318. }
  319. .detail-tab-card {
  320. width: 50%;
  321. .tab-item {
  322. height: 80rpx;
  323. position: relative;
  324. z-index: 11;
  325. .tab-title {
  326. font-size: 30rpx;
  327. }
  328. .cur-tab-title {
  329. font-weight: $font-weight-bold;
  330. }
  331. .tab-line {
  332. width: 60rpx;
  333. height: 6rpx;
  334. border-radius: 6rpx;
  335. position: absolute;
  336. left: 50%;
  337. transform: translateX(-50%);
  338. bottom: 10rpx;
  339. background-color: var(--ui-BG-Main);
  340. z-index: 12;
  341. }
  342. }
  343. }
  344. </style>