recharge.vue 11 KB

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