敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
8.1 KiB

  1. <template>
  2. <view class="page">
  3. <navbar />
  4. <view class="user">
  5. <uv-checkbox-group shape="circle" v-model="checkboxValue">
  6. <uv-swipe-action>
  7. <view v-for="(item, index) in list" :key="item.id">
  8. <view style="margin-top: 20rpx;"></view>
  9. <uv-swipe-action-item @click="e => deleteCart(e, item)" :options="options">
  10. <view class="item">
  11. <view class="checkbox">
  12. <uv-checkbox :name="item.id" activeColor="#eb3300" size="40rpx"
  13. icon-size="35rpx"></uv-checkbox>
  14. </view>
  15. <image class="image" :src="item.image &&
  16. item.image.split(',')[0]" mode=""></image>
  17. <view class="info">
  18. <view class="title">
  19. <view class="">
  20. {{ item.title }}
  21. </view>
  22. </view>
  23. <view class="unit">
  24. 规格{{ item.sku }}
  25. <!-- <uv-icon name="arrow-down"></uv-icon> -->
  26. </view>
  27. <view style="display: flex;
  28. justify-content: space-between;
  29. align-items: center;">
  30. <view class="price">
  31. <text>{{ item.price }}</text>
  32. </view>
  33. <view class="">
  34. <uv-number-box v-model="item.num"
  35. @change="e => valChange(item, e)"></uv-number-box>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </uv-swipe-action-item>
  41. </view>
  42. </uv-swipe-action>
  43. </uv-checkbox-group>
  44. <uv-empty v-if="list.length == 0" text="空空如也" textSize="30rpx" iconSize="200rpx" icon="list"></uv-empty>
  45. <view class="action">
  46. <view class="icon">
  47. <image src="/static/image/cart/1.png" mode=""></image>
  48. <view class="num">
  49. {{ checkboxValue.length }}
  50. </view>
  51. </view>
  52. <view class="price">
  53. <view class="count">
  54. 合计
  55. <view class="">
  56. <text>{{ totalPrice }}</text>
  57. </view>
  58. </view>
  59. <view class="text">
  60. {{ checkboxValue.length }}已享受更低优惠
  61. </view>
  62. </view>
  63. <view class="btn" @click="submit">
  64. 去结算
  65. </view>
  66. </view>
  67. </view>
  68. <tabber select="cart" />
  69. </view>
  70. </template>
  71. <script>
  72. import tabber from '@/components/base/tabbar.vue'
  73. import mixinsList from '@/mixins/list.js'
  74. export default {
  75. mixins: [mixinsList],
  76. components: {
  77. tabber,
  78. },
  79. data() {
  80. return {
  81. value: 0,
  82. checkboxValue: [],
  83. options: [
  84. {
  85. text: '删除',
  86. style: {
  87. backgroundColor: '#f40'
  88. }
  89. },
  90. ],
  91. mixinsListApi: 'getCartPageList',
  92. }
  93. },
  94. computed: {
  95. totalPrice() {
  96. if (!this.checkboxValue.length) {
  97. return 0
  98. }
  99. let price = 0
  100. this.list.forEach(n => {
  101. if (this.checkboxValue.includes(n.id)) {
  102. price += n.price * n.num
  103. }
  104. })
  105. return price
  106. },
  107. },
  108. methods: {
  109. valChange(item, e) {
  110. this.$api('updateCartNum', {
  111. id: item.id,
  112. num: e.value,
  113. })
  114. },
  115. // 立即下单
  116. submit() {
  117. if (this.checkboxValue.length == 0) {
  118. uni.showToast({
  119. title: '请选择商品',
  120. icon: 'none',
  121. })
  122. return
  123. }
  124. let arr = []
  125. this.list.forEach(n => {
  126. if (this.checkboxValue.includes(n.id)) {
  127. arr.push(n)
  128. }
  129. })
  130. this.$store.commit('setPayOrderProduct', arr)
  131. this.$utils.navigateTo('/pages_order/order/createOrder')
  132. },
  133. deleteCart(e, item) {
  134. this.$api('deleteCart', {
  135. ids: item.id
  136. }, res => {
  137. this.getData()
  138. })
  139. },
  140. }
  141. }
  142. </script>
  143. <style scoped lang="scss">
  144. .page {
  145. padding-bottom: 200rpx;
  146. /deep/ .uv-swipe-action {
  147. width: 100%;
  148. }
  149. }
  150. .user {
  151. .item {
  152. background-color: #fff;
  153. display: flex;
  154. padding: 30rpx;
  155. .checkbox {
  156. display: flex;
  157. justify-content: center;
  158. align-items: center;
  159. }
  160. .image {
  161. width: 200rpx;
  162. height: 200rpx;
  163. border-radius: 20rpx;
  164. }
  165. .info {
  166. flex: 1;
  167. .title {
  168. display: flex;
  169. padding: 10rpx 20rpx;
  170. justify-content: space-between;
  171. }
  172. .unit {
  173. font-size: 24rpx;
  174. padding: 10rpx 20rpx;
  175. color: #717171;
  176. display: flex;
  177. align-items: center;
  178. }
  179. .price {
  180. color: $uni-color;
  181. font-size: 28rpx;
  182. padding: 10rpx 20rpx;
  183. text {
  184. font-size: 36rpx;
  185. font-weight: 900;
  186. }
  187. }
  188. }
  189. }
  190. .action {
  191. width: 700rpx;
  192. position: fixed;
  193. bottom: 220rpx;
  194. left: 25rpx;
  195. background-color: #fff;
  196. height: 100rpx;
  197. border-radius: 50rpx;
  198. box-shadow: 0 0 6rpx 6rpx #00000010;
  199. display: flex;
  200. justify-content: center;
  201. align-items: center;
  202. overflow: hidden;
  203. z-index: 999;
  204. .icon {
  205. position: relative;
  206. width: 80rpx;
  207. height: 80rpx;
  208. margin: 0 20rpx;
  209. image {
  210. width: 80rpx;
  211. height: 80rpx;
  212. }
  213. .num {
  214. position: absolute;
  215. right: 10rpx;
  216. top: 0rpx;
  217. background-color: $uni-color;
  218. color: #fff;
  219. font-size: 18rpx;
  220. border-radius: 50%;
  221. height: 30rpx;
  222. width: 30rpx;
  223. display: flex;
  224. justify-content: center;
  225. align-items: center;
  226. }
  227. }
  228. .price {
  229. .count {
  230. display: flex;
  231. font-size: 26rpx;
  232. align-items: center;
  233. view {
  234. color: $uni-color;
  235. margin-left: 10rpx;
  236. text {
  237. font-size: 32rpx;
  238. font-weight: 900;
  239. }
  240. }
  241. }
  242. .text {
  243. font-size: 20rpx;
  244. color: #717171;
  245. }
  246. }
  247. .btn {
  248. margin-left: auto;
  249. background-color: $uni-color;
  250. height: 100%;
  251. padding: 0 50rpx;
  252. color: #fff;
  253. display: flex;
  254. justify-content: center;
  255. align-items: center;
  256. }
  257. }
  258. }
  259. </style>