submitBar.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="">
  3. <view class="submitBar">
  4. <view class="left">
  5. <button class="item serviceBtn" open-type="contact" >
  6. <u-icon :size="40" name="server-fill"></u-icon>
  7. <view class="text shu-elip-1">客服</view>
  8. </button>
  9. <!-- <view class="item">
  10. <u-icon name="server-fill" :size="46" :color="$u.color['contentColor']"></u-icon>
  11. <view class="text shu-elip-1">客服</view>
  12. </view> -->
  13. <view class="item collection" @click="collectionFun">
  14. <u-icon :name="isCollection==1?'star-fill':'star'" :color="isCollection==1?'#ed3f14':'#333'" :size="40" ></u-icon>
  15. <view class="text shu-elip-1">{{isCollection==1?'已收藏':'收藏'}}</view>
  16. </view>
  17. <view class="item car" @click="goShoppingCart">
  18. <u-badge class="car-num" :count="cartNums" type="error" :absolute="true" :offset="[-5, 2]" v-if="cartNums>0"></u-badge>
  19. <u-icon name="shopping-cart" :size="40"></u-icon>
  20. <view class="text shu-elip-1">购物车</view>
  21. </view>
  22. </view>
  23. <view class="right">
  24. <view class="soldOutBtn" v-if="data.stock_total<=0||Number(data.price_selling)<=0">
  25. 已售罄
  26. </view>
  27. <template v-else>
  28. <view class="joinCartBtn" @click="addShoppingCart">加入购物车</view>
  29. <view class="buyBtn" @click="buyNow">立即购买</view>
  30. </template>
  31. </view>
  32. </view>
  33. <view class="siteBar"></view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. name: 'goods-operate',
  39. props: {
  40. // 数据源
  41. data: {
  42. type: Object,
  43. default: () => {
  44. return {};
  45. }
  46. }
  47. },
  48. watch:{
  49. data(val){
  50. this.isCollection = val.is_collection;
  51. }
  52. },
  53. data() {
  54. return {
  55. isCollection:false,
  56. cartNums:0,
  57. };
  58. },
  59. mounted(){
  60. this.isCollection = this.data.is_collection;
  61. this.getCartNums();
  62. },
  63. methods: {
  64. // 获取购物车数量
  65. getCartNums(){
  66. this.$u.api.getCartNumsAjax().then(({code,data})=>{
  67. console.log('购物车数量>>>>>>',data)
  68. this.cartNums = data;
  69. })
  70. },
  71. // 加入购物车
  72. addShoppingCart() {
  73. this.$emit('addShoppingCart');
  74. },
  75. collectionFun(){
  76. const token = uni.getStorageSync('token');
  77. if(!token){
  78. uni.navigateTo({
  79. url:'/pages/login/index'
  80. })
  81. return false;
  82. }
  83. // this.isCollection = this.isCollection==1?2:1
  84. this.$u.api.collectonAjax(this.data.id).then(({code,msg,data})=>{
  85. if(code==1){
  86. this.$u.toast(msg);
  87. this.isCollection = data.is_collection;
  88. }
  89. })
  90. },
  91. // 立即购买
  92. buyNow() {
  93. this.$emit('buyNow');
  94. },
  95. // 去购物车
  96. goShoppingCart() {
  97. uni.switchTab({
  98. url: '/pages/mall/shopping-cart'
  99. });
  100. }
  101. }
  102. };
  103. </script>
  104. <style lang="scss" scoped>
  105. .siteBar{
  106. height: 120rpx;
  107. // padding-bottom: constant(safe-area-inset-bottom);
  108. // padding-bottom: env(safe-area-inset-bottom);
  109. // box-sizing: content-box;
  110. @extend .safeAreaPad;
  111. }
  112. .submitBar {
  113. border-top: solid 2rpx #f2f2f2;
  114. // padding: 16rpx 0;
  115. position: fixed;
  116. bottom: 0;
  117. left: 0;
  118. width: 100%;
  119. height: 120rpx;
  120. display: flex;
  121. justify-content: space-between;
  122. align-items: center;
  123. background-color: $app-theme-bg-color;
  124. z-index: $app-zIndex-fixed;
  125. // padding-bottom: constant(safe-area-inset-bottom);
  126. // padding-bottom: env(safe-area-inset-bottom);
  127. // box-sizing: content-box;
  128. @extend .safeAreaPad;
  129. .left {
  130. display: flex;
  131. font-size: 24rpx;
  132. .item {
  133. width: 90rpx;
  134. // margin: 0 15rpx;
  135. text-align: center;
  136. &.car {
  137. position: relative;
  138. .car-num {
  139. // position: absolute;
  140. // top: -10rpx;
  141. // right: -10rpx;
  142. }
  143. }
  144. // &.collection{
  145. // width: ;
  146. // }
  147. }
  148. .text{
  149. font-size: 24rpx;
  150. line-height: 1.5;
  151. margin-top: 5rpx;
  152. }
  153. }
  154. .right {
  155. flex: 1;
  156. display: flex;
  157. font-size: 28rpx;
  158. align-items: center;
  159. justify-content: space-evenly;
  160. margin-left: 20rpx;
  161. // width: 480rpx;
  162. .btn {
  163. // flex: 1;
  164. min-width: 200rpx;
  165. line-height: 66rpx;
  166. // padding: 0 20rpx;
  167. border-radius: 36rpx;
  168. color: #ffffff;
  169. // margin-right: 20rpx;
  170. text-align: center;
  171. }
  172. .cart {
  173. background-color: #ff7900;
  174. }
  175. .buy {
  176. background-color: #ed3f14;
  177. }
  178. }
  179. }
  180. .serviceBtn{
  181. background-color: transparent;
  182. padding: 0;
  183. border: none;
  184. line-height: 1;
  185. &::after{
  186. content: '';
  187. border: none;
  188. display: none;
  189. }
  190. }
  191. </style>