cm-cart-supplier-area.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="cart-supplier-area">
  3. <view class="area-top">
  4. <view
  5. class="icon iconfont"
  6. :class="isCheckedAll ? 'icon-xuanze' : 'icon-weixuanze'"
  7. @click="selectAllToggle"
  8. ></view>
  9. <view class="shop-name">{{ shopInfo.name }}</view>
  10. </view>
  11. <!-- 有效商品列表 -->
  12. <checkbox-group @change="checkboxChange">
  13. <view class="section" v-for="(item, index) in productList" :key="item.productId">
  14. <tui-divider height="60" v-if="index !== 0"></tui-divider>
  15. <view class="checkbox">
  16. <label class="icon iconfont " :class="isChecked(item.productId) ? 'icon-xuanze' : 'icon-weixuanze'">
  17. <checkbox :value="item.productId" :checked="item.checked" v-show="false" />
  18. </label>
  19. <cm-cart-product
  20. class="product"
  21. :isExpired="false"
  22. :productInfo="item"
  23. @countChange="onCountChange"
  24. ></cm-cart-product>
  25. </view>
  26. </view>
  27. </checkbox-group>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. name: 'cm-cart-supplier-area',
  33. props: {
  34. shopInfo: {
  35. type: Object,
  36. default: () => {}
  37. }
  38. },
  39. data() {
  40. return {
  41. checkedList: []
  42. }
  43. },
  44. watch: {
  45. checkedList(nVal) {
  46. this.$emit('change', {
  47. shopId: this.shopInfo.shopId,
  48. checkedList: nVal
  49. })
  50. }
  51. },
  52. computed: {
  53. productList() {
  54. return this.shopInfo.productList || []
  55. },
  56. isCheckedAll() {
  57. return this.checkedList.length === this.productList.length
  58. }
  59. },
  60. methods: {
  61. // 选择全部
  62. selectAllToggle() {
  63. if (this.isCheckedAll) {
  64. this.checkedList = []
  65. } else {
  66. this.checkedList = this.productList.map(item => item.productId.toString())
  67. }
  68. },
  69. // 选中全部
  70. selectAll() {
  71. this.checkedList = this.productList.map(item => item.productId.toString())
  72. },
  73. // 取消全选
  74. unSelectAll() {
  75. this.checkedList = []
  76. },
  77. // 选择商品
  78. checkboxChange(e) {
  79. this.checkedList = e.detail.value
  80. },
  81. // 判断商品是否被选中
  82. isChecked(id) {
  83. return this.checkedList.includes(id.toString())
  84. },
  85. // 商品数量改变
  86. onCountChange(e) {
  87. this.$emit('countChange', e)
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .cart-supplier-area {
  94. padding: 24rpx;
  95. background: #fff;
  96. .icon {
  97. width: 72rpx;
  98. }
  99. .icon {
  100. margin-right: 8rpx;
  101. }
  102. .area-top {
  103. @extend .cm-flex-between;
  104. margin-bottom: 24rpx;
  105. .hover-class {
  106. background: #ffeff0 !important;
  107. border-color: #ff457b;
  108. }
  109. .shop-name {
  110. @include ellipsis(1);
  111. flex: 1;
  112. max-width: 620rpx;
  113. font-size: 30rpx;
  114. font-weight: bold;
  115. color: #333333;
  116. }
  117. .expired {
  118. font-size: 30rpx;
  119. color: #333333;
  120. }
  121. .clear {
  122. @extend .cm-flex-center;
  123. width: 184rpx;
  124. height: 42rpx;
  125. background: #fff8fd;
  126. border: 1rpx solid #ff457b;
  127. border-radius: 28rpx;
  128. font-size: 26rpx;
  129. color: #ff457b;
  130. }
  131. }
  132. .checkbox {
  133. @extend .cm-flex-between;
  134. .product {
  135. flex: 1;
  136. }
  137. }
  138. }
  139. </style>