index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div class="paytype-layout">
  3. <div class="paytype">
  4. <div class="pay-item" v-for="(item,i) in data" :key="i" @click="goPay(item)">
  5. <span>{{language==='en'?item.En:item.name}}</span>
  6. <img :src="item.img" alt="">
  7. <form v-if="item.name === 'PayPal'" id="formid1" class="form-con" :action="`${$serverName}api/order/pay/paypalH5`" method="post">
  8. <input v-model="$route.params.orderId" type="text" name='orderId'>
  9. <input v-model="$route.params.orderType" type="text" name='orderType'>
  10. <input type="submit" value="提交">
  11. </form>
  12. </div>
  13. </div>
  14. <div class="btn-back" @click="$router.back()">{{language==='en'?'Back':'返回'}}</div>
  15. </div>
  16. </template>
  17. <script>
  18. import { mapState } from 'vuex'
  19. import browser from '@/util/browser'
  20. let PAYS = {
  21. 0: 'wechatMobilePay',
  22. 1: 'aliMobilePay',
  23. 2: 'paypal'
  24. }
  25. // let to = {
  26. // 0: {path: '/order'},
  27. // 1: {path: '/order'},
  28. // 2: {path: '/order'}
  29. // }
  30. export default {
  31. computed: {
  32. ...mapState({
  33. language: state => state.language.current,
  34. langToast: state => state.language.home.toast,
  35. token: state => state.user.token || ''
  36. })
  37. },
  38. data () {
  39. let country = this.$route.query.country || ''
  40. let data = Number(country) ? [{
  41. id: 2,
  42. name: 'PayPal',
  43. img: this.$cdn + `images/ic_paypal_mb@2x.png`
  44. }] : [{
  45. name: '支付宝',
  46. En: 'Alipay',
  47. img: this.$cdn + `images/ic_alipay_mb@2x.png`,
  48. id: 1
  49. }, {
  50. id: 0,
  51. name: '微信支付',
  52. En: 'Wechat',
  53. img: this.$cdn + `images/ic_weixin@2x.png`
  54. }]
  55. let weichtdata = [{
  56. id: 0,
  57. name: '微信支付',
  58. En: 'Wechat',
  59. img: this.$cdn + `images/ic_weixin@2x.png`
  60. }]
  61. return {
  62. data: browser.weixin ? weichtdata : data,
  63. isWeixin: browser.weixin
  64. }
  65. },
  66. mounted () {
  67. },
  68. methods: {
  69. async goPay (item) {
  70. let {orderId, orderType} = this.$route.params
  71. let {spaceId} = this.$route.query
  72. let params = {
  73. orderId: orderId,
  74. orderType: Number(orderType),
  75. spaceId: spaceId || null
  76. }
  77. if (PAYS[item.id] !== 'paypal') {
  78. if (this.isWeixin) {
  79. let href = spaceId ? `https://open.weixin.qq.com/connect/oauth2/authorize?redirect_uri=http%3a%2f%2ftest.4dkankan.com%2fapi%2forder%2fpay%2fwechatPreJsPay%3forderId=${orderId}%26spaceId=${spaceId || null}%26orderType=${Number(orderType)}&appid=wx779dbafb46bab697&response_type=code&scope=snsapi_base&state=1&connect_redirect=1#wechat_redirect`
  80. : `https://open.weixin.qq.com/connect/oauth2/authorize?redirect_uri=http%3a%2f%2ftest.4dkankan.com%2fapi%2forder%2fpay%2fwechatPreJsPay%3forderId=${orderId}%26orderType=${Number(orderType)}&appid=wx779dbafb46bab697&response_type=code&scope=snsapi_base&state=1&connect_redirect=1#wechat_redirect`
  81. return location.replace(href)
  82. }
  83. let response = await this.$http
  84. .post(`/order/pay/${PAYS[item.id]}`, params, {
  85. headers: {
  86. token: this.token
  87. }
  88. })
  89. if (response.data.code !== 0) {
  90. return this.$toast.show('warn', this.langToast['41'])
  91. }
  92. let url = item.id === 1 ? response.data.data.form : response.data.data.mweb_url
  93. location.replace(url)
  94. } else {
  95. this.$toast.show('warn', this.langToast['3'])
  96. }
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. @import './style.scss';
  103. </style>