index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="mianBox">
  3. <!-- <van-row class="balance">
  4. <van-col span="24">余额:32.00元</van-col>
  5. </van-row> -->
  6. <van-row class="contentBox">
  7. <van-row class="input_wrap">
  8. <span>¥</span>
  9. <input
  10. type="number"
  11. placeholder="请输入充值金额( 元 )"
  12. class="input"
  13. @input="Input"
  14. v-model="data.money"
  15. />
  16. </van-row>
  17. </van-row>
  18. <van-row class="select_amount" >
  19. <van-col span="8" @tap="btn50" :style="state1" data="50" >50</van-col>
  20. <van-col style="margin-left:8%" span="8" @tap="btn100" :style="state2" data="100">100</van-col>
  21. <van-col style="margin-left:8%" span="8" @tap="btn150" :style="state3" data="150">150</van-col>
  22. <van-col span="8" @tap="btn200" :style="state4" data="200">200</van-col>
  23. <van-col style="margin-left:8%" span="8" @tap="btn250" :style="state5" data="250">250</van-col>
  24. <van-col style="margin-left:8%" span="8" @tap="btn300" :style="state6" data="300">300</van-col>
  25. </van-row>
  26. <van-row class="pay_money" type="flex" justify="space-around">
  27. <van-col span="12" class="left">到账金额</van-col>
  28. <van-col span="12" class="right">¥{{data.money}}元</van-col>
  29. </van-row>
  30. <!-- <van-row class="tip">
  31. 服务费 ¥0元<br>
  32. 费率 0%
  33. </van-row> -->
  34. <van-button class="amount" color="#F22E3C" @tap="recharge">立即充值</van-button>
  35. <van-dialog id="van-dialog" />
  36. <van-toast id="van-toast" />
  37. <!-- <van-loading size="24px" v-if = "loading" vertical style="z-index:999999;position:fixed;top:40%;left:0;right:0;" >加载中...</van-loading>
  38. <van-overlay :show="loading" style="z-index:100;position:fixed"/> -->
  39. </div>
  40. </template>
  41. <script>
  42. import Toast from '../../wxcomponents/vant/weapp/dist/toast/toast';
  43. import Dialog from '../../wxcomponents/vant/weapp/dist/dialog/dialog'
  44. export default {
  45. data() {
  46. return {
  47. show: false,
  48. loading: false,
  49. overlayShow: false,
  50. env:null, //识别是否为扫描用户进入,以便直接进入支付跳转
  51. state1:"color:#000;background: #ccc;",
  52. state2:"color:#000;background: #ccc;",
  53. state3:"color:#000;background: #ccc;",
  54. state4:"color:#000;background: #ccc;",
  55. state5:"color:#000;background: #ccc;",
  56. state6:"color:#000;background: #ccc;",
  57. data:{
  58. money: "0",
  59. openid:null
  60. }
  61. };
  62. },
  63. watch: {
  64. money(val) {
  65. // if (/^0[1-9]/.test(val)) {
  66. // this.data.money = val.substring(1);
  67. // }
  68. },
  69. },
  70. components: {
  71. // [Field.name]: Field,
  72. // [NumberKeyboard.name]: NumberKeyboard,
  73. // [Dialog.name]: Dialog,
  74. // [Toast.name]: Toast,
  75. },
  76. onLoad(options){
  77. },
  78. created(){
  79. let _this = this
  80. uni.getStorage({
  81. key: 'openid',
  82. success: function (res) {
  83. _this.data.openid = res.data
  84. }
  85. });
  86. },
  87. methods: {
  88. recharge(){
  89. if(this.data.money && this.data.money != 0 && this.data.money != "0.00"){
  90. if(this.data.money.toString().indexOf(".")<1){
  91. this.data.money = this.data.money + ".00"
  92. }
  93. if(this.data.openid){
  94. //console.log(`"去支付页1"${JSON.stringify(this.data)}`)
  95. uni.navigateTo({
  96. url: `../order/index?params=${JSON.stringify(this.data)}`
  97. });
  98. }else{
  99. //console.log(`"去支付页2"${JSON.stringify(this.data)}`)
  100. uni.navigateTo({
  101. url: `../login/index?params=${JSON.stringify(this.data)}`
  102. });
  103. }
  104. }else{
  105. Toast('支付金额不能为空或0元');
  106. }
  107. },
  108. Input(e){
  109. let val = e.target.value.replace(/(^\s*)|(\s*$)/g, "")
  110. if (!val) {
  111. this.amount = '';
  112. return
  113. }
  114. var reg = /[^\d.]/g
  115. // 只能是数字和小数点,不能是其他输入
  116. val = val.replace(reg, "")
  117. // // 保证第一位只能是数字,不能是点
  118. val = val.replace(/^\./g, "");
  119. // // 小数只能出现1位
  120. val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  121. // // 小数点后面保留2位
  122. val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
  123. if(val.indexOf("0") == 0){
  124. if(val.length == 2){
  125. val = "0."
  126. }
  127. }
  128. this.$nextTick(() => {
  129. this.data.money = val;
  130. })
  131. this.state1 = "color:#000;background: #ccc;",
  132. this.state2 = "color:#000;background: #ccc;",
  133. this.state3 = "color:#000;background: #ccc;",
  134. this.state4 = "color:#000;background: #ccc;",
  135. this.state5 = "color:#000;background: #ccc;",
  136. this.state6 = "color:#000;background: #ccc;",
  137. this.data.money = this.data.money + "";
  138. },
  139. // handleInput(key) {
  140. // console.log(key)
  141. // this.state1 = "color:#000;background: #ccc;",
  142. // this.state2 = "color:#000;background: #ccc;",
  143. // this.state3 = "color:#000;background: #ccc;",
  144. // this.state4 = "color:#000;background: #ccc;",
  145. // this.state5 = "color:#000;background: #ccc;",
  146. // this.state6 = "color:#000;background: #ccc;",
  147. // this.data.money = this.data.money + "";
  148. // if (this.data.money === "" && key === ".") {
  149. // this.data.money = "0";
  150. // } else if (this.data.money.indexOf(".") !== -1 && key === ".") {
  151. // return;
  152. // } else if (
  153. // this.data.money.indexOf("0") !== -1 &&
  154. // this.data.money.length === 1 &&
  155. // key === 0
  156. // ) {
  157. // return;
  158. // } else if (/\.\d{2}$/.test(this.data.money)) {
  159. // return;
  160. // }
  161. // this.data.money += key;
  162. // },
  163. // handleDelete() {
  164. // this.data.money = this.data.money + "";
  165. // if (!this.data.money) {
  166. // return;
  167. // }
  168. // this.data.money = this.data.money.substring(0, this.data.money.length - 1) || 0;
  169. // },
  170. // handleClose() {
  171. // this.data.money = Number(this.data.money);
  172. // this.overlayShow = false
  173. // },
  174. // isWeixinOrAlipay(){
  175. // let ua = window.navigator.userAgent;
  176. // //判断是不是微信
  177. // if ( ua.indexOf("MicroMessenger") > 0 ) {
  178. // this.env = "WeiXin"
  179. // }
  180. // //判断是不是支付宝
  181. // if(ua.indexOf("Alipay") > 0) {
  182. // this.env = "Alipay"
  183. // }
  184. // },
  185. // async pay(money, topPayType, payType){
  186. // this.loading = true
  187. // if(window.localStorage.getItem('token')){
  188. // getPayApi(money, topPayType, payType)
  189. // }else{
  190. // getTokenApi(money, topPayType, payType)
  191. // }
  192. // },
  193. jumpMode(){
  194. //console.log(this.data.money)
  195. if(this.data.money && this.data.money != 0 && this.data.money != "0.00"){
  196. //this.pay(this.data.money, "A01", "3")
  197. }else{
  198. Toast('支付金额不能为空或0元');
  199. Dialog.alert({
  200. context: this, // 增加this可用
  201. selector:"#van-dialog",//选择器
  202. title: '提示',
  203. message: '充值金额不能为0元!'
  204. }).then(() => {
  205. // on close
  206. });
  207. }
  208. },
  209. // recharge(){
  210. // this.jumpMode()
  211. // },
  212. btn50() {
  213. this.state1 = "color:#fff;background:rgba(242, 46, 60, 1);",
  214. this.state2 = "color:#000;background: #ccc;",
  215. this.state3 = "color:#000;background: #ccc;",
  216. this.state4 = "color:#000;background: #ccc;",
  217. this.state5 = "color:#000;background: #ccc;",
  218. this.state6 = "color:#000;background: #ccc;",
  219. this.data.money = 50
  220. },
  221. btn100() {
  222. this.state1 = "color:#000;background: #ccc;",
  223. this.state2 = "color:#fff;background: rgba(242, 46, 60, 1);",
  224. this.state3 = "color:#000;background: #ccc;",
  225. this.state4 = "color:#000;background: #ccc;",
  226. this.state5 = "color:#000;background: #ccc;",
  227. this.state6 = "color:#000;background: #ccc;",
  228. this.data.money = 100
  229. },
  230. btn150() {
  231. this.state1 = "color:#000;background: #ccc;",
  232. this.state2 = "color:#000;background: #ccc;",
  233. this.state3 = "color:#fff;background: rgba(242, 46, 60, 1);",
  234. this.state4 = "color:#000;background: #ccc;",
  235. this.state5 = "color:#000;background: #ccc;",
  236. this.state6 = "color:#000;background: #ccc;",
  237. this.data.money = 150
  238. },
  239. btn200() {
  240. this.state1 = "color:#000;background: #ccc;",
  241. this.state2 = "color:#000;background: #ccc;",
  242. this.state3 = "color:#000;background: #ccc;",
  243. this.state4 = "color:#fff;background: rgba(242, 46, 60, 1);",
  244. this.state5 = "color:#000;background: #ccc;",
  245. this.state6 = "color:#000;background: #ccc;",
  246. this.data.money = 200
  247. },
  248. btn250() {
  249. this.state1 = "color:#000;background: #ccc;",
  250. this.state2 = "color:#000;background: #ccc;",
  251. this.state3 = "color:#000;background: #ccc;",
  252. this.state4 = "color:#000;background: #ccc;",
  253. this.state5 = "color:#fff;background: rgba(242, 46, 60, 1);",
  254. this.state6 = "color:#000;background: #ccc;",
  255. this.data.money = 250
  256. },
  257. btn300() {
  258. this.state1 = "color:#000;background: #ccc;",
  259. this.state2 = "color:#000;background: #ccc;",
  260. this.state3 = "color:#000;background: #ccc;",
  261. this.state4 = "color:#000;background: #ccc;",
  262. this.state5 = "color:#000;background: #ccc;",
  263. this.state6 = "color:#fff;background: rgba(242, 46, 60, 1);",
  264. this.data.money = 300
  265. },
  266. },
  267. };
  268. </script>
  269. <style lang="scss" scoped>
  270. .mianBox {
  271. width: 90%;
  272. padding: 0 5% 0 5%;
  273. height: 100%;
  274. position: absolute;
  275. // .balance{
  276. // font-size: 16px;
  277. // margin-top:20px;
  278. // display: block;
  279. // /deep/ .van-col{
  280. // color:red;
  281. // display: block;
  282. // }
  283. // }
  284. .contentBox {
  285. width: 90%;
  286. position: absolute;
  287. background-color: orange !important;
  288. .input_wrap{
  289. width:100%;
  290. box-sizing: border-box;
  291. border:1px solid #E6E6E6;
  292. position: absolute;
  293. margin-top:20px;
  294. span{
  295. font-size: 20px;
  296. margin-left:10px;
  297. color:rgba(242, 46, 60, 1);
  298. display: inline-block;
  299. vertical-align: middle;
  300. }
  301. input{
  302. color:#000;
  303. width:70%;
  304. padding:8px 10px;
  305. display: inline-block;
  306. vertical-align: middle;
  307. }
  308. ::placeholder{
  309. color:#000000;
  310. }
  311. }
  312. }
  313. .select_amount{
  314. width:100%;
  315. margin-top:60px;
  316. display: block;
  317. text-align: center;
  318. /deep/ van-col{
  319. padding:10px 0;
  320. background-color: #ccc;
  321. color:#000;
  322. text-align: center;
  323. font-size: 16px;
  324. border-radius: 6px;
  325. margin-top:20px;
  326. float:left;
  327. width:28%;
  328. }
  329. .van-col.active{
  330. background: rgba(242, 46, 60, 1);
  331. color:#fff;
  332. }
  333. /deep/ .van-col{
  334. text-align: center !important;
  335. width:100%;
  336. display: block;
  337. }
  338. }
  339. .pay_money{
  340. font-size: 16px;
  341. margin:15px 0;
  342. display: block;
  343. .left{
  344. text-align: left;
  345. }
  346. .right{
  347. text-align: right;
  348. color: rgba(242, 46, 60, 1);
  349. }
  350. }
  351. .tip{
  352. font-size: 14px;
  353. color: #CCC;
  354. }
  355. /deep/ .van-button{
  356. border-radius: 6px;
  357. width: 100% !important;
  358. }
  359. .amount{
  360. position: absolute;
  361. bottom: 25px;
  362. width:90%;
  363. height: 50px;
  364. font-size: 18px;
  365. border-radius: 10px;
  366. }
  367. .van-field__label{
  368. color:rgba(242, 46, 60, 1) !important;
  369. }
  370. }
  371. </style>