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