recharge.vue 11 KB

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