result.vue 8.7 KB

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