market.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <view class="market">
  3. <view class="marketTop">
  4. <view class="top_L">
  5. <u-icon name="map" color="#999" size="16"></u-icon>
  6. <view class="top_text">{{AddressData.address}}</view>
  7. <u-icon name="arrow-right" color="#999" size="16"></u-icon>
  8. </view>
  9. <view @click="linkto('address')" class="top_R">
  10. 编辑
  11. </view>
  12. </view>
  13. <view class="marketContent">
  14. <u-swipe-action >
  15. <u-swipe-action-item class="mc_item" v-for="(item,index) in dataList" :key="item.id" @click="swipeAaction(index,$event)"
  16. :options="options1" :show="swipeShow"
  17. >
  18. <view class="item_swipe">
  19. <checkbox :checked="item.check" @click="checkitem(item)" shape="circle"></checkbox>
  20. <view class="box_img">
  21. <u--image radius='16rpx' width="180rpx" height="180rpx" :src="item.fileList[0].fileUrl" ></u--image>
  22. </view>
  23. <view class="box_text">
  24. <view class="box_title">
  25. {{ item.productName }}
  26. </view>
  27. <view class="box_type">
  28. 已选择 {{item.specsName}}
  29. </view>
  30. <view class="box_num">
  31. <view class="bn_left">
  32. ¥{{item.specsPrice}}
  33. </view>
  34. <view class="bn_right">
  35. <u-number-box :min="1" :max="999" button-size="28" v-model="item.num"
  36. @blur="valblur($event,item,index)" @change="valChange(index,item.num)"></u-number-box>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </u-swipe-action-item>
  42. </u-swipe-action>
  43. </view>
  44. <view class="bottom">
  45. <view class="w700 bottomflexac">
  46. <view class="checkall">
  47. <u-checkbox-group >
  48. <u-checkbox :checked="checked" shape="circle" class="" @change="checkAll"></u-checkbox><text>全选</text>
  49. </u-checkbox-group>
  50. </view>
  51. <view class="bt_r">
  52. <view class="num">
  53. <view>合计:
  54. <text class="num_n">
  55. <text style="font-size:36rpx">{{shoppingCarCalcData.totalPrice || 0}}</text>
  56. </text>
  57. </view>
  58. <view @click="popupShow = !popupShow" style="font-size: 24rpx;color: #FF655B;text-align: right;margin-right: 20rpx;">{{popupShow?'关闭明细':'查看明细'}}</view>
  59. </view>
  60. <view class="btn">
  61. <u-button shape="circle" size="medium" type="primary"
  62. @click="submit">结算</u-button>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <u-popup :closeable='true' :round="10" :show="popupShow" @close="close" @open="open">
  68. <view class="popupView">
  69. <view class="scrollview">
  70. <view class="popuptitle">金额明细</view>
  71. <view class="popupimg">
  72. <view style="margin: 20rpx 10rpx" v-for="(item,index) in tempCheckArray" :key="index">
  73. <view class="box_img">
  74. <u--image radius='16rpx' width="180rpx" height="180rpx" :src="item.fileList[0].fileUrl" ></u--image>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="popupInfo">
  79. <view class="popupInfo_item">
  80. <view>商品总额</view>
  81. <view>¥ {{shoppingCarCalcData.productPrice || 0}}</view>
  82. </view>
  83. <view class="popupInfo_item">
  84. <view>加工费用</view>
  85. <view>¥ {{shoppingCarCalcData.processPrice || 0}}</view>
  86. </view>
  87. <view class="popupInfo_item">
  88. <view>包装袋费</view>
  89. <view>¥ {{shoppingCarCalcData.packagePrice || 0}}</view>
  90. </view>
  91. <!-- <view class="popupInfo_item">
  92. <view>优惠券</view>
  93. <view>¥ 0.00</view>
  94. </view> -->
  95. </view>
  96. <view class="popupInfo2">
  97. <view class="popupInfo_item2">
  98. <view>合计</view>
  99. <view>¥ {{shoppingCarCalcData.totalPrice || 0}}</view>
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. </u-popup>
  105. </view>
  106. </template>
  107. <script>
  108. import {
  109. deliveryAddressList,shoppingCartPage,
  110. cancelCollection,productcollection,removeShoppingCart,
  111. shoppingCartCreateOrder,calcShoppingCart
  112. } from '@/http/api/common.js'
  113. import * as util from '@/pages/util/util.js'
  114. export default {
  115. data() {
  116. return {
  117. popupShow:false,
  118. checked: false,
  119. disabled: false,
  120. tempCheckArray:[],//选中的数据列表
  121. dataList:[],//购物车列表
  122. options1: [
  123. // {
  124. // text: '分享',
  125. // style: {
  126. // backgroundColor: '#BBB'
  127. // }
  128. // },
  129. {
  130. text: '收藏',
  131. style: {
  132. backgroundColor: '#FF8C33'
  133. }
  134. }, {
  135. text: '删除',
  136. style: {
  137. backgroundColor: '#F6514F'
  138. }
  139. }
  140. ],
  141. swipeShow:false,
  142. AddressData:{
  143. address:'请填写收货地址'
  144. },
  145. shoppingCarCalcData:{
  146. totalPrice:0,//总价
  147. productPrice:0,//商品价格
  148. packagePrice:0,//包装费
  149. processPrice:0,//加工费
  150. }
  151. };
  152. },
  153. async onShow(e) {
  154. if(uni.getStorageSync('AppAuthorization')){
  155. //获取地址列表
  156. await this.getdeliveryAddressList()
  157. //获取购物车列表
  158. await this.getshoppingCartPage()
  159. }
  160. },
  161. methods: {
  162. async getdeliveryAddressList(){
  163. let res = await deliveryAddressList()
  164. if (res.data.code == 200) {
  165. if (res.data.data) {
  166. this.AddressData = res.data.data.find(v=>v.defaultAddress == '1')
  167. }
  168. }
  169. },
  170. async getshoppingCartPage(){
  171. //获取购物车列表
  172. let res = await shoppingCartPage({
  173. pageSize:10,
  174. pageNum:1
  175. })
  176. if (res.data.code == 200) {
  177. if (res.data.data) {
  178. this.dataList = res.data.data.rows.map(v=>{
  179. let findoldData = this.dataList.find(vv => vv.id == v.id)
  180. let check = false
  181. if (findoldData) {
  182. check = findoldData.check
  183. }
  184. return {
  185. check:check,
  186. ...v
  187. }
  188. })
  189. //获取购物车后 自动计算一次
  190. this.calcShoppingCart()
  191. }
  192. }
  193. },
  194. open() {
  195. },
  196. close() {
  197. this.popupShow = false
  198. },
  199. valblur(e,item,index){
  200. console.log(e);
  201. if (e.value == '') {
  202. console.log(item === 'object');
  203. if (typeof item === 'object') {
  204. item.num = 1
  205. this.valChange(index,item.num)
  206. }else{
  207. this[item] = 2
  208. }
  209. }
  210. },
  211. async valChange(index,num){
  212. if (this.disabled) {
  213. return
  214. }
  215. this.dataList[index].check = true
  216. this.dataList[index].num = num
  217. this.disabled = true
  218. setTimeout(() => {
  219. //点击数量触发计算
  220. this.calcShoppingCart()
  221. }, 100);
  222. },
  223. async checkitem(item){
  224. // console.log(this.dataList);
  225. item.check = !item.check
  226. // this.dataList[index].check = !this.dataList[index]?.check
  227. //点击单选框触发计算
  228. setTimeout(() => {
  229. //点击数量触发计算
  230. this.calcShoppingCart()
  231. }, 100);
  232. },
  233. //全选
  234. async checkAll() {
  235. this.checked = !this.checked
  236. this.dataList.forEach(v => {
  237. v.check = this.checked
  238. })
  239. //点击单选框触发计算
  240. setTimeout(() => {
  241. //点击数量触发计算
  242. this.calcShoppingCart()
  243. }, 100);
  244. },
  245. async calcShoppingCart(){
  246. //计算购物车价格
  247. this.tempCheckArray = this.dataList.filter(v => v.check)
  248. let shoppingCarSubmitVOList = this.tempCheckArray.map(v => {
  249. let a = {
  250. id:v.id,
  251. num:v.num
  252. }
  253. return a
  254. })
  255. let res = await calcShoppingCart({
  256. shoppingCarSubmitVOList:shoppingCarSubmitVOList
  257. })
  258. this.disabled = false
  259. if (res.data.code == 200) {
  260. this.shoppingCarCalcData = res.data.data
  261. }
  262. },
  263. swipeAaction(index,options){
  264. //index操作了第几个 ,options点了 第几个按钮
  265. console.log(index,options);
  266. // 0 收藏 1删除
  267. if (options.index == 0) {
  268. if (this.dataList[index].favorites) {
  269. util.toastFunc('已经收藏过了')
  270. }else{
  271. this.toCollection(this.dataList[index])
  272. }
  273. }else{
  274. this.removeShoppingCart(this.dataList[index])
  275. }
  276. },
  277. async toCollection(data){
  278. //收藏
  279. let res = null
  280. if (data.favorites) {
  281. // favorites true 为收藏过了 调用取消收藏接口
  282. res = await cancelCollection(data.productId)
  283. }else{
  284. res = await productcollection(data.productId)
  285. }
  286. if (res.data.code == 200) {
  287. let title = data.favorites ? '取消收藏成功' :'收藏成功'
  288. uni.showToast({
  289. title: title,
  290. duration: 2000
  291. });
  292. }
  293. },
  294. async removeShoppingCart(data){
  295. //删除
  296. let res = await removeShoppingCart(data.id)
  297. if (res.data.code == 200) {
  298. util.toastFunc('已从购物车中移除',()=>{
  299. this.getshoppingCartPage()
  300. })
  301. }
  302. },
  303. async submit(){
  304. //确认订单
  305. if (this.tempCheckArray.lenght==0) {
  306. util.toastFunc('已从购物车中移除',()=>{
  307. this.getshoppingCartPage()
  308. })
  309. }
  310. let shoppingCarSubmitVOList = this.tempCheckArray.map(v => {
  311. let a = {
  312. id:v.id
  313. }
  314. return a
  315. })
  316. //购物车下单
  317. let res = await shoppingCartCreateOrder({
  318. shoppingCarSubmitVOList:shoppingCarSubmitVOList,
  319. deliveryAddressId:this.AddressData.id
  320. })
  321. if (res.data.code == 200) {
  322. let orderId = res.data.data.id
  323. uni.navigateTo({
  324. url: '/pages/market/confirmOrder?orderId=' + orderId
  325. });
  326. }
  327. },
  328. linkto(key){
  329. if (key == 'address') {
  330. uni.navigateTo({
  331. url: '/pages/myinfo/address'
  332. });
  333. }
  334. },
  335. },
  336. };
  337. </script>
  338. <style lang="scss">
  339. .market{
  340. display: flex;
  341. flex-direction: column;
  342. align-items: center;
  343. }
  344. .btn{
  345. width: 200rpx;
  346. height: 80rpx;
  347. margin-left: 20rpx;
  348. }
  349. .bottomflexac{
  350. display: flex;
  351. align-items: center;
  352. justify-content: space-between;
  353. }
  354. .marketTop{
  355. width: 700rpx;
  356. height: 90rpx;
  357. background: #FFFFFF;
  358. border-radius: 0rpx 0rpx 0rpx 0rpx;
  359. opacity: 1;
  360. display: flex;
  361. align-items: center;
  362. justify-content: space-between;
  363. }
  364. .bottom{
  365. width: 750rpx;
  366. height: 120rpx;
  367. background-color: white;
  368. display: flex;
  369. flex-direction: row;
  370. justify-content: center;
  371. position: absolute;
  372. bottom: 0;
  373. z-index: 10076;
  374. }
  375. .top_text{
  376. width: 260rpx;
  377. max-height: 80rpx;
  378. font-size: 28rpx;
  379. font-weight: 500;
  380. color: #999999;
  381. line-height: 40rpx;
  382. // display: flex;
  383. // align-items: center;
  384. display: -webkit-box;
  385. word-break: break-all;
  386. text-overflow: ellipsis;
  387. overflow: hidden;
  388. -webkit-box-orient: vertical;
  389. -webkit-line-clamp:2;
  390. }
  391. .top_L{
  392. display: flex;
  393. align-items: center;
  394. }
  395. .top_R{
  396. width: 56rpx;
  397. height: 40rpx;
  398. font-size: 28rpx;
  399. font-weight: 500;
  400. color: #666666;
  401. }
  402. .checkall{
  403. display: flex;
  404. align-items: center;
  405. width: 150rpx;
  406. height: 40rpx;
  407. font-size: 28rpx;
  408. font-weight: 500;
  409. color: #666666;
  410. }
  411. .bt_r{
  412. min-width: 440rpx;
  413. display: flex;
  414. align-items: center;
  415. }
  416. .num{
  417. min-width: 220rpx;
  418. height: 47rpx;
  419. font-size: 28rpx;
  420. font-weight: 500;
  421. color: #666666;
  422. display: flex;
  423. flex-direction: column;
  424. }
  425. .num_n{
  426. font-size: 28rpx;
  427. font-weight: bold;
  428. color: #F6514F;
  429. }
  430. .marketContent{
  431. width: 750rpx;
  432. height: calc(100vh - 200rpx);
  433. background: #F1F1F1;
  434. border-radius: 0rpx 0rpx 0rpx 0rpx;
  435. overflow: auto;
  436. display: flex;
  437. flex-direction: column;
  438. align-items: center;
  439. }
  440. .mc_item{
  441. width: 702rpx;
  442. height: 244rpx;
  443. background: #FFFFFF;
  444. border-radius: 16rpx 16rpx 16rpx 16rpx;
  445. opacity: 1;
  446. margin-top: 24rpx;
  447. }
  448. .item_swipe{
  449. width: 702rpx;
  450. height: 244rpx;
  451. background: #FFFFFF;
  452. border-radius: 16rpx 16rpx 16rpx 16rpx;
  453. opacity: 1;
  454. display: flex;
  455. align-items: center;
  456. flex-direction: row;
  457. padding-left: 24rpx;
  458. }
  459. .box_img{
  460. width: 180rpx;
  461. height: 180rpx;
  462. background-color: #999999;
  463. border-radius: 16rpx;
  464. }
  465. .box_text{
  466. width: 392rpx;
  467. height: 200rpx;
  468. margin-left: 20rpx;
  469. display: flex;
  470. flex-direction: column;
  471. justify-content: space-between;
  472. }
  473. .box_title{
  474. width: 392rpx;
  475. height: 40rpx;
  476. font-size: 28rpx;
  477. font-weight: bold;
  478. color: #333333;
  479. line-height: 40rpx;
  480. display: -webkit-box;
  481. word-break: break-all;
  482. text-overflow: ellipsis;
  483. overflow: hidden;
  484. -webkit-box-orient: vertical;
  485. -webkit-line-clamp:1;
  486. }
  487. .box_type{
  488. width: 390rpx;
  489. height: 48rpx;
  490. background: #EEEEEE;
  491. border-radius: 8rpx 8rpx 8rpx 8rpx;
  492. opacity: 1;
  493. font-size: 28rpx;
  494. font-weight: 500;
  495. color: #999999;
  496. padding-left: 24rpx;
  497. line-height: 48rpx;
  498. display: -webkit-box;
  499. word-break: break-all;
  500. text-overflow: ellipsis;
  501. overflow: hidden;
  502. -webkit-box-orient: vertical;
  503. -webkit-line-clamp:1;
  504. }
  505. .box_num{
  506. width: 410rpx;
  507. display: flex;
  508. justify-content: space-between;
  509. align-items: center;
  510. }
  511. .bn_left{
  512. width: 106rpx;
  513. height: 38rpx;
  514. font-size: 28rpx;
  515. font-weight: bold;
  516. color: #F6514F;
  517. line-height: 36rpx;
  518. }
  519. .popupView{
  520. height: 1000rpx;
  521. display: flex;
  522. padding-top: 40rpx;
  523. flex-direction: column;
  524. align-items: center;
  525. }
  526. .scrollview{
  527. height: 850rpx;
  528. width: 702rpx;
  529. overflow: auto;
  530. }
  531. .popuptitle{
  532. // width: 128rpx;
  533. // height: 45rpx;
  534. font-size: 32rpx;
  535. font-weight: bold;
  536. color: #000000;
  537. text-align: center;
  538. }
  539. .popupimg{
  540. display: flex;
  541. flex-wrap: wrap;
  542. justify-content: flex-start;
  543. margin-top: 40rpx;
  544. }
  545. .popupInfo{
  546. width: 702rpx;
  547. height: 180rpx;
  548. background: #EEEEEE;
  549. border-radius: 16rpx 16rpx 16rpx 16rpx;
  550. opacity: 1;
  551. display: flex;
  552. align-items: center;
  553. justify-content: center;
  554. flex-direction: column;
  555. }
  556. .popupInfo_item{
  557. display: flex;
  558. justify-content: space-between;
  559. width: 654rpx;
  560. height: 40rpx;
  561. font-size: 28rpx;
  562. font-weight: 500;
  563. color: #666666;
  564. line-height: 36rpx;
  565. }
  566. .popupInfo2{
  567. width: 702rpx;
  568. height: 80rpx;
  569. display: flex;
  570. align-items: center;
  571. justify-content: center;
  572. flex-direction: column;
  573. }
  574. .popupInfo_item2{
  575. display: flex;
  576. justify-content: space-between;
  577. width: 654rpx;
  578. height: 40rpx;
  579. font-size: 28rpx;
  580. font-weight: bold;
  581. color: #333;
  582. line-height: 36rpx;
  583. }
  584. checkbox .wx-checkbox-input {
  585. width: 32rpx;
  586. height: 32rpx;
  587. border-color: #409eff;
  588. background-color: transparent;
  589. transition: background-color .2s;
  590. border-radius: 50%;
  591. }
  592. checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  593. color: #fff; /* 这里也可以设置对钩的颜色 */
  594. background-color: #409eff;
  595. border-radius: 50%;
  596. }
  597. .u-swipe-action-item{
  598. margin-top: 24rpx;
  599. border-radius: 16rpx;
  600. }
  601. </style>