index.vue 8.3 KB

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