Recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <div class="rechargeBox">
  3. <NavBar title="充值中心"></NavBar>
  4. <div class="payment-top acea-row row-column row-center-wrapper">
  5. <span class="name">我的余额</span>
  6. <div class="pic">
  7. ¥<span class="pic-font">{{ now_money || 0 }}</span>
  8. </div>
  9. </div>
  10. <div class="recharge">
  11. <div class="nav acea-row row-around row-middle" v-show="promoter">
  12. <div
  13. class="item"
  14. :class="active === index ? 'on' : ''"
  15. v-for="(item, index) in navRecharge"
  16. :key="index"
  17. @click="navRecharges(index)"
  18. >
  19. {{ item }}
  20. </div>
  21. </div>
  22. <div class="info-wrapper">
  23. <div v-if="active">
  24. <div class="money">
  25. <span>¥</span>
  26. <input type="number" placeholder="0.00" v-model="money" />
  27. </div>
  28. <div class="tip-box">
  29. <span class="tip">提示:</span>
  30. <div class="tip-samll">
  31. 当前可转入佣金:
  32. <span class="font-color">
  33. ¥{{ userInfo.commissionCount || 0 }}</span
  34. >
  35. </div>
  36. </div>
  37. </div>
  38. <div class="picList acea-row row-between mt-20" v-if="!active">
  39. <div
  40. class="pic-box pic-box-color acea-row row-center-wrapper row-column"
  41. :class="activePic == index ? 'pic-box-color-active' : ''"
  42. v-for="(item, index) in picList"
  43. :key="index"
  44. @click="picCharge(index, item)"
  45. >
  46. <div class="pic-number-pic">
  47. {{ item.price }}<span class="pic-number"> 元</span>
  48. </div>
  49. <div class="pic-number">赠送:{{ item.give_money }} 元</div>
  50. </div>
  51. <div
  52. class="pic-box pic-box-color acea-row row-center-wrapper"
  53. :class="activePic == picList.length ? 'pic-box-color-active' : ''"
  54. @click="picCharge(picList.length)"
  55. >
  56. <input
  57. type="number"
  58. placeholder="其他"
  59. v-model="money"
  60. class="pic-box-money pic-number-pic"
  61. :class="activePic == picList.length ? 'pic-box-color-active' : ''"
  62. />
  63. </div>
  64. </div>
  65. <div class="acea-row row-column">
  66. <div class="tip mt-30">注意事项:</div>
  67. <div class="tip-samll" v-for="item in rechargeAttention" :key="item">
  68. {{ item }}
  69. </div>
  70. </div>
  71. <div class="pay-btn" @click="recharge">
  72. {{ active ? "立即转入" : "立即充值" }}
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import { mapGetters } from "vuex";
  80. import { pay } from "@libs/wechat";
  81. import { isWeixin } from "@utils";
  82. import { rechargeWechat, getRechargeApi } from "@api/user";
  83. import { add, sub } from "@utils/bc";
  84. import NavBar from "@components/NavBar";
  85. export default {
  86. name: "Recharge",
  87. components: {
  88. NavBar
  89. },
  90. props: {},
  91. data: function() {
  92. return {
  93. navRecharge: ["账户充值", "佣金导入"],
  94. active: 0,
  95. payType: ["weixin"],
  96. from: isWeixin() ? "weixin" : "weixinh5",
  97. money: "",
  98. now_money: "",
  99. picList: [],
  100. activePic: 0,
  101. numberPic: "",
  102. rechar_id: 0,
  103. rechargeAttention: [],
  104. promoter: false
  105. };
  106. },
  107. computed: mapGetters(["userInfo"]),
  108. mounted: function() {
  109. this.now_money = this.userInfo.now_money;
  110. this.getRecharge();
  111. this.promoter = this.userInfo.is_promoter;
  112. },
  113. methods: {
  114. /**
  115. * 充值额度选择
  116. */
  117. getRecharge() {
  118. getRechargeApi().then(res => {
  119. this.picList = res.data.recharge_quota;
  120. if (this.picList[0]) {
  121. this.rechar_id = this.picList[0].id;
  122. this.numberPic = this.picList[0].price;
  123. }
  124. this.rechargeAttention = res.data.recharge_attention || [];
  125. });
  126. },
  127. /**
  128. * 选择金额
  129. */
  130. picCharge(idx, item) {
  131. this.activePic = idx;
  132. if (item === undefined) {
  133. this.rechar_id = 0;
  134. this.numberPic = "";
  135. } else {
  136. this.money = "";
  137. this.rechar_id = item.id;
  138. this.numberPic = item.price;
  139. }
  140. },
  141. navRecharges: function(index) {
  142. this.active = index;
  143. this.rechar_id = this.picList[0].id;
  144. this.numberPic = this.picList[0].price;
  145. this.activePic = 0;
  146. this.money = "";
  147. },
  148. recharge: function() {
  149. let that = this,
  150. price = Number(this.money);
  151. if (that.active) {
  152. if (price === 0) {
  153. return that.$dialog.toast({ mes: "请输入您要转入的金额" });
  154. } else if (price < 0.01) {
  155. return that.$dialog.toast({ mes: "转入金额不能低于0.01" });
  156. } else if (price > this.userInfo.commissionCount) {
  157. return that.$dialog.toast({ mes: "转入金额不能大于可提现佣金" });
  158. }
  159. this.$dialog.confirm({
  160. mes: "转入余额无法在转出,请确认转入",
  161. title: "转入余额",
  162. opts: [
  163. {
  164. txt: "确认",
  165. color: false,
  166. callback: () => {
  167. rechargeWechat({ price: price, from: that.from, type: 1 })
  168. .then(res => {
  169. that.now_money = add(price, parseInt(that.now_money));
  170. that.userInfo.commissionCount = sub(
  171. that.userInfo.commissionCount,
  172. price
  173. );
  174. that.money = "";
  175. return that.$dialog.toast({ mes: res.msg });
  176. })
  177. .catch(res => {
  178. that.$dialog.toast({ mes: res.msg });
  179. });
  180. }
  181. },
  182. {
  183. txt: "取消",
  184. color: false,
  185. callback: () => {
  186. return that.$dialog.toast({ mes: "已取消" });
  187. }
  188. }
  189. ]
  190. });
  191. } else {
  192. if (this.picList.length == this.activePic && price === 0) {
  193. return that.$dialog.toast({ mes: "请输入您要充值的金额" });
  194. } else if (this.picList.length == this.activePic && price < 0.01) {
  195. return that.$dialog.toast({ mes: "充值金额不能低于0.01" });
  196. }
  197. rechargeWechat({
  198. price: that.rechar_id == 0 ? that.money : that.numberPic,
  199. from: that.from,
  200. rechar_id: that.rechar_id
  201. })
  202. .then(res => {
  203. let data = res.data;
  204. if (data.type == "weixinh5") {
  205. location.replace(data.data.mweb_url);
  206. this.$dialog.confirm({
  207. mes: "充值余额",
  208. opts: [
  209. {
  210. txt: "已充值",
  211. color: false,
  212. callback: () => {
  213. that.$router.replace({
  214. path: "/user/account"
  215. });
  216. }
  217. },
  218. {
  219. txt: "查看余额",
  220. color: false,
  221. callback: () => {
  222. that.$router.replace({
  223. path: "/user/account"
  224. });
  225. }
  226. }
  227. ]
  228. });
  229. } else {
  230. pay(data.data)
  231. .finally(() => {
  232. that.now_money = add(
  233. price,
  234. parseInt(that.userInfo.now_money)
  235. );
  236. that.$dialog.toast({ mes: "支付成功" });
  237. })
  238. .catch(function() {
  239. that.$dialog.toast({ mes: "支付失败" });
  240. });
  241. }
  242. })
  243. .catch(res => {
  244. that.$dialog.toast({ mes: res.msg });
  245. });
  246. }
  247. }
  248. }
  249. };
  250. </script>
  251. <style scoped>
  252. .rechargeBox {
  253. height: 100%;
  254. background: #fff;
  255. }
  256. #iframe {
  257. display: none;
  258. }
  259. .pic-box-color-active {
  260. background-color: #ff1f44 !important;
  261. color: #fff !important;
  262. }
  263. .pic-box-active {
  264. width: 2.16rem;
  265. height: 1.2rem;
  266. background-color: #ff1f44;
  267. border-radius: 0.2rem;
  268. }
  269. .picList {
  270. margin-bottom: 0.3rem;
  271. margin-top: 0.3rem;
  272. }
  273. .font-color {
  274. color: #ff1f44;
  275. }
  276. .recharge {
  277. border-radius: 0.1rem;
  278. width: 100%;
  279. background-color: #fff;
  280. margin: 0.2rem auto 0 auto;
  281. padding: 0.3rem;
  282. border-top-right-radius: 0.39rem;
  283. border-top-left-radius: 0.39rem;
  284. margin-top: -0.45rem;
  285. box-sizing: border-box;
  286. }
  287. .recharge .nav {
  288. height: 0.75rem;
  289. line-height: 0.75rem;
  290. padding: 0 1rem;
  291. }
  292. .recharge .nav .item {
  293. font-size: 0.3rem;
  294. color: #333;
  295. }
  296. .recharge .nav .item.on {
  297. font-weight: bold;
  298. border-bottom: 0.04rem solid #ff1f44;
  299. }
  300. .recharge .info-wrapper {
  301. }
  302. .recharge .info-wrapper .money {
  303. margin-top: 0.6rem;
  304. padding-bottom: 0.2rem;
  305. border-bottom: 1px dashed #ddd;
  306. text-align: center;
  307. }
  308. .recharge .info-wrapper .money span {
  309. font-size: 0.56rem;
  310. color: #333;
  311. font-weight: bold;
  312. }
  313. .recharge .info-wrapper .money input {
  314. display: inline-block;
  315. width: 3rem;
  316. font-size: 0.84rem;
  317. text-align: center;
  318. color: #282828;
  319. font-weight: bold;
  320. padding-right: 0.7rem;
  321. }
  322. .recharge .info-wrapper .money input::placeholder {
  323. color: #ddd;
  324. }
  325. .recharge .info-wrapper .money input::-webkit-input-placeholder {
  326. color: #ddd;
  327. }
  328. .recharge .info-wrapper .money input:-moz-placeholder {
  329. color: #ddd;
  330. }
  331. .recharge .info-wrapper .money input::-moz-placeholder {
  332. color: #ddd;
  333. }
  334. .recharge .info-wrapper .money input:-ms-input-placeholder {
  335. color: #ddd;
  336. }
  337. .tip {
  338. font-size: 0.28rem;
  339. color: #333333;
  340. font-weight: 800;
  341. margin-bottom: 0.14rem;
  342. }
  343. .tip-samll {
  344. font-size: 0.24rem;
  345. color: #333333;
  346. margin-bottom: 0.14rem;
  347. }
  348. .tip-box {
  349. margin-top: 0.3rem;
  350. }
  351. .recharge .info-wrapper .tips span {
  352. color: #ff1f44;
  353. }
  354. .recharge .info-wrapper .pay-btn {
  355. display: block;
  356. width: 100%;
  357. height: 0.86rem;
  358. margin: 0.5rem auto 0 auto;
  359. line-height: 0.86rem;
  360. text-align: center;
  361. color: #fff;
  362. border-radius: 0.5rem;
  363. font-size: 0.3rem;
  364. font-weight: bold;
  365. background: linear-gradient(
  366. 90deg,
  367. rgba(255, 51, 102, 1) 0%,
  368. rgba(255, 101, 51, 1) 100%
  369. );
  370. opacity: 1;
  371. }
  372. .payment-top {
  373. width: 100%;
  374. height: 3.5rem;
  375. background: linear-gradient(
  376. 90deg,
  377. rgba(255, 51, 102, 1) 0%,
  378. rgba(255, 101, 51, 1) 100%
  379. );
  380. opacity: 1;
  381. }
  382. .payment-top .name {
  383. font-size: 0.26rem;
  384. color: rgba(255, 255, 255, 0.8);
  385. margin-top: -0.38rem;
  386. margin-bottom: 0.3rem;
  387. }
  388. .payment-top .pic {
  389. font-size: 0.32rem;
  390. color: #fff;
  391. }
  392. .payment-top .pic-font {
  393. font-size: 0.78rem;
  394. color: #fff;
  395. }
  396. .picList .pic-box {
  397. width: 32%;
  398. height: auto;
  399. border-radius: 0.2rem;
  400. margin-top: 0.21rem;
  401. padding: 0.2rem 0;
  402. }
  403. .pic-box-color {
  404. background-color: #f4f4f4;
  405. color: #656565;
  406. }
  407. .pic-number {
  408. font-size: 0.22rem;
  409. }
  410. .pic-number-pic {
  411. font-size: 0.38rem;
  412. margin-right: 0.1rem;
  413. text-align: center;
  414. }
  415. .pic-box-money {
  416. width: 100%;
  417. display: block;
  418. }
  419. </style>