cm-cart-product.vue 12 KB

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