recharge.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <view class="content">
  3. <view class="title">
  4. <text class="iconfont icon-qian"></text>
  5. <text>江西南昌交通学院</text>
  6. </view>
  7. <view class="input_amount">
  8. <view class="amount_tip">充值金额(元)</view>
  9. <view class="amount_inp">
  10. <text></text>
  11. <input class="inp" type="number" maxlength="4" v-model="amount" @input="onInput" @blur="onBlur"
  12. placeholder="请输入大于10元,小于100元" placeholder-class="ph_class" />
  13. </view>
  14. <text>最多可输入金额100元</text>
  15. </view>
  16. <view class="amount_select">
  17. <view class="amount_btn">
  18. <text @tap="sel_amount(10)" :class="{selStyle:amount == 10}">充10元</text>
  19. <text @tap="sel_amount(20)" :class="{selStyle:amount == 20}">充20元</text>
  20. <text @tap="sel_amount(50)" :class="{selStyle:amount == 50}">充50元</text>
  21. <text @tap="sel_amount(100)" :class="{selStyle:amount == 100}">充100元</text>
  22. </view>
  23. <view class="reminder">温馨提示:最少充值金额为10元</view>
  24. <view class="payment">支付金额:<text>{{amount}}</text>元</view>
  25. <button class="btn_submit" type="primary" @tap="chongzhi">确认提交</button>
  26. <button class="btn_tel" type="default" @tap="callPhone">客服热线:{{phone_number}}</button>
  27. <view class="tips">
  28. 尊敬的用户,你好!因项目提现业务配置问题导致您无法提现对此,我们深表歉意!您可致电运营商处理提现问题,运营商电话:13645689854。感谢您对我们工作的支持和理解。
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. amount: '', // 金额
  38. phone_number: '13645689854', // 客户热线电话
  39. IP: '',
  40. code: '',
  41. ceshi: 'code',
  42. test: this.$store.state.test
  43. };
  44. },
  45. onLoad() {
  46. if (this.test) {
  47. this.amount = 0.01
  48. }
  49. },
  50. methods: {
  51. /**
  52. * 获得code
  53. */
  54. getCode(param_ip) {
  55. uni.login({
  56. success: (res) => {
  57. // console.log('recharge', res);
  58. if (res.code) {
  59. // 组合地址,发起支付
  60. this.jsapi(param_ip, res.code)
  61. } else {
  62. uni.showToast({
  63. title: res.errMsg,
  64. icon: 'none'
  65. });
  66. }
  67. }
  68. })
  69. },
  70. /**
  71. * 获取IP
  72. */
  73. async getIP() {
  74. const res = await this.$myRequest({
  75. host: 'ip',
  76. url: '?ie=utf-8',
  77. method: 'POST'
  78. })
  79. if (res) {
  80. // console.log(res);
  81. const reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
  82. let ip = reg.exec(res.data);
  83. // 获取code
  84. this.getCode(ip[0])
  85. }
  86. },
  87. /**
  88. * 请求服务器,获取支付参数,并支付
  89. */
  90. async jsapi(param_ip, param_code) {
  91. if (param_code == '' || this.amount == '' || param_ip == '') {
  92. uni.showToast({
  93. icon: 'none',
  94. title: 'code、充值金额或IP为空'
  95. });
  96. return
  97. }
  98. const res = await this.$myRequest({
  99. host: this.ceshi,
  100. url: '/HotWaters/wpPay.action',
  101. method: 'POST',
  102. header: {
  103. 'content-type': 'application/x-www-form-urlencoded'
  104. },
  105. data: {
  106. code: param_code,
  107. num: this.amount,
  108. ip: param_ip
  109. }
  110. })
  111. // console.log(res);
  112. if (res.data.pay == 'error') {
  113. uni.showToast({
  114. title: '未获得支付参数',
  115. icon: 'success',
  116. duration: 3000
  117. });
  118. } else {
  119. wx.requestPayment({
  120. timeStamp: res.data.pay.timeStamp,
  121. nonceStr: res.data.pay.nonceStr,
  122. package: 'prepay_id=' + res.data.pay.prepay_id,
  123. signType: res.data.pay.signType,
  124. paySign: res.data.pay.paySign,
  125. success: (res) => {
  126. if (res.errMsg == 'requestPayment:ok') {
  127. this.$store.state.payInfo.from = 'reshui_pay'
  128. this.$store.state.payInfo.resultMsg = '支付成功'
  129. this.$store.state.reshui_amount = this.amount
  130. uni.navigateBack({
  131. delta: 1
  132. })
  133. }
  134. },
  135. fail: (res) => {
  136. if (res.errMsg == 'requestPayment:fail cancel') {
  137. uni.showToast({
  138. title: '支付已取消',
  139. icon: 'success',
  140. duration: 2000
  141. });
  142. }
  143. },
  144. complete: (res) => {
  145. // console.log(res);
  146. }
  147. });
  148. }
  149. },
  150. /**
  151. * 输入充值金额
  152. */
  153. onInput(e) {
  154. if (this.test) { // 测试环境
  155. return
  156. }
  157. const v = e.detail.value
  158. const zero = /^(0{1,})|[^0-9]/g
  159. let final = 0
  160. if (!v) {
  161. final = 0
  162. } else {
  163. final = v.toString().replace(zero, (v) => {
  164. return 0
  165. })
  166. if (final.split('')[0] * 1 === 0) {
  167. final = final.slice(1) - 0 || 0
  168. }
  169. if (final > 100) {
  170. final = 100
  171. }
  172. }
  173. this.$nextTick(() => {
  174. if (final.toString() == '0') {
  175. this.amount = ''
  176. } else {
  177. this.amount = final.toString() || '0'
  178. }
  179. })
  180. },
  181. /**
  182. * 输入框,失去焦点时
  183. */
  184. onBlur() {
  185. if (this.test) { // 测试环境
  186. return
  187. }
  188. if (this.amount < 10) {
  189. this.amount = 10
  190. }
  191. },
  192. /**
  193. * 选择充值金额
  194. */
  195. sel_amount(m) {
  196. this.amount = m
  197. },
  198. /**
  199. * 调用接口实现充值功能
  200. */
  201. chongzhi() {
  202. if (isNaN(this.amount)) {
  203. uni.showToast({
  204. title: '请输入正确金额',
  205. duration: 2000
  206. })
  207. return
  208. }
  209. // 测试环境下执行
  210. if (this.test) { // 测试环境
  211. uni.showModal({
  212. title: '提示',
  213. content: '您选择了充值:¥' + this.amount + ' 元',
  214. cancelText: '算了',
  215. confirmText: '充值',
  216. success: (res) => {
  217. if (res.confirm) {
  218. // 获取IP
  219. this.getIP()
  220. } else if (res.cancel) {
  221. return
  222. }
  223. }
  224. })
  225. return
  226. }
  227. // 生产环境
  228. if (this.amount < 10 || this.amount > 100) {
  229. uni.showToast({
  230. icon: 'none',
  231. title: '最少充值10元,最多充值100元!',
  232. mask: true,
  233. duration: 3000
  234. })
  235. return
  236. }
  237. // 确认
  238. uni.showModal({
  239. title: '提示',
  240. content: '您选择了充值:¥' + this.amount + ' 元',
  241. cancelText: '算了',
  242. confirmText: '充值',
  243. success: (res) => {
  244. if (res.confirm) {
  245. // 获取IP
  246. this.getIP()
  247. } else if (res.cancel) {
  248. return
  249. }
  250. }
  251. })
  252. },
  253. /**
  254. * 拨打电话
  255. */
  256. callPhone() {
  257. uni.makePhoneCall({
  258. phoneNumber: this.phone_number
  259. });
  260. }
  261. }
  262. }
  263. </script>
  264. <style scoped lang="scss">
  265. .content {
  266. display: flex;
  267. flex-direction: column;
  268. background-color: #F5F5F5;
  269. width: 750rpx;
  270. .title {
  271. display: flex;
  272. align-items: center;
  273. padding: 40rpx;
  274. text:nth-child(1) {
  275. color: $my-color-primary;
  276. font-size: 50rpx;
  277. }
  278. text:nth-child(2) {
  279. font-size: 32rpx;
  280. margin-left: 15rpx;
  281. font-family: Microsoft YaHei-3970(82674968);
  282. color: #333333;
  283. }
  284. }
  285. .input_amount {
  286. background-color: #FFFFFF;
  287. width: 670rpx;
  288. height: 210rpx;
  289. padding: 40rpx 40rpx 0rpx 40rpx;
  290. border-radius: 40rpx 40rpx 0rpx 0rpx;
  291. .amount_tip {
  292. font-size: 32rpx;
  293. font-family: Microsoft YaHei-3970(82674968);
  294. }
  295. .amount_inp {
  296. display: flex;
  297. flex-direction: row;
  298. border-bottom: 1px solid #cccccc;
  299. margin-top: 20rpx;
  300. margin-bottom: 10rpx;
  301. text {
  302. width: 50rpx;
  303. height: 74rpx;
  304. font-size: 50rpx;
  305. font-weight: bold;
  306. padding-top: 6rpx;
  307. font-family: Microsoft YaHei-3970(82674968);
  308. }
  309. text::before {
  310. content: '¥';
  311. }
  312. .inp {
  313. width: 620rpx;
  314. height: 80rpx;
  315. font-size: 50rpx;
  316. font-weight: bold;
  317. font-family: Microsoft YaHei-3970(82674968);
  318. }
  319. /deep/.ph_class {
  320. font-size: 32rpx;
  321. font-weight: normal;
  322. color: #B2B2B2;
  323. }
  324. }
  325. text {
  326. font-size: 26rpx;
  327. font-family: Microsoft YaHei-3970(82674968);
  328. font-weight: 500;
  329. }
  330. }
  331. .amount_select {
  332. padding: 0rpx 40rpx 40rpx 40rpx;
  333. .amount_btn {
  334. display: flex;
  335. justify-content: space-between;
  336. margin: 30rpx 0 20rpx;
  337. text {
  338. width: 150rpx;
  339. height: 120rpx;
  340. line-height: 120rpx;
  341. font-size: 32rpx;
  342. font-family: Microsoft YaHei-3970(82674968);
  343. color: #333333;
  344. text-align: center;
  345. background: #FFFFFF;
  346. border: 3rpx solid #AAAAAA;
  347. }
  348. .selStyle {
  349. border: 0rpx;
  350. width: 156rpx;
  351. height: 126rpx;
  352. background: url(../../static/images/jinebeijing2x.png) 0rpx 0rpx no-repeat;
  353. background-size: 100%;
  354. }
  355. }
  356. .reminder {
  357. height: 26rpx;
  358. font-size: 26rpx;
  359. font-family: Microsoft YaHei-3970(82674968);
  360. color: $my-color-primary;
  361. }
  362. .payment {
  363. margin-top: 65rpx;
  364. font-size: 32rpx;
  365. font-family: Microsoft YaHei-3970(82674968);
  366. color: #333333;
  367. text {
  368. color: $my-color-primary;
  369. }
  370. }
  371. button {
  372. margin-top: 38rpx;
  373. }
  374. .btn_submit {
  375. border-radius: 10rpx;
  376. background-color: $my-color-primary;
  377. font-family: Microsoft YaHei-3970(82674968);
  378. color: #FFFFFF;
  379. }
  380. .btn_tel {
  381. border-radius: 10rpx;
  382. background: #CCCCCC;
  383. font-family: Microsoft YaHei-3970(82674968);
  384. color: #FFFFFF;
  385. }
  386. .tips {
  387. margin-top: 20rpx;
  388. font-size: 24rpx;
  389. font-family: Microsoft YaHei-3970(82674968);
  390. color: $my-color-primary;
  391. line-height: 36rpx;
  392. }
  393. }
  394. }
  395. </style>