index.vue 7.6 KB

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