珠宝小程序前端代码
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.

298 lines
5.6 KiB

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