payment.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <template>
  2. <view class="container">
  3. <view v-if="loading" class="loading-wrap">
  4. <text class="loading-text">加载中...</text>
  5. </view>
  6. <scroll-view v-else scroll-y class="content">
  7. <!-- Header Section -->
  8. <view class="header-section">
  9. <text class="header-title">订单待支付</text>
  10. <text class="header-countdown" v-if="countdown > 0">
  11. 支付剩余时间: {{ formatCountdown }}
  12. </text>
  13. <text class="header-cancelled" v-else>
  14. 订单已取消
  15. </text>
  16. </view>
  17. <!-- Order Info Card -->
  18. <view class="section">
  19. <view class="info-row">
  20. <text class="info-label">订单编号</text>
  21. <text class="info-value">{{ orderNo }}</text>
  22. </view>
  23. <view class="info-row" v-if="pointsUsed > 0">
  24. <text class="info-label">积分抵扣</text>
  25. <text class="info-value points-value">-{{ formatPrice(pointsUsed) }} ({{ pointsUsed }}积分)</text>
  26. </view>
  27. <view class="info-row">
  28. <text class="info-label">订单金额</text>
  29. <text class="order-amount">{{ formatPriceWithSymbol(amount) }}</text>
  30. </view>
  31. </view>
  32. <!-- Payment Method -->
  33. <view class="section">
  34. <text class="section-title">支付方式</text>
  35. <view class="payment-method-row">
  36. <view class="payment-method-left">
  37. <text class="payment-icon">💳</text>
  38. <text class="payment-name">微信支付</text>
  39. </view>
  40. <text class="payment-checked">✓</text>
  41. </view>
  42. </view>
  43. <!-- Pay Button -->
  44. <view class="pay-section">
  45. <button
  46. :class="['pay-btn', (paying || countdown <= 0) ? 'disabled' : '']"
  47. :disabled="paying || countdown <= 0"
  48. @click="onPay"
  49. >
  50. {{ paying ? '支付中...' : '微信支付 ' + formatPriceWithSymbol(amount) }}
  51. </button>
  52. <text class="cancel-link" @click="onCancelOrder">取消订单</text>
  53. </view>
  54. <!-- Post-payment Upgrade Card -->
  55. <view v-if="showUpgradeCard" class="upgrade-card">
  56. <view class="upgrade-card-header">
  57. <text class="upgrade-card-icon">🎉</text>
  58. <text class="upgrade-card-title">支付成功!开通会员更划算</text>
  59. </view>
  60. <view class="upgrade-card-body">
  61. <view class="upgrade-benefit-row">
  62. <text class="upgrade-benefit-icon">✓</text>
  63. <text class="upgrade-benefit-text">全场商品享受会员专享价</text>
  64. </view>
  65. <view class="upgrade-benefit-row">
  66. <text class="upgrade-benefit-icon">✓</text>
  67. <text class="upgrade-benefit-text">不限次一对一成长咨询服务</text>
  68. </view>
  69. <view class="upgrade-benefit-row">
  70. <text class="upgrade-benefit-icon">✓</text>
  71. <text class="upgrade-benefit-text">专属家庭成长计划与测评报告</text>
  72. </view>
  73. <view class="upgrade-price-row">
  74. <text class="upgrade-price-label">仅需</text>
  75. <text class="upgrade-price-value">{{ formatPriceWithSymbol(familyYearlyPrice * 100) }}</text>
  76. <text class="upgrade-price-unit">/年</text>
  77. <text class="upgrade-price-original" v-if="familyYearlyPrice > 0">{{ formatPriceWithSymbol((familyYearlyPrice * 1.5 * 100).toFixed(0)) }}</text>
  78. </view>
  79. </view>
  80. <view class="upgrade-card-action">
  81. <button class="upgrade-btn" @click="goUpgrade">立即开通</button>
  82. <text class="upgrade-skip" @click="showUpgradeCard = false">暂不开通</text>
  83. </view>
  84. </view>
  85. </scroll-view>
  86. </view>
  87. </template>
  88. <script>
  89. import config from '@/config.js'
  90. import { getMyMembership } from '@/utils/api.js'
  91. export default {
  92. data() {
  93. return {
  94. orderNo: '',
  95. amount: 0,
  96. countdown: 900,
  97. paying: false,
  98. loading: false,
  99. timer: null,
  100. pointsUsed: 0,
  101. isMember: false,
  102. showUpgradeCard: false,
  103. familyYearlyPrice: '365'
  104. }
  105. },
  106. computed: {
  107. formatCountdown() {
  108. var min = Math.floor(this.countdown / 60)
  109. var sec = this.countdown % 60
  110. return String(min).padStart(2, '0') + ':' + String(sec).padStart(2, '0')
  111. }
  112. },
  113. onLoad(options) {
  114. this.checkMemberStatus()
  115. this.checkMembershipLevels()
  116. if (options.orderNo) {
  117. this.orderNo = options.orderNo
  118. }
  119. if (options.amount) {
  120. this.amount = parseFloat(options.amount)
  121. }
  122. if (options.pointsUsed) {
  123. this.pointsUsed = parseInt(options.pointsUsed)
  124. }
  125. this.startCountdown()
  126. },
  127. onUnload() {
  128. if (this.timer) {
  129. clearInterval(this.timer)
  130. this.timer = null
  131. }
  132. },
  133. methods: {
  134. checkMemberStatus() {
  135. var that = this
  136. getMyMembership().then(function(res) {
  137. if (res.data && res.data.memberLevel) {
  138. that.isMember = res.data.memberLevel !== 'FREE'
  139. }
  140. }).catch(function() {})
  141. },
  142. checkMembershipLevels() {
  143. var that = this
  144. uni.request({
  145. url: config.api('/api/membership/levels'),
  146. method: 'POST',
  147. header: { 'Authorization': 'Bearer ' + uni.getStorageSync('token') },
  148. success: function(res) {
  149. if (res.data && res.data.code === 200 && res.data.data) {
  150. var levels = res.data.data
  151. for (var i = 0; i < levels.length; i++) {
  152. if (levels[i].levelCode === 'FAMILY' && levels[i].priceYearly > 0) {
  153. that.familyYearlyPrice = (levels[i].priceYearly / 100).toFixed(0)
  154. break
  155. }
  156. }
  157. }
  158. }
  159. })
  160. },
  161. handlePaymentSuccess() {
  162. var that = this
  163. if (!this.isMember) {
  164. setTimeout(function() {
  165. that.showUpgradeCard = true
  166. }, 2000)
  167. }
  168. },
  169. goUpgrade() {
  170. uni.navigateTo({ url: '/pages/membership/upgrade' })
  171. },
  172. startCountdown() {
  173. var that = this
  174. this.timer = setInterval(function() {
  175. if (that.countdown > 0) {
  176. that.countdown = that.countdown - 1
  177. } else {
  178. if (that.timer) {
  179. clearInterval(that.timer)
  180. that.timer = null
  181. }
  182. }
  183. }, 1000)
  184. },
  185. onPay() {
  186. if (this.countdown <= 0) {
  187. uni.showToast({ title: '订单已取消,无法支付', icon: 'none' })
  188. return
  189. }
  190. this.paying = true
  191. var that = this
  192. uni.request({
  193. url: config.api('/api/product/order/pay'),
  194. method: 'POST',
  195. data: { orderNo: this.orderNo },
  196. header: {
  197. 'Content-Type': 'application/json',
  198. 'Authorization': 'Bearer ' + uni.getStorageSync('token')
  199. },
  200. success: function(res) {
  201. that.paying = false
  202. if (res.data && res.data.code === 200) {
  203. var data = res.data.data
  204. if (data.noMoneyPayment) {
  205. // Points fully covered the order, no WeChat needed
  206. uni.request({
  207. url: config.api('/api/product/order/handlePaymentSuccess'),
  208. method: 'POST',
  209. data: { orderNo: that.orderNo },
  210. header: {
  211. 'Content-Type': 'application/json',
  212. 'Authorization': 'Bearer ' + uni.getStorageSync('token')
  213. },
  214. success: function(payRes) {
  215. if (payRes.data && payRes.data.code === 200) {
  216. uni.showToast({ title: '支付成功', icon: 'success' })
  217. that.handlePaymentSuccess()
  218. setTimeout(function() {
  219. uni.redirectTo({
  220. url: '/pages/shop/order-list/order-list?tab=paid'
  221. })
  222. }, 1500)
  223. } else {
  224. uni.showToast({ title: payRes.data.message || '处理失败', icon: 'none' })
  225. }
  226. },
  227. fail: function() {
  228. uni.showToast({ title: '网络请求失败', icon: 'none' })
  229. }
  230. })
  231. } else if (data.wechatPayParams) {
  232. var params = data.wechatPayParams
  233. uni.requestPayment({
  234. timeStamp: params.timeStamp,
  235. nonceStr: params.nonceStr,
  236. package: params.package,
  237. signType: params.signType || 'RSA',
  238. paySign: params.paySign,
  239. success: function() {
  240. // Notify backend to update order status
  241. uni.request({
  242. url: config.api('/api/product/order/handlePaymentSuccess'),
  243. method: 'POST',
  244. data: { orderNo: that.orderNo },
  245. header: {
  246. 'Content-Type': 'application/json',
  247. 'Authorization': 'Bearer ' + uni.getStorageSync('token')
  248. }
  249. })
  250. uni.showToast({ title: '支付成功', icon: 'success' })
  251. that.handlePaymentSuccess()
  252. setTimeout(function() {
  253. uni.redirectTo({
  254. url: '/pages/shop/order-list/order-list?tab=paid'
  255. })
  256. }, 1500)
  257. },
  258. fail: function() {
  259. uni.showToast({ title: '支付失败', icon: 'none' })
  260. }
  261. })
  262. } else {
  263. uni.showToast({ title: '获取支付参数失败', icon: 'none' })
  264. }
  265. } else {
  266. uni.showToast({ title: res.data.message || '支付失败', icon: 'none' })
  267. }
  268. },
  269. fail: function() {
  270. that.paying = false
  271. uni.showToast({ title: '网络请求失败', icon: 'none' })
  272. }
  273. })
  274. },
  275. onCancelOrder() {
  276. var that = this
  277. uni.showModal({
  278. title: '确认取消',
  279. content: '确定取消该订单吗?',
  280. success: function(confirm) {
  281. if (confirm.confirm) {
  282. uni.request({
  283. url: config.api('/api/product/order/cancel'),
  284. method: 'POST',
  285. data: { orderNo: that.orderNo },
  286. header: {
  287. 'Content-Type': 'application/json',
  288. 'Authorization': 'Bearer ' + uni.getStorageSync('token')
  289. },
  290. success: function(res) {
  291. if (res.data && res.data.code === 200) {
  292. uni.showToast({ title: '订单已取消', icon: 'success' })
  293. setTimeout(function() {
  294. uni.navigateBack()
  295. }, 1500)
  296. } else {
  297. uni.showToast({ title: res.data.message || '取消失败', icon: 'none' })
  298. }
  299. }
  300. })
  301. }
  302. }
  303. })
  304. },
  305. formatPrice(price) {
  306. if (price === null || price === undefined) return '0.00'
  307. return (Number(price) / 100).toFixed(2)
  308. }
  309. }
  310. }
  311. </script>
  312. <style>
  313. .container {
  314. min-height: 100vh;
  315. background: #f5f5f5;
  316. }
  317. .loading-wrap {
  318. display: flex;
  319. justify-content: center;
  320. padding-top: 200rpx;
  321. }
  322. .loading-text {
  323. font-size: 28rpx;
  324. color: #999;
  325. }
  326. .content {
  327. height: calc(100vh - 120rpx);
  328. }
  329. .header-section {
  330. background: linear-gradient(135deg, #F97316, #FB923C);
  331. padding: 50rpx 30rpx;
  332. display: flex;
  333. flex-direction: column;
  334. align-items: center;
  335. }
  336. .header-title {
  337. font-size: 36rpx;
  338. font-weight: bold;
  339. color: #fff;
  340. margin-bottom: 12rpx;
  341. }
  342. .header-countdown {
  343. font-size: 26rpx;
  344. color: rgba(255,255,255,0.9);
  345. }
  346. .header-cancelled {
  347. font-size: 26rpx;
  348. color: rgba(255,255,255,0.7);
  349. }
  350. .section {
  351. background: #fff;
  352. margin: 20rpx;
  353. border-radius: 16rpx;
  354. padding: 24rpx;
  355. }
  356. .section-title {
  357. font-size: 28rpx;
  358. font-weight: bold;
  359. color: #333;
  360. margin-bottom: 20rpx;
  361. display: block;
  362. }
  363. .info-row {
  364. display: flex;
  365. justify-content: space-between;
  366. align-items: center;
  367. padding: 16rpx 0;
  368. border-bottom: 1rpx solid #f5f5f5;
  369. }
  370. .info-row:last-child {
  371. border-bottom: none;
  372. }
  373. .info-label {
  374. font-size: 26rpx;
  375. color: #999;
  376. }
  377. .info-value {
  378. font-size: 26rpx;
  379. color: #333;
  380. }
  381. .order-amount {
  382. font-size: 40rpx;
  383. color: #F97316;
  384. font-weight: bold;
  385. }
  386. .payment-method-row {
  387. display: flex;
  388. align-items: center;
  389. justify-content: space-between;
  390. padding: 16rpx 0;
  391. }
  392. .payment-method-left {
  393. display: flex;
  394. align-items: center;
  395. }
  396. .payment-icon {
  397. font-size: 40rpx;
  398. margin-right: 16rpx;
  399. }
  400. .payment-name {
  401. font-size: 28rpx;
  402. color: #333;
  403. }
  404. .payment-checked {
  405. font-size: 32rpx;
  406. color: #52c41a;
  407. font-weight: bold;
  408. }
  409. .pay-section {
  410. display: flex;
  411. flex-direction: column;
  412. align-items: center;
  413. padding: 40rpx 30rpx;
  414. }
  415. .pay-btn {
  416. width: 100%;
  417. height: 88rpx;
  418. line-height: 88rpx;
  419. background: linear-gradient(135deg, #F97316, #FB923C);
  420. color: #fff;
  421. font-size: 32rpx;
  422. font-weight: bold;
  423. border-radius: 44rpx;
  424. border: none;
  425. text-align: center;
  426. }
  427. .pay-btn::after {
  428. border: none;
  429. }
  430. .pay-btn.disabled {
  431. background: #ddd;
  432. color: #999;
  433. }
  434. .cancel-link {
  435. margin-top: 24rpx;
  436. font-size: 26rpx;
  437. color: #999;
  438. text-decoration: underline;
  439. padding: 10rpx;
  440. }
  441. .points-value {
  442. color: #F97316;
  443. }
  444. /* Upgrade Card */
  445. .upgrade-card {
  446. margin: 30rpx 20rpx;
  447. background: linear-gradient(135deg, #FFF7ED, #FFEDD5);
  448. border-radius: 20rpx;
  449. padding: 30rpx;
  450. border: 2rpx solid #FED7AA;
  451. animation: fadeInUp 0.5s ease;
  452. }
  453. .upgrade-card-header {
  454. display: flex;
  455. align-items: center;
  456. margin-bottom: 20rpx;
  457. }
  458. .upgrade-card-icon {
  459. font-size: 40rpx;
  460. margin-right: 12rpx;
  461. }
  462. .upgrade-card-title {
  463. font-size: 30rpx;
  464. font-weight: bold;
  465. color: #333;
  466. }
  467. .upgrade-card-body {
  468. margin-bottom: 24rpx;
  469. }
  470. .upgrade-benefit-row {
  471. display: flex;
  472. align-items: center;
  473. padding: 8rpx 0;
  474. }
  475. .upgrade-benefit-icon {
  476. font-size: 24rpx;
  477. color: #22C55E;
  478. margin-right: 12rpx;
  479. font-weight: bold;
  480. }
  481. .upgrade-benefit-text {
  482. font-size: 26rpx;
  483. color: #666;
  484. }
  485. .upgrade-price-row {
  486. display: flex;
  487. align-items: baseline;
  488. margin-top: 16rpx;
  489. padding-top: 16rpx;
  490. border-top: 1rpx solid #FED7AA;
  491. }
  492. .upgrade-price-label {
  493. font-size: 26rpx;
  494. color: #999;
  495. margin-right: 8rpx;
  496. }
  497. .upgrade-price-value {
  498. font-size: 48rpx;
  499. font-weight: bold;
  500. color: #F97316;
  501. }
  502. .upgrade-price-unit {
  503. font-size: 24rpx;
  504. color: #999;
  505. margin-left: 6rpx;
  506. }
  507. .upgrade-price-original {
  508. font-size: 24rpx;
  509. color: #ccc;
  510. text-decoration: line-through;
  511. margin-left: 12rpx;
  512. }
  513. .upgrade-card-action {
  514. display: flex;
  515. flex-direction: column;
  516. align-items: center;
  517. }
  518. .upgrade-btn {
  519. width: 100%;
  520. height: 80rpx;
  521. line-height: 80rpx;
  522. background: linear-gradient(135deg, #F97316, #FB923C);
  523. color: #fff;
  524. font-size: 30rpx;
  525. font-weight: bold;
  526. border-radius: 40rpx;
  527. border: none;
  528. text-align: center;
  529. }
  530. .upgrade-btn::after {
  531. border: none;
  532. }
  533. .upgrade-skip {
  534. margin-top: 16rpx;
  535. font-size: 24rpx;
  536. color: #999;
  537. padding: 8rpx;
  538. }
  539. @keyframes fadeInUp {
  540. from {
  541. opacity: 0;
  542. transform: translateY(30rpx);
  543. }
  544. to {
  545. opacity: 1;
  546. transform: translateY(0);
  547. }
  548. }
  549. </style>