cm-cart-product.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view class="cm-cart-product">
  3. <template v-if="productList.length > 0">
  4. <!-- 供应商名称 -->
  5. <view class="shop-info">
  6. <template v-if="listType === 'expired'">
  7. <view class="expired">失效商品{{ productList.length }}件</view>
  8. </template>
  9. <template v-else>
  10. <view
  11. class="radio iconfont"
  12. :class="data.checked ? 'icon-xuanze' : 'icon-weixuanze'"
  13. @click="chooseAll"
  14. ></view>
  15. <view class="name">{{ data.name }}</view>
  16. </template>
  17. </view>
  18. <!-- 商品列表 -->
  19. <view class="product-list">
  20. <view
  21. class="row"
  22. v-for="(item, index) in productList"
  23. :key="index"
  24. :class="{ 'no-border': index === 0 }"
  25. >
  26. <view class="expired" v-if="listType === 'expired'">失效</view>
  27. <view
  28. class="radio iconfont"
  29. :class="item.productsChecked ? 'icon-xuanze' : 'icon-weixuanze'"
  30. @click="chooseOne(item)"
  31. v-else
  32. ></view>
  33. <view class="product">
  34. <image class="cover" :src="item.mainImage"></image>
  35. <view class="content">
  36. <view class="title">{{ item.productName }}</view>
  37. <!-- 普通列表 -->
  38. <template v-if="['list', 'delete'].includes(listType)">
  39. <view class="params">规格:{{ item.unit || '' }}</view>
  40. <view class="tags">
  41. <view class="tag type1" v-if="!item.heUserId">自营</view>
  42. <view class="tag type2" v-if="item.activeStatus == 1" @click="clickPopupShow(item, 2)"
  43. >活动价</view
  44. >
  45. </view>
  46. <view class="footer">
  47. <view class="price">¥{{ item.price }}</view>
  48. <view>
  49. <number-box
  50. @change="numberChange(item, $event)"
  51. v-if="listType !== 'delete'"
  52. :value="item.productCount"
  53. ></number-box>
  54. </view>
  55. </view>
  56. </template>
  57. <template v-if="listType === 'expired'">
  58. <view class="tip">商品已下架</view>
  59. </template>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 合计价格 -->
  65. <view class="total" v-if="listType === 'list'">
  66. <text class="title">合计:</text> <text class="price">¥{{ data.totalPrice | formatPrice }}</text>
  67. </view>
  68. </template>
  69. <!-- 促销活动弹窗 -->
  70. <activi-popup :product="handlerPros" :popupShow="popupShow"></activi-popup>
  71. </view>
  72. </template>
  73. <script>
  74. import NumberBox from './number-box.vue'
  75. import activiPopup from '@/components/cm-module/productDetails/cm-activipopu'
  76. import { mapGetters, mapActions, mapMutations } from 'vuex'
  77. export default {
  78. name: 'cm-cart-product',
  79. components: {
  80. NumberBox,
  81. activiPopup
  82. },
  83. data() {
  84. return {
  85. popupShow: false,
  86. handlerPros: {}
  87. }
  88. },
  89. props: {
  90. // 列表类型 list普通列表 delete删除列表 expired失效列表
  91. listType: {
  92. type: String,
  93. default: 'list'
  94. },
  95. // 数据
  96. data: {
  97. type: [Array, Object],
  98. default: () => {}
  99. },
  100. vkey: {
  101. type: String,
  102. default: ''
  103. }
  104. },
  105. filters: {
  106. formatPrice(val) {
  107. return Number(val).toFixed(2)
  108. }
  109. },
  110. computed: {
  111. productList() {
  112. if (this.listType === 'expired') {
  113. return this.data
  114. } else {
  115. return this.data[this.vkey]
  116. }
  117. }
  118. },
  119. methods: {
  120. ...mapActions('cart', ['initCart', 'updateShoppogCount', 'removeFromCart', 'removeFailureFromCart']),
  121. ...mapMutations('cart', [
  122. 'selectProduct',
  123. 'selectAllShopProduct',
  124. 'selectAllProduct',
  125. 'saveCartIds',
  126. 'selectFailure',
  127. 'selectAllFailure'
  128. ]),
  129. // 商品数量变化
  130. numberChange(product, count) {
  131. this.countChange(product, count)
  132. },
  133. // 勾选 / 取消勾选 供应商下所有商品
  134. chooseAll() {
  135. this.selectAllShopProduct({
  136. shopId: this.data.shopId,
  137. checked: !this.data.checked
  138. })
  139. this.$emit('chooseAll')
  140. },
  141. // 勾选到单个商品
  142. chooseOne(product) {
  143. this.selectProduct({
  144. shopId: this.data.shopId,
  145. productId: product.productId,
  146. checked: !product.productsChecked
  147. })
  148. this.$emit('chooseOne')
  149. },
  150. //商品数量加加
  151. countChange(product, count) {
  152. this.updateShoppogCount({
  153. cartId: product.cartId,
  154. productCount: count
  155. })
  156. },
  157. // 促销活动弹窗
  158. clickPopupShow(pros, type) {
  159. if (pros.ladderList.length > 0) {
  160. this.popupShow = true
  161. this.handlerPros = pros
  162. }
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. $grid: 24rpx;
  169. .cm-cart-product {
  170. overflow: hidden;
  171. background: #fff;
  172. margin-bottom: $grid;
  173. }
  174. .shop-info {
  175. display: flex;
  176. justify-content: space-between;
  177. align-items: center;
  178. padding: $grid $grid 0;
  179. .name {
  180. width: 622rpx;
  181. font-size: 30rpx;
  182. font-weight: bold;
  183. color: #333333;
  184. }
  185. .expired {
  186. font-size: 30rpx;
  187. color: #333333;
  188. }
  189. }
  190. .radio {
  191. font-size: 36rpx;
  192. color: #b2b2b2;
  193. &.icon-xuanze {
  194. color: #f83c6c;
  195. }
  196. }
  197. .product-list {
  198. .row {
  199. display: flex;
  200. justify-content: space-between;
  201. align-items: center;
  202. margin: 0 $grid;
  203. padding: 30rpx 0;
  204. border-top: 1px solid #e1e1e1;
  205. &.no-border {
  206. border-top: 0;
  207. }
  208. .expired {
  209. display: flex;
  210. justify-content: center;
  211. align-items: center;
  212. width: 72rpx;
  213. height: 36rpx;
  214. background: rgba(51, 51, 51, 0.3);
  215. border-radius: 24rpx;
  216. font-size: 24rpx;
  217. color: #ffffff;
  218. }
  219. }
  220. .product {
  221. width: 622rpx;
  222. display: flex;
  223. justify-content: space-between;
  224. align-items: center;
  225. .cover {
  226. width: 180rpx;
  227. height: 180rpx;
  228. box-sizing: border-box;
  229. border: 1rpx dashed #e1e1e1;
  230. }
  231. .content {
  232. width: 442rpx;
  233. .title,
  234. .tags,
  235. .params,
  236. .footer,
  237. .tip {
  238. padding-left: $grid;
  239. }
  240. .tags,
  241. .params {
  242. margin-top: 10rpx;
  243. }
  244. .tip {
  245. margin-top: 80rpx;
  246. margin-bottom: 0;
  247. font-size: 26rpx;
  248. color: #f83c6c;
  249. }
  250. .title {
  251. height: 66rpx;
  252. font-size: 26rpx;
  253. color: #333333;
  254. overflow: hidden;
  255. text-overflow: ellipsis;
  256. display: -webkit-box;
  257. -webkit-line-clamp: 2; // 这里控制几行显示省略号
  258. -webkit-box-orient: vertical;
  259. }
  260. .tags {
  261. display: flex;
  262. justify-content: flex-start;
  263. align-items: center;
  264. height: 24rpx;
  265. .tag {
  266. display: flex;
  267. justify-content: center;
  268. align-items: center;
  269. height: 30rpx;
  270. margin-right: 8rpx;
  271. font-size: 22rpx;
  272. &.type1 {
  273. width: 56rpx;
  274. background: #ff457b;
  275. border-radius: 4rpx;
  276. color: #ffffff;
  277. }
  278. &.type2 {
  279. width: 80rpx;
  280. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  281. no-repeat;
  282. background-size: 80rpx 30rpx;
  283. color: #f83c6c;
  284. }
  285. }
  286. }
  287. .params {
  288. font-size: 20rpx;
  289. color: #999999;
  290. }
  291. .footer {
  292. display: flex;
  293. justify-content: space-between;
  294. align-items: flex-end;
  295. margin-top: 4rpx;
  296. .add-cart {
  297. display: flex;
  298. justify-content: center;
  299. align-items: center;
  300. width: 44rpx;
  301. height: 44rpx;
  302. background: #ff457b;
  303. color: #fff;
  304. border-radius: 50%;
  305. }
  306. .price {
  307. flex: 1;
  308. font-size: 26rpx;
  309. font-weight: 600;
  310. color: #f83c6c;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. .total {
  317. display: flex;
  318. justify-content: flex-end;
  319. align-items: center;
  320. padding: 30rpx $grid;
  321. font-size: 26rpx;
  322. font-weight: bold;
  323. .title {
  324. color: #333333;
  325. }
  326. .price {
  327. color: #ff457b;
  328. }
  329. }
  330. </style>