recharge.vue 8.8 KB

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