wallet.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <template>
  2. <div class="wallet">
  3. <el-col :span="24">
  4. <div class="head-account">
  5. <div class="balance" @click="goDetail">
  6. <div class="balance_name">账户余额(元)</div>
  7. <div class="balance_price">{{amount}}</div>
  8. <div class="balance_sign"><img src="../../../static/image/1.png" alt="" srcset=""> 为了您能高效发单,请保持账户资金充足</div>
  9. </div>
  10. <div class="balance coupon" @click="goCoupon">
  11. <div class="balance_name">优惠券(张)</div>
  12. <div class="balance_price">{{$store.state.userInfo.couponNum}}</div>
  13. <div class="balance_sign">可用优惠券</div>
  14. </div>
  15. </div>
  16. </el-col>
  17. <el-col class="wallet-content" :span="20" v-if="memberType !==3">
  18. <div class="recharge_title">充值金额</div>
  19. <div class="recharge_list recharge_list_m">
  20. <div @click="chooseMoney(v,i)" :class="curIdx === i ? 'item item_ac' : 'item'" v-for="(v,i) in moneyList" :key="i"><span v-if="v.couponList || v.giveValue" class="item_tips">充值有礼</span>{{v.value}}元</div>
  21. <el-input type='num' @focus="open" v-model="value" clearable :class="curIdx === -1 ? 'item item_ac' : 'item'" placeholder="其他金额" />
  22. </div>
  23. <div class="recharge_coupon" v-if="couponList.length || giveValue">
  24. <div class="recharge_coupon_top">
  25. <img src="../../../static/image/recharge_coupon.png" alt="" srcset="">
  26. <div class="recharge_coupon_top_left">充{{moneyList[curIdx].value}}元,
  27. 赠送<span v-if="giveValue">{{giveValue}}元</span><span v-if="moneyList[curIdx].giveCouponAmount">{{giveValue&&moneyList[curIdx].giveCouponAmount ? '和' : ''}}{{moneyList[curIdx].giveCouponAmount}}元优惠券</span>
  28. </div>
  29. <div class="recharge_coupon_top_right ">
  30. <div v-for="(v,i) in couponList" :key="i">{{`${v.couponName} x${v.memberReciveNum}张 `}}</div>
  31. </div>
  32. </div>
  33. <div class="recharge_coupon_bottom">
  34. <div class="recharge_coupon_bottom_item" v-for="(item,index) in couponList" :key="index">
  35. <div class="recharge_coupon_bottom_left">
  36. <div class="recharge_coupon_bottom_left_num">
  37. <span v-if="item.couponType == 1 || item.couponType == 3">¥</span>
  38. <span class="num" v-if="item.couponType == 1 || item.couponType == 3">{{item.money}}</span>
  39. <span class="num" v-if="item.couponType == 2">{{item.discount}}</span>
  40. <span v-if="item.couponType == 2">折</span>
  41. </div>
  42. <div class="recharge_coupon_bottom_sub">
  43. <span v-if="item.couponType == 2">最高减{{ item.maxDiscount }}元</span>
  44. <span v-if="item.couponType == 1">满{{ item.limitFee }}元可用</span>
  45. </div>
  46. </div>
  47. <div class="recharge_coupon_bottom_middle">
  48. <div></div>
  49. </div>
  50. <div class="recharge_coupon_bottom_right">
  51. <div class="recharge_coupon_bottom_date">
  52. <div>{{item.couponName}}</div>
  53. <div>有效期:{{item.days}}天(自领取后生效)</div>
  54. </div>
  55. <div class="recharge_coupon_bottom_number">
  56. <span>x{{item.memberReciveNum}}张</span>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="recharge_title">支付方式</div>
  63. <div class="recharge_list">
  64. <div @click="paymentType = 1" :class="paymentType === 1 ? 'item item_ac' : 'item'"><img class="img" src="../../../static/image/alipay.png" alt="" srcset=""> 支付宝支付<img class="choose" v-if="paymentType === 1" src="../../../static/image/icon_choose.png" alt=""></div>
  65. <div @click="paymentType = 2" :class="paymentType === 2 ? 'item item_ac' : 'item'"><img class="img" src="../../../static/image/we-chat.png" alt="" srcset="">微信支付<img class="choose" v-if="paymentType === 2" src="../../../static/image/icon_choose.png" alt=""></div>
  66. </div>
  67. <div>
  68. <el-checkbox v-model="checked">充值即同意 <span @click="getExplain" class="agreement">《充值协议》</span> </el-checkbox>
  69. </div>
  70. <el-button @click="recharge" class="recharge_color">去充值</el-button>
  71. </el-col>
  72. <!-- 支付二维码 -->
  73. <qr-code v-if="showCode" @paySuccess="paySuccess" @refreshCode="recharge" @closeCode="showCode = false" ref="code" :payAmount="payAmount" :link="link" :paymentType="paymentType" :orderSn="orderSn"></qr-code>
  74. <!-- 充值协议 -->
  75. <el-dialog :visible.sync="centerDialogVisible" width="800px" center>
  76. <div v-html="text"></div>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script>
  81. import {
  82. getWallet,
  83. getRechargeList,
  84. recharge,
  85. getExplain,
  86. } from "../../api/amount.js";
  87. import qrCode from "../../common/qrCode.vue";
  88. export default {
  89. name: "wallet",
  90. props: {
  91. products: {
  92. type: Array,
  93. default: function () {
  94. return [];
  95. },
  96. },
  97. },
  98. data() {
  99. return {
  100. amount: 0,
  101. moneyList: [],
  102. curIdx: 0,
  103. paymentType: 1,
  104. money: 0,
  105. id: "",
  106. link: "",
  107. timer: null,
  108. orderSn: "",
  109. showCode: false,
  110. payAmount: 0,
  111. centerDialogVisible: false,
  112. text: "",
  113. value: "",
  114. checked: false,
  115. memberType: this.$store.state.userInfo.memberType,
  116. couponList: [],
  117. giveValue: 0,
  118. };
  119. },
  120. watch: {
  121. "$store.state.userInfo": {
  122. handler(newVal, oldVal) {
  123. this.memberType = newVal.memberType;
  124. },
  125. deep: true,
  126. },
  127. },
  128. components: {
  129. qrCode,
  130. },
  131. created() {
  132. this.getWallet();
  133. this.getRechargeList();
  134. },
  135. methods: {
  136. goDetail() {
  137. this.$router.push({ name: "walletDetail" });
  138. },
  139. goCoupon() {
  140. this.$router.push({ name: "coupon" });
  141. },
  142. paySuccess() {
  143. this.showCode = false;
  144. this.$store.dispatch("getUserInfo");
  145. this.getWallet();
  146. },
  147. getExplain() {
  148. getExplain({ type: 6 }).then((res) => {
  149. console.log("object", res);
  150. if (res.code === 200) {
  151. this.text = res.data;
  152. this.centerDialogVisible = true;
  153. } else {
  154. this.$message({
  155. type: "error",
  156. message: res.msg,
  157. });
  158. }
  159. });
  160. },
  161. getRechargeList() {
  162. getRechargeList().then((res) => {
  163. if (res.code === 200) {
  164. this.moneyList = res.data;
  165. this.couponList = this.moneyList[this.curIdx].couponList || [];
  166. this.giveValue = this.moneyList[this.curIdx].giveValue;
  167. this.money = this.moneyList[this.curIdx].value;
  168. this.id = this.moneyList[this.curIdx].id;
  169. } else {
  170. this.$message({
  171. type: "error",
  172. message: res.msg,
  173. });
  174. }
  175. });
  176. },
  177. getWallet() {
  178. getWallet().then((res) => {
  179. if (res.code === 200) {
  180. this.amount = res.data.amount;
  181. } else {
  182. this.$message({
  183. type: "error",
  184. message: res.msg,
  185. });
  186. }
  187. });
  188. },
  189. chooseMoney(v, i) {
  190. this.value = "";
  191. this.curIdx = i;
  192. this.money = v.value;
  193. this.id = v.id;
  194. this.couponList = this.moneyList[i].couponList || [];
  195. this.giveValue = this.moneyList[i].giveValue ?? 0;
  196. },
  197. open() {
  198. this.curIdx = -1;
  199. this.money = "";
  200. this.id = "";
  201. this.couponList = [];
  202. },
  203. recharge() {
  204. let params = {
  205. money: this.value ? this.value : this.money,
  206. paymentType: this.paymentType,
  207. createType: 1,
  208. id: this.id,
  209. };
  210. if (!this.paymentType) {
  211. return this.$message({
  212. type: "info",
  213. message: "请先选择支付方式再充值!",
  214. });
  215. }
  216. let reg = new RegExp(/^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/);
  217. if (!reg.test(Number(params.money))) {
  218. return this.$message({
  219. type: "info",
  220. message: "请先输入正确充值金额再充值(最多2位小数)!",
  221. });
  222. }
  223. if (!this.checked) {
  224. return this.$message({
  225. type: "info",
  226. message: "请先勾选同意后再充值!",
  227. });
  228. }
  229. recharge(params).then((res) => {
  230. if (res.code === 200) {
  231. this.link = res.data.data;
  232. this.orderSn = res.data.orderSn;
  233. this.payAmount = res.data.amount;
  234. this.showCode = true;
  235. } else {
  236. this.$message({
  237. type: "info",
  238. message: res.msg,
  239. });
  240. }
  241. });
  242. },
  243. },
  244. };
  245. </script>
  246. <style lang="scss" scoped>
  247. .wallet {
  248. width: 100%;
  249. height: 100%;
  250. background: #ffffff;
  251. .head-account {
  252. display: flex;
  253. .balance {
  254. border-radius: 5px;
  255. background-image: url(../../../static/image/wallet1.png);
  256. background-size: 100% 100%;
  257. width: 618px;
  258. height: 168px;
  259. padding-left: 25px;
  260. box-sizing: border-box;
  261. margin-bottom: 42px;
  262. cursor: pointer;
  263. .balance_name {
  264. font-size: 14px;
  265. line-height: 22px;
  266. font-weight: 400;
  267. color: #ffffff;
  268. padding-top: 24px;
  269. }
  270. .balance_price {
  271. font-size: 42px;
  272. line-height: 59px;
  273. font-weight: bold;
  274. color: #ffffff;
  275. margin: 8px 0;
  276. }
  277. .balance_sign {
  278. font-size: 12px;
  279. font-weight: 400;
  280. color: #ffffff;
  281. opacity: 0.8;
  282. line-height: 17px;
  283. display: flex;
  284. align-items: center;
  285. img {
  286. width: 12px;
  287. height: 12px;
  288. margin-right: 4px;
  289. }
  290. }
  291. }
  292. .coupon {
  293. width: 298px;
  294. height: 168px;
  295. background-image: url(../../../static/image/wallet2.png);
  296. }
  297. }
  298. .wallet-content {
  299. padding-left: 15px;
  300. }
  301. .recharge_title {
  302. font-size: 16px;
  303. font-weight: 500;
  304. color: #333333;
  305. }
  306. .recharge_color {
  307. width: 160px;
  308. background: #fc7200;
  309. color: #fff;
  310. }
  311. .agreement {
  312. font-size: 12px;
  313. font-weight: 400;
  314. color: #fc7200;
  315. margin-top: 10px;
  316. span {
  317. color: #3662a1;
  318. cursor: pointer;
  319. }
  320. }
  321. .recharge_list /deep/ .el-input__inner {
  322. padding: 0 15px;
  323. height: 36px;
  324. border: none !important;
  325. text-align: center;
  326. }
  327. .recharge_list /deep/ input::placeholder {
  328. font-size: 14px !important;
  329. }
  330. .recharge_list {
  331. width: 100%;
  332. display: flex;
  333. flex-wrap: wrap;
  334. margin-top: 24px;
  335. margin-bottom: 10px;
  336. .item {
  337. position: relative;
  338. width: 200px;
  339. height: 40px;
  340. border: 1px solid #e6e6e6;
  341. color: #333333;
  342. font-size: 16px;
  343. font-weight: 500;
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. border-radius: 3px;
  348. margin: 0 15px 15px 0;
  349. cursor: pointer;
  350. .img {
  351. width: 24px;
  352. height: 24px;
  353. margin-right: 6px;
  354. }
  355. .choose {
  356. position: absolute;
  357. top: 0;
  358. right: 0;
  359. width: 16px;
  360. height: 16px;
  361. }
  362. }
  363. .item_ac {
  364. border-color: #fc7200;
  365. color: #fc7200;
  366. }
  367. }
  368. .recharge_list_m {
  369. .item {
  370. width: 90px;
  371. height: 36px;
  372. margin: 0 24px 15px 0;
  373. position: relative;
  374. .item_tips {
  375. height: 19px;
  376. position: absolute;
  377. right: -22px;
  378. top: -28px;
  379. padding: 5px;
  380. background-image: url("../../../static/image/recharge.png");
  381. background-position: center;
  382. background-repeat: no-repeat;
  383. background-size: contain;
  384. font-size: 12px;
  385. font-weight: 100;
  386. color: #ffffff;
  387. }
  388. }
  389. }
  390. .recharge_coupon {
  391. width: 880px;
  392. background: #fef2e9;
  393. border-radius: 8px;
  394. padding: 3px 10px;
  395. margin-bottom: 42px;
  396. .recharge_coupon_top {
  397. display: flex;
  398. flex-wrap: wrap;
  399. align-items: center;
  400. img {
  401. width: 28px;
  402. height: 30px;
  403. }
  404. .recharge_coupon_top_left {
  405. padding: 0 10px 0 8px;
  406. display: flex;
  407. align-items: center;
  408. font-size: 16px;
  409. font-family: PingFang SC;
  410. font-weight: bold;
  411. color: #fc7200;
  412. }
  413. .recharge_coupon_top_right {
  414. display: flex;
  415. flex-wrap: wrap;
  416. align-items: flex-end;
  417. font-size: 12px;
  418. font-weight: 400;
  419. color: #fc7200;
  420. padding-top: 2px;
  421. div {
  422. margin-right: 10px;
  423. }
  424. }
  425. }
  426. .recharge_coupon_bottom {
  427. margin: 15px 10px;
  428. display: flex;
  429. justify-content: space-between;
  430. flex-wrap: wrap;
  431. .recharge_coupon_bottom_item {
  432. width: 410px;
  433. height: 72px;
  434. display: flex;
  435. justify-content: flex-start;
  436. margin-bottom: 10px;
  437. // margin-right: 24px;
  438. .recharge_coupon_bottom_left {
  439. display: flex;
  440. flex-direction: column;
  441. justify-content: center;
  442. align-items: center;
  443. width: 110px;
  444. margin-top: 10px auto;
  445. text-align: center;
  446. border-radius: 8px;
  447. background-color: #fff;
  448. padding: 10px 0;
  449. .recharge_coupon_bottom_left_num {
  450. span {
  451. font-size: 14px;
  452. font-family: PingFang SC;
  453. font-weight: 400;
  454. line-height: 20px;
  455. margin-left: 2px;
  456. color: #ec1414;
  457. }
  458. .num {
  459. font-size: 26px;
  460. font-family: PingFang SC;
  461. font-weight: bold;
  462. color: #ec1414;
  463. }
  464. }
  465. .recharge_coupon_bottom_sub {
  466. font-size: 14px;
  467. font-family: PingFang SC;
  468. font-weight: 400;
  469. line-height: 20px;
  470. color: #666666;
  471. }
  472. }
  473. .recharge_coupon_bottom_middle {
  474. display: flex;
  475. align-items: center;
  476. div {
  477. height: 100%;
  478. padding: 10px 0;
  479. height: 55px;
  480. border-right: 1px dashed #ec1414;
  481. box-sizing: border-box;
  482. }
  483. }
  484. .recharge_coupon_bottom_right {
  485. border-radius: 8px;
  486. background-color: #fff;
  487. flex: 1;
  488. position: relative;
  489. padding: 10px;
  490. display: flex;
  491. justify-content: space-between;
  492. align-items: center;
  493. .recharge_coupon_bottom_date {
  494. font-size: 18px;
  495. font-family: PingFang SC;
  496. font-weight: bold;
  497. line-height: 25px;
  498. color: #333333;
  499. div:last-child {
  500. height: 20px;
  501. font-size: 14px;
  502. font-family: PingFang SC;
  503. font-weight: 400;
  504. line-height: 20px;
  505. color: #999999;
  506. }
  507. }
  508. .recharge_coupon_bottom_number {
  509. display: flex;
  510. align-items: center;
  511. span {
  512. width: 63px;
  513. height: 22px;
  514. line-height: 22px;
  515. border: 1px solid #ec1414;
  516. border-radius: 18px;
  517. text-align: center;
  518. font-size: 12px;
  519. font-family: PingFang SC;
  520. font-weight: 500;
  521. color: #ec1414;
  522. cursor: pointer;
  523. &:hover {
  524. background-color: #ec1414;
  525. color: #ffffff;
  526. }
  527. }
  528. }
  529. }
  530. }
  531. }
  532. }
  533. }
  534. </style>