wallet.vue 14 KB

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