Cart.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <member-base :show="false"><view class="div ui-cart-wrapper">
  3. <!-- header -->
  4. <v-cart-header
  5. ref="header"
  6. :issShowTabbar="type"
  7. :isEmpty="isEmpty"
  8. ></v-cart-header>
  9. <view class="div" v-if="!isEmpty">
  10. <!-- list -->
  11. <v-cart-list
  12. ref="list"
  13. :issShowTabbar="type"
  14. :isCheckedAll="isFinish"
  15. ></v-cart-list>
  16. <!-- footer -->
  17. <v-cart-footer
  18. :issShowTabbar="type"
  19. :isCheckedAll="isFinish"
  20. :isStatus="isStatus"
  21. :totalPrice="totalPrice"
  22. :totalAmount="totalAmount"
  23. :cartId="cartId"
  24. ></v-cart-footer>
  25. </view>
  26. <view v-if="isEmpty" class="div empty-cart">
  27. <view class="p" v-if="isOnline">您的购物车还是空的</view>
  28. <view class="p" v-if="!isOnline">登录后即可查看购物车中的商品</view>
  29. <text class="span" @click="goHome()" v-if="isOnline">随便逛逛</text>
  30. <text class="span" @click="goSingin()" v-if="!isOnline">去登录</text>
  31. </view>
  32. </view></member-base>
  33. </template>
  34. <script>
  35. import {getFontSize} from '@/util/common'
  36. import MemberBase from '../MemberBase'
  37. import cartHeader from './child/CartHeader'
  38. import cartList from './child/CartList'
  39. import cartFooter from './child/CartFooter'
  40. import { mapState, mapMutations } from 'vuex'
  41. export default {
  42. data () {
  43. return {
  44. totalPrice: 0,
  45. totalAmount: 0,
  46. cartId: '',
  47. type: 0, // 判断是否显示购物车底部的tabbar 1 : 显示 0 不显示
  48. isFinish: false, // 编辑 false - 编辑~完成 true - 完成~编辑 false
  49. isStatus: true, // 是否默认选中底部的全选按钮
  50. isshowpromos: true, // 是否显示促销信息
  51. target: '', // 设置高度的element元素
  52. isEmpty: false
  53. }
  54. },
  55. computed: {
  56. fontSize(){
  57. return getFontSize()
  58. },
  59. ...mapState({
  60. isOnline: state => state.member.isOnline
  61. })
  62. },
  63. created () {
  64. this.isSignin()
  65. // 监听是否改变购物车列表选中的状态
  66. uni.$on('change-list-selected', data => {
  67. // data.isFinish ? 表示是完成状态,1,列表默认全不选中 2,促销信息不显示, 3,改变列表的高度 : 编辑状态 1,列表默认全选中 2,促销信息显示, 3,改变列表的高度
  68. if (!this.isEmpty) {
  69. this.isFinish = data.isFinish
  70. if (data.isFinish) {
  71. this.isshowpromos = false
  72. this.$refs.list.addChecked(false)
  73. } else {
  74. this.isshowpromos = true
  75. this.$refs.list.addChecked(true)
  76. }
  77. this.$refs.list.renderCart()
  78. }
  79. })
  80. // 监听是否更新购物车列表
  81. uni.$on('update-cart-list', data => {
  82. if (data.isdelete) {
  83. this.$refs.list.deleteSelected()
  84. }
  85. })
  86. // 监听是否获取购物车促销信息
  87. uni.$on('get-promos-data', data => {
  88. // this.$refs.promos.getCartPromos(data);
  89. })
  90. // 监听选中的购物车
  91. uni.$on('calcu-cart-data', data => {
  92. this.totalPrice = data.totalPrice
  93. this.totalAmount = data.totalAmount
  94. this.cartId = data.cartId
  95. })
  96. // 监听购物车底部全选按钮是否选中
  97. uni.$on('cart-bottom-status', data => {
  98. // data.isCheckAll ? true 1,显示促销信息, 2,重新计算列表的高度: false 1.隐藏促销信息, 2,重新计算列表的高度
  99. if (data.isCheckAll && !this.isFinish) {
  100. this.isshowpromos = true
  101. } else {
  102. this.isshowpromos = false
  103. }
  104. this.$refs.list.addChecked(data.isCheckAll)
  105. this.$refs.list.renderCart()
  106. })
  107. // 监听列表一个个选中底部全选按钮默认选中
  108. uni.$on('change-footer-status', status => {
  109. this.isStatus = status
  110. })
  111. uni.$on('list-is-empty', data => {
  112. if (data.length > 0) {
  113. this.isEmpty = false
  114. } else {
  115. this.isEmpty = true
  116. }
  117. })
  118. },
  119. mounted () {
  120. },
  121. beforeDestroy: function () {
  122. uni.$off('change-list-selected')
  123. uni.$off('update-cart-list')
  124. uni.$off('get-promos-data')
  125. uni.$off('calcu-cart-data')
  126. uni.$off('cart-bottom-status')
  127. uni.$off('change-footer-status')
  128. uni.$off('list-is-empty')
  129. },
  130. components:{
  131. MemberBase,
  132. 'v-cart-header': cartHeader,
  133. 'v-cart-list': cartList,
  134. 'v-cart-footer': cartFooter
  135. },
  136. methods: {
  137. /*
  138. * isSignin: 是否登录
  139. */
  140. isSignin () {
  141. if (this.isOnline) {
  142. this.isEmpty = false
  143. } else {
  144. this.isEmpty = true
  145. }
  146. },
  147. /*
  148. * goHome: 跳转到首页
  149. */
  150. goHome () {
  151. uni.navigateTo({url:'/pages/home/pointsgoods/Index'})
  152. },
  153. goSingin () {
  154. uni.navigateTo({url:'/pages/home/memberlogin/Login'})
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .ui-cart-wrapper {
  161. }
  162. .empty-cart {
  163. padding-top:6.2rem;
  164. text-align: center;
  165. .img {
  166. width:3.7rem;
  167. height:3.7rem;
  168. }
  169. .p {
  170. font-size:$h2;
  171. color: #333;
  172. line-height:1.1rem;
  173. padding: 1.3rem 0 2rem 0;
  174. }
  175. .span {
  176. font-size:$h2;
  177. color: rgba(255, 255, 255, 1);
  178. height:2.2rem;
  179. background: $primaryColor;
  180. border-radius:0.15rem;
  181. line-height:2.2rem;
  182. display: inline-block;
  183. width:10rem;
  184. }
  185. }
  186. </style>