cm-cart-product.vue 12 KB

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