shopping-cart.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <view class="shopping-cart">
  3. <view class="shopping-cart-item" v-for="seller in cart">
  4. <view class="shopping-cart-item-head">
  5. <view class="select">
  6. <checkbox class="checkbox" :checked="seller.checked" @tap="selectSeller(seller.seller_id)" />
  7. </view>
  8. <view class="factory-name">{{seller.seller_nickname?seller.seller_nickname:'省心直供(该厂家暂未设置昵称)'}}</view>
  9. </view>
  10. <view class="shopping-cart-info">
  11. <view class="product-item" v-for="product in seller.products">
  12. <view class="select">
  13. <checkbox class="checkbox" :checked="product.checked"
  14. @tap="select(product.id,product.spec_index)" />
  15. </view>
  16. <view class="product-image">
  17. <image class="image" :src="product.spec_image|imagesFilter" mode="scaleToFill"></image>
  18. </view>
  19. <view class="product-info">
  20. <view class="row row-1">
  21. <text class="title"><text class="sxzg-icon">省心直供</text>{{product.name}}</text>
  22. </view>
  23. <view class="row">
  24. <view class="spec">{{product.spec_name}}</view>
  25. </view>
  26. <view class="row row-2">
  27. <text class="org-price">¥{{product.spec_org_price}}</text>
  28. </view>
  29. <view class="row">
  30. <text class="sxj-icon">省心价</text>
  31. <text class="price">¥{{product.spec_price}}</text>
  32. </view>
  33. </view>
  34. <view class="counter">
  35. <view class="sub" @tap="subnum(product.id,product.num,product.spec_index)">-</view>
  36. <input class="num" type="text" v-model="product.num" />
  37. <view class="plus" @tap="plusnum(product.id,product.num,product.spec_index)">+</view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="footer">
  43. <view class="select-all">
  44. <label @tap="selectAll()">
  45. <checkbox color="#ff5d5b" class="checkbox" :checked="checkall" />全选
  46. </label>
  47. </view>
  48. <view class="total">合计 <text>¥{{total}}</text></view>
  49. <view class="settlement"><button class="settlement-btn" type="default">结算</button></view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. mapState
  56. } from 'vuex'
  57. export default {
  58. data() {
  59. return {
  60. checkall: false
  61. }
  62. },
  63. computed: mapState({
  64. cart: state => state.cart,
  65. total() {
  66. return this.$store.getters['cart/total']
  67. }
  68. }),
  69. onLoad() {
  70. // uni.removeStorageSync("cart")
  71. },
  72. methods: {
  73. selectSeller(seller_id) {
  74. this.$store.commit("cart/selectSeller", {
  75. seller_id: seller_id
  76. })
  77. },
  78. select(id, spec_index) {
  79. this.$store.commit("cart/select", {
  80. id: id,
  81. spec_index: spec_index
  82. })
  83. },
  84. selectAll() {
  85. this.checkall = !this.checkall;
  86. this.$store.commit("cart/selectAll", {
  87. checked: this.checkall
  88. })
  89. },
  90. subnum(id, num, spec_index) {
  91. if (num === 0) {
  92. uni.showModal({
  93. title: "移除商品",
  94. content: "确认移除该商品?",
  95. success: (res) => {
  96. if (res.confirm) {
  97. this.$store.commit("cart/remove", {
  98. id: id,
  99. num: num,
  100. spec_index: spec_index
  101. })
  102. }
  103. }
  104. })
  105. } else {
  106. num--
  107. }
  108. this.$store.commit("cart/numchange", {
  109. id: id,
  110. num: num,
  111. spec_index: spec_index
  112. })
  113. },
  114. plusnum(id, num, spec_index) {
  115. num++
  116. this.$store.commit("cart/numchange", {
  117. id: id,
  118. num: num,
  119. spec_index: spec_index
  120. })
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="scss">
  126. .shopping-cart {
  127. padding-bottom: 80upx;
  128. overflow: hidden;
  129. position: relative;
  130. }
  131. .shopping-cart-item {
  132. padding: 20upx;
  133. background: white;
  134. // padding-left: 100upx;
  135. margin: 20upx;
  136. border-radius: 20upx;
  137. .shopping-cart-item-head {
  138. margin-bottom: 20upx;
  139. font-size: 28upx;
  140. font-weight: bold;
  141. position: relative;
  142. display: flex;
  143. }
  144. .select {
  145. align-self: center;
  146. position: relative;
  147. margin-top: -4upx;
  148. margin-right: 20upx;
  149. }
  150. .checkbox {
  151. transform: scale(0.7);
  152. /deep/ .uni-checkbox-input {
  153. border: 2upx solid #CCCCCC;
  154. &.uni-checkbox-input-checked {
  155. color: $primary-color !important;
  156. }
  157. }
  158. /deep/ .uni-checkbox-input:hover {
  159. border: 2upx solid #CCCCCC;
  160. }
  161. }
  162. .product-item {
  163. display: flex;
  164. position: relative;
  165. margin-bottom: 20upx;
  166. .checkbox::before {
  167. top: 70upx;
  168. }
  169. .product-image {
  170. margin-right: 20upx;
  171. width: 180upx;
  172. height: 180upx;
  173. .image {
  174. width: 180upx;
  175. height: 180upx;
  176. margin-top: 5upx;
  177. }
  178. }
  179. .title {
  180. font-size: 24rpx;
  181. display: inline-block;
  182. white-space: normal;
  183. display: -webkit-box;
  184. -webkit-box-orient: vertical;
  185. -webkit-line-clamp: 2;
  186. overflow: hidden;
  187. height: 68upx;
  188. }
  189. .spec {
  190. font-size: 22upx;
  191. background: #CCCCCC;
  192. color: white;
  193. padding: 0 5upx;
  194. border-radius: 10upx;
  195. margin-top: 10upx;
  196. // display: inline-block;
  197. }
  198. .counter {
  199. position: absolute;
  200. bottom: 0upx;
  201. right: 10upx;
  202. display: flex;
  203. border: 2upx solid #CCCCCC;
  204. font-size: 28upx;
  205. align-items: center;
  206. border-radius: 10upx;
  207. .sub,
  208. .plus {
  209. // transform: scale(0.5);
  210. font-weight: 0;
  211. width: 42upx;
  212. text-align: center;
  213. &:active {
  214. background: rgba(0, 0, 0, .1);
  215. }
  216. }
  217. .num {
  218. text-align: center;
  219. font-size: 24upx;
  220. border-left: 2upx solid #EEEEEE;
  221. border-right: 2upx solid #EEEEEE;
  222. width: 50upx;
  223. }
  224. }
  225. }
  226. }
  227. .sxzg-icon {
  228. color: $primary-color;
  229. font-size: 16rpx;
  230. width: 80rpx;
  231. text-align: center;
  232. line-height: normal;
  233. border: 2rpx solid $primary-color;
  234. border-radius: 20rpx;
  235. display: inline-block;
  236. position: relative;
  237. top: -4rpx;
  238. margin-right: 10upx;
  239. // transform: scale(0.9);
  240. }
  241. .sxj-icon {
  242. background: $primary-color;
  243. color: white;
  244. font-size: 20upx;
  245. padding: 0 5upx;
  246. border-radius: 5upx;
  247. vertical-align: middle;
  248. }
  249. .row {
  250. display: flex;
  251. align-items: center;
  252. }
  253. .org-price {
  254. text-decoration: line-through;
  255. font-size: 26rpx;
  256. color: #cccccc;
  257. }
  258. .price {
  259. font-size: 26rpx;
  260. color: $primary-color;
  261. font-weight: bold;
  262. }
  263. .footer {
  264. display: flex;
  265. position: fixed;
  266. height: 100upx;
  267. background: $primary-color;
  268. bottom: 0;
  269. width: 100%;
  270. box-shadow: 0 0 10upx #999999;
  271. align-items: center;
  272. /* #ifdef H5 */
  273. bottom: 100upx;
  274. /* #endif */
  275. color: white;
  276. .select-all {
  277. width: 200upx;
  278. flex: 0 0 200upx;
  279. position: relative;
  280. margin-left: 20upx;
  281. .checkbox {
  282. transform: scale(0.7);
  283. position: relative;
  284. top: -4upx
  285. }
  286. /deep/ .uni-checkbox-input {
  287. border: none;
  288. }
  289. /deep/ .uni-checkbox-input:hover {
  290. border: none;
  291. }
  292. }
  293. .total {
  294. flex-grow: 1;
  295. text-align: right;
  296. }
  297. .settlement {
  298. flex-grow: 0;
  299. text-align: right;
  300. margin: 0 20upx;
  301. }
  302. .settlement-btn {
  303. background: #ffa82e;
  304. padding: 15upx 60upx;
  305. color: white;
  306. line-height: normal;
  307. font-size: 32upx;
  308. border-radius: 50upx;
  309. }
  310. }
  311. </style>