cart.vue 15 KB

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