cm-cart-product.vue 9.0 KB

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