cart.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <view class="content">
  3. <!-- 商品列表 -->
  4. <view class="goods-list">
  5. <view class="item" v-for="(item,index) in carts" :key="index">
  6. <view class="choose" @click.stop="checkChange(item,index)">
  7. <image src="https://hdtobs.obs.cn-north-4.myhuaweicloud.com/fs/20250729/1753758788583.png" v-show="item.checked"></image>
  8. <image src="https://hdtobs.obs.cn-north-4.myhuaweicloud.com/fs/20250729/1753758821601.png" v-show="!item.checked"></image>
  9. </view>
  10. <image class="goods-img" :src="item.imgUrl" mode="aspectFit" @click="showProduct"></image>
  11. <view class="info-box" @click="showProduct">
  12. <view>
  13. <view class="title-box">
  14. <view class="title ellipsis">{{ item.goodsName }}</view>
  15. </view>
  16. </view>
  17. <view class="price-num">
  18. <view class="price">
  19. <text class="text" >{{item.newIntegral}}</text>
  20. <text class="unit">积分</text>
  21. <text class="unit">+</text>
  22. <text class="text" >{{item.newCash.toFixed(2)}}</text>
  23. <text class="unit">元</text>
  24. </view>
  25. <view class="num-box" @click.stop>
  26. <u-number-box v-model="item.cartNum" buttonSize="48rpx" integer :step="1" :min="1" :max="100000" @change="changeCartNum($event,item)"></u-number-box>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view v-if="carts.length == 0" class="no-data-box">
  33. <image src="https://hdtobs.obs.cn-north-4.myhuaweicloud.com/hdtappimgs/cf4a86b913a04341bb44e34bb4d37aa2.png" mode="aspectFit"></image>
  34. <view class="empty-title">购物车为空</view>
  35. <view class="empty-cart-btn x-f" @click="goPage">去逛逛</view>
  36. </view>
  37. <!-- 猜你喜欢 -->
  38. <!-- <view class="like-product">
  39. <likeProduct ref="product" />
  40. </view> -->
  41. <!-- 底部按钮 -->
  42. <view class="btn-foot">
  43. <view class="left">
  44. <view class="choose" @click="handleCheckAll()">
  45. <image src="https://hdtobs.obs.cn-north-4.myhuaweicloud.com/fs/20250729/1753758788583.png" v-show="checkAll"></image>
  46. <image src="https://hdtobs.obs.cn-north-4.myhuaweicloud.com/fs/20250729/1753758821601.png" v-show="!checkAll"></image>
  47. </view>
  48. <text class="text">全选</text>
  49. <text class="text" @click="delCart()">删除</text>
  50. </view>
  51. <view class="right">
  52. <view>
  53. <view class="total">
  54. <text class="label">合计:</text>
  55. <view class="price">
  56. <text class="unit">¥</text>
  57. <text class="num">{{totalMoney.toFixed(2)}}</text>
  58. </view>
  59. </view>
  60. <view class="total">
  61. <text class="label">所需积分:</text>
  62. <view class="price">
  63. <text class="num">{{totalIntegral}}</text>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="btn" @click="submit">结算</view>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import { getCarts,addOrUpdateCart,delCart } from '@/api/integral.js'
  74. // import likeProduct from '@/components/likeProduct.vue'
  75. export default {
  76. // components: {
  77. // likeProduct
  78. // },
  79. data() {
  80. return {
  81. totalMoney:0.00,
  82. totalIntegral: 0,
  83. carts:[],
  84. checkAll:false,
  85. }
  86. },
  87. onLoad() {
  88. this.getCarts();
  89. },
  90. onReachBottom() {
  91. // this.$refs.product.getGoodsProducts();
  92. },
  93. methods: {
  94. delCart(){
  95. var selectCarts=this.carts.filter(ele => ele.checked==true).map(ele => {
  96. return ele.id
  97. });
  98. if(selectCarts.length==0){
  99. uni.showToast({
  100. icon:'none',
  101. title: "请选择商品删除",
  102. });
  103. return;
  104. }
  105. let data = {ids:selectCarts};
  106. delCart(selectCarts).then(
  107. res => {
  108. if(res.code==200){
  109. uni.showToast({
  110. icon:'success',
  111. title: "操作成功",
  112. });
  113. this.getCarts()
  114. }else{
  115. uni.showToast({
  116. icon:'none',
  117. title: res.msg,
  118. });
  119. }
  120. },
  121. rej => {}
  122. );
  123. },
  124. computedMoney(){
  125. let totalIntegral = 0;
  126. let totalMoney = 0;
  127. let arry = this.carts.filter(item=>item.checked)
  128. arry.forEach(item => {
  129. totalIntegral += item.newIntegral * item.cartNum;
  130. totalMoney += item.newCash * item.cartNum;
  131. });
  132. this.totalIntegral = totalIntegral;
  133. this.totalMoney = totalMoney;
  134. },
  135. handleCheckAll(){
  136. this.checkAll=!this.checkAll;
  137. var that=this;
  138. this.carts.forEach((item,index,arr)=>{
  139. item.checked=that.checkAll;
  140. })
  141. this.computedMoney();
  142. },
  143. checkChange(item,index){
  144. item.checked=!item.checked;
  145. this.checkAll = this.carts.length > 0 &&this.carts.every(item=>item.checked)
  146. this.computedMoney();
  147. },
  148. changeNum(e,item) {
  149. item.cartNum = e.detail.value.replace(/\D/g, '')
  150. if (item.cartNum <= 1) {
  151. uni.showToast({
  152. title: "已经是底线啦!",
  153. icon: "none",
  154. duration: 2000
  155. });
  156. return;
  157. }
  158. if(item.cartNum < 1) {
  159. item.cartNum = 1
  160. }
  161. if(item.cartNum>=item.stock){
  162. item.cartNum=item.stock;
  163. }
  164. this.changeCartNum(item)
  165. },
  166. getCarts(){
  167. getCarts().then(
  168. res => {
  169. if(res.code==200){
  170. this.carts=res.carts;
  171. this.carts.forEach((item,index,arr)=>{
  172. item.checked=false;
  173. })
  174. this.checkAll = this.carts.length > 0 &&this.carts.every(item=>item.checked)
  175. this.computedMoney();
  176. }else{
  177. uni.showToast({
  178. icon:'none',
  179. title: "请求失败",
  180. });
  181. }
  182. },
  183. rej => {}
  184. );
  185. },
  186. changeCartNum(e,item){
  187. let data = {cartNum:e.value,goodsId:item.goodsId,isCart: 1};
  188. addOrUpdateCart(data).then(
  189. res => {
  190. if(res.code==200){
  191. this.computedMoney();
  192. }else{
  193. uni.showToast({
  194. icon:'none',
  195. title: res.msg,
  196. });
  197. }
  198. },
  199. rej => {}
  200. );
  201. },
  202. // 结算
  203. submit() {
  204. var selectCarts=this.carts.filter(ele => ele.checked==true).map(ele => {
  205. return ele.id
  206. });
  207. if(selectCarts.length==0){
  208. uni.showToast({
  209. icon:'none',
  210. title: "请选择商品",
  211. });
  212. return;
  213. }
  214. uni.navigateTo({
  215. url: '/pages_user/user/confirmIntegralOrder?type=cart&cartIds='+selectCarts.toString()
  216. })
  217. },
  218. showProduct(item){
  219. uni.navigateTo({
  220. url: '/pages_user/user/integralGoodsDetails?goodsId='+item.goodsId
  221. })
  222. },
  223. goPage() {
  224. uni.navigateTo({
  225. url: '/pages_user/integralGoodsList'
  226. })
  227. }
  228. }
  229. }
  230. </script>
  231. <style lang="scss">
  232. page {
  233. height: 100%;
  234. }
  235. .content{
  236. height: 100%;
  237. padding: 20upx;
  238. .goods-list{
  239. .item{
  240. box-sizing: border-box;
  241. background: #FFFFFF;
  242. border-radius: 16upx;
  243. margin-bottom: 20upx;
  244. padding: 30upx;
  245. display: flex;
  246. align-items: center;
  247. &:last-child{
  248. margin-bottom: 0;
  249. }
  250. .goods-img{
  251. width: 160upx;
  252. height: 160upx;
  253. background: #FFFFFF;
  254. margin-right: 30upx;
  255. flex-shrink: 0;
  256. }
  257. .info-box{
  258. display: flex;
  259. flex-direction: column;
  260. justify-content: space-between;
  261. width: calc(100% - 255upx);
  262. .title-box{
  263. width: 100%;
  264. display: flex;
  265. align-items: center;
  266. .title{
  267. flex: 1;
  268. font-size: 28upx;
  269. font-family: PingFang SC;
  270. font-weight: 500;
  271. color: #111111;
  272. line-height: 1;
  273. }
  274. }
  275. .price-num{
  276. margin-top: 24rpx;
  277. .price{
  278. margin-bottom: 24rpx;
  279. display: flex;
  280. align-items: flex-end;
  281. .unit{
  282. font-size: 24upx;
  283. font-family: PingFang SC;
  284. font-weight: 500;
  285. color: #DA251C;
  286. line-height: 1.2;
  287. margin-right: 4upx;
  288. }
  289. .text{
  290. font-size: 32upx;
  291. font-family: PingFang SC;
  292. font-weight: bold;
  293. color: #DA251C;
  294. line-height: 1;
  295. }
  296. }
  297. .num-box{
  298. display: flex;
  299. align-items: center;
  300. justify-content: flex-end;
  301. .img-box{
  302. width: 60upx;
  303. height: 60upx;
  304. // border-radius: 4upx;
  305. border: 1px solid #dddddd;
  306. display: flex;
  307. align-items: center;
  308. justify-content: center;
  309. image{
  310. width: 25rpx;
  311. height: 25rpx;
  312. }
  313. }
  314. input{
  315. width: 60upx;
  316. height: 60upx;
  317. line-height: 60upx;
  318. font-size: 28upx;
  319. font-family: PingFang SC;
  320. font-weight: 500;
  321. color: #111111;
  322. // border-radius: 4upx;
  323. border-top: 1px solid #dddddd;
  324. border-bottom: 1px solid #dddddd;
  325. text-align: center;
  326. // margin: 0 16upx;
  327. }
  328. }
  329. }
  330. }
  331. }
  332. }
  333. .like-product{
  334. padding-bottom: 120upx;
  335. }
  336. .btn-foot{
  337. box-sizing: border-box;
  338. width: 100%;
  339. height: 121upx;
  340. background: #FFFFFF;
  341. padding: 16upx 30upx 16upx 30upx;
  342. display: flex;
  343. align-items: center;
  344. justify-content: space-between;
  345. position: fixed;
  346. left: 0;
  347. bottom: 0;
  348. z-index: 99;
  349. .left{
  350. display: flex;
  351. align-items: center;
  352. .text{
  353. margin-left: 14upx;
  354. font-size: 28upx;
  355. font-family: PingFang SC;
  356. font-weight: 500;
  357. color: #666666;
  358. line-height: 1;
  359. }
  360. }
  361. .right{
  362. display: flex;
  363. align-items: center;
  364. .total{
  365. display: flex;
  366. align-items: flex-end;
  367. margin-right: 36upx;
  368. .label{
  369. font-size: 26upx;
  370. font-family: PingFang SC;
  371. font-weight: 500;
  372. color: #999999;
  373. line-height: 1.5;
  374. }
  375. .price{
  376. display: flex;
  377. align-items: flex-end;
  378. .unit{
  379. font-size: 24upx;
  380. font-family: PingFang SC;
  381. font-weight: bold;
  382. color: #DA251C;
  383. line-height: 1.2;
  384. margin-right: 10upx;
  385. }
  386. .num{
  387. font-size: 32rpx;
  388. font-family: PingFang SC;
  389. font-weight: bold;
  390. color: #DA251C;
  391. line-height: 1;
  392. }
  393. }
  394. }
  395. .btn{
  396. width: 200upx;
  397. height: 88upx;
  398. line-height: 88upx;
  399. text-align: center;
  400. font-size: 30upx;
  401. font-family: PingFang SC;
  402. font-weight: bold;
  403. color: #FFFFFF;
  404. background: #DA251C;
  405. border-radius: 44upx;
  406. }
  407. }
  408. }
  409. }
  410. .choose {
  411. margin-right: 20rpx;
  412. image{
  413. width: 36rpx;
  414. height: 36rpx;
  415. flex-shrink: 0;
  416. }
  417. }
  418. .empty-cart-btn {
  419. border: 1rpx solid #DA251C;
  420. color: #DA251C;
  421. padding: 10rpx 30rpx;
  422. border-radius: 40rpx;
  423. margin-bottom: 20vh;
  424. margin-top: 50rpx;
  425. display: inline-block;
  426. }
  427. </style>