123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- <template>
- <div class="payment">
- <Header></Header>
- <section class="section">
- <div class="container">
- <div class="section__header">
- <div class="icon">
- <i class="img el-icon-bank-card"></i>
- </div>
- <div class="title">支付中心</div>
- </div>
- <div class="section__body">
- <div class="order-msg">
- <div class="order-msg__header" v-if="orderSn">
- <!-- <div class="icon">✔</div> -->
- <!-- <div class="title">订单提交成功!订单编号:20220305100636</div> -->
- <div class="title">订单编号:{{ orderSn }}</div>
- <!-- <div class="desc">订单详情▼</div> -->
- </div>
- <div class="order-msg__body">
- <div
- class="goods_item"
- v-for="(goodsItem, goodsIndex) in checkGoodsList"
- :key="goodsIndex"
- >
- 商品名称:{{ goodsItem.goodsName }}
- <span>应付金额:{{ goodsItem.standPrice | toFixed }}元</span>
- </div>
- </div>
- </div>
- <div class="payment-way">
- <ul>
- <li :class="{ active: radio == 1 }">
- <el-radio v-model="radio" label="1">
- <img src="@/assets/wep.png" alt="" />
- </el-radio>
- </li>
- <!-- <li :class="{ active: radio == 2 }">
- <el-radio v-model="radio" label="2">
- <img src="@/assets/unp.png" alt="" />
- </el-radio>
- </li> -->
- </ul>
- </div>
- <div class="payment-btn">
- 应付金额:
- <div class="price">{{ total | toFixed }}</div>
- <el-button type="danger" class="btn" id="pay" @click="pay"
- >立即支付</el-button
- >
- </div>
- </div>
- </div>
- </section>
- <el-dialog
- title="请使用微信扫码支付"
- :visible.sync="qrCodeShow"
- width="348px"
- center
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- :before-close="closePay"
- class="qrcode"
- >
- <div class="qrcode__body">
- <div class="img" @click="refreshCode">
- <img
- :src="lastTime <= 0 ? require('@/assets/qrcode.png') : urlBase64"
- alt=""
- />
- </div>
- <p v-if="lastTime > 0">
- 距离二维码过期还剩<span>{{ lastTime }}</span
- >秒
- </p>
- <p v-else>二维码已过期,点击图片重新获取二维码</p>
- <p>过期后请刷新重新获取二维码</p>
- <p>客服电话:020-12345678</p>
- </div>
- </el-dialog>
- <ToolBar></ToolBar>
- <Footer></Footer>
- </div>
- </template>
- <script>
- import Footer from "@/components/footer/index";
- import Header from "@/components/header/index";
- import ToolBar from "@/components/toolbar/index";
- import { mapGetters, mapMutations } from "vuex";
- export default {
- name: "Payment",
- components: {
- Footer,
- Header,
- ToolBar,
- },
- data() {
- return {
- lastTime: 60,
- radio: "1",
- qrCodeShow: false,
- total: 0,
- urlBase64: "",
- orderSn: "",
- checkOrderTimer: null,
- loading: null,
- countTimer: null,
- isBK: "",
- };
- },
- computed: {
- ...mapGetters(["checkGoodsList"]),
- },
- beforeDestroy() {
- clearInterval(this.countTimer);
- clearInterval(this.checkOrderTimer);
- },
- mounted() {
- console.log(this.checkGoodsList);
- this.isBK = this.$route.query.isBK;
- if (this.checkGoodsList.length <= 0 && !this.$route.params.orderSn) {
- this.$router.back(-1);
- return;
- } else {
- if (this.$route.params.orderSn) {
- this.orderSn = this.$route.params.orderSn;
- this.total = this.$route.params.total;
- } else if (this.checkGoodsList.length > 0) {
- this.caculate();
- }
- }
- },
- methods: {
- ...mapMutations(["setCheckGoodsList"]),
- refreshCode() {
- if (this.lastTime > 0) {
- return;
- }
- this.$request
- .orderResumePCOrder({ orderSn: this.orderSn })
- .then((res) => {
- this.loading.close();
- this.urlBase64 = res.data.urlBase64;
- this.orderSn = res.data.orderSn;
- this.checkOrderTimer = setInterval(() => {
- this.orderPayStatus();
- }, 2000);
- this.lastTime = 60;
- this.countTimer = setInterval(() => {
- if (this.lastTime <= 0) {
- clearInterval(this.countTimer);
- clearInterval(this.checkOrderTimer);
- return;
- }
- this.lastTime--;
- }, 1000);
- })
- .catch((err) => {
- // this.loading.close();
- });
- },
- closePay() {
- console.log(999);
- this.$confirm("确定离开支付页面吗", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- })
- .then((_) => {
- this.qrCodeShow = false;
- this.$router.back(-1);
- })
- .catch((_) => {});
- },
- caculate() {
- this.total = 0;
- this.checkGoodsList.forEach((item) => {
- this.total += item.standPrice;
- console.log(this.total);
- });
- },
- pay() {
- if (this.radio == 1) {
- //微信
- this.loading = this.$loading({
- lock: true,
- text: "支付中",
- spinner: "el-icon-loading",
- background: "rgba(0, 0, 0, 0)",
- target: document.querySelector(".section__body"),
- });
- if (this.orderSn) {
- //订单继续支付
- this.orderResumePCOrder();
- } else {
- //购物车进入支付
- this.orderPlacePcOrder();
- }
- } else {
- //银联
- }
- },
- orderPlacePcOrder() {
- this.$request
- .orderPlacePcOrder({ goodsList: this.checkGoodsList })
- .then((res) => {
- this.loading.close();
- console.log(res);
- this.urlBase64 = res.data.urlBase64;
- this.orderSn = res.data.orderSn;
- this.qrCodeShow = true;
- this.checkOrderTimer = setInterval(() => {
- this.orderPayStatus();
- }, 2000);
- this.lastTime = 60;
- this.countTimer = setInterval(() => {
- if (this.lastTime <= 0) {
- clearInterval(this.countTimer);
- clearInterval(this.checkOrderTimer);
- return;
- }
- this.lastTime--;
- }, 1000);
- })
- .catch((err) => {
- this.loading.close();
- setTimeout(() => {
- if (err.code == 510) {
- this.$confirm(err.msg + "。点击确定跳转待支付订单列表", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- })
- .then((_) => {
- this.$router.push({
- path: "/person-center/my-order",
- });
- })
- .catch((_) => {});
- // this.qrCodeShow = true;
- } else {
- this.$message({
- type: "warning",
- message: err.msg,
- });
- }
- }, 500);
- });
- },
- orderResumePCOrder() {
- this.$request
- .orderResumePCOrder({ orderSn: this.orderSn })
- .then((res) => {
- this.loading.close();
- this.urlBase64 = res.data.urlBase64;
- this.orderSn = res.data.orderSn;
- this.qrCodeShow = true;
- this.checkOrderTimer = setInterval(() => {
- this.orderPayStatus();
- }, 2000);
- this.lastTime = 60;
- this.countTimer = setInterval(() => {
- if (this.lastTime <= 0) {
- clearInterval(this.countTimer);
- clearInterval(this.checkOrderTimer);
- return;
- }
- this.lastTime--;
- }, 1000);
- })
- .catch((err) => {
- // this.loading.close();
- });
- },
- orderPayStatus() {
- this.$request
- .orderPayStatus(this.orderSn)
- .then((res) => {
- if (res.data) {
- this.setCheckGoodsList([]);
- clearInterval(this.checkOrderTimer);
- if (this.isBK) {
- this.$router.replace({
- path: "/payment-success",
- name: "支付成功",
- params: {
- orderSn: this.orderSn,
- total: this.total,
- isBK: this.isBK,
- goodsId: this.checkGoodsList[0].learnGoodsId,
- gradeId: this.checkGoodsList[0].learnGradeId,
- orderGoodsId: this.checkGoodsList[0].learnOrderGoodsId,
- },
- });
- } else {
- this.$router.replace({
- path: "/payment-success",
- name: "支付成功",
- params: {
- orderSn: this.orderSn,
- total: this.total,
- },
- });
- }
- }
- })
- .catch((err) => {});
- },
- },
- };
- </script>
- <!-- Add "scoped" attribute to limit CSS to this component only -->
- <style scoped lang="scss">
- .payment {
- .section {
- &__header {
- height: 80px;
- background: #ebf3ff;
- display: flex;
- align-items: center;
- padding: 0 20px;
- .icon {
- width: 40px;
- height: 40px;
- background: #3f8dfd;
- box-shadow: 0px 0px 9px 1px rgba(63, 141, 253, 0.3);
- border-radius: 50%;
- text-align: center;
- line-height: 40px;
- .img {
- vertical-align: middle;
- display: inline-block;
- color: #fff;
- font-size: 24px;
- }
- }
- .title {
- margin-left: 20px;
- flex: 1;
- font-size: 30px;
- font-family: Microsoft YaHei;
- font-weight: 400;
- color: #333333;
- }
- }
- &__body {
- .order-msg {
- border-bottom: 2px solid #eee;
- &__header {
- display: flex;
- align-items: center;
- padding: 0 20px;
- height: 40px;
- .icon {
- color: #fff;
- width: 24px;
- height: 24px;
- line-height: 24px;
- border-radius: 50%;
- text-align: center;
- background: rgba(52, 199, 89, 1);
- }
- .title {
- flex: 1;
- margin-left: 10px;
- }
- }
- &__body {
- padding-left: 50px;
- .goods_item {
- margin: 16px 0;
- span {
- margin-left: 20px;
- }
- }
- }
- }
- .payment-way {
- border-bottom: 2px solid #eee;
- ul {
- li {
- margin: 24px 0;
- width: 100%;
- background: #fafbfc;
- box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
- border-radius: 16px;
- height: 80px;
- border-radius: 16px;
- display: flex;
- align-items: center;
- padding: 0 20px;
- &.active {
- background: #f2f7fc;
- border: 1px solid #3f8dfd;
- box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
- }
- /deep/ .el-radio__label {
- vertical-align: middle;
- }
- }
- }
- }
- .payment-btn {
- margin: 24px 0;
- display: flex;
- align-items: center;
- .price {
- font-size: 24px;
- font-family: Microsoft YaHei;
- font-weight: 400;
- color: #ff3b30;
- }
- .btn {
- cursor: pointer;
- margin-left: 40px;
- width: 120px;
- height: 40px;
- padding: 0;
- background-color: #ff3b30;
- border-radius: 20px;
- text-align: center;
- line-height: 40px;
- color: #fff;
- font-size: 16px;
- &:hover {
- background-color: #f78989;
- }
- }
- }
- }
- }
- .qrcode {
- &__body {
- .img {
- cursor: pointer;
- margin: 0 auto;
- width: 180px;
- height: 180px;
- img {
- width: 100%;
- height: 100%;
- }
- }
- p {
- margin: 5px 0;
- text-align: center;
- font-size: 14px;
- font-family: Microsoft YaHei;
- font-weight: 400;
- color: #333333;
- line-height: 24px;
- span {
- color: #ff3b30;
- }
- }
- }
- }
- }
- </style>
|