cart.vue 10 KB

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