wallet.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <template>
  2. <div>
  3. <el-col :span="24">
  4. <div class="head-account">
  5. <div class="balance">
  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. goCoupon() {
  137. this.$router.push({ name: "coupon" });
  138. },
  139. paySuccess() {
  140. this.showCode = false;
  141. this.$store.dispatch("getUserInfo");
  142. this.getWallet();
  143. },
  144. getExplain() {
  145. getExplain({ type: 6 }).then((res) => {
  146. console.log("object", res);
  147. if (res.code === 200) {
  148. this.text = res.data;
  149. this.centerDialogVisible = true;
  150. } else {
  151. this.$message({
  152. type: "error",
  153. message: res.msg,
  154. });
  155. }
  156. });
  157. },
  158. getRechargeList() {
  159. getRechargeList().then((res) => {
  160. if (res.code === 200) {
  161. this.moneyList = res.data;
  162. this.couponList = this.moneyList[this.curIdx].couponList;
  163. this.giveValue = this.moneyList[this.curIdx].giveValue;
  164. this.money = this.moneyList[this.curIdx].value;
  165. this.id = this.moneyList[this.curIdx].id;
  166. } else {
  167. this.$message({
  168. type: "error",
  169. message: res.msg,
  170. });
  171. }
  172. });
  173. },
  174. getWallet() {
  175. getWallet().then((res) => {
  176. if (res.code === 200) {
  177. this.amount = res.data.amount;
  178. } else {
  179. this.$message({
  180. type: "error",
  181. message: res.msg,
  182. });
  183. }
  184. });
  185. },
  186. chooseMoney(v, i) {
  187. this.value = "";
  188. this.curIdx = i;
  189. this.money = v.value;
  190. this.id = v.id;
  191. this.couponList = this.moneyList[i].couponList || [];
  192. this.giveValue = this.moneyList[i].giveValue ?? 0;
  193. },
  194. open() {
  195. this.curIdx = -1;
  196. this.money = "";
  197. this.id = "";
  198. this.couponList = [];
  199. },
  200. recharge() {
  201. let params = {
  202. money: this.value ? this.value : this.money,
  203. paymentType: this.paymentType,
  204. createType: 1,
  205. id: this.id,
  206. };
  207. if (!this.paymentType) {
  208. return this.$message({
  209. type: "info",
  210. message: "请先选择支付方式再充值!",
  211. });
  212. }
  213. let reg = new RegExp(/^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/);
  214. if (!reg.test(Number(params.money))) {
  215. return this.$message({
  216. type: "info",
  217. message: "请先输入正确充值金额再充值(最多2位小数)!",
  218. });
  219. }
  220. if (!this.checked) {
  221. return this.$message({
  222. type: "info",
  223. message: "请先勾选同意后再充值!",
  224. });
  225. }
  226. recharge(params).then((res) => {
  227. if (res.code === 200) {
  228. this.link = res.data.data;
  229. this.orderSn = res.data.orderSn;
  230. this.payAmount = res.data.amount;
  231. this.showCode = true;
  232. } else {
  233. this.$message({
  234. type: "info",
  235. message: res.msg,
  236. });
  237. }
  238. });
  239. },
  240. },
  241. };
  242. </script>
  243. <style lang="scss" scoped>
  244. .head-account {
  245. display: flex;
  246. .balance {
  247. border-radius: 5px;
  248. background-image: url(../../../static/image/wallet1.png);
  249. background-size: 100% 100%;
  250. width: 618px;
  251. height: 168px;
  252. padding-left: 25px;
  253. box-sizing: border-box;
  254. margin-bottom: 42px;
  255. cursor: pointer;
  256. .balance_name {
  257. font-size: 14px;
  258. line-height: 22px;
  259. font-weight: 400;
  260. color: #ffffff;
  261. padding-top: 24px;
  262. }
  263. .balance_price {
  264. font-size: 42px;
  265. line-height: 59px;
  266. font-weight: bold;
  267. color: #ffffff;
  268. margin: 8px 0;
  269. }
  270. .balance_sign {
  271. font-size: 12px;
  272. font-weight: 400;
  273. color: #ffffff;
  274. opacity: 0.8;
  275. line-height: 17px;
  276. display: flex;
  277. align-items: center;
  278. img {
  279. width: 12px;
  280. height: 12px;
  281. margin-right: 4px;
  282. }
  283. }
  284. }
  285. .coupon {
  286. width: 298px;
  287. height: 168px;
  288. background-image: url(../../../static/image/wallet2.png);
  289. }
  290. }
  291. .wallet-content {
  292. padding-left: 15px;
  293. }
  294. .recharge_title {
  295. font-size: 16px;
  296. font-weight: 500;
  297. color: #333333;
  298. }
  299. .recharge_color {
  300. width: 160px;
  301. background: #fc7200;
  302. color: #fff;
  303. }
  304. .agreement {
  305. font-size: 12px;
  306. font-weight: 400;
  307. color: #fc7200;
  308. margin-top: 10px;
  309. span {
  310. color: #3662a1;
  311. cursor: pointer;
  312. }
  313. }
  314. .recharge_list /deep/ .el-input__inner {
  315. padding: 0 15px;
  316. height: 36px;
  317. border: none !important;
  318. text-align: center;
  319. }
  320. .recharge_list {
  321. width: 100%;
  322. display: flex;
  323. flex-wrap: wrap;
  324. margin-top: 24px;
  325. margin-bottom: 10px;
  326. .item {
  327. position: relative;
  328. width: 200px;
  329. height: 40px;
  330. border: 1px solid #e6e6e6;
  331. color: #333333;
  332. font-size: 16px;
  333. font-weight: 500;
  334. display: flex;
  335. align-items: center;
  336. justify-content: center;
  337. border-radius: 3px;
  338. margin: 0 15px 15px 0;
  339. cursor: pointer;
  340. .img {
  341. width: 24px;
  342. height: 24px;
  343. margin-right: 6px;
  344. }
  345. .choose {
  346. position: absolute;
  347. top: 0;
  348. right: 0;
  349. width: 16px;
  350. height: 16px;
  351. }
  352. }
  353. .item_ac {
  354. border-color: #fc7200;
  355. color: #fc7200;
  356. }
  357. }
  358. .recharge_list_m {
  359. .item {
  360. width: 90px;
  361. height: 36px;
  362. margin: 0 24px 15px 0;
  363. position: relative;
  364. .item_tips {
  365. height: 19px;
  366. position: absolute;
  367. right: -22px;
  368. top: -28px;
  369. padding: 5px;
  370. background-image: url("../../../static/image/recharge.png");
  371. background-position: center;
  372. background-repeat: no-repeat;
  373. background-size: contain;
  374. font-size: 12px;
  375. font-weight: 100;
  376. color: #ffffff;
  377. }
  378. }
  379. }
  380. .recharge_coupon {
  381. width: 100%;
  382. background: #fef2e9;
  383. border-radius: 8px;
  384. padding: 3px 10px;
  385. margin-bottom: 42px;
  386. .recharge_coupon_top {
  387. display: flex;
  388. flex-wrap: wrap;
  389. align-items: center;
  390. img {
  391. width: 28px;
  392. height: 30px;
  393. }
  394. .recharge_coupon_top_left {
  395. padding: 0 10px 0 8px;
  396. display: flex;
  397. align-items: center;
  398. font-size: 16px;
  399. font-family: PingFang SC;
  400. font-weight: bold;
  401. color: #fc7200;
  402. }
  403. .recharge_coupon_top_right {
  404. display: flex;
  405. flex-wrap: wrap;
  406. align-items: flex-end;
  407. font-size: 12px;
  408. font-weight: 400;
  409. color: #fc7200;
  410. padding-top: 2px;
  411. div {
  412. margin-right: 10px;
  413. }
  414. }
  415. }
  416. .recharge_coupon_bottom {
  417. margin: 15px 17px;
  418. display: flex;
  419. flex-wrap: wrap;
  420. .recharge_coupon_bottom_item {
  421. width: 410px;
  422. height: 72px;
  423. display: flex;
  424. justify-content: flex-start;
  425. margin-bottom: 10px;
  426. margin-right: 24px;
  427. .recharge_coupon_bottom_left {
  428. display: flex;
  429. flex-direction: column;
  430. justify-content: center;
  431. align-items: center;
  432. width: 110px;
  433. margin-top: 10px auto;
  434. text-align: center;
  435. border-radius: 8px;
  436. background-color: #fff;
  437. padding: 10px 0;
  438. .recharge_coupon_bottom_left_num {
  439. span {
  440. font-size: 14px;
  441. font-family: PingFang SC;
  442. font-weight: 400;
  443. line-height: 20px;
  444. margin-left: 2px;
  445. color: #ec1414;
  446. }
  447. .num {
  448. font-size: 26px;
  449. font-family: PingFang SC;
  450. font-weight: bold;
  451. color: #ec1414;
  452. }
  453. }
  454. .recharge_coupon_bottom_sub {
  455. font-size: 14px;
  456. font-family: PingFang SC;
  457. font-weight: 400;
  458. line-height: 20px;
  459. color: #666666;
  460. }
  461. }
  462. .recharge_coupon_bottom_middle {
  463. display: flex;
  464. align-items: center;
  465. div {
  466. height: 100%;
  467. padding: 10px 0;
  468. height: 55px;
  469. border-right: 1px dashed #ec1414;
  470. box-sizing: border-box;
  471. }
  472. }
  473. .recharge_coupon_bottom_right {
  474. border-radius: 8px;
  475. background-color: #fff;
  476. flex: 1;
  477. position: relative;
  478. padding: 10px;
  479. display: flex;
  480. justify-content: space-between;
  481. align-items: center;
  482. .recharge_coupon_bottom_date {
  483. font-size: 18px;
  484. font-family: PingFang SC;
  485. font-weight: bold;
  486. line-height: 25px;
  487. color: #333333;
  488. div:last-child {
  489. height: 20px;
  490. font-size: 14px;
  491. font-family: PingFang SC;
  492. font-weight: 400;
  493. line-height: 20px;
  494. color: #999999;
  495. }
  496. }
  497. .recharge_coupon_bottom_number {
  498. display: flex;
  499. align-items: center;
  500. span {
  501. width: 63px;
  502. height: 22px;
  503. line-height: 22px;
  504. border: 1px solid #ec1414;
  505. border-radius: 18px;
  506. text-align: center;
  507. font-size: 12px;
  508. font-family: PingFang SC;
  509. font-weight: 500;
  510. color: #ec1414;
  511. cursor: pointer;
  512. &:hover {
  513. background-color: #ec1414;
  514. color: #ffffff;
  515. }
  516. }
  517. }
  518. }
  519. }
  520. }
  521. }
  522. </style>