detail-tabbar.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!-- 产品详情的底部导航 -->
  2. <template>
  3. <su-fixed bottom placeholder bg="bg-white">
  4. <view class="ui-tabbar-box">
  5. <view class="ui-tabbar ss-flex ss-col-center ss-row-between">
  6. <view v-if="collectIcon" class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center"
  7. @tap="onFavorite">
  8. <block v-if="modelValue.favorite">
  9. <image class="item-icon" :src="sheep.$url.static('/static/img/shop/goods/collect_1.gif')"
  10. mode="aspectFit" />
  11. <view class="item-title">已收藏</view>
  12. </block>
  13. <block v-else>
  14. <image class="item-icon" :src="sheep.$url.static('/static/img/shop/goods/collect_0.png')"
  15. mode="aspectFit" />
  16. <view class="item-title">收藏</view>
  17. </block>
  18. </view>
  19. <!-- <view
  20. v-if="serviceIcon"
  21. class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center"
  22. @tap="onChat"
  23. >
  24. <image
  25. class="item-icon"
  26. :src="sheep.$url.static('/static/img/shop/goods/message.png')"
  27. mode="aspectFit"
  28. />
  29. <view class="item-title">客服</view>
  30. </view> -->
  31. <view v-if="shareIcon" class="detail-tabbar-item ss-flex ss-flex-col ss-row-center ss-col-center"
  32. @tap="showShareModal">
  33. <image class="item-icon" :src="sheep.$url.static('/static/img/shop/goods/share.png')" mode="aspectFit" />
  34. <view class="item-title">分享</view>
  35. </view>
  36. <slot></slot>
  37. </view>
  38. </view>
  39. </su-fixed>
  40. </template>
  41. <script setup>
  42. /**
  43. *
  44. * 底部导航
  45. *
  46. * @property {String} bg - 背景颜色Class
  47. * @property {String} ui - 自定义样式Class
  48. * @property {Boolean} noFixed - 是否定位
  49. * @property {Boolean} topRadius - 上圆角
  50. */
  51. import { reactive } from 'vue';
  52. import sheep from '@/sheep';
  53. import { showShareModal } from '@/sheep/hooks/useModal';
  54. import FavoriteApi from '@/sheep/api/product/favorite';
  55. // 数据
  56. const state = reactive({});
  57. // 接收参数
  58. const props = defineProps({
  59. modelValue: {
  60. type: Object,
  61. default() { },
  62. },
  63. bg: {
  64. type: String,
  65. default: 'bg-white',
  66. },
  67. bgStyles: {
  68. type: Object,
  69. default() { },
  70. },
  71. ui: {
  72. type: String,
  73. default: '',
  74. },
  75. noFixed: {
  76. type: Boolean,
  77. default: false,
  78. },
  79. topRadius: {
  80. type: Number,
  81. default: 0,
  82. },
  83. collectIcon: {
  84. type: Boolean,
  85. default: true,
  86. },
  87. serviceIcon: {
  88. type: Boolean,
  89. default: true,
  90. },
  91. shareIcon: {
  92. type: Boolean,
  93. default: true,
  94. },
  95. });
  96. async function onFavorite() {
  97. // 情况一:取消收藏
  98. if (props.modelValue.favorite) {
  99. const { code } = await FavoriteApi.deleteFavorite(props.modelValue.id);
  100. if (code !== 0) {
  101. return
  102. }
  103. sheep.$helper.toast('取消收藏');
  104. props.modelValue.favorite = false;
  105. // 情况二:添加收藏
  106. } else {
  107. const { code } = await FavoriteApi.createFavorite(props.modelValue.id);
  108. if (code !== 0) {
  109. return
  110. }
  111. sheep.$helper.toast('收藏成功');
  112. props.modelValue.favorite = true;
  113. }
  114. }
  115. const onChat = () => {
  116. sheep.$router.go('/pages/chat/index', {
  117. id: props.modelValue.id,
  118. });
  119. };
  120. </script>
  121. <style lang="scss" scoped>
  122. .ui-tabbar-box {
  123. box-shadow: 0px -6px 10px 0px rgba(51, 51, 51, 0.2);
  124. }
  125. .ui-tabbar {
  126. display: flex;
  127. height: 50px;
  128. background: #fff;
  129. .detail-tabbar-item {
  130. width: 100rpx;
  131. .item-icon {
  132. width: 40rpx;
  133. height: 40rpx;
  134. }
  135. .item-title {
  136. font-size: 20rpx;
  137. font-weight: 500;
  138. line-height: 20rpx;
  139. margin-top: 12rpx;
  140. }
  141. }
  142. }
  143. </style>