confirmIntegralOrder.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <template>
  2. <view>
  3. <view class="inner-box">
  4. <!-- 收货人 -->
  5. <view class="address-box" v-if="address==null" @click="openAddress()">
  6. <view class="left">
  7. <view class="name-box">
  8. <text class="text name">添加收货地址</text>
  9. </view>
  10. </view>
  11. <view class="arrow-box">
  12. <image src="https://hdtobs.obs.cn-north-4.myhuaweicloud.com/miniapp/arrow_gray.png" mode=""></image>
  13. </view>
  14. </view>
  15. <view class="address-box" v-if="address!=null" @click="openAddress()">
  16. <view class="left">
  17. <view class="name-box">
  18. <text class="text name">{{address.realName}}</text>
  19. <text class="text" v-if="address.phone!=null">{{address.phone}}</text>
  20. </view>
  21. <view class="address">
  22. {{address.province}}{{address.city}}{{address.district}}{{address.detail}}
  23. </view>
  24. </view>
  25. <view class="arrow-box">
  26. <image src="https://hdtobs.obs.cn-north-4.myhuaweicloud.com/miniapp/arrow_gray.png" mode=""></image>
  27. </view>
  28. </view>
  29. <!-- 药品列表 -->
  30. <view class="goods-list">
  31. <view class="item" v-for="(item,index) in goodsList" :key="index">
  32. <view class="img-box">
  33. <image :src="item.imgUrl==''?'https://hdtobs.obs.cn-north-4.myhuaweicloud.com/miniapp/drug.svg':item.imgUrl" mode="aspectFill"></image>
  34. </view>
  35. <view class="info-box">
  36. <view>
  37. <view class="name-box ellipsis2">
  38. {{item.goodsName}}
  39. </view>
  40. </view>
  41. <view class="price-num">
  42. <view class="price">
  43. <text class="num">{{item.newIntegral}}</text>
  44. <text class="unit">积分</text>
  45. <text class="num" v-show="item.newCash>0">+{{item.newCash.toFixed(2)}}</text>
  46. <text class="unit" v-show="item.newCash>0">元</text>
  47. </view>
  48. <view class="num" >x{{item.cartNum}}</view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="other-info">
  54. <view class="item">
  55. <view class="left">
  56. <text class="label">所需积分:</text>
  57. </view>
  58. <view class="right">
  59. <text class="text">{{totalIntegral}}</text>
  60. </view>
  61. </view>
  62. <view class="item">
  63. <view class="left">
  64. <text class="label">我的积分:</text>
  65. </view>
  66. <view class="right">
  67. <text class="text">{{integral}}</text>
  68. </view>
  69. </view>
  70. <view class="item" v-if='totalMoney>0'>
  71. <view class="left">
  72. <text class="label">支付金额:</text>
  73. </view>
  74. <view class="right">
  75. <text class="text">{{totalMoney.toFixed(2)}}</text>
  76. </view>
  77. </view>
  78. </view>
  79. <view class="pay-type" v-if='totalMoney>0'>
  80. <view class="title">支付方式</view>
  81. <radio-group>
  82. <view class="item">
  83. <view class="left" >
  84. <image src="https://hdtobs.obs.cn-north-4.myhuaweicloud.com/miniapp/wecha_pay.png" mode=""></image>
  85. <text class="text">全款支付</text>
  86. </view>
  87. <label>
  88. <radio :value="1" :checked="payType=='1'" color="#2BC7B9" />
  89. </label>
  90. </view>
  91. </radio-group>
  92. </view>
  93. <!-- 备注 -->
  94. <!-- <view class="remarks" v-if='totalMoney>0&&order!=null'>
  95. <input type="text" v-model="order.remark" placeholder="备注留言(选填)" placeholder-class="input" />
  96. </view> -->
  97. </view>
  98. <!-- 底部按钮 -->
  99. <view class="btn-box" v-if="goodsList&&goodsList.length > 0">
  100. <view class="btn" @click="payOrder()">{{totalMoney>0?'立即支付':'立即兑换'}}</view>
  101. </view>
  102. </view>
  103. </template>
  104. <script>
  105. import {getAddressList} from '@/api/address'
  106. import {getCartByIds,createCartOrder} from '@/api/integral.js'
  107. import {getUserInfo} from '@/api/user'
  108. export default {
  109. data() {
  110. return {
  111. addressId:null,
  112. address:null,
  113. orderId:null,
  114. order:null,
  115. goodsList:[],
  116. integral: 0,
  117. totalIntegral: 0,
  118. payTypes: [],
  119. payType: '1',
  120. alipayQrCode:null,
  121. showPayTips:false,
  122. cartIds: '',
  123. totalMoney: 0
  124. }
  125. },
  126. onLoad(option) {
  127. this.getAddressList()
  128. this.cartIds=option.cartIds || '';
  129. var that=this;
  130. uni.$on('updateAddress', (e) => {
  131. that.addressId=e.addressId;
  132. that.address=e;
  133. that.address.address=e.province+e.city+e.district+e.detail
  134. })
  135. this.getCartByIds();
  136. this.getUserInfo();
  137. },
  138. methods: {
  139. getAddressList(){
  140. uni.showLoading({
  141. title:"正在加载中"
  142. })
  143. getAddressList().then(
  144. res => {
  145. uni.hideLoading()
  146. if(res.code==200){
  147. const defaultAddress = res.data.find(item => item.isDefault == 1);
  148. if(defaultAddress){
  149. this.address = defaultAddress;
  150. this.addressId=defaultAddress.addressId
  151. console.log('找到默认地址:', defaultAddress);
  152. } else {
  153. // 如果没有找到默认地址,可以选择第一个地址或者设为null
  154. this.address = res.data.length > 0 ? res.data[0] : null;
  155. console.log('未找到默认地址,使用第一个地址或设为null');
  156. }
  157. }else{
  158. uni.showToast({
  159. icon:'none',
  160. title: "请求失败",
  161. });
  162. }
  163. },
  164. rej => {}
  165. );
  166. },
  167. getUserInfo(){
  168. getUserInfo().then(
  169. res => {
  170. if(res.code==200){
  171. if(res.user!=null){
  172. this.integral=res.user.integral;
  173. }
  174. }
  175. },
  176. rej => {}
  177. );
  178. },
  179. getCartByIds(){
  180. const ids = this.cartIds.split(',')
  181. getCartByIds(ids).then(
  182. res => {
  183. if(res.code==200){
  184. this.goodsList=res.data;
  185. this.totalIntegral = this.calcTotal(this.goodsList,'integral')
  186. this.totalMoney = this.calcTotal(this.goodsList,'newCash')
  187. }else{
  188. }
  189. },
  190. rej => {}
  191. );
  192. },
  193. calcTotal(cartData,type) {
  194. let total = 0;
  195. cartData.forEach(item => {
  196. total += item[type] * item.cartNum;
  197. });
  198. return total;
  199. },
  200. openAddress(){
  201. uni.navigateTo({
  202. url: '/pages_user/user/address'
  203. })
  204. },
  205. payOrder(){
  206. if(this.addressId==null){
  207. uni.showToast({
  208. icon:'none',
  209. title: "请选择收货地址",
  210. });
  211. return;
  212. }
  213. var data = {
  214. ids:this.cartIds.split(','),
  215. addressId:this.addressId,
  216. };
  217. var that=this;
  218. uni.showLoading();
  219. createCartOrder(data).then(
  220. res => {
  221. if(res.code==200){
  222. this.orderId = res.order.orderId
  223. if(this.totalMoney > 0) {
  224. uni.redirectTo({
  225. url:"./integralPayment?orderId="+res.order.orderId
  226. })
  227. } else {
  228. uni.redirectTo({
  229. url:"./integralOrderPaySuccess?orderId="+res.order.orderId
  230. })
  231. }
  232. }else{
  233. uni.showToast({
  234. icon:'none',
  235. title: res.msg,
  236. });
  237. }
  238. },
  239. rej => {}
  240. );
  241. },
  242. }
  243. }
  244. </script>
  245. <style lang="scss">
  246. .inner-box{
  247. padding: 20upx 20upx 160upx;
  248. .address-box{
  249. box-sizing: border-box;
  250. min-height: 171upx;
  251. background: #FFFFFF;
  252. border-radius: 16upx;
  253. background-image: url(https://hdtobs.obs.cn-north-4.myhuaweicloud.com/miniapp/address_bg.png);
  254. background-repeat: no-repeat;
  255. background-size: 100% 30upx;
  256. background-position: left bottom;
  257. padding: 38upx 30upx 36upx;
  258. display: flex;
  259. align-items: center;
  260. justify-content: space-between;
  261. .left{
  262. width: 92%;
  263. .name-box{
  264. display: flex;
  265. align-items: center;
  266. .text{
  267. font-size: 32upx;
  268. font-family: PingFang SC;
  269. font-weight: bold;
  270. color: #111111;
  271. line-height: 1;
  272. &.name{
  273. margin-right: 30upx;
  274. }
  275. }
  276. }
  277. .address{
  278. font-size: 28upx;
  279. font-family: PingFang SC;
  280. font-weight: 500;
  281. color: #666666;
  282. line-height: 42upx;
  283. text-align:left;
  284. margin-top: 23upx;
  285. }
  286. }
  287. .arrow-box{
  288. width: 12upx;
  289. height: 23upx;
  290. display: flex;
  291. align-items: cenetr;
  292. justify-content: cenetr;
  293. image{
  294. width: 100%;
  295. height: 100%;
  296. }
  297. }
  298. }
  299. .goods-list{
  300. margin-top: 20upx;
  301. padding: 0 30upx;
  302. background-color: #FFFFFF;
  303. border-radius: 16upx;
  304. .item{
  305. padding: 30upx 0;
  306. border-bottom: 1px solid #EDEEEF;
  307. display: flex;
  308. align-items: center;
  309. .img-box{
  310. width: 160upx;
  311. height: 160upx;
  312. margin-right: 30upx;
  313. image{
  314. width: 100%;
  315. height: 100%;
  316. }
  317. }
  318. .info-box{
  319. width: calc(100% - 190upx);
  320. height: 160upx;
  321. display: flex;
  322. flex-direction: column;
  323. justify-content: space-between;
  324. .name-box{
  325. font-size: 28upx;
  326. font-family: PingFang SC;
  327. font-weight: 500;
  328. color: #111111;
  329. line-height: 40upx;
  330. .tag{
  331. display: inline-block;
  332. padding: 0 6upx;
  333. height: 30upx;
  334. background: linear-gradient(90deg, #C39A58 0%, #E2C99E 100%);
  335. border-radius: 4upx;
  336. margin-right: 10upx;
  337. font-size: 22upx;
  338. font-family: PingFang SC;
  339. font-weight: bold;
  340. color: #FFFFFF;
  341. line-height: 30upx;
  342. float: left;
  343. margin-top: 7upx;
  344. }
  345. }
  346. .spec{
  347. margin-top: 10upx;
  348. font-size: 24upx;
  349. font-family: PingFang SC;
  350. font-weight: 500;
  351. color: #999999;
  352. line-height: 1;
  353. }
  354. .price-num{
  355. display: flex;
  356. align-items: center;
  357. justify-content: space-between;
  358. .price{
  359. display: flex;
  360. align-items: flex-end;
  361. .unit{
  362. font-size: 24upx;
  363. font-family: PingFang SC;
  364. font-weight: 500;
  365. color: #111111;
  366. line-height: 1.2;
  367. margin-right: 4upx;
  368. }
  369. .num{
  370. font-size: 32upx;
  371. font-family: PingFang SC;
  372. font-weight: 500;
  373. color: #111111;
  374. line-height: 1;
  375. }
  376. }
  377. .num{
  378. font-size: 24upx;
  379. font-family: PingFang SC;
  380. font-weight: 500;
  381. color: #999999;
  382. line-height: 1;
  383. }
  384. }
  385. }
  386. }
  387. .sub-total{
  388. height: 88upx;
  389. display: flex;
  390. align-items: center;
  391. justify-content: flex-end;
  392. .label{
  393. font-size: 24upx;
  394. font-family: PingFang SC;
  395. font-weight: 500;
  396. color: #999999;
  397. }
  398. .price{
  399. display: flex;
  400. align-items: flex-end;
  401. .unit{
  402. font-size: 24upx;
  403. font-family: PingFang SC;
  404. font-weight: 500;
  405. color: #FF6633;
  406. line-height: 1.2;
  407. margin-right: 4upx;
  408. }
  409. .num{
  410. font-size: 32upx;
  411. font-family: PingFang SC;
  412. font-weight: bold;
  413. color: #FF6633;
  414. line-height: 1;
  415. }
  416. }
  417. }
  418. }
  419. .other-info{
  420. margin-top: 20upx;
  421. background-color: #fff;
  422. border-radius: 20upx;
  423. overflow: hidden;
  424. padding: 0 30upx;
  425. .title{
  426. height: 80upx;
  427. line-height: 80upx;
  428. font-size: 30upx;
  429. color: #000;
  430. font-weight: bold;
  431. border-bottom: 2upx solid #eeeeee;
  432. }
  433. .item{
  434. height: 80upx;
  435. display: flex;
  436. align-items: center;
  437. justify-content: space-between;
  438. &:last-child{
  439. border-bottom: none;
  440. }
  441. .left{
  442. flex: 1;
  443. display: flex;
  444. align-items: center;
  445. .label{
  446. min-width: 140rpx;
  447. font-size: 28upx;
  448. color: #000;
  449. }
  450. .text{
  451. font-size: 28upx;
  452. color: #1b1b1b;
  453. }
  454. }
  455. .right{
  456. display: flex;
  457. align-items: center;
  458. justify-content: flex-end;
  459. .text{
  460. font-size: 28upx;
  461. color: #1b1b1b;
  462. }
  463. .ic-close{
  464. margin-left: 10rpx;
  465. width: 30rpx;
  466. height:30rpx;
  467. }
  468. .ic-back{
  469. margin-left: 10rpx;
  470. width: 15rpx;
  471. height:30rpx;
  472. }
  473. }
  474. .item-btn{
  475. max-width: 200rpx;
  476. padding: 0rpx 15rpx;
  477. height: 48upx;
  478. border-radius: 24upx;
  479. line-height: 48upx;
  480. font-size: 24upx;
  481. color: #000;
  482. border: 1upx solid #d8d8d8;
  483. display: flex;
  484. align-items: center;
  485. justify-content: center;
  486. }
  487. }
  488. }
  489. .remarks{
  490. height: 88upx;
  491. padding: 0 30upx;
  492. background: #FFFFFF;
  493. border-radius: 16upx;
  494. margin-top: 20upx;
  495. display: flex;
  496. align-items: center;
  497. input{
  498. width: 100%;
  499. font-size: 28upx;
  500. font-family: PingFang SC;
  501. font-weight: 500;
  502. color: #000000;
  503. }
  504. .input{
  505. font-size: 28upx;
  506. font-family: PingFang SC;
  507. font-weight: 500;
  508. color: #999999;
  509. }
  510. }
  511. }
  512. .btn-box{
  513. height: 140upx;
  514. z-index: 99;
  515. width: 100%;
  516. padding: 0rpx 30upx;
  517. position: fixed;
  518. bottom: 0;
  519. left: 0;
  520. box-sizing: border-box;
  521. background-color: #ffffff;
  522. display: flex;
  523. align-items: center;
  524. justify-content: center;
  525. .btn{
  526. width: 100%;
  527. height: 88upx;
  528. line-height: 88upx;
  529. text-align: center;
  530. font-size: 34upx;
  531. font-family: PingFang SC;
  532. font-weight: 400;
  533. color: #FFFFFF;
  534. background: #2BC7B9;
  535. border-radius: 10upx;
  536. }
  537. }
  538. .pay-type{
  539. box-sizing: border-box;
  540. height: 192upx;
  541. background: #FFFFFF;
  542. border-radius: 16upx;
  543. margin-top: 20upx;
  544. padding: 40upx 30upx;
  545. display: flex;
  546. flex-direction: column;
  547. justify-content: space-between;
  548. .title{
  549. font-size: 28upx;
  550. font-family: PingFang SC;
  551. font-weight: 500;
  552. color: #999999;
  553. line-height: 1;
  554. }
  555. .item{
  556. display: flex;
  557. align-items: center;
  558. justify-content: space-between;
  559. .left{
  560. display: flex;
  561. align-items: center;
  562. image{
  563. width: 44upx;
  564. height: 44upx;
  565. margin-right: 20upx;
  566. }
  567. .text{
  568. font-size: 30upx;
  569. font-family: PingFang SC;
  570. font-weight: bold;
  571. color: #222222;
  572. line-height: 1;
  573. }
  574. }
  575. }
  576. }
  577. .coupon{
  578. height: 100%;
  579. .empty{
  580. display: flex;
  581. align-items: center;
  582. justify-content: center;
  583. height: 650rpx;
  584. width: 100%;
  585. image{
  586. width: 280rpx;
  587. height: 200rpx;
  588. }
  589. }
  590. }
  591. .coupon-box{
  592. overflow-y: auto;
  593. padding: 80rpx 20rpx 80rpx;
  594. height: 650rpx;
  595. width: 100%;
  596. display: flex;
  597. flex-direction: column;
  598. align-items: flex-start;
  599. justify-content: flex-start;
  600. box-sizing: border-box;
  601. .coupon-item{
  602. width: 100%;
  603. display: flex;
  604. align-items: center;
  605. justify-content: flex-start;
  606. margin-bottom: 16rpx;
  607. height:170rpx;
  608. &:last-child{
  609. margin-bottom: 0rpx;
  610. }
  611. .left{
  612. color: #fff;
  613. font-size: 36rpx;
  614. font-weight: bold;
  615. text-align: center;
  616. display: flex;
  617. flex-direction: column;
  618. align-items: center;
  619. justify-content: center;
  620. position: relative;
  621. width: 230rpx;
  622. image{
  623. position: absolute;
  624. width: 230rpx;
  625. height:170rpx;
  626. color: #fff;
  627. }
  628. .num{
  629. font-size: 40rpx;
  630. }
  631. .pic-num{
  632. font-size: 20rpx;
  633. z-index: 99;
  634. }
  635. }
  636. .right{
  637. display: flex;
  638. flex-direction: column;
  639. align-items: flex-start;
  640. justify-content: flex-start;
  641. height:170rpx;
  642. width: calc(100% - 230rpx);
  643. padding: 0 17rpx 0 24rpx;
  644. background-color: #fff;
  645. box-sizing: border-box;
  646. .title{
  647. width: 100%;
  648. font-size: 0.3 * 100rpx;
  649. color: #282828;
  650. height: 0.93 * 100rpx;
  651. line-height: 0.93 * 100rpx;
  652. border-bottom: 1px solid #f0f0f0;
  653. }
  654. .btns{
  655. display: flex;
  656. align-items: center;
  657. justify-content: space-between;
  658. width: 100%;
  659. font-size: 0.2 * 100rpx;
  660. color: #999;
  661. height: 0.76 * 100rpx;
  662. .btn{
  663. width: 1.36 * 100rpx;
  664. height: 0.44 * 100rpx;
  665. border-radius: 0.22 * 100rpx;
  666. font-size: 0.22 * 100rpx;
  667. color: #fff;
  668. text-align: center;
  669. line-height: 0.44 * 100rpx;
  670. background-color: #2BC7B9;
  671. .gray{
  672. background-color: #ccc;
  673. }
  674. }
  675. }
  676. }
  677. }
  678. }
  679. </style>