index.vue 7.0 KB

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