cart.vue 9.9 KB

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