123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- <template>
- <div class="pay-layout">
- <div class="pay-header">
- <div class="h-left">
- <img src="@/assets/images/logo-black.png" alt>
- <span class="h-line"></span>
- <span>支付中心</span>
- </div>
- <div class="h-right">当前账号:{{info.userName}}</div>
- </div>
- <div class="pay-con">
- <div class="mid">
- <div class="attr">支付方式:</div>
- <div class="body">
- <div class="pay-tag" :class="{'tag-active':paytype==='alipay'}" @click="paytype='alipay'">
- <img src="@/assets/images/ali-pay.png" class="t-icon" alt>
- <span>支付宝</span>
- <img src="@/assets/images/tag-icon.png" class="t-click" alt>
- </div>
- <div class="pay-tag" :class="{'tag-active':paytype==='wechatPay'}" @click="paytype='wechatPay'">
- <img src="@/assets/images/wechat-pay.png" class="t-icon" alt>
- <span>微信支付</span>
- <img src="@/assets/images/tag-icon.png" class="t-click" alt>
- </div>
- <div class="pay-tag paypal-con" :class="{'tag-active':paytype==='paypal'}" @click="paytype='paypal'">
- <img src="@/assets/images/paypal.png" class="t-icon" alt>
- <span>paypal</span>
- <img src="@/assets/images/tag-icon.png" class="t-click" alt>
- <form id="formid" class="form-con" :action="`${$serverName}api/order/pay/paypal`" method="post">
- <input v-model="$route.params.orderId" type="text" name='orderId'>
- <input v-model="$route.params.orderType" type="text" name='orderType'>
- <input type="submit" value="提交">
- </form>
- </div>
- </div>
- </div>
- <div class="bottom" v-if="paytype !== 'paypal'">
- <div class="attr">应付金额:</div>
- <div class="price-detail">
- <div class="price">¥{{response.price}}</div>
- <img v-if="response.src" :src="`${$serverName}${response.src}`" alt="">
- <div class="dec">使用<span style="color:#ff0000">{{payZH}}</span>app扫码完成支付</div>
- </div>
- </div>
- </div>
- <div class="pay-bottom">
- ©2019 4dkankan移动开放平台
- </div>
- </div>
- </template>
- <script>
- import { mapState } from 'vuex'
- let payTypes = {
- wechatPay: '微信',
- alipay: '支付宝',
- paypal: 'paypal'
- }
- let PAYS = {
- 0: 'wechatPay',
- 1: 'alipay',
- 2: 'paypal'
- }
- let PAYSID = {
- wechatPay: 0,
- alipay: 1,
- paypal: 2
- }
- export default {
- data () {
- return {
- privilege: 'year',
- response: '',
- t1: null,
- paytype: PAYS[this.$route.params.payType]
- }
- },
- computed: {
- ...mapState({
- token: state => state.user.token,
- info: state => state.user.info
- }),
- payZH () {
- return payTypes[this.paytype]
- }
- },
- watch: {
- paytype (newVal, oldVal) {
- this.getCode()
- }
- },
- mounted () {
- this.getCode()
- },
- methods: {
- inverRequest () {
- clearInterval(this.t1)
- this.t1 = null
- this.t1 = setInterval(() => {
- this.queryOrderStatus()
- }, 5000)
- },
- async queryOrderStatus () {
- if (this.t1) {
- let {orderSn, orderType} = this.$route.params
- if (!orderSn) {
- return this.$toast.show('error', '获取订单信息失败')
- }
- let params = {
- orderSn,
- orderType: Number(orderType),
- payType: Number(PAYSID[this.paytype])
- }
- let res = await this.$http
- .post('/user/order/queryOrderStatus', params, {
- headers: {
- token: this.token
- }
- })
- let response = res.data
- if (response.code === 0 && response.data) {
- this.t1 = null
- this.t1 && clearInterval(this.t1)
- this.$router.replace({
- name: 'payresult',
- params: {
- isSuccess: 'success'
- }
- })
- }
- }
- },
- async getCode () {
- let {orderId, orderType} = this.$route.params
- if (!orderId || (!orderType && orderType !== 0)) {
- return this.$toast.show('error', '获取订单信息失败')
- }
- if (this.paytype !== 'paypal') {
- let params = {
- orderId: orderId,
- orderType: Number(orderType)
- }
- let res = await this.$http
- .post(`/order/pay/${this.paytype}`, params, {
- headers: {
- token: this.token
- }
- })
- let response = res.data
- if (response.code !== 0) {
- return this.$toast.show('error', '获取支付二维码失败', () => {
- this.t1 = null
- this.t1 && clearInterval(this.t1)
- })
- }
- this.response = response.data
- this.inverRequest()
- } else {
- document.getElementById('formid').submit()
- this.$toast.show('warn', '正在跳转至paypal支付链接,请稍等')
- }
- }
- },
- beforeDestroy () {
- clearInterval(this.t1)
- this.t1 = null
- }
- }
- </script>
- <style lang="scss" scoped>
- $theme-color: #1fe4dc;
- .pay-layout {
- width: 1030px;
- min-height: 74vh;
- margin: 25px auto;
- .pay-header {
- width: 100%;
- margin-bottom: 50px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- .h-left {
- display: flex;
- justify-content: space-between;
- align-items: center;
- .h-line {
- width: 1px;
- height: 20px;
- background: #000;
- margin: 0 10px;
- display: inline-block;
- }
- span {
- font-size: 20px;
- color: #2d2d2d;
- }
- }
- .h-right {
- font-size: 14px;
- color: #2d2d2d;
- }
- }
- .pay-con {
- background: #f4f4f4;
- padding: 40px;
- .top,
- .mid,
- .bottom {
- display: flex;
- margin-bottom: 50px;
- .attr {
- font-size: 14px;
- color: #2d2d2d;
- }
- .val {
- display: flex;
- align-items: center;
- margin-left: 20px;
- .tag {
- height: 100%;
- font-size: 0;
- margin-right: 50px;
- display: flex;
- align-items: center;
- border: 1px solid #f4f4f4;
- position: relative;
- .year {
- width: 52px;
- height: 48px;
- line-height: 48px;
- text-align: center;
- display: inline-block;
- background: #ededed;
- color: #777777;
- font-size: 14px;
- flex-shrink: 0;
- }
- .price {
- background: #fff;
- height: 48px;
- width: 160px;
- line-height: 48px;
- display: inline-block;
- font-size: 18px;
- color: #ff0000;
- text-align: center;
- .per {
- font-size: 12px;
- margin-left: 20px;
- color: #777777;
- }
- }
- img {
- position: absolute;
- bottom: 0;
- right: 0;
- width: 14px;
- }
- }
- .tag-active {
- border: 1px solid $theme-color;
- box-sizing: border-box;
- }
- }
- .body {
- margin-left: 20px;
- .pay-tag {
- cursor: pointer;
- border: 1px solid #e7e7e7;
- width: 200px;
- line-height: 36px;
- height: 36px;
- margin-bottom: 20px;
- position: relative;
- span {
- margin-left: 36px;
- display: inline-block;
- text-align: center;
- padding-left: 60px;
- }
- img {
- position: absolute;
- }
- .t-icon {
- width: 36px;
- height: 36px;
- padding: 6px;
- left: 0;
- border-right: 1px solid #e7e7e7;
- }
- .t-click {
- right: 0;
- bottom: 0;
- display: none;
- }
- }
- .paypal-con{
- position: relative;
- .form-con{
- opacity: 0;
- input[type='text']{
- width: 1px;
- height: 1px;
- position: absolute;
- top: 0;
- opacity: 0;
- left: 0;
- }
- input[type='submit']{
- width: 100%;
- position: absolute;
- top: 0;
- left: 0;
- opacity: 0;
- height: 100%;
- }
- }
- }
- .tag-active {
- border: 1px solid $theme-color;
- span {
- color: #000;
- }
- .t-icon {
- border-right: 1px solid $theme-color;
- }
- .t-click {
- display: inline-block;
- }
- }
- }
- .price-detail{
- margin-left: 6px;
- text-align: center;
- position: relative;
- width: 160px;
- top: -15px;
- .price{
- font-size: 30px;
- color: #ff0000;
- margin: 0 0 0 8px;
- text-align: left;
- padding: 0;
- margin-bottom: 40px;
- }
- .sao{
- font-size: 14px;
- color: #2d2d2d;
- margin-bottom: 5px;
- }
- .dec{
- color: #2d2d2d;
- font-size: 12px;
- margin-top: 10px;
- }
- img{
- width: 130px;
- height: 130px;
- }
- }
- }
- .bottom {
- margin-bottom: 0;
- }
- }
- .pay-bottom{
- color: #969696;
- font-size: 12px;
- text-align: center;
- margin-top: 20px;
- }
- }
- </style>
|