recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <view class="content">
  3. <view class="title">
  4. <text class="iconfont icon-qian"></text>
  5. <text>江西南昌交通学院</text>
  6. <text>(墨轩湖校区)</text>
  7. </view>
  8. <view class="input_amount">
  9. <view class="amount_tip">充值金额(元)</view>
  10. <view class="amount_inp">
  11. <text></text>
  12. <input class="inp" type="number" maxlength="4" v-model="amount" @input="onInput" @blur="onBlur"
  13. placeholder="请输入大于10元,小于100元" placeholder-class="ph_class" />
  14. </view>
  15. <text>最多可输入金额100元</text>
  16. </view>
  17. <view class="amount_select">
  18. <view class="amount_btn">
  19. <text @tap="sel_amount(10)" :class="{selStyle:amount == 10}">充10元</text>
  20. <text @tap="sel_amount(20)" :class="{selStyle:amount == 20}">充20元</text>
  21. <text @tap="sel_amount(50)" :class="{selStyle:amount == 50}">充50元</text>
  22. <text @tap="sel_amount(100)" :class="{selStyle:amount == 100}">充100元</text>
  23. </view>
  24. <view class="reminder">温馨提示:最少充值金额为10元</view>
  25. <view class="payment">支付金额:<text>{{amount}}</text>元</view>
  26. <button class="btn_submit" type="primary" @tap="tip(true)">确认提交</button>
  27. <button class="btn_tel" type="default" @tap="callPhone">客服热线:{{phone_number}}</button>
  28. <view class="tips">
  29. 尊敬的用户,你好!因项目提现业务配置问题导致您无法提现对此,我们深表歉意!您可致电运营商处理提现问题,运营商电话:13645689854。感谢您对我们工作的支持和理解。
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. card_number: '',
  39. amount: '', // 金额
  40. phone_number: '13645689854', // 客户热线电话
  41. IP: '',
  42. code: '',
  43. ceshi: 'code',
  44. test: this.$store.state.test,
  45. isXiaoqu: false
  46. };
  47. },
  48. onLoad() {
  49. // 系统正在维护...
  50. if (this.test == 'weihuzhong') {
  51. uni.redirectTo({
  52. url: '../../pages/index/index'
  53. })
  54. return;
  55. }
  56. // 测试环境
  57. if (this.test) {
  58. this.amount = 0.01
  59. }
  60. },
  61. onReady() {
  62. this.has_user_info();
  63. },
  64. methods: {
  65. /**
  66. * 获得code
  67. */
  68. getCode(param_ip) {
  69. uni.login({
  70. success: (res) => {
  71. // console.log('recharge', res);
  72. if (res.code) {
  73. // 组合地址,发起支付
  74. // this.jsapi(param_ip, res.code)
  75. this.jsapi(res.code)
  76. } else {
  77. uni.showToast({
  78. title: res.errMsg,
  79. icon: 'none'
  80. });
  81. }
  82. }
  83. })
  84. },
  85. /**
  86. * 获取IP
  87. */
  88. // async getIP() {
  89. // const res = await this.$myRequest({
  90. // host: 'ip',
  91. // url: '?ie=utf-8',
  92. // // url: '/json',
  93. // method: 'POST'
  94. // })
  95. // if (res.data) {
  96. // // console.log(res);
  97. // const reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
  98. // let ip = reg.exec(res.data);
  99. // // 获取code
  100. // this.getCode(ip[0])
  101. // } else {
  102. // uni.showToast({
  103. // title: 未获得IP地址,
  104. // icon: 'none',
  105. // duration: 2000
  106. // })
  107. // }
  108. // },
  109. /**
  110. * 请求服务器,获取支付参数,并支付
  111. */
  112. async jsapi(param_code) {
  113. if (param_code == '' || this.amount == '') {
  114. uni.showToast({
  115. icon: 'none',
  116. title: 'code或充值金额为空'
  117. });
  118. return
  119. }
  120. const res = await this.$myRequest({
  121. host: this.ceshi,
  122. url: '/HotWaters/wpPay.action',
  123. method: 'POST',
  124. header: {
  125. 'content-type': 'application/x-www-form-urlencoded'
  126. },
  127. data: {
  128. // ip: param_ip,
  129. code: param_code,
  130. card_number: this.card_number,
  131. num: this.amount
  132. }
  133. })
  134. // console.log(res);
  135. if (res.data.pay == 'error') {
  136. uni.showToast({
  137. title: '未获得支付参数',
  138. icon: 'success',
  139. duration: 3000
  140. });
  141. } else {
  142. wx.requestPayment({
  143. timeStamp: res.data.pay.timeStamp,
  144. nonceStr: res.data.pay.nonceStr,
  145. package: 'prepay_id=' + res.data.pay.prepay_id,
  146. signType: res.data.pay.signType,
  147. paySign: res.data.pay.paySign,
  148. success: (res) => {
  149. // console.log(res);
  150. if (res.errMsg == 'requestPayment:ok') {
  151. this.$store.state.payInfo.from = 'reshui_pay';
  152. this.$store.state.payInfo.resultMsg = '支付成功';
  153. this.$store.state.reshui_amount = this.amount;
  154. uni.$emit('update_reshui_amount', {
  155. msg: '充值成功,刷新金额!'
  156. });
  157. uni.navigateBack({
  158. delta: 1
  159. });
  160. }
  161. },
  162. fail: (res) => {
  163. if (res.errMsg == 'requestPayment:fail cancel') {
  164. uni.showToast({
  165. title: '支付已取消',
  166. icon: 'success',
  167. duration: 2000
  168. });
  169. }
  170. },
  171. complete: (res) => {
  172. // console.log(res);
  173. }
  174. });
  175. }
  176. },
  177. /**
  178. * 输入充值金额
  179. */
  180. onInput(e) {
  181. if (this.test) { // 测试环境
  182. return
  183. }
  184. const v = e.detail.value
  185. const zero = /^(0{1,})|[^0-9]/g
  186. let final = 0
  187. if (!v) {
  188. final = 0
  189. } else {
  190. final = v.toString().replace(zero, (v) => {
  191. return 0
  192. })
  193. if (final.split('')[0] * 1 === 0) {
  194. final = final.slice(1) - 0 || 0
  195. }
  196. if (final > 100) {
  197. final = 100
  198. }
  199. }
  200. this.$nextTick(() => {
  201. if (final.toString() == '0') {
  202. this.amount = ''
  203. } else {
  204. this.amount = final.toString() || '0'
  205. }
  206. })
  207. },
  208. /**
  209. * 输入框,失去焦点时
  210. */
  211. onBlur() {
  212. if (this.test) { // 测试环境
  213. return
  214. }
  215. if (this.amount < 10) {
  216. this.amount = 10
  217. }
  218. },
  219. /**
  220. * 选择充值金额
  221. */
  222. sel_amount(m) {
  223. this.amount = m
  224. },
  225. /**
  226. * 是否有用户信息
  227. */
  228. has_user_info() {
  229. try {
  230. const value = uni.getStorageSync('userinfo_storage_key');
  231. if (value)
  232. this.card_number = value.card_number;
  233. // console.log(value.campus);
  234. if (value.campus != '墨轩湖校区') {
  235. this.isXiaoqu = false;
  236. } else {
  237. this.isXiaoqu = true;
  238. }
  239. } catch (e) {
  240. // console.log(e)
  241. uni.showToast({
  242. title: '异常:' + e,
  243. duration: 3000
  244. })
  245. }
  246. this.tip(false);
  247. },
  248. /**
  249. * 打开页面时提示
  250. */
  251. tip(param) {
  252. let _this = this;
  253. if (!this.isXiaoqu) {
  254. if (param == false) {
  255. uni.showModal({
  256. title: '提示',
  257. content: '目前只对【墨轩湖校区】进行充值!请知晓!',
  258. showCancel: false,
  259. confirmText: '我已知晓',
  260. confirmColor: '#F00',
  261. success: function(res) {
  262. if (res.confirm) {
  263. // console.log('用户点击确定');
  264. }
  265. }
  266. });
  267. } else {
  268. uni.showModal({
  269. title: '提示',
  270. content: '目前只对【墨轩湖校区】的【热水钱包】进行充值!',
  271. confirmText: '对,没错',
  272. confirmColor: '#F00',
  273. cancelText: '哦,错了',
  274. success: function(res) {
  275. if (res.confirm) {
  276. // console.log('用户点击确定');
  277. _this.chongzhi()
  278. } else if (res.cancel) {
  279. // console.log('用户点击取消');
  280. }
  281. }
  282. });
  283. }
  284. } else {
  285. if (param == true) {
  286. this.chongzhi()
  287. }
  288. }
  289. },
  290. /**
  291. * 调用接口实现充值功能
  292. */
  293. chongzhi() {
  294. var _this = this;
  295. if (isNaN(this.amount)) {
  296. uni.showToast({
  297. title: '请输入正确金额',
  298. duration: 2000
  299. })
  300. return
  301. }
  302. // 测试环境下执行
  303. if (this.test) { // 测试环境
  304. uni.showModal({
  305. title: '提示',
  306. content: '您选择了充值:¥' + this.amount + ' 元',
  307. cancelText: '算了',
  308. confirmText: '充值',
  309. success: (res) => {
  310. if (res.confirm) {
  311. // 获取IP
  312. // _this.getIP()
  313. // 获取code
  314. this.getCode()
  315. } else if (res.cancel) {
  316. return
  317. }
  318. }
  319. })
  320. return
  321. }
  322. // 生产环境
  323. if (this.amount < 10 || this.amount > 100) {
  324. uni.showToast({
  325. icon: 'none',
  326. title: '最少充值10元,最多充值100元!',
  327. mask: true,
  328. duration: 3000
  329. })
  330. return
  331. }
  332. // 确认
  333. uni.showModal({
  334. title: '提示',
  335. content: '您选择了充值:¥' + this.amount + ' 元',
  336. cancelText: '算了',
  337. confirmText: '充值',
  338. success: (res) => {
  339. if (res.confirm) {
  340. // 获取IP
  341. // _this.getIP()
  342. // 获取code
  343. this.getCode()
  344. } else if (res.cancel) {
  345. return
  346. }
  347. }
  348. })
  349. },
  350. /**
  351. * 拨打电话
  352. */
  353. callPhone() {
  354. uni.makePhoneCall({
  355. phoneNumber: this.phone_number
  356. });
  357. }
  358. }
  359. }
  360. </script>
  361. <style scoped lang="scss">
  362. .content {
  363. display: flex;
  364. flex-direction: column;
  365. background-color: #F5F5F5;
  366. width: 750rpx;
  367. .title {
  368. display: flex;
  369. align-items: center;
  370. padding: 40rpx;
  371. font-size: 36rpx;
  372. font-family: Microsoft YaHei-3970(82674968);
  373. color: #333333;
  374. font-weight: bold;
  375. text:nth-child(1) {
  376. color: $my-color-primary;
  377. font-size: 50rpx;
  378. }
  379. text:nth-child(2) {
  380. margin-left: 15rpx;
  381. }
  382. text:nth-child(3) {
  383. color: #F00;
  384. }
  385. }
  386. .input_amount {
  387. background-color: #FFFFFF;
  388. width: 670rpx;
  389. height: 210rpx;
  390. padding: 40rpx 40rpx 0rpx 40rpx;
  391. border-radius: 40rpx 40rpx 0rpx 0rpx;
  392. .amount_tip {
  393. font-size: 32rpx;
  394. font-family: Microsoft YaHei-3970(82674968);
  395. }
  396. .amount_inp {
  397. display: flex;
  398. flex-direction: row;
  399. border-bottom: 1px solid #cccccc;
  400. margin-top: 20rpx;
  401. margin-bottom: 10rpx;
  402. text {
  403. width: 50rpx;
  404. height: 74rpx;
  405. font-size: 50rpx;
  406. font-weight: bold;
  407. padding-top: 6rpx;
  408. font-family: Microsoft YaHei-3970(82674968);
  409. }
  410. text::before {
  411. content: '¥';
  412. }
  413. .inp {
  414. width: 620rpx;
  415. height: 80rpx;
  416. font-size: 50rpx;
  417. font-weight: bold;
  418. font-family: Microsoft YaHei-3970(82674968);
  419. }
  420. /deep/.ph_class {
  421. font-size: 32rpx;
  422. font-weight: normal;
  423. color: #B2B2B2;
  424. }
  425. }
  426. text {
  427. font-size: 26rpx;
  428. font-family: Microsoft YaHei-3970(82674968);
  429. font-weight: 500;
  430. }
  431. }
  432. .amount_select {
  433. padding: 0rpx 40rpx 40rpx 40rpx;
  434. .amount_btn {
  435. display: flex;
  436. justify-content: space-between;
  437. margin: 30rpx 0 20rpx;
  438. text {
  439. width: 150rpx;
  440. height: 120rpx;
  441. line-height: 120rpx;
  442. font-size: 32rpx;
  443. font-family: Microsoft YaHei-3970(82674968);
  444. color: #333333;
  445. text-align: center;
  446. background: #FFFFFF;
  447. border: 3rpx solid #AAAAAA;
  448. }
  449. .selStyle {
  450. border: 0rpx;
  451. width: 156rpx;
  452. height: 126rpx;
  453. background: url(../../static/images/jinebeijing2x.png) 0rpx 0rpx no-repeat;
  454. background-size: 100%;
  455. }
  456. }
  457. .reminder {
  458. height: 26rpx;
  459. font-size: 26rpx;
  460. font-family: Microsoft YaHei-3970(82674968);
  461. color: $my-color-primary;
  462. }
  463. .payment {
  464. margin-top: 65rpx;
  465. font-size: 32rpx;
  466. font-family: Microsoft YaHei-3970(82674968);
  467. color: #333333;
  468. text {
  469. color: $my-color-primary;
  470. }
  471. }
  472. button {
  473. margin-top: 38rpx;
  474. }
  475. .btn_submit {
  476. border-radius: 10rpx;
  477. background-color: $my-color-primary;
  478. font-family: Microsoft YaHei-3970(82674968);
  479. color: #FFFFFF;
  480. }
  481. .btn_tel {
  482. border-radius: 10rpx;
  483. background: #CCCCCC;
  484. font-family: Microsoft YaHei-3970(82674968);
  485. color: #FFFFFF;
  486. }
  487. .tips {
  488. margin-top: 20rpx;
  489. font-size: 24rpx;
  490. font-family: Microsoft YaHei-3970(82674968);
  491. color: $my-color-primary;
  492. line-height: 36rpx;
  493. }
  494. }
  495. }
  496. </style>