recharge.vue 9.1 KB

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