MenuPayH5.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. <template>
  2. <!-- 鸿币充值 -->
  3. <div class="menu_pay_h5">
  4. <!-- 充值账号 -->
  5. <div class="pay_account">
  6. <span class="left"> 充值账号:</span>
  7. <div class="right">
  8. <span class="account">{{ userInfo.passport }}</span>
  9. <span class="money">(余额 {{ finance }} HB)</span>
  10. </div>
  11. </div>
  12. <!-- 充值金额 -->
  13. <div class="pay_money">
  14. <span class="left">充值金额:</span>
  15. <!-- <div class="right">
  16. <ul>
  17. <li
  18. class="default"
  19. :class="{
  20. active: currentCount === index,
  21. }"
  22. v-for="(item, index) in payCountList"
  23. :key="index"
  24. @click="onSelectCount(item.count, index)"
  25. >
  26. {{ item.name }}
  27. </li>
  28. <li
  29. class="count_input"
  30. :class="{
  31. active: currentCount === -1,
  32. }"
  33. @click="onSelectCount(null, -1)"
  34. @keyup.enter="onConfirmCount"
  35. >
  36. <input type="number" v-model="payCount2" />
  37. <div class="confirm" @click="onConfirmCount">确认</div>
  38. </li>
  39. </ul>
  40. </div> -->
  41. <!-- 类似购物车 -->
  42. <div class="right">
  43. <ul class="clear">
  44. <!-- 第一档 -->
  45. <li
  46. class="default"
  47. :class="{
  48. active: firstCount,
  49. }"
  50. @click="select(0)"
  51. >
  52. {{ payCountList[0] }} HB
  53. </li>
  54. <li class="count clear">
  55. <div class="reduce" @click="reduce(0)">-</div>
  56. <input
  57. type="tel"
  58. v-model="firstCount"
  59. pattern="[0-9]*"
  60. compositionstart="compositionstartInput"
  61. oninput="this.value=this.value.replace(/\D/g,'')"
  62. onafterpaste="this.value=this.value.replace(/\D/g,'')"
  63. @blur="checkInput(0)"
  64. />
  65. <div class="add" @click="add(0)">+</div>
  66. </li>
  67. <!-- 第二档 -->
  68. <li
  69. class="default"
  70. :class="{
  71. active: secondCount,
  72. }"
  73. @click="select(1)"
  74. >
  75. {{ payCountList[1] }} HB
  76. </li>
  77. <li class="count clear">
  78. <div class="reduce" @click="reduce(1)">-</div>
  79. <input
  80. type="tel"
  81. v-model="secondCount"
  82. pattern="[0-9]*"
  83. compositionstart="compositionstartInput"
  84. oninput="this.value=this.value.replace(/\D/g,'')"
  85. onafterpaste="this.value=this.value.replace(/\D/g,'')"
  86. @blur="checkInput(1)"
  87. />
  88. <div class="add" @click="add(1)">+</div>
  89. </li>
  90. <!-- 第三档 -->
  91. <li
  92. class="default"
  93. :class="{
  94. active: thirdCount,
  95. }"
  96. @click="select(2)"
  97. >
  98. {{ payCountList[2] }} HB
  99. </li>
  100. <li class="count clear">
  101. <div class="reduce" @click="reduce(2)">-</div>
  102. <input
  103. type="tel"
  104. v-model="thirdCount"
  105. pattern="[0-9]*"
  106. compositionstart="compositionstartInput"
  107. oninput="this.value=this.value.replace(/\D/g,'')"
  108. onafterpaste="this.value=this.value.replace(/\D/g,'')"
  109. @blur="checkInput(2)"
  110. />
  111. <div class="add" @click="add(2)">+</div>
  112. </li>
  113. <!-- 第四档 -->
  114. <li
  115. class="default"
  116. :class="{
  117. active: fourthCount,
  118. }"
  119. @click="select(3)"
  120. >
  121. {{ payCountList[3] }} HB
  122. </li>
  123. <!-- <li
  124. class="count_input"
  125. :class="{
  126. active: currentCount === -1,
  127. }"
  128. @click="onSelectCount(null, -1)"
  129. @keyup.enter="onConfirmCount"
  130. >
  131. <input type="number" v-model="payCount2" />
  132. <div class="confirm" @click="onConfirmCount">确认</div>
  133. </li> -->
  134. <li class="count clear">
  135. <div class="reduce" @click="reduce(3)">-</div>
  136. <input
  137. type="tel"
  138. v-model="fourthCount"
  139. pattern="[0-9]*"
  140. compositionstart="compositionstartInput"
  141. oninput="this.value=this.value.replace(/\D/g,'')"
  142. onafterpaste="this.value=this.value.replace(/\D/g,'')"
  143. @blur="checkInput(3)"
  144. />
  145. <div class="add" @click="add(3)">+</div>
  146. </li>
  147. </ul>
  148. </div>
  149. </div>
  150. <!-- 支付方式 -->
  151. <div class="pay_type">
  152. <span class="left"> 支付方式:</span>
  153. <div class="right">
  154. <div
  155. class="alipay"
  156. :class="{
  157. active: payPlatform === 'ALIPAY',
  158. }"
  159. @click="onSelectpayPlatform('ALIPAY')"
  160. >
  161. <img src="~@/assets/image/alipay.png" alt="" />
  162. <span>支付宝</span>
  163. </div>
  164. <div
  165. class="wxpay"
  166. :class="{
  167. active: payPlatform === 'WECHATPAY',
  168. }"
  169. @click="onSelectpayPlatform('WECHATPAY')"
  170. >
  171. <img src="~@/assets/image/wxpay.png" alt="" />
  172. <span>微信</span>
  173. </div>
  174. </div>
  175. </div>
  176. <!-- 应付金额 -->
  177. <div class="pay_all_money">
  178. <span class="left"> 应付金额:</span>
  179. <div class="right">
  180. <!-- <div class="old">
  181. <span class="account">{{ allCount }}</span>
  182. <span>元</span>
  183. </div> -->
  184. <span class="account new_count">{{ payCount }}</span>
  185. <span>元</span>
  186. </div>
  187. </div>
  188. <!-- 实得鸿币 -->
  189. <div class="pay_all_money">
  190. <span class="left"> 实得鸿币:</span>
  191. <div class="right">
  192. <div class="old">
  193. <span class="account">{{ payCount }}</span>
  194. <span>HB</span>
  195. </div>
  196. <span class="account new_count">{{ newHB }}</span>
  197. <span>HB</span>
  198. </div>
  199. </div>
  200. <!-- 立即付款 -->
  201. <div class="to_pay" @click="toPay">立即付款</div>
  202. </div>
  203. </template>
  204. <script>
  205. import { mapActions, mapState } from "vuex";
  206. export default {
  207. name: "MenuPayH5",
  208. components: {},
  209. inject: ["checkCode", "getFinance", "checkCodeHandler", "onRecharge"],
  210. data() {
  211. return {
  212. payCountList: ["0.01", "200", "500", "1000"], // 可选充值金额列表
  213. // payCountList: ["100", "200", "500", "1000"], // 可选充值金额列表
  214. currentCount: 0, // 默认选中的充值金额
  215. payPlatform: "ALIPAY", // 默认支付方式
  216. payCount: 0, // 应付金额
  217. payCount2: "", // 输入框的应付金额
  218. canPay: true, // 是否可以点击支付
  219. firstCount: 0, // 第一档 数量
  220. secondCount: 0, // 第二档 数量
  221. thirdCount: 0, // 第三档 数量
  222. fourthCount: 0, // 第四档 数量
  223. allCount: 0, // 本应付金额
  224. oldHB: 0, // 原得鸿币
  225. newHB: 0, // 应得鸿币
  226. };
  227. },
  228. computed: {
  229. ...mapState([
  230. "userInfo",
  231. "finance",
  232. "query",
  233. "isWeChat",
  234. "CONFIG",
  235. "appid",
  236. ]),
  237. },
  238. watch: {
  239. // 第一档 100
  240. firstCount(firstCountNew) {
  241. this.checkInput(0);
  242. this.computeMoney();
  243. },
  244. // 第二档 200
  245. secondCount(secondCountNew) {
  246. this.checkInput(1);
  247. this.computeMoney();
  248. },
  249. // 第三档 500
  250. thirdCount(thirdCountNew) {
  251. this.checkInput(2);
  252. this.computeMoney();
  253. },
  254. // 第四档 1000
  255. fourthCount(fourthCountNew) {
  256. this.checkInput(3);
  257. this.computeMoney();
  258. },
  259. },
  260. created() {},
  261. mounted() {
  262. // 默认选中第一栏
  263. this.add(0);
  264. },
  265. methods: {
  266. ...mapActions(["isPayAction"]),
  267. // ios中文输入
  268. compositionstartInput() {
  269. this.account = "";
  270. },
  271. // 选择充值金额
  272. onSelectCount(count, index) {
  273. this.currentCount = index;
  274. if (count) {
  275. this.payCount = count;
  276. this.payCount2 = "";
  277. }
  278. },
  279. // 显示哪个组件(工具函数)
  280. showInnerControl(name) {
  281. this.$emit("showInnerControl", name);
  282. },
  283. // 选中充值金额
  284. select(index) {
  285. switch (index) {
  286. // 100
  287. case 0:
  288. if (this.firstCount == 0) {
  289. this.firstCount++;
  290. }
  291. break;
  292. // 200
  293. case 1:
  294. if (this.secondCount == 0) {
  295. this.secondCount++;
  296. }
  297. break;
  298. // 500
  299. case 2:
  300. if (this.thirdCount == 0) {
  301. this.thirdCount++;
  302. }
  303. break;
  304. // 1000
  305. case 3:
  306. if (this.fourthCount == 0) {
  307. this.fourthCount++;
  308. }
  309. break;
  310. }
  311. },
  312. // 选择支付方式
  313. onSelectpayPlatform(payPlatform) {
  314. this.payPlatform = payPlatform;
  315. },
  316. // 自定义金额
  317. onConfirmCount() {
  318. if (!this.payCount2) {
  319. this.$toast.text("请输入正确的金额");
  320. return;
  321. }
  322. this.payCount2 = Math.ceil(parseFloat(this.payCount2 * 100)) / 100;
  323. this.payCount = this.payCount2;
  324. },
  325. // 充值鸿币 立即付款
  326. toPay() {
  327. // 查看金额是否为0
  328. const { payCount } = this;
  329. if (!payCount) {
  330. this.$toast.text("请选择充值金额");
  331. return;
  332. }
  333. if (!this.canPay) {
  334. return;
  335. }
  336. this.canPay = false;
  337. this.payFun();
  338. },
  339. // 支付接口
  340. payFun(extra) {
  341. const { payPlatform, payCount } = this;
  342. const payType = this.$utils.payType(payPlatform).h5;
  343. this.onRecharge({
  344. amount: payCount * 100,
  345. goods_name: `${payCount}元`,
  346. pay_type: payType,
  347. pay_platform: payPlatform,
  348. extra,
  349. }).then((res) => {
  350. this.canPay = true;
  351. this.back();
  352. });
  353. return;
  354. },
  355. // 返回
  356. back() {
  357. this.showInnerControl("");
  358. },
  359. /**
  360. * 第几档 减
  361. * @param index 档位下标
  362. */
  363. reduce(index) {
  364. switch (index) {
  365. // 100
  366. case 0:
  367. if (this.firstCount == 0) {
  368. return;
  369. }
  370. this.firstCount--;
  371. break;
  372. // 200
  373. case 1:
  374. if (this.secondCount == 0) {
  375. return;
  376. }
  377. this.secondCount--;
  378. break;
  379. // 500
  380. case 2:
  381. if (this.thirdCount == 0) {
  382. return;
  383. }
  384. this.thirdCount--;
  385. break;
  386. // 1000
  387. case 3:
  388. if (this.fourthCount == 0) {
  389. return;
  390. }
  391. this.fourthCount--;
  392. break;
  393. }
  394. },
  395. /**
  396. * 第几档 加
  397. * @param index 档位下标
  398. */
  399. add(index) {
  400. switch (index) {
  401. // 100
  402. case 0:
  403. this.firstCount++;
  404. break;
  405. // 200
  406. case 1:
  407. this.secondCount++;
  408. break;
  409. // 500
  410. case 2:
  411. this.thirdCount++;
  412. break;
  413. // 1000
  414. case 3:
  415. this.fourthCount++;
  416. break;
  417. }
  418. },
  419. // 第几档 校验
  420. checkInput(index) {
  421. switch (index) {
  422. // 100
  423. case 0:
  424. if (this.firstCount === "") {
  425. this.firstCount = 0;
  426. return;
  427. }
  428. this.firstCount = parseInt(this.firstCount);
  429. break;
  430. // 200
  431. case 1:
  432. if (this.secondCount === "") {
  433. this.secondCount = 0;
  434. return;
  435. }
  436. this.secondCount = parseInt(this.secondCount);
  437. break;
  438. // 500
  439. case 2:
  440. if (this.thirdCount === "") {
  441. this.thirdCount = 0;
  442. return;
  443. }
  444. this.thirdCount = parseInt(this.thirdCount);
  445. break;
  446. // 1000
  447. case 3:
  448. if (this.fourthCount === "") {
  449. this.fourthCount = 0;
  450. return;
  451. }
  452. this.fourthCount = parseInt(this.fourthCount);
  453. break;
  454. }
  455. },
  456. // 计算总额
  457. computeMoney() {
  458. const { firstCount, secondCount, thirdCount, fourthCount, payCountList } =
  459. this;
  460. this.payCount =
  461. payCountList[0] * firstCount +
  462. payCountList[1] * secondCount +
  463. payCountList[2] * thirdCount +
  464. payCountList[3] * fourthCount;
  465. // 计算折后金额
  466. this.discount(this.payCount);
  467. },
  468. /**
  469. * 获取折扣
  470. * @param payCount 应付金额
  471. */
  472. discount(payCount) {
  473. let rate = 1;
  474. switch (true) {
  475. case payCount > 3000: // > 3000 9折
  476. rate = 1.1;
  477. break;
  478. case payCount == 3000: // 3000 92折
  479. rate = 1.08;
  480. break;
  481. case payCount >= 2000: // >= 2000 94折
  482. rate = 1.06;
  483. break;
  484. case payCount >= 1500: // >= 1500 95折
  485. rate = 1.05;
  486. break;
  487. case payCount >= 1000: // >= 1000 96折
  488. rate = 1.04;
  489. break;
  490. case payCount >= 500: // >= 500 97折
  491. rate = 1.03;
  492. break;
  493. case payCount >= 200: // >= 200 98折
  494. rate = 1.02;
  495. break;
  496. case payCount >= 100: // >= 100 99折
  497. rate = 1.01;
  498. break;
  499. }
  500. this.newHB = Math.floor(payCount * rate);
  501. },
  502. },
  503. };
  504. </script>
  505. <style lang='less' scoped>
  506. .menu_pay_h5 {
  507. .pay_account,
  508. .pay_money,
  509. .pay_type,
  510. .pay_all_money {
  511. font-size: 32 / @rem;
  512. overflow: hidden;
  513. .left,
  514. .right {
  515. float: left;
  516. }
  517. .left {
  518. width: 25%;
  519. text-align: right;
  520. color: #9d9d9d;
  521. }
  522. .right {
  523. width: 75%;
  524. padding-left: 20 / @rem;
  525. box-sizing: border-box;
  526. text-align: left;
  527. }
  528. }
  529. .active {
  530. border: 2px solid #3faeed !important;
  531. }
  532. .pay_account {
  533. height: 70 / @rem;
  534. line-height: 70 / @rem;
  535. margin-top: 20 / @rem;
  536. border-top: 1px solid #e6e6e6;
  537. .money {
  538. color: #9d9d9d;
  539. }
  540. }
  541. .pay_money {
  542. line-height: 60 / @rem;
  543. li {
  544. width: 47%;
  545. float: left;
  546. text-align: center;
  547. }
  548. .default {
  549. margin-right: 2%;
  550. border-radius: 8 / @rem;
  551. border: 2px solid #e2e2e2;
  552. margin-bottom: 10 / @rem;
  553. }
  554. .count {
  555. .reduce,
  556. input,
  557. .add {
  558. width: 33%;
  559. height: 70 / @rem;
  560. line-height: 70 / @rem;
  561. float: left;
  562. border: 2px solid #e2e2e2;
  563. box-sizing: border-box;
  564. font-size: 30 / @rem;
  565. }
  566. input {
  567. text-align: center;
  568. }
  569. .reduce {
  570. border-right: 0;
  571. border-radius: 5px 0 0 5px;
  572. }
  573. .add {
  574. border-left: 0;
  575. border-radius: 0 5px 5px 0;
  576. }
  577. }
  578. // .count_input {
  579. // width: 60%;
  580. // display: flex;
  581. // border: 2px solid #e2e2e2;
  582. // border-radius: 8 / @rem;
  583. // overflow: hidden;
  584. // input,
  585. // .confirm {
  586. // width: 50%;
  587. // float: left;
  588. // color: #555555;
  589. // }
  590. // input {
  591. // padding: 0 10 / @rem;
  592. // box-sizing: border-box;
  593. // font-size: 30 / @rem;
  594. // }
  595. // .confirm {
  596. // color: #fff;
  597. // background-color: #3faeed;
  598. // }
  599. // }
  600. }
  601. .pay_type {
  602. line-height: 70 / @rem;
  603. .alipay,
  604. .wxpay {
  605. padding: 0 30 / @rem;
  606. float: left;
  607. text-align: center;
  608. border: 2px solid #e2e2e2;
  609. box-sizing: border-box;
  610. border-radius: 8 / @rem;
  611. img {
  612. width: 52 / @rem;
  613. margin-top: 8 / @rem;
  614. float: left;
  615. }
  616. i,
  617. span {
  618. float: left;
  619. }
  620. }
  621. i {
  622. margin-right: 10 / @rem;
  623. width: 52 / @rem;
  624. height: 52 / @rem;
  625. margin-top: 9 / @rem;
  626. }
  627. .alipay {
  628. i {
  629. background: url("../../../assets/image/alipay.png") no-repeat;
  630. }
  631. }
  632. .wxpay {
  633. margin-left: 70 / @rem;
  634. i {
  635. background: url("../../../assets/image/wxpay.png") no-repeat;
  636. }
  637. }
  638. }
  639. .pay_all_money {
  640. line-height: 70 / @rem;
  641. .right {
  642. .account {
  643. }
  644. .new_count {
  645. color: #3faeed;
  646. }
  647. }
  648. .old {
  649. position: relative;
  650. float: left;
  651. margin-right: 20 / @rem;
  652. &::after {
  653. content: "";
  654. display: block;
  655. width: 110%;
  656. height: 2 / @rem;
  657. position: absolute;
  658. top: 50%;
  659. left: -5%;
  660. background-color: #ca0000;
  661. }
  662. }
  663. }
  664. .to_pay {
  665. width: 60%;
  666. line-height: 70 / @rem;
  667. margin: 0 auto;
  668. background-color: #3faeed;
  669. color: #fff;
  670. border-radius: 8 / @rem;
  671. }
  672. }
  673. // 正常横屏样式
  674. @media all and (orientation: landscape),
  675. /** 伪竖屏*/only screen and (min-device-width: 768px) and (min-device-height: 768px) and (orientation: portrait) {
  676. .menu_pay_h5 {
  677. width: 100%;
  678. height: 250 / @rem;
  679. overflow-y: auto;
  680. .pay_account,
  681. .pay_money,
  682. .pay_type,
  683. .pay_all_money {
  684. font-size: 16 / @rem;
  685. .right {
  686. padding-left: 10 / @rem;
  687. }
  688. }
  689. .pay_account {
  690. height: 35 / @rem;
  691. line-height: 35 / @rem;
  692. margin-top: 5 / @rem;
  693. .money {
  694. color: #9d9d9d;
  695. }
  696. }
  697. .pay_money {
  698. line-height: 30 / @rem;
  699. li {
  700. width: 48%;
  701. }
  702. .default {
  703. margin-right: 1%;
  704. border-radius: 4 / @rem;
  705. margin-bottom: 8 / @rem;
  706. }
  707. .count {
  708. .reduce,
  709. input,
  710. .add {
  711. height: 35 / @rem;
  712. line-height: 35 / @rem;
  713. font-size: 15 / @rem;
  714. }
  715. }
  716. // .count_input {
  717. // border-radius: 4 / @rem;
  718. // input {
  719. // padding: 0 5 / @rem;
  720. // font-size: 16 / @rem;
  721. // }
  722. // }
  723. }
  724. .pay_type {
  725. line-height: 35 / @rem;
  726. .alipay,
  727. .wxpay {
  728. padding: 0 10 / @rem;
  729. border-radius: 4 / @rem;
  730. img {
  731. width: 25 / @rem;
  732. margin-top: 4.5 / @rem;
  733. margin-left: 5 / @rem;
  734. margin-right: 5 / @rem;
  735. }
  736. }
  737. .wxpay {
  738. margin-left: 10 / @rem;
  739. }
  740. i {
  741. width: 32 / @rem;
  742. height: 32 / @rem;
  743. margin-top: 3 / @rem;
  744. margin-right: 5 / @rem;
  745. }
  746. }
  747. .pay_all_money {
  748. line-height: 35 / @rem;
  749. }
  750. .to_pay {
  751. line-height: 35 / @rem;
  752. margin: 10 / @rem auto;
  753. border-radius: 4 / @rem;
  754. }
  755. }
  756. }
  757. // ipad 横屏
  758. @media /** 伪竖屏*/all and (orientation: portrait) and (min-width: 600px) and (min-height: 800px),
  759. /**ipad伪横屏 */ all and (orientation: landscape) and (min-width: 800px) and (min-height: 600px),
  760. all and (min-device-aspect-ratio: 3/4) and (max-device-aspect-ratio: 4/3),
  761. all and (device-aspect-ratio: 4/3) {
  762. .menu_pay_h5 {
  763. height: 260 / @rem;
  764. }
  765. }
  766. </style>