DetailFooter.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <!-- footer.vue -->
  2. <template>
  3. <view
  4. class="div ui-detail-footer"
  5. v-if="detailInfo"
  6. >
  7. <view class="div footer-flex">
  8. <view class="div left">
  9. <view class="div item" v-on:click="goCart()">
  10. <text class="span iconfont">&#xe6ae;</text>
  11. <text class="span icon" v-if="cartNumber > 0">{{ getCarCount }}</text>
  12. <text class="span text">购物车</text>
  13. </view>
  14. </view>
  15. <view class="div right">
  16. <view class="div right-wrapper">
  17. <view
  18. class="div button active-cart"
  19. v-on:click="addShopping(true)"
  20. v-if="detailInfo.pgoods_storage > 0"
  21. >
  22. 加入购物车
  23. </view>
  24. <view class="div button disabled-cart" v-if="detailInfo.pgoods_storage <= 0">
  25. 加入购物车
  26. </view>
  27. <view
  28. class="div button active-buy"
  29. v-on:click="checkout()"
  30. v-if="detailInfo.pgoods_storage > 0"
  31. >
  32. 立即购买
  33. </view>
  34. <view class="div button disabled-buy" v-if="detailInfo.pgoods_storage <= 0">
  35. 立即购买
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="p good-stock-none" v-if="detailInfo.pgoods_storage <= 0">
  41. 所选产品暂时无货,非常抱歉!
  42. </view>
  43. <shopping></shopping>
  44. <!-- 加入购物车显示动画 -->
  45. <view class="div ui-cart-animation" v-if="isAnimation">
  46. <uni-load-more status="loading" color="#e93b3d"></uni-load-more>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import { urlencode } from '@/util/common'
  52. import { mapState, mapMutations } from 'vuex'
  53. import shopping from './child/Shopping'
  54. import { cartQuantity } from '../../../api/memberPointscart'
  55. export default {
  56. data () {
  57. return {
  58. cartNumber: 0,
  59. isAnimation: false // 加入购物车成功之后是否显示动画
  60. }
  61. },
  62. components: {
  63. shopping
  64. },
  65. props: {
  66. ishidefooter: {
  67. type: Boolean,
  68. default: false
  69. }
  70. },
  71. computed: {
  72. ...mapState({
  73. // 是否显示购物车浮层
  74. isShowcartInfo: state => state.pointsgoods.isShowcartInfo,
  75. detailInfo: state => state.pointsgoods.detailInfo,
  76. isOnline: state => state.member.isOnline,
  77. number: state => state.pointsgoods.number
  78. }),
  79. getCarCount () {
  80. if (this.cartNumber > 0 && this.cartNumber < 100) {
  81. return this.cartNumber
  82. } else if (this.cartNumber >= 100) {
  83. return '99+'
  84. }
  85. }
  86. },
  87. created () {
  88. uni.$on('start-addcart-animation', () => {
  89. this.isAnimation = true
  90. })
  91. uni.$on('end-addcart-animation', () => {
  92. this.isAnimation = false
  93. this.saveCartState(false)
  94. })
  95. this.getCartCount()
  96. uni.$on('update-cart-num', () => {
  97. this.getCartCount()
  98. })
  99. },
  100. beforeDestroy: function () {
  101. uni.$off('start-addcart-animation')
  102. uni.$off('end-addcart-animation')
  103. uni.$off('update-cart-num')
  104. },
  105. methods: {
  106. ...mapMutations({
  107. saveCartState: 'saveCartState',
  108. changeType: 'changeType'
  109. }),
  110. getCartCount () {
  111. cartQuantity().then(res => {
  112. if (res) {
  113. this.cartNumber = res.result.cart_count
  114. }
  115. })
  116. },
  117. // 加入购物车
  118. addShopping (value) {
  119. this.saveCartState(value)
  120. this.changeType('确定')
  121. },
  122. // 立即购买
  123. checkout () {
  124. uni.navigateTo({ url: '/pages/member/pointsbuy/step1'+'?'+urlencode( { buy_now: 1, cart_id: this.detailInfo.pgoods_id + '|1' } )})
  125. },
  126. // 购物车
  127. goCart () {
  128. if (this.isOnline) {
  129. uni.navigateTo({ url: '/pages/member/pointscart/Cart', params: { type: 0 } })
  130. } else {
  131. uni.navigateTo({ url: '/pages/home/memberlogin/Login' })
  132. }
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .ui-detail-footer {
  139. background: rgba(255, 255, 255, 1);
  140. border-top: 0.5px solid #e8eaed;
  141. width: auto;
  142. position: absolute;
  143. bottom: var(--window-bottom);
  144. left: 0;
  145. right: 0;
  146. z-index: 0;
  147. &.hidden-cart-footer {
  148. display: none;
  149. }
  150. &.show-cart-footer {
  151. display: block;
  152. }
  153. .footer-flex {
  154. display: flex;
  155. justify-content: space-between;
  156. align-content: center;
  157. align-items: center;
  158. height: $footerHeight;
  159. padding-bottom: constant(safe-area-inset-bottom);/*兼容 IOS<11.2*/padding-bottom: env(safe-area-inset-bottom);/*兼容 IOS>11.2*/box-sizing: content-box;
  160. }
  161. .p.good-stock-none {
  162. width: 100%;
  163. height: 1.6rem;
  164. background: #c3c3c3;
  165. opacity: 0.5;
  166. font-size:$subFontSize;
  167. color: #333;
  168. position: absolute;
  169. text-align: center;
  170. line-height: 1.6rem;
  171. padding: 0;
  172. margin: 0;
  173. bottom: 3rem;
  174. }
  175. .div.left {
  176. display: flex;
  177. justify-content: center;
  178. align-items: center;
  179. width: 5rem;
  180. .item{flex:1;text-align: center;line-height: 1;position:relative;
  181. .iconfont {
  182. flex-shrink: 0;
  183. font-size:1.3rem;
  184. }
  185. .text{font-size:$h6;color:gray;display: block}
  186. }
  187. .span.icon {
  188. position: absolute;
  189. right: 0;
  190. top: 0;
  191. font-size:$h6;
  192. line-height: 0.7rem;
  193. width: 0.9rem;
  194. height: 0.7rem;
  195. background: #ef3338;
  196. border-radius: 1rem;
  197. text-align: center;
  198. color: #ffffff;
  199. }
  200. }
  201. .div.right {
  202. flex: 1;
  203. align-items: center;
  204. padding-right:$pageSpace;
  205. .right-wrapper{
  206. display: flex;
  207. flex-direction: row;
  208. border-radius:2rem;
  209. overflow: hidden;
  210. }
  211. .button {
  212. flex: 1;
  213. height: 2rem;
  214. font-size:$subFontSize;
  215. display:flex;align-items:center;justify-content:center;
  216. color: #ffffff;
  217. text-align: center;
  218. line-height: 2rem;
  219. cursor: pointer;
  220. }
  221. .disabled-cart {
  222. background: #c3c3c3;
  223. }
  224. .active-cart {
  225. background: $primaryColor;
  226. }
  227. .disabled-buy {
  228. background: #999999;
  229. }
  230. .active-buy {
  231. background: #000;
  232. }
  233. }
  234. }
  235. .ui-cart-animation {
  236. position: fixed;
  237. top: 50%;
  238. left: 50%;
  239. }
  240. </style>