recharge.vue 11 KB

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