integralOrderPay.vue 16 KB

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