result.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view class="result-page">
  3. <!-- 成功态 -->
  4. <view class="result-body" v-if="status === 'success'">
  5. <view class="result-icon success">
  6. <text class="icon-text">✅</text>
  7. </view>
  8. <text class="result-title">开通成功</text>
  9. <text class="result-sub">{{ levelName }} {{ levelCode }}</text>
  10. <view class="info-card">
  11. <view class="info-row">
  12. <text class="info-label">有效期至</text>
  13. <text class="info-value">{{ expireText }}</text>
  14. </view>
  15. <view class="info-row" v-if="giftCoupons.length > 0">
  16. <text class="info-label">开通赠券</text>
  17. <text class="info-value gift">{{ giftCouponsText }}</text>
  18. </view>
  19. </view>
  20. <view class="btn-group">
  21. <button class="btn-primary" @click="goBenefits">查看我的权益</button>
  22. <button class="btn-secondary" @click="goHome">返回会员中心</button>
  23. </view>
  24. </view>
  25. <!-- 失败态 -->
  26. <view class="result-body" v-else>
  27. <view class="result-icon fail">
  28. <text class="icon-text">❌</text>
  29. </view>
  30. <text class="result-title">支付未完成</text>
  31. <text class="result-sub">{{ failReason }}</text>
  32. <view class="btn-group">
  33. <button class="btn-primary" v-if="canContinue" @click="continuePay">继续支付</button>
  34. <button class="btn-primary" v-else @click="retryPay">重新支付</button>
  35. <button class="btn-secondary" @click="goUpgrade">返回套餐选择</button>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import { getMyMembership, getJoinCouponRules, nextOrder, requestVirtualPayment } from '../../utils/api.js'
  42. import { parseDate } from '../../utils/format.js'
  43. export default {
  44. data() {
  45. return {
  46. orderNo: '',
  47. status: 'success',
  48. levelName: '会员',
  49. levelCode: '',
  50. expireText: '',
  51. giftCoupons: [],
  52. failReason: '支付未完成,请重试',
  53. canContinue: false,
  54. nextPayParams: null
  55. }
  56. },
  57. computed: {
  58. giftCouponsText: function() {
  59. var self = this
  60. return this.giftCoupons.map(function(r) {
  61. return '「' + r.name + '」×' + (r.grantQuantity || 1)
  62. }).join('、')
  63. }
  64. },
  65. onLoad: function(options) {
  66. this.orderNo = options.orderNo || ''
  67. this.status = options.status || 'success'
  68. if (this.status === 'success') {
  69. this.loadSuccess()
  70. } else {
  71. this.loadFail()
  72. }
  73. },
  74. methods: {
  75. loadSuccess: function() {
  76. var self = this
  77. // 轮询确认开通
  78. var times = 0
  79. var timer = setInterval(function() {
  80. times++
  81. getMyMembership().then(function(res) {
  82. var m = res.data || {}
  83. var mem = m.membership
  84. if (mem && mem.isActive) {
  85. clearInterval(timer)
  86. self.levelCode = mem.levelCode || ''
  87. self.levelName = mem.levelName || self.levelName
  88. self.expireText = self.formatDate(mem.endDate)
  89. self.loadGiftCoupons()
  90. } else if (times >= 8) {
  91. clearInterval(timer)
  92. self.loadGiftCoupons()
  93. }
  94. }).catch(function() {
  95. if (times >= 8) {
  96. clearInterval(timer)
  97. self.loadGiftCoupons()
  98. }
  99. })
  100. }, 1500)
  101. },
  102. loadGiftCoupons: function() {
  103. var self = this
  104. getJoinCouponRules().then(function(res) {
  105. var rules = res.data || []
  106. self.giftCoupons = rules.filter(function(r) {
  107. return r.grantLevelCode === self.levelCode
  108. })
  109. }).catch(function() {})
  110. },
  111. loadFail: function() {
  112. var self = this
  113. if (!this.orderNo) {
  114. this.failReason = '订单信息缺失'
  115. return
  116. }
  117. // 尝试获取下一期支付参数(拆单未付清时可用)
  118. nextOrder({ orderNo: this.orderNo }).then(function(res) {
  119. var nd = res.data
  120. if (nd && nd.done) {
  121. self.failReason = '订单已全部支付,请稍后查看会员状态'
  122. self.canContinue = false
  123. } else if (nd && nd.orderInfo && nd.sign) {
  124. self.canContinue = true
  125. self.nextPayParams = nd
  126. self.failReason = '第 ' + (nd.currentPeriod || 1) + ' 期尚未支付'
  127. } else {
  128. self.failReason = '支付未完成,请重试'
  129. self.canContinue = false
  130. }
  131. }).catch(function() {
  132. self.failReason = '支付未完成,请重试'
  133. })
  134. },
  135. continuePay: function() {
  136. var self = this
  137. if (!this.nextPayParams) {
  138. this.retryPay()
  139. return
  140. }
  141. requestVirtualPayment(this.nextPayParams, {
  142. success: function() {
  143. uni.redirectTo({ url: '/pages/membership/result?orderNo=' + self.orderNo + '&status=success' })
  144. },
  145. fail: function(err) {
  146. var errCode = err && err.errCode
  147. if (errCode === -2) {
  148. uni.showToast({ title: '支付已取消', icon: 'none' })
  149. } else {
  150. uni.showToast({ title: '支付未完成', icon: 'none' })
  151. }
  152. }
  153. })
  154. },
  155. retryPay: function() {
  156. uni.redirectTo({ url: '/pages/membership/upgrade' })
  157. },
  158. goBenefits: function() {
  159. uni.redirectTo({ url: '/pages/membership/benefits' })
  160. },
  161. goHome: function() {
  162. uni.switchTab({ url: '/pages/index/index' })
  163. },
  164. goUpgrade: function() {
  165. uni.redirectTo({ url: '/pages/membership/upgrade' })
  166. },
  167. formatDate: function(date) {
  168. if (!date) return ''
  169. var d = parseDate(date)
  170. if (!d) return ''
  171. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
  172. }
  173. }
  174. }
  175. </script>
  176. <style scoped>
  177. .result-page {
  178. min-height: 100vh;
  179. background: #FFF7ED;
  180. display: flex;
  181. justify-content: center;
  182. padding: 120rpx 30rpx 60rpx;
  183. box-sizing: border-box;
  184. }
  185. .result-body {
  186. width: 100%;
  187. display: flex;
  188. flex-direction: column;
  189. align-items: center;
  190. }
  191. .result-icon {
  192. width: 160rpx;
  193. height: 160rpx;
  194. border-radius: 50%;
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. margin-bottom: 32rpx;
  199. }
  200. .result-icon.success {
  201. background: #D1FAE5;
  202. }
  203. .result-icon.fail {
  204. background: #FEE2E2;
  205. }
  206. .icon-text {
  207. font-size: 80rpx;
  208. }
  209. .result-title {
  210. font-size: 40rpx;
  211. font-weight: bold;
  212. color: #1E293B;
  213. display: block;
  214. margin-bottom: 12rpx;
  215. }
  216. .result-sub {
  217. font-size: 28rpx;
  218. color: #64748B;
  219. display: block;
  220. margin-bottom: 48rpx;
  221. }
  222. .info-card {
  223. width: 100%;
  224. background: #FFFFFF;
  225. border-radius: 20rpx;
  226. padding: 30rpx;
  227. box-shadow: 0 4rpx 24rpx rgba(249, 115, 22, 0.08);
  228. margin-bottom: 60rpx;
  229. }
  230. .info-row {
  231. display: flex;
  232. justify-content: space-between;
  233. align-items: center;
  234. padding: 16rpx 0;
  235. }
  236. .info-label {
  237. font-size: 28rpx;
  238. color: #64748B;
  239. }
  240. .info-value {
  241. font-size: 28rpx;
  242. color: #1E293B;
  243. font-weight: 600;
  244. }
  245. .info-value.gift {
  246. color: #F97316;
  247. }
  248. .btn-group {
  249. width: 100%;
  250. display: flex;
  251. flex-direction: column;
  252. }
  253. .btn-primary {
  254. width: 100%;
  255. height: 96rpx;
  256. line-height: 96rpx;
  257. background: linear-gradient(135deg, #F97316 0%, #EA580C 100%);
  258. color: #fff;
  259. font-size: 32rpx;
  260. font-weight: 600;
  261. border-radius: 48rpx;
  262. border: none;
  263. margin-bottom: 24rpx;
  264. }
  265. .btn-primary::after {
  266. border: none;
  267. }
  268. .btn-secondary {
  269. width: 100%;
  270. height: 96rpx;
  271. line-height: 96rpx;
  272. background: #FFFFFF;
  273. color: #F97316;
  274. font-size: 32rpx;
  275. font-weight: 600;
  276. border-radius: 48rpx;
  277. border: 2rpx solid #FED7AA;
  278. }
  279. .btn-secondary::after {
  280. border: none;
  281. }
  282. </style>