index.vue 7.7 KB

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