confirmIntegralOrder.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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. }
  154. }else{
  155. uni.showToast({
  156. icon:'none',
  157. title: "请求失败",
  158. });
  159. }
  160. },
  161. rej => {}
  162. );
  163. },
  164. getUserInfo(){
  165. getUserInfo().then(
  166. res => {
  167. if(res.code==200){
  168. if(res.user!=null){
  169. this.integral=res.user.integral;
  170. }
  171. }
  172. },
  173. rej => {}
  174. );
  175. },
  176. getCartByIds(){
  177. const ids = this.cartIds.split(',')
  178. getCartByIds(ids).then(
  179. res => {
  180. if(res.code==200){
  181. this.goodsList=res.data;
  182. this.totalIntegral = this.calcTotal(this.goodsList,'integral')
  183. this.totalMoney = this.calcTotal(this.goodsList,'newCash')
  184. }else{
  185. }
  186. },
  187. rej => {}
  188. );
  189. },
  190. calcTotal(cartData,type) {
  191. let total = 0;
  192. cartData.forEach(item => {
  193. total += item[type] * item.cartNum;
  194. });
  195. return total;
  196. },
  197. openAddress(){
  198. uni.navigateTo({
  199. url: '/pages_user/user/address'
  200. })
  201. },
  202. payOrder(){
  203. if(this.addressId==null){
  204. uni.showToast({
  205. icon:'none',
  206. title: "请选择收货地址",
  207. });
  208. return;
  209. }
  210. var data = {
  211. ids:this.cartIds.split(','),
  212. addressId:this.addressId,
  213. };
  214. var that=this;
  215. uni.showLoading();
  216. createCartOrder(data).then(
  217. res => {
  218. if(res.code==200){
  219. this.orderId = res.order.orderId
  220. if(this.totalMoney > 0) {
  221. uni.redirectTo({
  222. url:"./integralPayment?orderId="+res.order.orderId
  223. })
  224. } else {
  225. uni.redirectTo({
  226. url:"./integralOrderPaySuccess?orderId="+res.order.orderId
  227. })
  228. }
  229. }else{
  230. uni.showToast({
  231. icon:'none',
  232. title: res.msg,
  233. });
  234. }
  235. },
  236. rej => {}
  237. );
  238. },
  239. }
  240. }
  241. </script>
  242. <style lang="scss">
  243. .inner-box{
  244. padding: 20upx 20upx 160upx;
  245. .address-box{
  246. box-sizing: border-box;
  247. min-height: 171upx;
  248. background: #FFFFFF;
  249. border-radius: 16upx;
  250. background-image: url(https://hdtobs.obs.cn-north-4.myhuaweicloud.com/miniapp/address_bg.png);
  251. background-repeat: no-repeat;
  252. background-size: 100% 30upx;
  253. background-position: left bottom;
  254. padding: 38upx 30upx 36upx;
  255. display: flex;
  256. align-items: center;
  257. justify-content: space-between;
  258. .left{
  259. width: 92%;
  260. .name-box{
  261. display: flex;
  262. align-items: center;
  263. .text{
  264. font-size: 32upx;
  265. font-family: PingFang SC;
  266. font-weight: bold;
  267. color: #111111;
  268. line-height: 1;
  269. &.name{
  270. margin-right: 30upx;
  271. }
  272. }
  273. }
  274. .address{
  275. font-size: 28upx;
  276. font-family: PingFang SC;
  277. font-weight: 500;
  278. color: #666666;
  279. line-height: 42upx;
  280. text-align:left;
  281. margin-top: 23upx;
  282. }
  283. }
  284. .arrow-box{
  285. width: 12upx;
  286. height: 23upx;
  287. display: flex;
  288. align-items: cenetr;
  289. justify-content: cenetr;
  290. image{
  291. width: 100%;
  292. height: 100%;
  293. }
  294. }
  295. }
  296. .goods-list{
  297. margin-top: 20upx;
  298. padding: 0 30upx;
  299. background-color: #FFFFFF;
  300. border-radius: 16upx;
  301. .item{
  302. padding: 30upx 0;
  303. border-bottom: 1px solid #EDEEEF;
  304. display: flex;
  305. align-items: center;
  306. .img-box{
  307. width: 160upx;
  308. height: 160upx;
  309. margin-right: 30upx;
  310. image{
  311. width: 100%;
  312. height: 100%;
  313. }
  314. }
  315. .info-box{
  316. width: calc(100% - 190upx);
  317. height: 160upx;
  318. display: flex;
  319. flex-direction: column;
  320. justify-content: space-between;
  321. .name-box{
  322. font-size: 28upx;
  323. font-family: PingFang SC;
  324. font-weight: 500;
  325. color: #111111;
  326. line-height: 40upx;
  327. .tag{
  328. display: inline-block;
  329. padding: 0 6upx;
  330. height: 30upx;
  331. background: linear-gradient(90deg, #C39A58 0%, #E2C99E 100%);
  332. border-radius: 4upx;
  333. margin-right: 10upx;
  334. font-size: 22upx;
  335. font-family: PingFang SC;
  336. font-weight: bold;
  337. color: #FFFFFF;
  338. line-height: 30upx;
  339. float: left;
  340. margin-top: 7upx;
  341. }
  342. }
  343. .spec{
  344. margin-top: 10upx;
  345. font-size: 24upx;
  346. font-family: PingFang SC;
  347. font-weight: 500;
  348. color: #999999;
  349. line-height: 1;
  350. }
  351. .price-num{
  352. display: flex;
  353. align-items: center;
  354. justify-content: space-between;
  355. .price{
  356. display: flex;
  357. align-items: flex-end;
  358. .unit{
  359. font-size: 24upx;
  360. font-family: PingFang SC;
  361. font-weight: 500;
  362. color: #111111;
  363. line-height: 1.2;
  364. margin-right: 4upx;
  365. }
  366. .num{
  367. font-size: 32upx;
  368. font-family: PingFang SC;
  369. font-weight: 500;
  370. color: #111111;
  371. line-height: 1;
  372. }
  373. }
  374. .num{
  375. font-size: 24upx;
  376. font-family: PingFang SC;
  377. font-weight: 500;
  378. color: #999999;
  379. line-height: 1;
  380. }
  381. }
  382. }
  383. }
  384. .sub-total{
  385. height: 88upx;
  386. display: flex;
  387. align-items: center;
  388. justify-content: flex-end;
  389. .label{
  390. font-size: 24upx;
  391. font-family: PingFang SC;
  392. font-weight: 500;
  393. color: #999999;
  394. }
  395. .price{
  396. display: flex;
  397. align-items: flex-end;
  398. .unit{
  399. font-size: 24upx;
  400. font-family: PingFang SC;
  401. font-weight: 500;
  402. color: #FF6633;
  403. line-height: 1.2;
  404. margin-right: 4upx;
  405. }
  406. .num{
  407. font-size: 32upx;
  408. font-family: PingFang SC;
  409. font-weight: bold;
  410. color: #FF6633;
  411. line-height: 1;
  412. }
  413. }
  414. }
  415. }
  416. .other-info{
  417. margin-top: 20upx;
  418. background-color: #fff;
  419. border-radius: 20upx;
  420. overflow: hidden;
  421. padding: 0 30upx;
  422. .title{
  423. height: 80upx;
  424. line-height: 80upx;
  425. font-size: 30upx;
  426. color: #000;
  427. font-weight: bold;
  428. border-bottom: 2upx solid #eeeeee;
  429. }
  430. .item{
  431. height: 80upx;
  432. display: flex;
  433. align-items: center;
  434. justify-content: space-between;
  435. &:last-child{
  436. border-bottom: none;
  437. }
  438. .left{
  439. flex: 1;
  440. display: flex;
  441. align-items: center;
  442. .label{
  443. min-width: 140rpx;
  444. font-size: 28upx;
  445. color: #000;
  446. }
  447. .text{
  448. font-size: 28upx;
  449. color: #1b1b1b;
  450. }
  451. }
  452. .right{
  453. display: flex;
  454. align-items: center;
  455. justify-content: flex-end;
  456. .text{
  457. font-size: 28upx;
  458. color: #1b1b1b;
  459. }
  460. .ic-close{
  461. margin-left: 10rpx;
  462. width: 30rpx;
  463. height:30rpx;
  464. }
  465. .ic-back{
  466. margin-left: 10rpx;
  467. width: 15rpx;
  468. height:30rpx;
  469. }
  470. }
  471. .item-btn{
  472. max-width: 200rpx;
  473. padding: 0rpx 15rpx;
  474. height: 48upx;
  475. border-radius: 24upx;
  476. line-height: 48upx;
  477. font-size: 24upx;
  478. color: #000;
  479. border: 1upx solid #d8d8d8;
  480. display: flex;
  481. align-items: center;
  482. justify-content: center;
  483. }
  484. }
  485. }
  486. .remarks{
  487. height: 88upx;
  488. padding: 0 30upx;
  489. background: #FFFFFF;
  490. border-radius: 16upx;
  491. margin-top: 20upx;
  492. display: flex;
  493. align-items: center;
  494. input{
  495. width: 100%;
  496. font-size: 28upx;
  497. font-family: PingFang SC;
  498. font-weight: 500;
  499. color: #000000;
  500. }
  501. .input{
  502. font-size: 28upx;
  503. font-family: PingFang SC;
  504. font-weight: 500;
  505. color: #999999;
  506. }
  507. }
  508. }
  509. .btn-box{
  510. height: 140upx;
  511. z-index: 99;
  512. width: 100%;
  513. padding: 0rpx 30upx;
  514. position: fixed;
  515. bottom: 0;
  516. left: 0;
  517. box-sizing: border-box;
  518. background-color: #ffffff;
  519. display: flex;
  520. align-items: center;
  521. justify-content: center;
  522. .btn{
  523. width: 100%;
  524. height: 88upx;
  525. line-height: 88upx;
  526. text-align: center;
  527. font-size: 34upx;
  528. font-family: PingFang SC;
  529. font-weight: 400;
  530. color: #FFFFFF;
  531. background: #2BC7B9;
  532. border-radius: 10upx;
  533. }
  534. }
  535. .pay-type{
  536. box-sizing: border-box;
  537. height: 192upx;
  538. background: #FFFFFF;
  539. border-radius: 16upx;
  540. margin-top: 20upx;
  541. padding: 40upx 30upx;
  542. display: flex;
  543. flex-direction: column;
  544. justify-content: space-between;
  545. .title{
  546. font-size: 28upx;
  547. font-family: PingFang SC;
  548. font-weight: 500;
  549. color: #999999;
  550. line-height: 1;
  551. }
  552. .item{
  553. display: flex;
  554. align-items: center;
  555. justify-content: space-between;
  556. .left{
  557. display: flex;
  558. align-items: center;
  559. image{
  560. width: 44upx;
  561. height: 44upx;
  562. margin-right: 20upx;
  563. }
  564. .text{
  565. font-size: 30upx;
  566. font-family: PingFang SC;
  567. font-weight: bold;
  568. color: #222222;
  569. line-height: 1;
  570. }
  571. }
  572. }
  573. }
  574. .coupon{
  575. height: 100%;
  576. .empty{
  577. display: flex;
  578. align-items: center;
  579. justify-content: center;
  580. height: 650rpx;
  581. width: 100%;
  582. image{
  583. width: 280rpx;
  584. height: 200rpx;
  585. }
  586. }
  587. }
  588. .coupon-box{
  589. overflow-y: auto;
  590. padding: 80rpx 20rpx 80rpx;
  591. height: 650rpx;
  592. width: 100%;
  593. display: flex;
  594. flex-direction: column;
  595. align-items: flex-start;
  596. justify-content: flex-start;
  597. box-sizing: border-box;
  598. .coupon-item{
  599. width: 100%;
  600. display: flex;
  601. align-items: center;
  602. justify-content: flex-start;
  603. margin-bottom: 16rpx;
  604. height:170rpx;
  605. &:last-child{
  606. margin-bottom: 0rpx;
  607. }
  608. .left{
  609. color: #fff;
  610. font-size: 36rpx;
  611. font-weight: bold;
  612. text-align: center;
  613. display: flex;
  614. flex-direction: column;
  615. align-items: center;
  616. justify-content: center;
  617. position: relative;
  618. width: 230rpx;
  619. image{
  620. position: absolute;
  621. width: 230rpx;
  622. height:170rpx;
  623. color: #fff;
  624. }
  625. .num{
  626. font-size: 40rpx;
  627. }
  628. .pic-num{
  629. font-size: 20rpx;
  630. z-index: 99;
  631. }
  632. }
  633. .right{
  634. display: flex;
  635. flex-direction: column;
  636. align-items: flex-start;
  637. justify-content: flex-start;
  638. height:170rpx;
  639. width: calc(100% - 230rpx);
  640. padding: 0 17rpx 0 24rpx;
  641. background-color: #fff;
  642. box-sizing: border-box;
  643. .title{
  644. width: 100%;
  645. font-size: 0.3 * 100rpx;
  646. color: #282828;
  647. height: 0.93 * 100rpx;
  648. line-height: 0.93 * 100rpx;
  649. border-bottom: 1px solid #f0f0f0;
  650. }
  651. .btns{
  652. display: flex;
  653. align-items: center;
  654. justify-content: space-between;
  655. width: 100%;
  656. font-size: 0.2 * 100rpx;
  657. color: #999;
  658. height: 0.76 * 100rpx;
  659. .btn{
  660. width: 1.36 * 100rpx;
  661. height: 0.44 * 100rpx;
  662. border-radius: 0.22 * 100rpx;
  663. font-size: 0.22 * 100rpx;
  664. color: #fff;
  665. text-align: center;
  666. line-height: 0.44 * 100rpx;
  667. background-color: #2BC7B9;
  668. .gray{
  669. background-color: #ccc;
  670. }
  671. }
  672. }
  673. }
  674. }
  675. }
  676. </style>