index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. </Container>
  92. <!-- 客服 -->
  93. <view class="service">
  94. <CustomerService>联系客服</CustomerService>
  95. </view>
  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 paying = ref(false);
  109. const onSubmit = () => {
  110. if (paying.value) return;
  111. console.log(paying.value);
  112. if (!isSelected.value[0])
  113. return uni.showToast({
  114. icon: "none",
  115. title: "请阅读并确认",
  116. });
  117. paying.value = true;
  118. uni.login({
  119. provider: instance.proxy.$mpPlatform.substring(3),
  120. success: async ({ code }) => {
  121. if (!code) {
  122. paying.value = false;
  123. return;
  124. }
  125. const package_id = data.value[activeCurrent.value]?.id;
  126. // 先调用新增订单再支付
  127. const order = await request(
  128. "api/question_bank/question_reception/orders/add",
  129. {
  130. package_id,
  131. }
  132. );
  133. if (order.code !== "success") {
  134. paying.value = false;
  135. return;
  136. }
  137. const e = await request(
  138. "api/question_bank/question_reception/orders/wechat_pay",
  139. {
  140. code,
  141. order_id: order.data.order_id,
  142. app_id: ext.extAppid,
  143. }
  144. );
  145. if (e.code !== "success") {
  146. paying.value = false;
  147. return;
  148. }
  149. uni.requestPayment({
  150. provider: "wxpay",
  151. timeStamp: e.data.timeStamp, //时间戳
  152. nonceStr: e.data.nonceStr, //随机字符串
  153. package: e.data.package, //prepay_id
  154. signType: e.data.signType, //签名算法MD5
  155. paySign: e.data.paySign, //签名,
  156. success: (res) => {
  157. router.redirectTo("/pages/success/paysuccess");
  158. },
  159. fail: (err) => {
  160. router.redirectTo("/pages/success/error");
  161. },
  162. complete() {
  163. paying.value = false;
  164. },
  165. });
  166. },
  167. fail() {
  168. paying.value = false;
  169. },
  170. });
  171. };
  172. onMounted(async () => {
  173. const res = await request(
  174. "api/question_bank/question_reception/recharge_package/list"
  175. );
  176. data.value = res.data.data;
  177. });
  178. </script>
  179. <style scoped lang="scss">
  180. @import "@/uni.scss";
  181. .recharge-main {
  182. display: flex;
  183. flex-direction: column;
  184. position: relative;
  185. padding-bottom: 120rpx; // 预留底部按钮高度
  186. }
  187. .content {
  188. flex: 1;
  189. padding: 32rpx 24rpx 0 24rpx;
  190. }
  191. .plan-list {
  192. display: flex;
  193. gap: 24rpx;
  194. margin-bottom: 12rpx;
  195. }
  196. .title {
  197. font-family: PingFang SC, PingFang SC;
  198. font-weight: bold;
  199. font-size: 32rpx;
  200. color: #000000;
  201. margin-bottom: 10rpx;
  202. }
  203. .p {
  204. flex: 1;
  205. }
  206. .plan-card {
  207. flex: 1;
  208. border: 2rpx solid $default;
  209. border-radius: 16rpx;
  210. height: 332rpx;
  211. background: #fff;
  212. transition: border-color 0.2s;
  213. position: relative;
  214. display: flex;
  215. flex-direction: column;
  216. align-items: center;
  217. justify-content: center;
  218. gap: 52rpx;
  219. color: #666666;
  220. &.active {
  221. border-color: #e7c8ac;
  222. }
  223. .plan-title {
  224. font-size: 28rpx;
  225. color: #333;
  226. margin-bottom: 8rpx;
  227. .plan-tag {
  228. color: $error;
  229. font-size: 20rpx;
  230. margin-left: 8rpx;
  231. border: 1rpx solid $error;
  232. border-radius: 6rpx;
  233. padding: 0 8rpx;
  234. height: 28rpx;
  235. line-height: 28rpx;
  236. background: #fff;
  237. vertical-align: middle;
  238. }
  239. }
  240. .plan-price {
  241. display: flex;
  242. flex-direction: column;
  243. align-items: center;
  244. .price {
  245. font-size: 60rpx;
  246. font-weight: bold;
  247. color: $error;
  248. ::before {
  249. content: "¥";
  250. font-size: 32rpx;
  251. }
  252. }
  253. }
  254. .plan-origin {
  255. font-size: 22rpx;
  256. text-decoration: line-through;
  257. margin-top: 4rpx;
  258. }
  259. }
  260. .plan-tip {
  261. font-size: 22rpx;
  262. font-weight: bold;
  263. margin-bottom: 24rpx;
  264. margin-left: 8rpx;
  265. margin-top: 15rpx;
  266. }
  267. .benefit {
  268. display: flex;
  269. flex-direction: column;
  270. gap: 12rpx;
  271. }
  272. .benefit-item {
  273. border-radius: 12rpx;
  274. padding: 32rpx 24rpx;
  275. font-weight: bold;
  276. background: #ffffff;
  277. border-radius: 16rpx;
  278. display: flex;
  279. align-items: center;
  280. gap: 24rpx;
  281. .t {
  282. width: 105rpx;
  283. height: 56rpx;
  284. background: linear-gradient(90deg, #f0dfcd 0%, #e7c8ac 100%);
  285. border-radius: 8rpx 8rpx 8rpx 8rpx;
  286. font-family: PingFang SC, PingFang SC;
  287. font-weight: 500;
  288. font-size: 28rpx;
  289. color: #000000;
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. }
  294. view {
  295. font-size: 28rpx;
  296. color: #333;
  297. margin-bottom: 12rpx;
  298. &:last-child {
  299. margin-bottom: 0;
  300. }
  301. }
  302. }
  303. .service {
  304. color: $uni-primary;
  305. font-size: 28rpx;
  306. text-align: right;
  307. position: absolute;
  308. bottom: 30%;
  309. right: 5%;
  310. }
  311. .agreement {
  312. display: flex;
  313. align-items: center;
  314. font-size: 22rpx;
  315. color: #666;
  316. margin-bottom: 32rpx;
  317. .radio {
  318. margin-right: 12rpx;
  319. }
  320. }
  321. .footer-btn {
  322. position: fixed;
  323. left: 0;
  324. bottom: 0;
  325. width: 100vw;
  326. background: #fff;
  327. padding: 24rpx;
  328. box-sizing: border-box;
  329. z-index: 10;
  330. box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.03);
  331. }
  332. .open-btn {
  333. width: 100%;
  334. background: linear-gradient(90deg, #f0dfcd 0%, #e7c8ac 100%);
  335. color: #000;
  336. font-size: 32rpx;
  337. border-radius: 12rpx;
  338. height: 88rpx;
  339. line-height: 88rpx;
  340. text-align: center;
  341. font-weight: bold;
  342. border: none;
  343. margin-top: 0;
  344. &:active {
  345. background: linear-gradient(90deg, #f0dfcd 0%, #e7c8ac 100%);
  346. }
  347. }
  348. </style>