result.vue 8.2 KB

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