recharge.vue 11 KB

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