cm-cart-product.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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.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.updateShoppogCount({
  182. cartId: product.cartId,
  183. productCount: count
  184. })
  185. },
  186. // 促销活动弹窗
  187. clickPopupShow(pros, type) {
  188. if (pros.ladderList.length > 0) {
  189. this.popupShow = true
  190. this.handlerPros = pros
  191. }
  192. },
  193. // 清空失效商品
  194. deletefailureList() {
  195. this.modal = true
  196. this.contentModalText = '确定清除所有失效商品吗?'
  197. },
  198. // 确认清空
  199. confirm(e) {
  200. if (e.index !== 1) return (this.modal = false)
  201. this.removeFailureFromCart().finally(() => {
  202. this.modal = false
  203. })
  204. }
  205. }
  206. }
  207. </script>
  208. <style lang="scss" scoped>
  209. $grid: 24rpx;
  210. .cm-cart-product {
  211. overflow: hidden;
  212. background: #fff;
  213. margin-bottom: $grid;
  214. }
  215. .shop-info {
  216. display: flex;
  217. justify-content: space-between;
  218. align-items: center;
  219. padding: $grid $grid 0;
  220. .name {
  221. width: 622rpx;
  222. font-size: 30rpx;
  223. font-weight: bold;
  224. color: #333333;
  225. }
  226. .expired {
  227. font-size: 30rpx;
  228. color: #333333;
  229. }
  230. .clear {
  231. display: flex;
  232. justify-content: center;
  233. align-items: center;
  234. width: 184rpx;
  235. height: 42rpx;
  236. background: #fff8fd;
  237. border: 1rpx solid #ff457b;
  238. border-radius: 28rpx;
  239. font-size: 26rpx;
  240. color: #ff457b;
  241. }
  242. }
  243. .radio {
  244. font-size: 36rpx;
  245. color: #b2b2b2;
  246. &.icon-xuanze {
  247. color: #f83c6c;
  248. }
  249. }
  250. .product-list {
  251. .row {
  252. display: flex;
  253. justify-content: space-between;
  254. align-items: center;
  255. margin: 0 $grid;
  256. padding: 30rpx 0;
  257. border-top: 1px solid #e1e1e1;
  258. &.no-border {
  259. border-top: 0;
  260. }
  261. &:last-child {
  262. margin-bottom: 0;
  263. }
  264. .expired {
  265. display: flex;
  266. justify-content: center;
  267. align-items: center;
  268. width: 72rpx;
  269. height: 36rpx;
  270. background: rgba(51, 51, 51, 0.3);
  271. border-radius: 24rpx;
  272. font-size: 24rpx;
  273. color: #ffffff;
  274. }
  275. }
  276. .product {
  277. width: 622rpx;
  278. display: flex;
  279. justify-content: space-between;
  280. align-items: center;
  281. .cover {
  282. width: 180rpx;
  283. height: 180rpx;
  284. box-sizing: border-box;
  285. border: 1rpx dashed #e1e1e1;
  286. }
  287. .content {
  288. width: 442rpx;
  289. .title,
  290. .tags,
  291. .params,
  292. .footer,
  293. .tip {
  294. padding-left: $grid;
  295. }
  296. .tags,
  297. .params {
  298. margin-top: 10rpx;
  299. }
  300. .tip {
  301. margin-top: 80rpx;
  302. margin-bottom: 0;
  303. font-size: 26rpx;
  304. color: #f83c6c;
  305. }
  306. .title {
  307. height: 66rpx;
  308. font-size: 26rpx;
  309. color: #333333;
  310. overflow: hidden;
  311. text-overflow: ellipsis;
  312. display: -webkit-box;
  313. -webkit-line-clamp: 2; // 这里控制几行显示省略号
  314. -webkit-box-orient: vertical;
  315. }
  316. .tags {
  317. display: flex;
  318. justify-content: flex-start;
  319. align-items: center;
  320. height: 24rpx;
  321. .tag {
  322. display: flex;
  323. justify-content: center;
  324. align-items: center;
  325. height: 30rpx;
  326. margin-right: 8rpx;
  327. font-size: 22rpx;
  328. &.type1 {
  329. width: 56rpx;
  330. background: #ff457b;
  331. border-radius: 4rpx;
  332. color: #ffffff;
  333. }
  334. &.type2 {
  335. width: 80rpx;
  336. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  337. no-repeat;
  338. background-size: 80rpx 30rpx;
  339. color: #f83c6c;
  340. }
  341. }
  342. }
  343. .params {
  344. font-size: 20rpx;
  345. color: #999999;
  346. }
  347. .footer {
  348. display: flex;
  349. justify-content: space-between;
  350. align-items: flex-end;
  351. margin-top: 4rpx;
  352. height: 48rpx;
  353. .add-cart {
  354. display: flex;
  355. justify-content: center;
  356. align-items: center;
  357. width: 44rpx;
  358. height: 44rpx;
  359. background: #ff457b;
  360. color: #fff;
  361. border-radius: 50%;
  362. }
  363. .price {
  364. flex: 1;
  365. font-size: 26rpx;
  366. font-weight: 600;
  367. color: #f83c6c;
  368. }
  369. }
  370. }
  371. }
  372. }
  373. .total {
  374. display: flex;
  375. justify-content: flex-end;
  376. align-items: center;
  377. padding: 30rpx $grid;
  378. font-size: 26rpx;
  379. font-weight: bold;
  380. .title {
  381. color: #333333;
  382. }
  383. .price {
  384. color: #ff457b;
  385. }
  386. }
  387. </style>