recharge.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. }
  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. this.amount = 10
  160. const zero = /^(0{1,})|[^0-9]/g
  161. let final = 0
  162. if (!v) {
  163. final = 0
  164. } else {
  165. final = v.toString().replace(zero, (v) => {
  166. return 0
  167. })
  168. if (final.split('')[0] * 1 === 0) {
  169. final = final.slice(1) - 0 || 0
  170. }
  171. if (final > 100) {
  172. final = 100
  173. }
  174. }
  175. this.$nextTick(() => {
  176. this.amount = final.toString() || '0'
  177. })
  178. },
  179. /**
  180. * 输入框,失去焦点时
  181. */
  182. onBlur() {
  183. if (this.test) { // 测试环境
  184. return
  185. }
  186. if (this.amount < 10) {
  187. this.amount = 10
  188. }
  189. },
  190. /**
  191. * 选择充值金额
  192. */
  193. sel_amount(m) {
  194. this.amount = m
  195. },
  196. /**
  197. * 调用接口实现充值功能
  198. */
  199. chongzhi() {
  200. if (isNaN(this.amount)) {
  201. uni.showToast({
  202. title: '请输入正确金额',
  203. duration: 2000
  204. })
  205. return
  206. }
  207. // 测试环境下执行
  208. if (this.test) { // 测试环境
  209. uni.showModal({
  210. title: '提示',
  211. content: '您选择了充值:¥' + this.amount + ' 元',
  212. cancelText: '算了',
  213. confirmText: '充值',
  214. success: (res) => {
  215. if (res.confirm) {
  216. // 获取code
  217. this.getCode()
  218. } else if (res.cancel) {
  219. return
  220. }
  221. }
  222. })
  223. return
  224. }
  225. // 生产环境
  226. if (this.amount < 10 || this.amount > 100) {
  227. uni.showToast({
  228. icon: 'none',
  229. title: '最少充值10元,最多充值100元!',
  230. mask: true,
  231. duration: 3000
  232. })
  233. return
  234. }
  235. // 确认
  236. uni.showModal({
  237. title: '提示',
  238. content: '您选择了充值:¥' + this.amount + ' 元',
  239. cancelText: '算了',
  240. confirmText: '充值',
  241. success: (res) => {
  242. if (res.confirm) {
  243. // 获取code
  244. this.getCode()
  245. } else if (res.cancel) {
  246. return
  247. }
  248. }
  249. })
  250. },
  251. /**
  252. * 拨打电话
  253. */
  254. callPhone() {
  255. uni.makePhoneCall({
  256. phoneNumber: this.phone_number
  257. });
  258. }
  259. }
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. .content {
  264. display: flex;
  265. flex-direction: column;
  266. background-color: #F5F5F5;
  267. width: 750rpx;
  268. // height: 100%;
  269. // align-items: stretch;
  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 0 40rpx;
  290. border-radius: 40rpx 40rpx 0 0;
  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. input {
  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: 28rpx;
  321. font-weight: normal;
  322. }
  323. }
  324. text {
  325. font-size: 26rpx;
  326. font-family: Microsoft YaHei-3970(82674968);
  327. font-weight: 500;
  328. }
  329. }
  330. .amount_select {
  331. padding: 40rpx;
  332. .amount_btn {
  333. display: flex;
  334. justify-content: space-between;
  335. margin: 30rpx 0 20rpx;
  336. text {
  337. width: 150rpx;
  338. height: 120rpx;
  339. line-height: 120rpx;
  340. font-size: 32rpx;
  341. font-family: Microsoft YaHei-3970(82674968);
  342. color: #333333;
  343. text-align: center;
  344. background: #FFFFFF;
  345. border: 3rpx solid #AAAAAA;
  346. }
  347. .selStyle {
  348. border: 0rpx;
  349. width: 156rpx;
  350. height: 126rpx;
  351. background: url(../../static/images/jinebeijing2x.png) 0rpx 0rpx no-repeat;
  352. background-size: 100%;
  353. }
  354. }
  355. .reminder {
  356. height: 26rpx;
  357. font-size: 26rpx;
  358. font-family: Microsoft YaHei-3970(82674968);
  359. color: $my-color-primary;
  360. }
  361. .payment {
  362. margin-top: 65rpx;
  363. font-size: 32rpx;
  364. font-family: Microsoft YaHei-3970(82674968);
  365. color: #333333;
  366. text {
  367. color: $my-color-primary;
  368. }
  369. }
  370. button {
  371. margin-top: 38rpx;
  372. }
  373. .btn_submit {
  374. border-radius: 10rpx;
  375. background-color: $my-color-primary;
  376. font-family: Microsoft YaHei-3970(82674968);
  377. color: #FFFFFF;
  378. }
  379. .btn_tel {
  380. border-radius: 10rpx;
  381. background: #CCCCCC;
  382. font-family: Microsoft YaHei-3970(82674968);
  383. color: #FFFFFF;
  384. }
  385. .tips {
  386. margin-top: 20rpx;
  387. font-size: 24rpx;
  388. font-family: Microsoft YaHei-3970(82674968);
  389. color: $my-color-primary;
  390. line-height: 36rpx;
  391. }
  392. }
  393. }
  394. </style>