index.vue 13 KB

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