market.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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 @click="linkto('address','1')" 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. if (uni.getStorageSync('selectAddress')) {
  161. this.AddressData = JSON.parse(uni.getStorageSync('selectAddress'))
  162. }
  163. },
  164. methods: {
  165. async getdeliveryAddressList(){
  166. let res = await deliveryAddressList()
  167. if (res.data.code == 200) {
  168. if (res.data.data) {
  169. this.AddressData = res.data.data.find(v=>v.defaultAddress == '1')
  170. if (res.data.data.lenght == 1) {
  171. this.AddressData = res.data.data[0]
  172. }
  173. }
  174. }
  175. },
  176. async getshoppingCartPage(){
  177. //获取购物车列表
  178. let res = await shoppingCartPage({
  179. pageSize:10,
  180. pageNum:1
  181. })
  182. if (res.data.code == 200) {
  183. if (res.data.data) {
  184. this.dataList = res.data.data.rows.map(v=>{
  185. let findoldData = this.dataList.find(vv => vv.id == v.id)
  186. let check = false
  187. if (findoldData) {
  188. check = findoldData.check
  189. }
  190. return {
  191. check:check,
  192. ...v
  193. }
  194. })
  195. let total = res.data.data.total || 0
  196. uni.setStorageSync('shoppingCartTotal',total)
  197. if (total != 0) {
  198. uni.setTabBarBadge({
  199. index: 3,
  200. text: total+''
  201. });
  202. }else{
  203. uni.hideTabBarRedDot({
  204. index: 3,
  205. });
  206. }
  207. //获取购物车后 自动计算一次
  208. this.calcShoppingCart()
  209. }
  210. }
  211. },
  212. open() {
  213. },
  214. close() {
  215. this.popupShow = false
  216. },
  217. valblur(e,item,index){
  218. console.log(e);
  219. if (e.value == '') {
  220. console.log(item === 'object');
  221. if (typeof item === 'object') {
  222. item.num = 1
  223. this.valChange(index,item.num)
  224. }else{
  225. this[item] = 2
  226. }
  227. }
  228. },
  229. async valChange(index,num){
  230. if (this.disabled) {
  231. return
  232. }
  233. this.dataList[index].check = true
  234. this.dataList[index].num = num
  235. this.disabled = true
  236. setTimeout(() => {
  237. //点击数量触发计算
  238. this.calcShoppingCart()
  239. }, 100);
  240. },
  241. async checkitem(item){
  242. // console.log(this.dataList);
  243. item.check = !item.check
  244. // this.dataList[index].check = !this.dataList[index]?.check
  245. //点击单选框触发计算
  246. setTimeout(() => {
  247. //点击数量触发计算
  248. this.calcShoppingCart()
  249. }, 100);
  250. },
  251. //全选
  252. async checkAll() {
  253. this.checked = !this.checked
  254. this.dataList.forEach(v => {
  255. v.check = this.checked
  256. })
  257. //点击单选框触发计算
  258. setTimeout(() => {
  259. //点击数量触发计算
  260. this.calcShoppingCart()
  261. }, 100);
  262. },
  263. async calcShoppingCart(){
  264. //计算购物车价格
  265. this.tempCheckArray = this.dataList.filter(v => v.check)
  266. let shoppingCarSubmitVOList = this.tempCheckArray.map(v => {
  267. let a = {
  268. id:v.id,
  269. num:v.num
  270. }
  271. return a
  272. })
  273. let res = await calcShoppingCart({
  274. shoppingCarSubmitVOList:shoppingCarSubmitVOList
  275. })
  276. this.disabled = false
  277. if (res.data.code == 200) {
  278. this.shoppingCarCalcData = res.data.data
  279. }
  280. },
  281. swipeAaction(index,options){
  282. //index操作了第几个 ,options点了 第几个按钮
  283. console.log(index,options);
  284. // 0 收藏 1删除
  285. if (options.index == 0) {
  286. if (this.dataList[index].favorites) {
  287. util.toastFunc('已经收藏过了')
  288. }else{
  289. this.toCollection(this.dataList[index])
  290. }
  291. }else{
  292. this.removeShoppingCart(this.dataList[index])
  293. }
  294. },
  295. async toCollection(data){
  296. //收藏
  297. let res = null
  298. if (data.favorites) {
  299. // favorites true 为收藏过了 调用取消收藏接口
  300. res = await cancelCollection(data.productId)
  301. }else{
  302. res = await productcollection(data.productId)
  303. }
  304. if (res.data.code == 200) {
  305. let title = data.favorites ? '取消收藏成功' :'收藏成功'
  306. uni.showToast({
  307. title: title,
  308. duration: 2000
  309. });
  310. }
  311. },
  312. async removeShoppingCart(data){
  313. //删除
  314. let res = await removeShoppingCart(data.id)
  315. if (res.data.code == 200) {
  316. util.toastFunc('已从购物车中移除',()=>{
  317. this.getshoppingCartPage()
  318. })
  319. }
  320. },
  321. async submit(){
  322. if (!this.AddressData || !this.AddressData?.id) {
  323. util.toastFunc('请至少设置一个默认地址',()=>{
  324. this.linkto('address')
  325. })
  326. }
  327. //确认订单
  328. if (this.tempCheckArray.lenght==0) {
  329. util.toastFunc('已从购物车中移除',()=>{
  330. this.getshoppingCartPage()
  331. })
  332. }
  333. console.log('this.tempCheckArray',this.tempCheckArray);
  334. let shoppingCarSubmitVOList = this.tempCheckArray.map(v => {
  335. let a = {
  336. id:v.id
  337. }
  338. return a
  339. })
  340. //购物车下单
  341. let res = await shoppingCartCreateOrder({
  342. shoppingCarSubmitVOList:shoppingCarSubmitVOList,
  343. deliveryAddressId:this.AddressData.id
  344. })
  345. if (res.data.code == 200) {
  346. let orderId = res.data.data.id
  347. uni.navigateTo({
  348. url: '/pages/market/confirmOrder?orderId=' + orderId
  349. });
  350. }
  351. },
  352. linkto(key,type=''){
  353. if (key == 'address') {
  354. uni.navigateTo({
  355. url: '/pages/myinfo/address?selectAddress='+type
  356. });
  357. }
  358. },
  359. },
  360. };
  361. </script>
  362. <style lang="scss">
  363. .market{
  364. display: flex;
  365. flex-direction: column;
  366. align-items: center;
  367. }
  368. .btn{
  369. width: 200rpx;
  370. height: 80rpx;
  371. margin-left: 20rpx;
  372. }
  373. .bottomflexac{
  374. display: flex;
  375. align-items: center;
  376. justify-content: space-between;
  377. }
  378. .marketTop{
  379. width: 700rpx;
  380. height: 90rpx;
  381. background: #FFFFFF;
  382. border-radius: 0rpx 0rpx 0rpx 0rpx;
  383. opacity: 1;
  384. display: flex;
  385. align-items: center;
  386. justify-content: space-between;
  387. }
  388. .bottom{
  389. width: 750rpx;
  390. height: 120rpx;
  391. background-color: white;
  392. display: flex;
  393. flex-direction: row;
  394. justify-content: center;
  395. position: absolute;
  396. bottom: 0;
  397. z-index: 10076;
  398. }
  399. .top_text{
  400. width: 260rpx;
  401. max-height: 80rpx;
  402. font-size: 28rpx;
  403. font-weight: 500;
  404. color: #999999;
  405. line-height: 40rpx;
  406. // display: flex;
  407. // align-items: center;
  408. display: -webkit-box;
  409. word-break: break-all;
  410. text-overflow: ellipsis;
  411. overflow: hidden;
  412. -webkit-box-orient: vertical;
  413. -webkit-line-clamp:2;
  414. }
  415. .top_L{
  416. display: flex;
  417. align-items: center;
  418. }
  419. .top_R{
  420. width: 56rpx;
  421. height: 40rpx;
  422. font-size: 28rpx;
  423. font-weight: 500;
  424. color: #666666;
  425. }
  426. .checkall{
  427. display: flex;
  428. align-items: center;
  429. width: 150rpx;
  430. height: 40rpx;
  431. font-size: 28rpx;
  432. font-weight: 500;
  433. color: #666666;
  434. }
  435. .bt_r{
  436. min-width: 440rpx;
  437. display: flex;
  438. align-items: center;
  439. }
  440. .num{
  441. min-width: 220rpx;
  442. height: 47rpx;
  443. font-size: 28rpx;
  444. font-weight: 500;
  445. color: #666666;
  446. display: flex;
  447. flex-direction: column;
  448. }
  449. .num_n{
  450. font-size: 28rpx;
  451. font-weight: bold;
  452. color: #F6514F;
  453. }
  454. .marketContent{
  455. width: 750rpx;
  456. height: calc(100vh - 200rpx);
  457. background: #F1F1F1;
  458. border-radius: 0rpx 0rpx 0rpx 0rpx;
  459. overflow: auto;
  460. display: flex;
  461. flex-direction: column;
  462. align-items: center;
  463. }
  464. .mc_item{
  465. width: 702rpx;
  466. height: 244rpx;
  467. background: #FFFFFF;
  468. border-radius: 16rpx 16rpx 16rpx 16rpx;
  469. opacity: 1;
  470. margin-top: 24rpx;
  471. }
  472. .item_swipe{
  473. width: 702rpx;
  474. height: 244rpx;
  475. background: #FFFFFF;
  476. border-radius: 16rpx 16rpx 16rpx 16rpx;
  477. opacity: 1;
  478. display: flex;
  479. align-items: center;
  480. flex-direction: row;
  481. padding-left: 24rpx;
  482. }
  483. .box_img{
  484. width: 180rpx;
  485. height: 180rpx;
  486. background-color: #999999;
  487. border-radius: 16rpx;
  488. }
  489. .box_text{
  490. width: 392rpx;
  491. height: 200rpx;
  492. margin-left: 20rpx;
  493. display: flex;
  494. flex-direction: column;
  495. justify-content: space-between;
  496. }
  497. .box_title{
  498. width: 392rpx;
  499. height: 40rpx;
  500. font-size: 28rpx;
  501. font-weight: bold;
  502. color: #333333;
  503. line-height: 40rpx;
  504. display: -webkit-box;
  505. word-break: break-all;
  506. text-overflow: ellipsis;
  507. overflow: hidden;
  508. -webkit-box-orient: vertical;
  509. -webkit-line-clamp:1;
  510. }
  511. .box_type{
  512. width: 390rpx;
  513. height: 48rpx;
  514. background: #EEEEEE;
  515. border-radius: 8rpx 8rpx 8rpx 8rpx;
  516. opacity: 1;
  517. font-size: 28rpx;
  518. font-weight: 500;
  519. color: #999999;
  520. padding-left: 24rpx;
  521. line-height: 48rpx;
  522. display: -webkit-box;
  523. word-break: break-all;
  524. text-overflow: ellipsis;
  525. overflow: hidden;
  526. -webkit-box-orient: vertical;
  527. -webkit-line-clamp:1;
  528. }
  529. .box_num{
  530. width: 410rpx;
  531. display: flex;
  532. justify-content: space-between;
  533. align-items: center;
  534. }
  535. .bn_left{
  536. width: 106rpx;
  537. height: 38rpx;
  538. font-size: 28rpx;
  539. font-weight: bold;
  540. color: #F6514F;
  541. line-height: 36rpx;
  542. }
  543. .popupView{
  544. height: 1000rpx;
  545. display: flex;
  546. padding-top: 40rpx;
  547. flex-direction: column;
  548. align-items: center;
  549. }
  550. .scrollview{
  551. height: 850rpx;
  552. width: 702rpx;
  553. overflow: auto;
  554. }
  555. .popuptitle{
  556. // width: 128rpx;
  557. // height: 45rpx;
  558. font-size: 32rpx;
  559. font-weight: bold;
  560. color: #000000;
  561. text-align: center;
  562. }
  563. .popupimg{
  564. display: flex;
  565. flex-wrap: wrap;
  566. justify-content: flex-start;
  567. margin-top: 40rpx;
  568. }
  569. .popupInfo{
  570. width: 702rpx;
  571. height: 180rpx;
  572. background: #EEEEEE;
  573. border-radius: 16rpx 16rpx 16rpx 16rpx;
  574. opacity: 1;
  575. display: flex;
  576. align-items: center;
  577. justify-content: center;
  578. flex-direction: column;
  579. }
  580. .popupInfo_item{
  581. display: flex;
  582. justify-content: space-between;
  583. width: 654rpx;
  584. height: 40rpx;
  585. font-size: 28rpx;
  586. font-weight: 500;
  587. color: #666666;
  588. line-height: 36rpx;
  589. }
  590. .popupInfo2{
  591. width: 702rpx;
  592. height: 80rpx;
  593. display: flex;
  594. align-items: center;
  595. justify-content: center;
  596. flex-direction: column;
  597. }
  598. .popupInfo_item2{
  599. display: flex;
  600. justify-content: space-between;
  601. width: 654rpx;
  602. height: 40rpx;
  603. font-size: 28rpx;
  604. font-weight: bold;
  605. color: #333;
  606. line-height: 36rpx;
  607. }
  608. checkbox .wx-checkbox-input {
  609. width: 32rpx;
  610. height: 32rpx;
  611. border-color: #409eff;
  612. background-color: transparent;
  613. transition: background-color .2s;
  614. border-radius: 50%;
  615. }
  616. checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  617. color: #fff; /* 这里也可以设置对钩的颜色 */
  618. background-color: #409eff;
  619. border-radius: 50%;
  620. }
  621. .u-swipe-action-item{
  622. margin-top: 24rpx;
  623. border-radius: 16rpx;
  624. }
  625. </style>