cm-cart-product.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. >活动价</view
  48. >
  49. </view>
  50. <view class="footer">
  51. <view class="price">¥{{ item.price }}</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. filters: {
  127. formatPrice(val) {
  128. return Number(val).toFixed(2)
  129. }
  130. },
  131. computed: {
  132. // 是普通商品列表
  133. isNormal() {
  134. return this.listType.indexOf('normal') !== -1
  135. },
  136. // 是失效商品列表
  137. isExpired() {
  138. return this.listType.indexOf('expired') !== -1
  139. },
  140. // 当前状态为删除状态
  141. isDelete() {
  142. return this.listType.indexOf('delete') !== -1
  143. },
  144. productList() {
  145. if (this.isExpired) {
  146. return this.data
  147. } else {
  148. return this.data[this.vkey]
  149. }
  150. }
  151. },
  152. methods: {
  153. ...mapActions('cart', ['updateShoppogCount', 'removeFailureFromCart']),
  154. ...mapMutations('cart', ['selectProduct', 'selectAllShopProduct', 'selectFailure']),
  155. // 商品数量变化
  156. numberChange(product, count) {
  157. this.$emit('countChange')
  158. this.countChange(product, count)
  159. },
  160. // 勾选 / 取消勾选 供应商下所有商品
  161. chooseAll() {
  162. this.selectAllShopProduct({
  163. shopId: this.data.shopId,
  164. checked: !this.data.checked
  165. })
  166. this.$emit('chooseAll')
  167. },
  168. // 勾选到单个商品
  169. chooseOne(product) {
  170. if (this.isNormal) {
  171. this.selectProduct({
  172. shopId: this.data.shopId,
  173. productId: product.productId,
  174. checked: !product.productsChecked
  175. })
  176. } else {
  177. this.selectFailure({
  178. productId: product.productId,
  179. checked: !product.productsChecked
  180. })
  181. }
  182. this.$emit('chooseOne')
  183. },
  184. //商品数量加加
  185. countChange(product, count) {
  186. this.showLoading = true
  187. this.updateShoppogCount({
  188. cartId: product.cartId,
  189. productCount: count
  190. }).finally(() => {
  191. this.showLoading = false
  192. })
  193. },
  194. // 促销活动弹窗
  195. clickPopupShow(pros, type) {
  196. if (pros.ladderList.length > 0) {
  197. this.popupShow = true
  198. this.handlerPros = pros
  199. }
  200. },
  201. // 清空失效商品
  202. deletefailureList() {
  203. this.modal = true
  204. this.contentModalText = '确定清除所有失效商品吗?'
  205. },
  206. // 确认清空
  207. confirm(e) {
  208. if (e.index !== 1) return (this.modal = false)
  209. this.showLoading = true
  210. this.removeFailureFromCart().finally(() => {
  211. this.modal = false
  212. this.showLoading = false
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. $grid: 24rpx;
  220. .cm-cart-product {
  221. overflow: hidden;
  222. background: #fff;
  223. margin-bottom: $grid;
  224. }
  225. .shop-info {
  226. display: flex;
  227. justify-content: space-between;
  228. align-items: center;
  229. padding: $grid $grid 0;
  230. .name {
  231. width: 622rpx;
  232. font-size: 30rpx;
  233. font-weight: bold;
  234. color: #333333;
  235. }
  236. .expired {
  237. font-size: 30rpx;
  238. color: #333333;
  239. }
  240. .clear {
  241. display: flex;
  242. justify-content: center;
  243. align-items: center;
  244. width: 184rpx;
  245. height: 42rpx;
  246. background: #fff8fd;
  247. border: 1rpx solid #ff457b;
  248. border-radius: 28rpx;
  249. font-size: 26rpx;
  250. color: #ff457b;
  251. }
  252. }
  253. .radio {
  254. font-size: 36rpx;
  255. color: #b2b2b2;
  256. &.icon-xuanze {
  257. color: #f83c6c;
  258. }
  259. }
  260. .product-list {
  261. .row {
  262. display: flex;
  263. justify-content: space-between;
  264. align-items: center;
  265. margin: 0 $grid;
  266. padding: 30rpx 0;
  267. border-top: 1px solid #e1e1e1;
  268. &.no-border {
  269. border-top: 0;
  270. }
  271. &:last-child {
  272. margin-bottom: 0;
  273. }
  274. .expired {
  275. display: flex;
  276. justify-content: center;
  277. align-items: center;
  278. width: 72rpx;
  279. height: 36rpx;
  280. background: rgba(51, 51, 51, 0.3);
  281. border-radius: 24rpx;
  282. font-size: 24rpx;
  283. color: #ffffff;
  284. }
  285. }
  286. .product {
  287. width: 622rpx;
  288. display: flex;
  289. justify-content: space-between;
  290. align-items: center;
  291. .cover {
  292. width: 180rpx;
  293. height: 180rpx;
  294. box-sizing: border-box;
  295. border: 1rpx dashed #e1e1e1;
  296. }
  297. .content {
  298. width: 442rpx;
  299. .title,
  300. .tags,
  301. .params,
  302. .footer,
  303. .tip {
  304. padding-left: $grid;
  305. }
  306. .tags,
  307. .params {
  308. margin-top: 10rpx;
  309. }
  310. .tip {
  311. margin-top: 80rpx;
  312. margin-bottom: 0;
  313. font-size: 26rpx;
  314. color: #f83c6c;
  315. }
  316. .title {
  317. height: 66rpx;
  318. font-size: 26rpx;
  319. color: #333333;
  320. overflow: hidden;
  321. text-overflow: ellipsis;
  322. display: -webkit-box;
  323. -webkit-line-clamp: 2; // 这里控制几行显示省略号
  324. -webkit-box-orient: vertical;
  325. }
  326. .tags {
  327. display: flex;
  328. justify-content: flex-start;
  329. align-items: center;
  330. height: 24rpx;
  331. .tag {
  332. display: flex;
  333. justify-content: center;
  334. align-items: center;
  335. height: 30rpx;
  336. margin-right: 8rpx;
  337. font-size: 22rpx;
  338. &.type1 {
  339. width: 56rpx;
  340. background: #ff457b;
  341. border-radius: 4rpx;
  342. color: #ffffff;
  343. }
  344. &.type2 {
  345. width: 80rpx;
  346. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  347. no-repeat;
  348. background-size: 80rpx 30rpx;
  349. color: #f83c6c;
  350. }
  351. }
  352. }
  353. .params {
  354. font-size: 20rpx;
  355. color: #999999;
  356. }
  357. .footer {
  358. display: flex;
  359. justify-content: space-between;
  360. align-items: flex-end;
  361. margin-top: 4rpx;
  362. height: 48rpx;
  363. .add-cart {
  364. display: flex;
  365. justify-content: center;
  366. align-items: center;
  367. width: 44rpx;
  368. height: 44rpx;
  369. background: #ff457b;
  370. color: #fff;
  371. border-radius: 50%;
  372. }
  373. .price {
  374. flex: 1;
  375. font-size: 26rpx;
  376. font-weight: 600;
  377. color: #f83c6c;
  378. }
  379. }
  380. }
  381. }
  382. }
  383. .total {
  384. display: flex;
  385. justify-content: flex-end;
  386. align-items: center;
  387. padding: 30rpx $grid;
  388. font-size: 26rpx;
  389. font-weight: bold;
  390. .title {
  391. color: #333333;
  392. }
  393. .price {
  394. color: #ff457b;
  395. }
  396. }
  397. </style>