detail-tabbar.vue 4.0 KB

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