MenuPayH5.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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: ["100", "200", "500", "1000"], // 可选充值金额列表
  213. currentCount: 0, // 默认选中的充值金额
  214. payPlatform: "ALIPAY", // 默认支付方式
  215. payCount: 0, // 应付金额
  216. payCount2: "", // 输入框的应付金额
  217. canPay: true, // 是否可以点击支付
  218. firstCount: 0, // 第一档 数量
  219. secondCount: 0, // 第二档 数量
  220. thirdCount: 0, // 第三档 数量
  221. fourthCount: 0, // 第四档 数量
  222. allCount: 0, // 本应付金额
  223. oldHB: 0, // 原得鸿币
  224. newHB: 0, // 应得鸿币
  225. };
  226. },
  227. computed: {
  228. ...mapState([
  229. "userInfo",
  230. "finance",
  231. "query",
  232. "isWeChat",
  233. "CONFIG",
  234. "appid",
  235. ]),
  236. },
  237. watch: {
  238. // 第一档 100
  239. firstCount(firstCountNew) {
  240. this.checkInput(0);
  241. this.computeMoney();
  242. },
  243. // 第二档 200
  244. secondCount(secondCountNew) {
  245. this.checkInput(1);
  246. this.computeMoney();
  247. },
  248. // 第三档 500
  249. thirdCount(thirdCountNew) {
  250. this.checkInput(2);
  251. this.computeMoney();
  252. },
  253. // 第四档 1000
  254. fourthCount(fourthCountNew) {
  255. this.checkInput(3);
  256. this.computeMoney();
  257. },
  258. },
  259. created() {},
  260. mounted() {
  261. // 默认选中第一栏
  262. this.add(0);
  263. },
  264. methods: {
  265. ...mapActions(["isPayAction"]),
  266. // ios中文输入
  267. compositionstartInput() {
  268. this.account = "";
  269. },
  270. // 选择充值金额
  271. onSelectCount(count, index) {
  272. this.currentCount = index;
  273. if (count) {
  274. this.payCount = count;
  275. this.payCount2 = "";
  276. }
  277. },
  278. // 显示哪个组件(工具函数)
  279. showInnerControl(name) {
  280. this.$emit("showInnerControl", name);
  281. },
  282. // 选中充值金额
  283. select(index) {
  284. switch (index) {
  285. // 100
  286. case 0:
  287. if (this.firstCount == 0) {
  288. this.firstCount++;
  289. }
  290. break;
  291. // 200
  292. case 1:
  293. if (this.secondCount == 0) {
  294. this.secondCount++;
  295. }
  296. break;
  297. // 500
  298. case 2:
  299. if (this.thirdCount == 0) {
  300. this.thirdCount++;
  301. }
  302. break;
  303. // 1000
  304. case 3:
  305. if (this.fourthCount == 0) {
  306. this.fourthCount++;
  307. }
  308. break;
  309. }
  310. },
  311. // 选择支付方式
  312. onSelectpayPlatform(payPlatform) {
  313. this.payPlatform = payPlatform;
  314. },
  315. // 自定义金额
  316. onConfirmCount() {
  317. if (!this.payCount2) {
  318. this.$toast.text("请输入正确的金额");
  319. return;
  320. }
  321. this.payCount2 = Math.ceil(parseFloat(this.payCount2 * 100)) / 100;
  322. this.payCount = this.payCount2;
  323. },
  324. // 充值鸿币 立即付款
  325. toPay() {
  326. // 查看金额是否为0
  327. const { payCount } = this;
  328. if (!payCount) {
  329. this.$toast.text("请选择充值金额");
  330. return;
  331. }
  332. if (!this.canPay) {
  333. return;
  334. }
  335. this.canPay = false;
  336. this.payFun();
  337. },
  338. // 支付接口
  339. payFun(extra) {
  340. const { payPlatform, payCount } = this;
  341. const { appid } = 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. this.$api
  355. .recharge({
  356. amount: payCount * 100,
  357. goods_name: `${payCount}元`,
  358. app_id: appid,
  359. pay_type: payType,
  360. pay_platform: payPlatform,
  361. return_url: window.location.href,
  362. extra,
  363. })
  364. .then((res) => {
  365. this.canPay = true;
  366. this.checkCodeHandler(res);
  367. const { data, code } = res.data;
  368. // 错误
  369. if (code) {
  370. return;
  371. }
  372. // 成功
  373. // 刷新鸿币
  374. const time = new Date().getTime();
  375. const orderItem = {
  376. order_id: data.order_id,
  377. time,
  378. };
  379. let orderList = JSON.parse(localStorage.getItem("orderList")) || [];
  380. orderList.push(orderItem);
  381. localStorage.setItem("orderList", JSON.stringify(orderList));
  382. window.location.href = data.url;
  383. this.back();
  384. });
  385. },
  386. // 返回
  387. back() {
  388. this.showInnerControl("");
  389. },
  390. /**
  391. * 第几档 减
  392. * @param index 档位下标
  393. */
  394. reduce(index) {
  395. switch (index) {
  396. // 100
  397. case 0:
  398. if (this.firstCount == 0) {
  399. return;
  400. }
  401. this.firstCount--;
  402. break;
  403. // 200
  404. case 1:
  405. if (this.secondCount == 0) {
  406. return;
  407. }
  408. this.secondCount--;
  409. break;
  410. // 500
  411. case 2:
  412. if (this.thirdCount == 0) {
  413. return;
  414. }
  415. this.thirdCount--;
  416. break;
  417. // 1000
  418. case 3:
  419. if (this.fourthCount == 0) {
  420. return;
  421. }
  422. this.fourthCount--;
  423. break;
  424. }
  425. },
  426. /**
  427. * 第几档 加
  428. * @param index 档位下标
  429. */
  430. add(index) {
  431. switch (index) {
  432. // 100
  433. case 0:
  434. this.firstCount++;
  435. break;
  436. // 200
  437. case 1:
  438. this.secondCount++;
  439. break;
  440. // 500
  441. case 2:
  442. this.thirdCount++;
  443. break;
  444. // 1000
  445. case 3:
  446. this.fourthCount++;
  447. break;
  448. }
  449. },
  450. // 第几档 校验
  451. checkInput(index) {
  452. switch (index) {
  453. // 100
  454. case 0:
  455. if (this.firstCount === "") {
  456. this.firstCount = 0;
  457. return;
  458. }
  459. this.firstCount = parseInt(this.firstCount);
  460. break;
  461. // 200
  462. case 1:
  463. if (this.secondCount === "") {
  464. this.secondCount = 0;
  465. return;
  466. }
  467. this.secondCount = parseInt(this.secondCount);
  468. break;
  469. // 500
  470. case 2:
  471. if (this.thirdCount === "") {
  472. this.thirdCount = 0;
  473. return;
  474. }
  475. this.thirdCount = parseInt(this.thirdCount);
  476. break;
  477. // 1000
  478. case 3:
  479. if (this.fourthCount === "") {
  480. this.fourthCount = 0;
  481. return;
  482. }
  483. this.fourthCount = parseInt(this.fourthCount);
  484. break;
  485. }
  486. },
  487. // 计算总额
  488. computeMoney() {
  489. const { firstCount, secondCount, thirdCount, fourthCount, payCountList } =
  490. this;
  491. this.payCount =
  492. payCountList[0] * firstCount +
  493. payCountList[1] * secondCount +
  494. payCountList[2] * thirdCount +
  495. payCountList[3] * fourthCount;
  496. // 计算折后金额
  497. this.discount(this.payCount);
  498. },
  499. /**
  500. * 获取折扣
  501. * @param payCount 应付金额
  502. */
  503. discount(payCount) {
  504. let rate = 1;
  505. switch (true) {
  506. case payCount > 3000: // > 3000 9折
  507. rate = 1.1;
  508. break;
  509. case payCount == 3000: // 3000 92折
  510. rate = 1.08;
  511. break;
  512. case payCount >= 2000: // >= 2000 94折
  513. rate = 1.06;
  514. break;
  515. case payCount >= 1500: // >= 1500 95折
  516. rate = 1.05;
  517. break;
  518. case payCount >= 1000: // >= 1000 96折
  519. rate = 1.04;
  520. break;
  521. case payCount >= 500: // >= 500 97折
  522. rate = 1.03;
  523. break;
  524. case payCount >= 200: // >= 200 98折
  525. rate = 1.02;
  526. break;
  527. case payCount >= 100: // >= 100 99折
  528. rate = 1.01;
  529. break;
  530. }
  531. this.newHB = Math.floor(payCount * rate);
  532. },
  533. },
  534. };
  535. </script>
  536. <style lang='less' scoped>
  537. .menu_pay_h5 {
  538. .pay_account,
  539. .pay_money,
  540. .pay_type,
  541. .pay_all_money {
  542. font-size: 32 / @rem;
  543. overflow: hidden;
  544. .left,
  545. .right {
  546. float: left;
  547. }
  548. .left {
  549. width: 25%;
  550. text-align: right;
  551. color: #9d9d9d;
  552. }
  553. .right {
  554. width: 75%;
  555. padding-left: 20 / @rem;
  556. box-sizing: border-box;
  557. text-align: left;
  558. }
  559. }
  560. .active {
  561. border: 2px solid #3faeed !important;
  562. }
  563. .pay_account {
  564. height: 70 / @rem;
  565. line-height: 70 / @rem;
  566. margin-top: 20 / @rem;
  567. border-top: 1px solid #e6e6e6;
  568. .money {
  569. color: #9d9d9d;
  570. }
  571. }
  572. .pay_money {
  573. line-height: 60 / @rem;
  574. li {
  575. width: 47%;
  576. float: left;
  577. text-align: center;
  578. }
  579. .default {
  580. margin-right: 2%;
  581. border-radius: 8 / @rem;
  582. border: 2px solid #e2e2e2;
  583. margin-bottom: 10 / @rem;
  584. }
  585. .count {
  586. .reduce,
  587. input,
  588. .add {
  589. width: 33%;
  590. height: 70 / @rem;
  591. line-height: 70 / @rem;
  592. float: left;
  593. border: 2px solid #e2e2e2;
  594. box-sizing: border-box;
  595. font-size: 30 / @rem;
  596. }
  597. input {
  598. text-align: center;
  599. }
  600. .reduce {
  601. border-right: 0;
  602. border-radius: 5px 0 0 5px;
  603. }
  604. .add {
  605. border-left: 0;
  606. border-radius: 0 5px 5px 0;
  607. }
  608. }
  609. // .count_input {
  610. // width: 60%;
  611. // display: flex;
  612. // border: 2px solid #e2e2e2;
  613. // border-radius: 8 / @rem;
  614. // overflow: hidden;
  615. // input,
  616. // .confirm {
  617. // width: 50%;
  618. // float: left;
  619. // color: #555555;
  620. // }
  621. // input {
  622. // padding: 0 10 / @rem;
  623. // box-sizing: border-box;
  624. // font-size: 30 / @rem;
  625. // }
  626. // .confirm {
  627. // color: #fff;
  628. // background-color: #3faeed;
  629. // }
  630. // }
  631. }
  632. .pay_type {
  633. line-height: 70 / @rem;
  634. .alipay,
  635. .wxpay {
  636. padding: 0 30 / @rem;
  637. float: left;
  638. text-align: center;
  639. border: 2px solid #e2e2e2;
  640. box-sizing: border-box;
  641. border-radius: 8 / @rem;
  642. img {
  643. width: 52 / @rem;
  644. margin-top: 8 / @rem;
  645. float: left;
  646. }
  647. i,
  648. span {
  649. float: left;
  650. }
  651. }
  652. i {
  653. margin-right: 10 / @rem;
  654. width: 52 / @rem;
  655. height: 52 / @rem;
  656. margin-top: 9 / @rem;
  657. }
  658. .alipay {
  659. i {
  660. background: url("../../../assets/image/alipay.png") no-repeat;
  661. }
  662. }
  663. .wxpay {
  664. margin-left: 70 / @rem;
  665. i {
  666. background: url("../../../assets/image/wxpay.png") no-repeat;
  667. }
  668. }
  669. }
  670. .pay_all_money {
  671. line-height: 70 / @rem;
  672. .right {
  673. .account {
  674. }
  675. .new_count {
  676. color: #3faeed;
  677. }
  678. }
  679. .old {
  680. position: relative;
  681. float: left;
  682. margin-right: 20 / @rem;
  683. &::after {
  684. content: "";
  685. display: block;
  686. width: 110%;
  687. height: 2 / @rem;
  688. position: absolute;
  689. top: 50%;
  690. left: -5%;
  691. background-color: #ca0000;
  692. }
  693. }
  694. }
  695. .to_pay {
  696. width: 60%;
  697. line-height: 70 / @rem;
  698. margin: 0 auto;
  699. background-color: #3faeed;
  700. color: #fff;
  701. border-radius: 8 / @rem;
  702. }
  703. }
  704. // 正常横屏样式
  705. @media all and (orientation: landscape),
  706. /** 伪竖屏*/only screen and (min-device-width: 768px) and (min-device-height: 768px) and (orientation: portrait) {
  707. .menu_pay_h5 {
  708. width: 100%;
  709. height: 200 / @rem;
  710. overflow-y: auto;
  711. .pay_account,
  712. .pay_money,
  713. .pay_type,
  714. .pay_all_money {
  715. font-size: 16 / @rem;
  716. .right {
  717. padding-left: 10 / @rem;
  718. }
  719. }
  720. .pay_account {
  721. height: 35 / @rem;
  722. line-height: 35 / @rem;
  723. margin-top: 10 / @rem;
  724. .money {
  725. color: #9d9d9d;
  726. }
  727. }
  728. .pay_money {
  729. line-height: 30 / @rem;
  730. li {
  731. width: 48%;
  732. }
  733. .default {
  734. margin-right: 1%;
  735. border-radius: 4 / @rem;
  736. margin-bottom: 10 / @rem;
  737. }
  738. .count {
  739. .reduce,
  740. input,
  741. .add {
  742. height: 35 / @rem;
  743. line-height: 35 / @rem;
  744. font-size: 15 / @rem;
  745. }
  746. }
  747. // .count_input {
  748. // border-radius: 4 / @rem;
  749. // input {
  750. // padding: 0 5 / @rem;
  751. // font-size: 16 / @rem;
  752. // }
  753. // }
  754. }
  755. .pay_type {
  756. line-height: 35 / @rem;
  757. .alipay,
  758. .wxpay {
  759. padding: 0 10 / @rem;
  760. border-radius: 4 / @rem;
  761. img {
  762. width: 25 / @rem;
  763. margin-top: 4.5 / @rem;
  764. margin-left: 5 / @rem;
  765. margin-right: 5 / @rem;
  766. }
  767. }
  768. .wxpay {
  769. margin-left: 10 / @rem;
  770. }
  771. i {
  772. width: 32 / @rem;
  773. height: 32 / @rem;
  774. margin-top: 3 / @rem;
  775. margin-right: 5 / @rem;
  776. }
  777. }
  778. .pay_all_money {
  779. line-height: 35 / @rem;
  780. }
  781. .to_pay {
  782. line-height: 35 / @rem;
  783. margin: 10 / @rem auto;
  784. border-radius: 4 / @rem;
  785. }
  786. }
  787. }
  788. // ipad 横屏
  789. @media /** 伪竖屏*/all and (orientation: portrait) and (min-width: 600px) and (min-height: 800px),
  790. /**ipad伪横屏 */ all and (orientation: landscape) and (min-width: 800px) and (min-height: 600px),
  791. all and (min-device-aspect-ratio: 3/4) and (max-device-aspect-ratio: 4/3),
  792. all and (device-aspect-ratio: 4/3) {
  793. .menu_pay_h5 {
  794. height: 260 / @rem;
  795. }
  796. }
  797. </style>