market.vue 14 KB

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