建材商城系统20241014
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.

355 lines
6.8 KiB

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