Cart.vue 5.5 KB

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