recharge.vue 11 KB

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