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

360 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. <quick-order-entry
  94. ref="quickOrderEntry"
  95. bottom="50vh"
  96. />
  97. <kefu></kefu>
  98. <tabber select="cart" />
  99. </view>
  100. </template>
  101. <script>
  102. import tabber from '@/components/base/tabbar.vue'
  103. import mixinsList from '@/mixins/list.js'
  104. export default {
  105. mixins : [mixinsList],
  106. components: {
  107. tabber,
  108. },
  109. data() {
  110. return {
  111. isLogin: false,
  112. value : 0,
  113. checkboxValue : [],
  114. options: [
  115. {
  116. text: '删除',
  117. style: {
  118. backgroundColor: '#f40'
  119. }
  120. },
  121. ],
  122. mixinsListApi : '',
  123. }
  124. },
  125. computed: {
  126. totalPrice(){
  127. if (!this.checkboxValue.length) {
  128. return 0
  129. }
  130. let price = 0
  131. this.list.forEach(n => {
  132. if(this.checkboxValue.includes(n.id)){
  133. price += n.price * n.selectNum
  134. }
  135. })
  136. return Number(price).toFixed(2)
  137. },
  138. },
  139. onLoad(){
  140. this.checkLogin()
  141. },
  142. onShow() {
  143. this.checkLogin()
  144. },
  145. methods: {
  146. // 检查是否登录
  147. checkLogin() {
  148. const token = uni.getStorageSync('token')
  149. this.isLogin = !!token
  150. if (this.isLogin) {
  151. this.mixinsListApi = 'getCartPageList'
  152. this.getData()
  153. }
  154. },
  155. getDataThen(list, total, result){
  156. result.records = list.map(res => {
  157. return {
  158. ...res.shop,
  159. cartId : res.id,
  160. selectNum : res.num,
  161. }
  162. })
  163. },
  164. valChange(item, e) {
  165. this.$api('updateCartNum', {
  166. id: item.cartId,
  167. num: e.value,
  168. })
  169. },
  170. // 立即下单
  171. submit(){
  172. if(this.checkboxValue.length == 0){
  173. uni.showToast({
  174. title: '请选择商品',
  175. icon: 'none',
  176. })
  177. return
  178. }
  179. let arr = []
  180. this.list.forEach(n => {
  181. if(this.checkboxValue.includes(n.id)){
  182. arr.push(n)
  183. }
  184. })
  185. this.$store.commit('setPayOrderProduct', arr)
  186. this.$utils.navigateTo('/pages_order/order/createOrder')
  187. },
  188. deleteCart(e, item){
  189. this.$api('deleteCart', {
  190. ids : item.cartId
  191. }, res => {
  192. this.getData()
  193. })
  194. },
  195. }
  196. }
  197. </script>
  198. <style scoped lang="scss">
  199. .page {
  200. padding-bottom: 200rpx;
  201. /deep/ .uv-swipe-action{
  202. width: 100%;
  203. }
  204. }
  205. .not-login {
  206. display: flex;
  207. flex-direction: column;
  208. align-items: center;
  209. justify-content: center;
  210. height: 400rpx;
  211. background-color: #fff;
  212. margin: 20rpx;
  213. border-radius: 16rpx;
  214. .tips {
  215. font-size: 32rpx;
  216. color: #666;
  217. margin-bottom: 30rpx;
  218. }
  219. .login-btn {
  220. background-color: $uni-color;
  221. color: #fff;
  222. padding: 20rpx 80rpx;
  223. border-radius: 40rpx;
  224. font-size: 30rpx;
  225. }
  226. }
  227. .user {
  228. .item{
  229. background-color: #fff;
  230. display: flex;
  231. padding: 30rpx;
  232. .checkbox{
  233. display: flex;
  234. justify-content: center;
  235. align-items: center;
  236. }
  237. .image{
  238. width: 200rpx;
  239. height: 200rpx;
  240. border-radius: 20rpx;
  241. }
  242. .info{
  243. flex: 1;
  244. .title{
  245. display: flex;
  246. padding: 10rpx 20rpx;
  247. justify-content: space-between;
  248. }
  249. .unit{
  250. font-size: 24rpx;
  251. padding: 10rpx 20rpx;
  252. color: #717171;
  253. display: flex;
  254. align-items: center;
  255. }
  256. .price{
  257. color: $uni-color;
  258. font-size: 28rpx;
  259. padding: 10rpx 20rpx;
  260. text{
  261. font-size: 36rpx;
  262. font-weight: 900;
  263. }
  264. }
  265. }
  266. }
  267. .action{
  268. width: 700rpx;
  269. position: fixed;
  270. bottom: 220rpx;
  271. left: 25rpx;
  272. background-color: #fff;
  273. height: 100rpx;
  274. border-radius: 50rpx;
  275. box-shadow: 0 0 6rpx 6rpx #00000010;
  276. display: flex;
  277. justify-content: center;
  278. align-items: center;
  279. overflow: hidden;
  280. z-index: 999;
  281. .icon{
  282. position: relative;
  283. width: 80rpx;
  284. height: 80rpx;
  285. margin: 0 20rpx;
  286. image{
  287. width: 80rpx;
  288. height: 80rpx;
  289. }
  290. .num{
  291. position: absolute;
  292. right: 10rpx;
  293. top: 0rpx;
  294. background-color: $uni-color;
  295. color: #fff;
  296. font-size: 18rpx;
  297. border-radius: 50%;
  298. height: 30rpx;
  299. width: 30rpx;
  300. display: flex;
  301. justify-content: center;
  302. align-items: center;
  303. }
  304. }
  305. .price{
  306. .count{
  307. display: flex;
  308. font-size: 26rpx;
  309. align-items: center;
  310. view{
  311. color: $uni-color;
  312. margin-left: 10rpx;
  313. text{
  314. font-size: 32rpx;
  315. font-weight: 900;
  316. }
  317. }
  318. }
  319. .text{
  320. font-size: 20rpx;
  321. color: #717171;
  322. }
  323. }
  324. .btn{
  325. margin-left: auto;
  326. background-color: $uni-color;
  327. height: 100%;
  328. padding: 0 50rpx;
  329. color: #fff;
  330. display: flex;
  331. justify-content: center;
  332. align-items: center;
  333. }
  334. }
  335. }
  336. </style>