cm-cart-supplier-area.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.skuId">
  14. <tui-divider height="60" v-if="index !== 0"></tui-divider>
  15. <view class="checkbox">
  16. <label
  17. class="icon iconfont "
  18. :class="isChecked(item.skuId) ? 'icon-xuanze' : 'icon-weixuanze'"
  19. :style="{ color: item.stock === 0 && !isDeleted ? '#ddd' : '' }"
  20. @click="onLabelClick(item)"
  21. >
  22. <checkbox
  23. :value="item.skuId"
  24. :checked="item.checked"
  25. v-show="false"
  26. :disabled="item.stock === 0 && !isDeleted"
  27. />
  28. </label>
  29. <cm-cart-product
  30. class="product"
  31. :isExpired="false"
  32. :emptyStock="item.stock === 0"
  33. :productInfo="item"
  34. @countChange="onCountChange"
  35. @unitChange="onUnitChange"
  36. ></cm-cart-product>
  37. </view>
  38. </view>
  39. </checkbox-group>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. name: 'cm-cart-supplier-area',
  45. props: {
  46. shopInfo: {
  47. type: Object,
  48. default: () => {}
  49. },
  50. isDeleted: {
  51. type: Boolean,
  52. default: false
  53. }
  54. },
  55. data() {
  56. return {
  57. checkedList: []
  58. }
  59. },
  60. watch: {
  61. checkedList(nVal) {
  62. this.$emit('change', {
  63. shopId: this.shopInfo.shopId,
  64. checkedList: nVal
  65. })
  66. }
  67. },
  68. computed: {
  69. productList() {
  70. return this.shopInfo.productList || []
  71. },
  72. selectProductList() {
  73. return this.shopInfo.productList.filter(item => item.stock !== 0 || this.isDeleted)
  74. },
  75. isCheckedAll() {
  76. return this.checkedList.length > 0 && this.checkedList.length === this.selectProductList.length
  77. }
  78. },
  79. methods: {
  80. // 选择全部
  81. selectAllToggle() {
  82. if (this.isCheckedAll) {
  83. this.checkedList = []
  84. } else {
  85. this.checkedList = this.selectProductList.map(item => item.skuId.toString())
  86. }
  87. },
  88. // 选中全部
  89. selectAll() {
  90. this.checkedList = this.selectProductList.map(item => item.skuId.toString())
  91. },
  92. // 取消全选
  93. unSelectAll() {
  94. this.checkedList = []
  95. },
  96. // 选择商品
  97. checkboxChange(e) {
  98. this.checkedList = e.detail.value
  99. },
  100. // 判断商品是否被选中
  101. isChecked(id) {
  102. return this.checkedList.includes(id.toString())
  103. },
  104. // 商品数量改变
  105. onCountChange(e) {
  106. this.$emit('countChange', e)
  107. },
  108. // 商品规格修改
  109. onUnitChange(e) {
  110. this.$emit('unitChange', e)
  111. },
  112. onLabelClick(item) {
  113. if (item.stock > 0) return
  114. this.$toast.error('商品规格已失效')
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .cart-supplier-area {
  121. padding: 24rpx;
  122. background: #fff;
  123. .icon {
  124. width: 72rpx;
  125. }
  126. .icon {
  127. margin-right: 8rpx;
  128. }
  129. .area-top {
  130. @extend .cm-flex-between;
  131. margin-bottom: 24rpx;
  132. .hover-class {
  133. background: #ffeff0 !important;
  134. border-color: #ff457b;
  135. }
  136. .shop-name {
  137. @include ellipsis(1);
  138. flex: 1;
  139. max-width: 620rpx;
  140. font-size: 30rpx;
  141. font-weight: bold;
  142. color: #333333;
  143. }
  144. .expired {
  145. font-size: 30rpx;
  146. color: #333333;
  147. }
  148. .clear {
  149. @extend .cm-flex-center;
  150. width: 184rpx;
  151. height: 42rpx;
  152. background: #fff8fd;
  153. border: 1rpx solid #ff457b;
  154. border-radius: 28rpx;
  155. font-size: 26rpx;
  156. color: #ff457b;
  157. }
  158. }
  159. .checkbox {
  160. @extend .cm-flex-between;
  161. .product {
  162. flex: 1;
  163. }
  164. }
  165. }
  166. </style>