index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <Container title="VIP充值" bgColor="#f8f8f8" headerColor="#fff">
  3. <view class="recharge-main">
  4. <!-- 内容区 -->
  5. <view class="content">
  6. <!-- 套餐选择 -->
  7. <view class="plan-list">
  8. <view
  9. class="plan-card"
  10. v-for="(item, index) in data"
  11. :class="activeCurrent === index && 'active'"
  12. @click="activeCurrent = index"
  13. >
  14. <view class="plan-title">{{ item?.package_name }}</view>
  15. <view class="plan-price">
  16. <text class="price">{{ item?.package_preferential_price }}</text>
  17. <view class="plan-origin"
  18. >¥{{ item?.package_original_price }}</view
  19. >
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 权益展示 -->
  24. <div class="title">权益展示</div>
  25. <view class="benefit">
  26. <view
  27. v-for="(item, i) in data[activeCurrent]?.binding_rights_info"
  28. :key="item.id"
  29. class="benefit-item"
  30. >
  31. <view class="t">权益{{ i + 1 }}</view>
  32. {{ item.authority_title }}
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 底部按钮 -->
  37. </view>
  38. <template #footer>
  39. <!-- 协议勾选 -->
  40. <view class="agreement">
  41. <uni-data-checkbox
  42. v-model="isSelected"
  43. multiple
  44. :localdata="[
  45. {
  46. text: '阅读并确认',
  47. value: 1,
  48. },
  49. ]"
  50. >
  51. <template #label="{ item }">
  52. <text
  53. :style="{
  54. paddingLeft: '10rpx',
  55. }"
  56. >{{ item.text }}</text
  57. >
  58. <text
  59. @click="
  60. () => {
  61. router.push({
  62. url: '/pages/richpage/index',
  63. params: {
  64. title: '会员服务权益',
  65. content_code: 'service_rights',
  66. },
  67. });
  68. }
  69. "
  70. >《会员服务权益》</text
  71. >
  72. <text
  73. @click="
  74. () => {
  75. router.push({
  76. url: '/pages/richpage/index',
  77. params: {
  78. title: '自动续费协议',
  79. content_code: 'automatic_renewal_agreement',
  80. },
  81. });
  82. }
  83. "
  84. >(自动续费协议)</text
  85. >
  86. </template>
  87. </uni-data-checkbox>
  88. </view>
  89. <button class="open-btn" @click="onSubmit">立即开通</button>
  90. </template>
  91. <!-- 客服 -->
  92. <view class="service">
  93. <CustomerService>联系客服</CustomerService>
  94. </view>
  95. </Container>
  96. </template>
  97. <script setup name="recharge">
  98. import Container from "@/components/Container/Container.vue";
  99. import CustomerService from "@/components/CustomerService/CustomerService.vue";
  100. import { ref, onMounted, getCurrentInstance } from "vue";
  101. import { request } from "../../utils/request";
  102. import ext from "../../ext.json";
  103. import { router } from "../../utils/router";
  104. const instance = getCurrentInstance();
  105. const activeCurrent = ref(0);
  106. const isSelected = ref([0]);
  107. const data = ref([]);
  108. const onSubmit = () => {
  109. if (!isSelected.value[0])
  110. return uni.showToast({
  111. icon: "none",
  112. title: "请阅读并确认",
  113. });
  114. uni.login({
  115. provider: instance.proxy.$mpPlatform.substring(3),
  116. success: async ({ code }) => {
  117. const package_id = data.value[activeCurrent.value]?.id;
  118. // 先调用新增订单再支付
  119. const order = await request(
  120. "api/question_bank/question_reception/orders/add",
  121. {
  122. package_id,
  123. }
  124. );
  125. const e = await request(
  126. "api/question_bank/question_reception/orders/wechat_pay",
  127. {
  128. code,
  129. order_id: order.data.order_id,
  130. app_id: ext.extAppid,
  131. }
  132. );
  133. uni.requestPayment({
  134. provider: "wxpay",
  135. timeStamp: e.data.timeStamp, //时间戳
  136. nonceStr: e.data.nonceStr, //随机字符串
  137. package: e.data.package, //prepay_id
  138. signType: e.data.signType, //签名算法MD5
  139. paySign: e.data.paySign, //签名,
  140. success(res) {
  141. router.redirectTo('/pages/success/paysuccess')
  142. },
  143. fail(err) {
  144. router.redirectTo('/pages/success/error')
  145. },
  146. });
  147. },
  148. });
  149. };
  150. onMounted(async () => {
  151. const res = await request(
  152. "api/question_bank/question_reception/recharge_package/list"
  153. );
  154. data.value = res.data.data;
  155. });
  156. </script>
  157. <style scoped lang="scss">
  158. @import "@/uni.scss";
  159. .recharge-main {
  160. display: flex;
  161. flex-direction: column;
  162. position: relative;
  163. padding-bottom: 120rpx; // 预留底部按钮高度
  164. }
  165. .content {
  166. flex: 1;
  167. padding: 32rpx 24rpx 0 24rpx;
  168. }
  169. .plan-list {
  170. display: flex;
  171. gap: 24rpx;
  172. margin-bottom: 12rpx;
  173. }
  174. .title {
  175. font-family: PingFang SC, PingFang SC;
  176. font-weight: bold;
  177. font-size: 32rpx;
  178. color: #000000;
  179. margin-bottom: 10rpx;
  180. }
  181. .p {
  182. flex: 1;
  183. }
  184. .plan-card {
  185. flex: 1;
  186. border: 2rpx solid $default;
  187. border-radius: 16rpx;
  188. height: 332rpx;
  189. background: #fff;
  190. transition: border-color 0.2s;
  191. position: relative;
  192. display: flex;
  193. flex-direction: column;
  194. align-items: center;
  195. justify-content: center;
  196. gap: 52rpx;
  197. color: #666666;
  198. &.active {
  199. border-color: #e7c8ac;
  200. }
  201. .plan-title {
  202. font-size: 28rpx;
  203. color: #333;
  204. margin-bottom: 8rpx;
  205. .plan-tag {
  206. color: $error;
  207. font-size: 20rpx;
  208. margin-left: 8rpx;
  209. border: 1rpx solid $error;
  210. border-radius: 6rpx;
  211. padding: 0 8rpx;
  212. height: 28rpx;
  213. line-height: 28rpx;
  214. background: #fff;
  215. vertical-align: middle;
  216. }
  217. }
  218. .plan-price {
  219. display: flex;
  220. flex-direction: column;
  221. align-items: center;
  222. .price {
  223. font-size: 60rpx;
  224. font-weight: bold;
  225. color: $error;
  226. ::before {
  227. content: "¥";
  228. font-size: 32rpx;
  229. }
  230. }
  231. }
  232. .plan-origin {
  233. font-size: 22rpx;
  234. text-decoration: line-through;
  235. margin-top: 4rpx;
  236. }
  237. }
  238. .plan-tip {
  239. font-size: 22rpx;
  240. font-weight: bold;
  241. margin-bottom: 24rpx;
  242. margin-left: 8rpx;
  243. margin-top: 15rpx;
  244. }
  245. .benefit {
  246. display: flex;
  247. flex-direction: column;
  248. gap: 12rpx;
  249. }
  250. .benefit-item {
  251. border-radius: 12rpx;
  252. padding: 32rpx 24rpx;
  253. font-weight: bold;
  254. background: #ffffff;
  255. border-radius: 16rpx;
  256. display: flex;
  257. align-items: center;
  258. gap: 24rpx;
  259. .t {
  260. width: 105rpx;
  261. height: 56rpx;
  262. background: linear-gradient(90deg, #f0dfcd 0%, #e7c8ac 100%);
  263. border-radius: 8rpx 8rpx 8rpx 8rpx;
  264. font-family: PingFang SC, PingFang SC;
  265. font-weight: 500;
  266. font-size: 28rpx;
  267. color: #000000;
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. }
  272. view {
  273. font-size: 28rpx;
  274. color: #333;
  275. margin-bottom: 12rpx;
  276. &:last-child {
  277. margin-bottom: 0;
  278. }
  279. }
  280. }
  281. .service {
  282. color: $uni-primary;
  283. font-size: 28rpx;
  284. margin-bottom: 40rpx;
  285. text-align: right;
  286. position: absolute;
  287. bottom: 10%;
  288. right: 5%;
  289. }
  290. .agreement {
  291. display: flex;
  292. align-items: center;
  293. font-size: 22rpx;
  294. color: #666;
  295. margin-bottom: 32rpx;
  296. .radio {
  297. margin-right: 12rpx;
  298. }
  299. }
  300. .footer-btn {
  301. position: fixed;
  302. left: 0;
  303. bottom: 0;
  304. width: 100vw;
  305. background: #fff;
  306. padding: 24rpx;
  307. box-sizing: border-box;
  308. z-index: 10;
  309. box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.03);
  310. }
  311. .open-btn {
  312. width: 100%;
  313. background: linear-gradient(90deg, #f0dfcd 0%, #e7c8ac 100%);
  314. color: #000;
  315. font-size: 32rpx;
  316. border-radius: 12rpx;
  317. height: 88rpx;
  318. line-height: 88rpx;
  319. text-align: center;
  320. font-weight: bold;
  321. border: none;
  322. margin-top: 0;
  323. &:active {
  324. background: linear-gradient(90deg, #f0dfcd 0%, #e7c8ac 100%);
  325. }
  326. }
  327. </style>