cart.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/jian.png" mode=""></image>
  26. <image v-else src="https://hst2-1323137866.cos.ap-chongqing.myqcloud.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://hst2-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/add.png" mode=""></image>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view>
  38. <u-popup :show="dictshow" @close="closedict" mode="center" :closeOnClickOverlay="false" round="20">
  39. <view class="w600 h500 radius20 ">
  40. <view class="p40 justify-end">
  41. <u-icon name="close" color="#7c7c7c" size="28" @click="closedict"></u-icon>
  42. <!-- <image src="/static/images/close24.png" class="w40 h40" ></image> -->
  43. </view>
  44. <view class="m20">
  45. <view class="justify-start align-center u-border radius20 p20">
  46. <view>订单类型:</view>
  47. <view class="color6 flex-1" @click="cardshow=true">{{cardvalue?cardvalue:'请选择订单类型'}}</view>
  48. </view>
  49. <view class="justify-start align-center u-border radius20 p20 mt20 mb60">
  50. <view>媒体类型:</view>
  51. <view class="color6 flex-1" @click="videoshow=true">{{videovalue?videovalue:'请选择媒体类型'}}</view>
  52. </view>
  53. </view>
  54. <view class="subdict " @click="submitgoods">确认</view>
  55. </view>
  56. </u-popup>
  57. </view>
  58. <view>
  59. <u-popup :show="cardshow" mode="bottom" @close="cardshow=!cardshow" :closeOnClickOverlay="true" closeIconPos='top-right'>
  60. <view class=" h600">
  61. <view class="mb20" style="text-align: center;">
  62. <view style="display: inline-block; ">订单类型</view>
  63. <u-icon name="close-circle" color="#ccc" size="28"
  64. @click="cardshow=!cardshow" style="display: inline-block;float: left;"></u-icon>
  65. </view>
  66. <view class="justify-start wrap">
  67. <view class="p16 mlr4" v-for="(item,index) in cardlist" :key="index">
  68. <u-tag :text="item.dictLabel" :plain="!item.checked" type="primary" :name="index"
  69. @click="checkboxClick">
  70. </u-tag>
  71. </view>
  72. <view class="base-color-red fs24 bor-red p8 radius8 plr12" v-if="cardlist.length==0">暂无订单类型</view>
  73. </view>
  74. <view class="centerV">
  75. <view @click="getcardid" class="surebtn">确定</view>
  76. </view>
  77. </view>
  78. </u-popup>
  79. </view>
  80. <view>
  81. <u-popup :show="videoshow" mode="bottom" @close="videoshow=!videoshow" :closeOnClickOverlay="true" closeIconPos='top-right'>
  82. <view class="h600">
  83. <view class="mb20" style="text-align: center;">
  84. <view style="display: inline-block; ">媒体类型</view>
  85. <u-icon name="close-circle" color="#ccc" size="28"
  86. @click="videoshow=!videoshow" style="display: inline-block;float: left;"></u-icon>
  87. </view>
  88. <view class="justify-start wrap">
  89. <view class="p16 mlr4" v-for="(item,index) in videolist" :key="index">
  90. <u-tag :text="item.dictLabel" :plain="!item.checked" type="primary" :name="index"
  91. @click="checkboxClickA">
  92. </u-tag>
  93. </view>
  94. <view class="base-color-red fs24 bor-red p8 radius8 plr12" v-if="videolist.length==0">暂无媒体类型</view>
  95. </view>
  96. <view class="centerV">
  97. <view @click="getvideoid" class="surebtn">确定</view>
  98. </view>
  99. </view>
  100. </u-popup>
  101. </view>
  102. <!-- 底部按钮 -->
  103. <view class="btn-foot">
  104. <view class="left">
  105. <label>
  106. <checkbox :checked="checkAll" @click="handleCheckAll()" />
  107. </label>
  108. <text class="text">全选</text>
  109. <text class="text" @click="delCart()">删除</text>
  110. </view>
  111. <view class="right">
  112. <view class="total">
  113. <text class="label">合计:</text>
  114. <view class="price">
  115. <text class="unit">¥</text>
  116. <text class="num">{{totalMoney.toFixed(2)}}</text>
  117. </view>
  118. </view>
  119. <view class="btn" @click="submit">制单</view>
  120. </view>
  121. </view>
  122. </view>
  123. </template>
  124. <script>
  125. import {getCarts,cartNum,delCart} from '@/api/product'
  126. import {createSalesOrder} from '@/api/companyOrder.js'
  127. export default {
  128. data() {
  129. return {
  130. totalMoney:0.00,
  131. carts:[],
  132. checkAll:false,
  133. selectCartsid:[],
  134. dictshow:false,
  135. cardvalue:'',
  136. cardid:'',
  137. videovalue:'',
  138. videoid:'',
  139. cardshow:false,
  140. videoshow:false,
  141. videolist:{},
  142. cardlist:{}
  143. }
  144. },
  145. onLoad() {
  146. this.getCarts();
  147. const dicts=JSON.parse(uni.getStorageSync('dicts'))
  148. console.log(dicts)
  149. this.videolist=dicts.storeOrderMedium.map(item => {
  150. return {
  151. ...item,
  152. checked: false,
  153. }
  154. })
  155. this.cardlist=dicts.storeOrderType.map(item => {
  156. return {
  157. ...item,
  158. checked: false,
  159. }
  160. })
  161. console.log(this.cardlist)
  162. },
  163. methods: {
  164. checkboxClickA(name){
  165. this.videolist.map((item, index) => {
  166. item.checked = index === name ? true : false;
  167. });
  168. console.log(name)
  169. },
  170. getvideoid(){
  171. this.videovalue = this.videolist.filter(item => item.checked)
  172. .map(v => v.dictLabel).join('')
  173. console.log(this.cardvalue)
  174. this.videoid = this.videolist.filter(item => item.checked).map(v => v.dictValue).join('')
  175. this.videoshow=false
  176. },
  177. checkboxClick(name){
  178. this.cardlist.map((item, index) => {
  179. item.checked = index === name ? true : false;
  180. });
  181. console.log(name)
  182. },
  183. getcardid(){
  184. this.cardvalue = this.cardlist.filter(item => item.checked)
  185. .map(v => v.dictLabel).join('')
  186. console.log(this.cardvalue)
  187. this.cardid = this.cardlist.filter(item => item.checked).map(v => v.dictValue).join('')
  188. this.cardshow=false
  189. },
  190. closedict(){
  191. this.dictshow=!this.dictshow
  192. },
  193. changeNum(e,item) {
  194. item.cartNum = e.detail.value.replace(/\D/g, '')
  195. if (item.cartNum <= 1) {
  196. uni.showToast({
  197. title: "已经是底线啦!",
  198. icon: "none",
  199. duration: 2000
  200. });
  201. return;
  202. }
  203. if(item.cartNum < 1) {
  204. item.cartNum = 1
  205. }
  206. if(item.cartNum>=item.stock){
  207. item.cartNum=item.stock;
  208. }
  209. this.changeCartNum(item)
  210. },
  211. delCart(){
  212. var selectCarts=this.carts.filter(ele => ele.checked==true).map(ele => {
  213. return ele.id
  214. });
  215. if(selectCarts.length==0){
  216. uni.showToast({
  217. icon:'none',
  218. title: "请选择商品删除",
  219. });
  220. return;
  221. }
  222. let data = {ids:selectCarts};
  223. delCart(data).then(
  224. res => {
  225. if(res.code==200){
  226. uni.showToast({
  227. icon:'success',
  228. title: "操作成功",
  229. });
  230. this.getCarts()
  231. }else{
  232. uni.showToast({
  233. icon:'none',
  234. title: res.msg,
  235. });
  236. }
  237. },
  238. rej => {}
  239. );
  240. console.log(selectCarts)
  241. },
  242. computedMoney(){
  243. var money=0;
  244. var that=this;
  245. this.carts.forEach((item,index,arr)=>{
  246. if(item.checked){
  247. money+=item.price*item.cartNum;
  248. }
  249. })
  250. console.log(money);
  251. this.totalMoney=money;
  252. },
  253. handleCheckAll(){
  254. this.checkAll=!this.checkAll;
  255. var that=this;
  256. this.carts.forEach((item,index,arr)=>{
  257. item.checked=that.checkAll;
  258. })
  259. this.computedMoney();
  260. },
  261. checkChange(item){
  262. item.checked=!item.checked;
  263. this.computedMoney();
  264. },
  265. changeCartNum(item){
  266. let data = {number:item.cartNum,id:item.id};
  267. cartNum(data).then(
  268. res => {
  269. if(res.code==200){
  270. uni.showToast({
  271. icon:'none',
  272. title: "操作成功",
  273. });
  274. this.computedMoney();
  275. }else{
  276. uni.showToast({
  277. icon:'none',
  278. title: res.msg,
  279. });
  280. }
  281. },
  282. rej => {}
  283. );
  284. },
  285. getCarts(){
  286. getCarts().then(
  287. res => {
  288. if(res.code==200){
  289. this.carts=res.carts;
  290. this.carts.forEach((item,index,arr)=>{
  291. item.checked=false;
  292. })
  293. this.computedMoney();
  294. }else{
  295. uni.showToast({
  296. icon:'none',
  297. title: "请求失败",
  298. });
  299. }
  300. },
  301. rej => {}
  302. );
  303. },
  304. // 购物车减法
  305. delNum(item) {
  306. if (item.cartNum <= 1) {
  307. uni.showToast({
  308. title: "已经是底线啦!",
  309. icon: "none",
  310. duration: 2000
  311. });
  312. return;
  313. }
  314. item.cartNum --
  315. if(item.cartNum < 1) {
  316. item.cartNum = 1
  317. }
  318. this.changeCartNum(item)
  319. },
  320. // 购物车加法
  321. addNum(item) {
  322. console.log(item)
  323. item.cartNum++
  324. if(item.cartNum>=item.stock){
  325. item.cartNum=item.stock;
  326. }
  327. this.changeCartNum(item)
  328. },
  329. submitgoods(){
  330. //选择后提交制单
  331. var data={
  332. token:uni.getStorageSync('CompanyUserToken'),
  333. cateIds:this.selectCartsid.toString(),
  334. orderType:this.cardid,
  335. orderMedium:this.videoid
  336. }
  337. createSalesOrder(data).then(
  338. res => {
  339. if(res.code==200){
  340. uni.navigateTo({
  341. url: './confirmCompanyOrder?orderKey='+res.orderKey
  342. })
  343. }else{
  344. uni.showToast({
  345. icon:'none',
  346. title: "请求失败",
  347. });
  348. }
  349. },
  350. rej => {}
  351. );
  352. },
  353. // 结算
  354. submit() {
  355. this.selectCartsid=this.carts.filter(ele => ele.checked==true).map(ele => {
  356. return ele.id
  357. });
  358. if(this.selectCartsid.length==0){
  359. uni.showToast({
  360. icon:'none',
  361. title: "请选择商品",
  362. });
  363. return;
  364. }
  365. this.dictshow=true
  366. console.log(this.dictshow)
  367. },
  368. }
  369. }
  370. </script>
  371. <style lang="scss">
  372. .surebtn{
  373. margin: 20rpx 0;
  374. background-color: #2BC7B9;
  375. color: #fff;
  376. width: 80%;
  377. text-align: center;
  378. padding: 20rpx 0;
  379. border-radius: 40rpx;
  380. }
  381. .subdict{
  382. width: 300rpx;
  383. height: 80rpx;
  384. line-height: 80rpx;
  385. background-color: #2BC7B9;
  386. border-radius: 200rpx;
  387. color: #fff;
  388. text-align: center;
  389. font-size: 28rpx;
  390. margin: 0 auto;
  391. }
  392. page {
  393. height: 100%;
  394. }
  395. .content{
  396. height: 100%;
  397. padding: 20upx;
  398. .goods-list{
  399. padding-bottom: 120upx;
  400. .item{
  401. box-sizing: border-box;
  402. height: 221upx;
  403. background: #FFFFFF;
  404. border-radius: 16upx;
  405. margin-bottom: 20upx;
  406. padding: 30upx;
  407. display: flex;
  408. align-items: center;
  409. &:last-child{
  410. margin-bottom: 0;
  411. }
  412. .goods-img{
  413. width: 160upx;
  414. height: 160upx;
  415. background: #FFFFFF;
  416. margin-right: 30upx;
  417. flex-shrink: 0;
  418. }
  419. .info-box{
  420. height: 160upx;
  421. display: flex;
  422. flex-direction: column;
  423. justify-content: space-between;
  424. width: calc(100% - 255upx);
  425. .title-box{
  426. width: 100%;
  427. display: flex;
  428. align-items: center;
  429. .tag{
  430. padding: 0 6upx;
  431. height: 30upx;
  432. line-height: 30upx;
  433. font-size: 22upx;
  434. font-family: PingFang SC;
  435. font-weight: bold;
  436. color: #FFFFFF;
  437. background: linear-gradient(90deg, #66b2ef 0%, #2BC7B9 100%);
  438. border-radius: 4upx;
  439. margin-right: 10upx;
  440. flex-shrink: 0;
  441. }
  442. .title{
  443. flex: 1;
  444. font-size: 28upx;
  445. font-family: PingFang SC;
  446. font-weight: 500;
  447. color: #111111;
  448. line-height: 1;
  449. }
  450. }
  451. .intro{
  452. font-size: 24upx;
  453. font-family: PingFang SC;
  454. font-weight: 500;
  455. color: #999999;
  456. margin-top: 22upx;
  457. line-height: 1;
  458. }
  459. .price-num{
  460. display: flex;
  461. align-items: center;
  462. justify-content: space-between;
  463. .price{
  464. display: flex;
  465. align-items: flex-end;
  466. .unit{
  467. font-size: 24upx;
  468. font-family: PingFang SC;
  469. font-weight: 500;
  470. color: #FF6633;
  471. line-height: 1.2;
  472. margin-right: 4upx;
  473. }
  474. .text{
  475. font-size: 32upx;
  476. font-family: PingFang SC;
  477. font-weight: bold;
  478. color: #FF6633;
  479. line-height: 1;
  480. }
  481. }
  482. .num-box{
  483. display: flex;
  484. align-items: center;
  485. .img-box{
  486. width: 60upx;
  487. height: 60upx;
  488. // border-radius: 4upx;
  489. border: 1px solid #dddddd;
  490. display: flex;
  491. align-items: center;
  492. justify-content: center;
  493. image{
  494. width: 25rpx;
  495. height: 25rpx;
  496. }
  497. }
  498. input{
  499. width: 60upx;
  500. height: 60upx;
  501. line-height: 60upx;
  502. font-size: 28upx;
  503. font-family: PingFang SC;
  504. font-weight: 500;
  505. color: #111111;
  506. // border-radius: 4upx;
  507. border-top: 1px solid #dddddd;
  508. border-bottom: 1px solid #dddddd;
  509. text-align: center;
  510. // margin: 0 16upx;
  511. }
  512. }
  513. }
  514. }
  515. }
  516. }
  517. .btn-foot{
  518. box-sizing: border-box;
  519. width: 100%;
  520. height: 121upx;
  521. background: #FFFFFF;
  522. padding: 16upx 30upx 16upx 60upx;
  523. display: flex;
  524. align-items: center;
  525. justify-content: space-between;
  526. position: fixed;
  527. left: 0;
  528. bottom: 0;
  529. z-index: 99;
  530. .left{
  531. display: flex;
  532. align-items: center;
  533. .text{
  534. margin-left: 14upx;
  535. font-size: 28upx;
  536. font-family: PingFang SC;
  537. font-weight: 500;
  538. color: #666666;
  539. line-height: 1;
  540. }
  541. }
  542. .right{
  543. display: flex;
  544. align-items: center;
  545. .total{
  546. display: flex;
  547. align-items: flex-end;
  548. margin-right: 36upx;
  549. .label{
  550. font-size: 26upx;
  551. font-family: PingFang SC;
  552. font-weight: 500;
  553. color: #999999;
  554. line-height: 1.5;
  555. }
  556. .price{
  557. display: flex;
  558. align-items: flex-end;
  559. .unit{
  560. font-size: 32upx;
  561. font-family: PingFang SC;
  562. font-weight: bold;
  563. color: #FF6633;
  564. line-height: 1.2;
  565. margin-right: 10upx;
  566. }
  567. .num{
  568. font-size: 30upx;
  569. font-family: PingFang SC;
  570. font-weight: bold;
  571. color: #FF6633;
  572. line-height: 1;
  573. }
  574. }
  575. }
  576. .btn{
  577. width: 200upx;
  578. height: 88upx;
  579. line-height: 88upx;
  580. text-align: center;
  581. font-size: 30upx;
  582. font-family: PingFang SC;
  583. font-weight: bold;
  584. color: #FFFFFF;
  585. background: #2BC7B9;
  586. border-radius: 44upx;
  587. }
  588. }
  589. }
  590. }
  591. </style>