index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <template>
  2. <view class="top-cont">
  3. <view :style="{height: statusBarHeight,background: bgColor }"></view>
  4. <u-navbar title="充值" titleStyle="font-weight: 500;" @rightClick="rightClick" :autoBack="true" leftIcon="arrow-left"
  5. :bg-color="bgColor">
  6. </u-navbar>
  7. <view class="top-bg">
  8. <image class="bg" src="https://user.test.ylrztop.com/images/cz_bg.png" mode="widthFix"></image>
  9. <view class="balance">
  10. <view class="align-center justify-between">
  11. <view class="text">我的账户余额</view>
  12. <view v-if="eTime!==null" class="right">距离结束还剩:{{eTime}}</view>
  13. </view>
  14. <view class="num">{{user.money||0}}</view>
  15. </view>
  16. </view>
  17. <view class="content">
  18. <view class="top">
  19. <view class="recharge">
  20. <view v-for="(item,index) in dataList" :key="index" @click="choosePackage(item)"
  21. :class="aIndex==item.id?'item active':'item'">
  22. <view class="align-center">
  23. <view class="title">储值¥{{item.rechargeAmount}}</view>
  24. <view v-if="item.tag!==''" class="align-center">
  25. <image class="w40 h40 hot" src="../../static/images/user/hot_list_icon20.png" mode="">
  26. </image>
  27. <view class="hot-box">
  28. <view class="count">{{item.tag}}</view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="align-center justify-between">
  33. <view class="text">{{item.shortDesc}}</view>
  34. <view class="align-center" @click.stop="showDetail(item)">
  35. <view class="detail">权益详情</view>
  36. <image class="w48 h48" src="../../static/images/user/my_right_arrow_right_icon24.png"
  37. mode=""></image>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- <view class="pay">
  43. <view class="title">
  44. <text class="name">付款给 壹柒玖康养集团</text>
  45. <text class="desc">微信收款</text>
  46. </view>
  47. <view class="pay-money">
  48. <view class="pay-money-title">支付金额</view>
  49. <view class="money">
  50. <text class="fh">¥</text>
  51. <input v-model="money" class="uni-input" @input="testMoney" type="digit" focus />
  52. </view>
  53. <textarea class="desc" placeholder="请填写备注说明" maxlength="20" v-model="desc" />
  54. </view>
  55. </view> -->
  56. <view class="btn-box">
  57. <view class="align-center mb20">
  58. <checkbox :checked="isAgreement" @click.stop="handleAgreement()" />
  59. <view class="text">我已阅读并同意</view>
  60. <view class="text color">《会员储值协议》</view>
  61. </view>
  62. <view class="btn" @click="toPay()">立即储存</view>
  63. </view>
  64. </view>
  65. <!-- <view class="ad">
  66. <ad unit-id="adunit-a018415a6deb69e8"></ad>
  67. </view> -->
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import {
  73. getPayment,
  74. toPayment,
  75. getTemplates
  76. } from '@/api/payment'
  77. import {
  78. getUserInfo
  79. } from '@/api/user'
  80. export default {
  81. data() {
  82. return {
  83. dataList: [
  84. // {id:1,price:66,text:'限时赠送6元现金券',count:'赠10元'},
  85. // {id:2,price:100,text:'限时赠送10元现金券',count:'赠10元'},
  86. // {id:3,price:200,text:'限时赠送20元现金券'},
  87. ],
  88. user: null,
  89. eTime: null,
  90. aIndex: 0,
  91. isAgreement: false,
  92. statusBarHeight: '',
  93. top: 0,
  94. companyUserId: null,
  95. companyId: null,
  96. desc: "",
  97. money: null,
  98. wxPay: true,
  99. templateId: 0
  100. }
  101. },
  102. computed: {
  103. // 计算属性的 getter
  104. bgColor: function() {
  105. var top = this.top / 30;
  106. return 'rgba(11,179,242, ' + top + ')';
  107. },
  108. },
  109. onLoad: function(options) {
  110. let currentTime = new Date();
  111. this.getUserInfo();
  112. this.getList()
  113. // if (options.hasOwnProperty('q') && options.q) {
  114. // // 通过下面这步解码,可以拿到url的值
  115. // const url = decodeURIComponent(options.q)
  116. // this.url=url;
  117. // // // 对url中携带的参数提取处理
  118. // const obj = this.utils.urlToObj(url)
  119. // console.log(obj)
  120. // this.companyId=obj.companyId;
  121. // this.companyUserId=obj.companyUserId;
  122. // }
  123. this.companyId = options.companyId;
  124. this.companyUserId = options.companyUserId;
  125. },
  126. onShareAppMessage(res) {
  127. return {
  128. title: '云联融智-收款',
  129. path: `/pages_user/user/pay?companyId=` + this.companyId + "&companyUserId=" + this.companyUserId
  130. }
  131. },
  132. methods: {
  133. handleAgreement() {
  134. this.isAgreement = !this.isAgreement;
  135. },
  136. choosePackage(item) {
  137. this.aIndex = item.id
  138. this.templateId = item.id
  139. // let time=this.utils.parseTime(item.endTime)
  140. this.eTime = this.utils.setTime(item.endTime)
  141. },
  142. getUserInfo() {
  143. getUserInfo().then(
  144. res => {
  145. if (res.code == 200) {
  146. if (res.user != null) {
  147. this.user = res.user;
  148. } else {
  149. this.utils.loginOut();
  150. }
  151. } else {
  152. uni.showToast({
  153. icon: 'none',
  154. title: "请求失败",
  155. });
  156. }
  157. },
  158. rej => {}
  159. );
  160. },
  161. testMoney(e) {
  162. let that = this;
  163. let price = e.detail.value
  164. if (price.indexOf(".") == 0) {
  165. //'首位小数点情况'
  166. price = price.replace(/[^$#$]/g, "0.");
  167. price = price.replace(/\.{2,}/g, ".");
  168. }
  169. price = price.match(/^\d*(\.?\d{0,2})/g)[0] || null;
  170. //重新赋值给input
  171. this.$nextTick(() => {
  172. this.money = price;
  173. });
  174. },
  175. getList() {
  176. getTemplates().then(
  177. res => {
  178. if (res.code == 200) {
  179. this.dataList = res.data
  180. } else {
  181. uni.showToast({
  182. icon: 'none',
  183. title: "请求失败",
  184. });
  185. }
  186. },
  187. rej => {}
  188. );
  189. },
  190. showDetail(item) {
  191. if (item) {
  192. uni.navigateTo({
  193. url: '/pages_user/recharge/detail?id=' + item.id
  194. })
  195. }
  196. },
  197. pay() {
  198. if (this.money == null) {
  199. uni.showToast({
  200. icon: 'none',
  201. title: "请输入支付金额"
  202. });
  203. return;
  204. }
  205. uni.login({
  206. success: res => {
  207. console.log(res)
  208. this.payment(res.code);
  209. }
  210. });
  211. },
  212. //充值余额
  213. toPay() {
  214. if (!this.isAgreement) {
  215. uni.showToast({
  216. icon: 'none',
  217. title: "请先同意协议后再储存",
  218. });
  219. return false;
  220. }
  221. if (this.templateId == 0) {
  222. uni.showToast({
  223. icon: 'none',
  224. title: "请选择储值套餐"
  225. });
  226. return;
  227. }
  228. var data = {
  229. userId: this.user.userId,
  230. templateId: this.templateId
  231. }
  232. var that = this;
  233. uni.showLoading();
  234. toPayment(data).then(
  235. res => {
  236. if (res.code == 200) {
  237. console.log(res);
  238. var payData = JSON.parse(res.data.pay_info)
  239. uni.requestPayment({
  240. provider: 'wxpay',
  241. timeStamp: payData.timeStamp,
  242. nonceStr: payData.nonceStr,
  243. package: payData.package,
  244. signType: payData.signType,
  245. paySign: payData.paySign,
  246. success: function(res) {
  247. uni.hideLoading();
  248. uni.showToast({
  249. icon: 'success',
  250. title: "支付成功",
  251. });
  252. uni.navigateBack({
  253. delta: 1
  254. })
  255. // uni.navigateTo({
  256. // url: '/pages/user/index'
  257. // })
  258. },
  259. fail: function(err) {
  260. console.log('fail:' + JSON.stringify(err));
  261. uni.hideLoading();
  262. }
  263. });
  264. } else {
  265. uni.showToast({
  266. icon: 'none',
  267. title: res.msg,
  268. });
  269. }
  270. },
  271. rej => {}
  272. );
  273. },
  274. payment(code) {
  275. var data = {
  276. payMoney: this.money,
  277. remark: this.desc,
  278. code: code,
  279. companyId: this.companyId,
  280. companyUserId: this.companyUserId
  281. };
  282. var that = this;
  283. uni.showLoading();
  284. payment(data).then(
  285. res => {
  286. if (res.code == 200) {
  287. console.log(res);
  288. uni.requestPayment({
  289. provider: 'wxpay',
  290. timeStamp: res.result.timeStamp,
  291. nonceStr: res.result.nonceStr,
  292. // package: res.result.packageValue,
  293. package: res.result.packageStr,
  294. signType: res.result.signType,
  295. paySign: res.result.paySign,
  296. success: function(res) {
  297. uni.hideLoading();
  298. uni.showToast({
  299. icon: 'success',
  300. title: "支付成功",
  301. });
  302. uni.navigateTo({
  303. url: './success'
  304. })
  305. },
  306. fail: function(err) {
  307. console.log('fail:' + JSON.stringify(err));
  308. uni.hideLoading();
  309. }
  310. });
  311. } else {
  312. uni.showToast({
  313. icon: 'none',
  314. title: res.msg,
  315. });
  316. }
  317. },
  318. rej => {}
  319. );
  320. }
  321. }
  322. }
  323. </script>
  324. <style lang="scss">
  325. page {
  326. height: 100%;
  327. background-color: #F5F7FA;
  328. }
  329. .top-bg {
  330. position: relative;
  331. .bg {
  332. width: 100%;
  333. position: relative;
  334. top: 0;
  335. left: 0;
  336. z-index: -1;
  337. }
  338. .balance {
  339. width: calc(100% - 40rpx);
  340. // height: 206rpx;
  341. background: linear-gradient(180deg, rgba(255, 255, 255, 0.8) 0%, #FFFFFF 100%);
  342. border-radius: 16rpx 16rpx 0rpx 0rpx;
  343. border: 4rpx solid #FFFFFF;
  344. padding: 30rpx;
  345. margin: 0 20rpx;
  346. position: absolute;
  347. bottom: 0;
  348. box-sizing: border-box;
  349. // margin-top: -214rpx;
  350. .text {
  351. font-family: PingFang SC, PingFang SC;
  352. font-weight: 400;
  353. font-size: 28rpx;
  354. color: #222426;
  355. text-align: left;
  356. }
  357. .right {
  358. padding: 0 24rpx;
  359. height: 54rpx;
  360. line-height: 54rpx;
  361. font-weight: 400;
  362. font-size: 24rpx;
  363. color: #FFFFFF;
  364. text-align: left;
  365. background: linear-gradient(90deg, #E73823 0%, #FD7620 100%);
  366. border-radius: 28rpx 0rpx 0rpx 28rpx;
  367. margin-right: -30rpx;
  368. }
  369. .num {
  370. font-family: Roboto, Roboto;
  371. font-weight: bold;
  372. font-size: 64rpx;
  373. color: #222426;
  374. }
  375. }
  376. }
  377. .content {
  378. height: 100%;
  379. display: flex;
  380. flex-direction: column;
  381. // padding-top: calc(var(--status-bar-height) + 40rpx) !important;
  382. // margin: 20upx 0upx;
  383. // padding:20upx;
  384. .top {
  385. flex: 1;
  386. padding: 20rpx;
  387. .recharge {
  388. .item {
  389. padding: 30rpx;
  390. background: #FFFFFF;
  391. border-radius: 16rpx 16rpx 16rpx 16rpx;
  392. border: 2rpx solid #EFF3F7;
  393. margin-bottom: 20rpx;
  394. &:last-child {
  395. margin-bottom: 0;
  396. }
  397. &.active {
  398. border: 2rpx solid #F3CDA7;
  399. background: #FFF6EA;
  400. .title {
  401. color: #AF6020;
  402. }
  403. .text {
  404. color: #AF6020;
  405. }
  406. }
  407. .title {
  408. font-family: PingFang SC, PingFang SC;
  409. font-weight: 600;
  410. font-size: 48rpx;
  411. color: #222426;
  412. line-height: 64rpx;
  413. text-align: left;
  414. margin-right: 20rpx;
  415. }
  416. .hot {
  417. margin-right: -20rpx;
  418. z-index: 9;
  419. }
  420. .hot-box {
  421. width: 124rpx;
  422. height: 32rpx;
  423. line-height: 32rpx;
  424. background: linear-gradient(90deg, #E73823 0%, #FD7620 100%);
  425. border-radius: 6rpx 6rpx 6rpx 6rpx;
  426. transform: skew(-10deg);
  427. padding-left: 30rpx;
  428. box-sizing: border-box;
  429. .count {
  430. font-family: PingFang SC, PingFang SC;
  431. font-weight: 500;
  432. font-size: 24rpx;
  433. color: #FEF5EA;
  434. transform: skew(10deg);
  435. }
  436. }
  437. .text {
  438. font-family: PingFang SC, PingFang SC;
  439. font-weight: 400;
  440. font-size: 26rpx;
  441. color: #898E91;
  442. line-height: 48rpx;
  443. text-align: left;
  444. }
  445. .detail {
  446. font-family: PingFang SC, PingFang SC;
  447. font-weight: 400;
  448. font-size: 24rpx;
  449. color: #AF6020;
  450. text-align: right;
  451. }
  452. }
  453. }
  454. .inner {
  455. width: 100%;
  456. display: flex;
  457. flex-direction: column;
  458. align-items: flex-start;
  459. justify-content: center;
  460. .pay {
  461. width: 100%;
  462. box-shadow: 1px 1px 5px #e6e6e6;
  463. background: #FFFFFF;
  464. border-radius: 5upx;
  465. display: flex;
  466. flex-direction: column;
  467. align-items: flex-start;
  468. .title {
  469. display: flex;
  470. flex-direction: column;
  471. align-items: flex-start;
  472. width: 100%;
  473. background-color: #f7f7f7;
  474. padding: 30rpx 0rpx;
  475. .name {
  476. padding: 15rpx 30rpx;
  477. font-size: 32rpx;
  478. }
  479. .desc {
  480. color: #989898;
  481. padding: 15rpx 30rpx;
  482. font-size: 25rpx;
  483. }
  484. }
  485. .pay-money {
  486. padding: 30rpx 0rpx;
  487. width: 100%;
  488. background: #FFFFFF;
  489. border-radius: 5upx;
  490. display: flex;
  491. flex-direction: column;
  492. align-items: flex-start;
  493. .pay-money-title {
  494. padding: 15rpx 30rpx;
  495. font-size: 32rpx;
  496. }
  497. .money {
  498. font-size: 42rpx;
  499. padding: 15rpx 30rpx;
  500. display: flex;
  501. flex-direction: row;
  502. align-items: flex-start;
  503. input {
  504. margin-left: 15rpx;
  505. }
  506. }
  507. .desc {
  508. width: 100%;
  509. padding: 30rpx 30rpx;
  510. border-top: 1rpx solid #e6e6e6;
  511. }
  512. textarea {
  513. height: 50rpx;
  514. line-height: 50rpx;
  515. }
  516. }
  517. }
  518. }
  519. .btn-box {
  520. padding: 30rpx;
  521. // height: 121upx;
  522. // display: flex;
  523. // align-items: center;
  524. // justify-content: center;
  525. background: #FFFFFF;
  526. position: fixed;
  527. z-index: 999;
  528. width: 100%;
  529. bottom: 0;
  530. left: 0;
  531. text-align: center;
  532. box-sizing: border-box;
  533. .text {
  534. font-family: PingFang SC, PingFang SC;
  535. font-weight: 400;
  536. font-size: 24rpx;
  537. color: #626468;
  538. line-height: 56rpx;
  539. &.color {
  540. color: #209DD8;
  541. }
  542. }
  543. .btn {
  544. width: 100%;
  545. height: 88upx;
  546. line-height: 88upx;
  547. font-size: 32upx;
  548. font-family: PingFang SC;
  549. font-weight: bold;
  550. color: #FFFFFF;
  551. text-align: center;
  552. background: #008FD3;
  553. border-radius: 44upx;
  554. }
  555. }
  556. }
  557. .ad {
  558. margin: 0rpx 0rpx 60rpx;
  559. }
  560. }
  561. </style>