index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div class="pay-layout">
  3. <div class="pay-header">
  4. <div class="h-left">
  5. <img src="@/assets/images/logo-black.png" alt>
  6. <span class="h-line"></span>
  7. <span>支付中心</span>
  8. </div>
  9. <div class="h-right">当前账号:{{info.userName}}</div>
  10. </div>
  11. <div class="pay-con">
  12. <div class="pay-left">
  13. <div class="mid">
  14. <div class="attr">支付方式:</div>
  15. <div class="body">
  16. <div class="pay-tag" :class="{'tag-active':paytype==='alipay'}" @click="paytype='alipay'">
  17. <img src="@/assets/images/ali-pay.png" class="t-icon" alt>
  18. <span>支付宝</span>
  19. <img src="@/assets/images/tag-icon.png" class="t-click" alt>
  20. </div>
  21. <div class="pay-tag" :class="{'tag-active':paytype==='wechatPay'}" @click="paytype='wechatPay'">
  22. <img src="@/assets/images/wechat-pay.png" class="t-icon" alt>
  23. <span>微信支付</span>
  24. <img src="@/assets/images/tag-icon.png" class="t-click" alt>
  25. </div>
  26. <div class="pay-tag paypal-con" :class="{'tag-active':paytype==='paypal'}" @click="paytype='paypal'">
  27. <img src="@/assets/images/paypal.png" class="t-icon" alt>
  28. <span>paypal</span>
  29. <img src="@/assets/images/tag-icon.png" class="t-click" alt>
  30. <form id="formid" class="form-con" :action="`${$serverName}api/order/pay/paypal`" method="post">
  31. <input v-model="$route.params.orderId" type="text" name='orderId'>
  32. <input v-model="$route.params.orderType" type="text" name='orderType'>
  33. <input type="submit" value="提交">
  34. </form>
  35. </div>
  36. </div>
  37. </div>
  38. <div class="bottom" v-if="paytype !== 'paypal'">
  39. <div class="attr">应付金额:</div>
  40. <div class="price-detail">
  41. <img class="scanicon" :src="`${$cdn}images/scanicon.png`" alt="">
  42. <div class="price">¥{{response.price}}</div>
  43. <img v-if="response.src" :src="`${$serverName}${response.src}`" alt="">
  44. <div class="dec">使用<span style="color:#ff0000">{{payZH}}</span>app扫码完成支付</div>
  45. </div>
  46. </div>
  47. </div>
  48. <div class="pay-right">
  49. <p class="p-title">功能卓越</p>
  50. <ul class="pay-icon">
  51. <li v-for="(item,i) in payicon" :key="i">
  52. <img :src="item.img" >
  53. <p>{{item.name}}</p>
  54. </li>
  55. </ul>
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import { mapState } from 'vuex'
  62. let payTypes = {
  63. wechatPay: '微信',
  64. alipay: '支付宝',
  65. paypal: 'paypal'
  66. }
  67. let PAYS = {
  68. 0: 'wechatPay',
  69. 1: 'alipay',
  70. 2: 'paypal'
  71. }
  72. let PAYSID = {
  73. wechatPay: 0,
  74. alipay: 1,
  75. paypal: 2
  76. }
  77. export default {
  78. data () {
  79. let payicon = [{
  80. img: require('@/assets/images/paylogo1.png'),
  81. name: '轻松操作高效建模'
  82. }, {
  83. img: require('@/assets/images/paylogo2.png'),
  84. name: '高精还原空间漫游'
  85. }, {
  86. img: require('@/assets/images/paylogo3.png'),
  87. name: '室内外皆可拍摄'
  88. }, {
  89. img: require('@/assets/images/paylogo4.png'),
  90. name: '自由编辑随时更新'
  91. }]
  92. return {
  93. payicon,
  94. privilege: 'year',
  95. response: '',
  96. t1: null,
  97. paytype: PAYS[this.$route.params.payType]
  98. }
  99. },
  100. computed: {
  101. ...mapState({
  102. token: state => state.user.token,
  103. info: state => state.user.info
  104. }),
  105. payZH () {
  106. return payTypes[this.paytype]
  107. }
  108. },
  109. watch: {
  110. paytype (newVal, oldVal) {
  111. this.getCode()
  112. }
  113. },
  114. mounted () {
  115. this.getCode()
  116. },
  117. methods: {
  118. inverRequest () {
  119. clearInterval(this.t1)
  120. this.t1 = null
  121. this.t1 = setInterval(() => {
  122. this.queryOrderStatus()
  123. }, 5000)
  124. },
  125. async queryOrderStatus () {
  126. if (this.t1) {
  127. let {orderSn, orderType} = this.$route.params
  128. if (!orderSn) {
  129. return this.$toast.show('error', '获取订单信息失败')
  130. }
  131. let params = {
  132. orderSn,
  133. orderType: Number(orderType),
  134. payType: Number(PAYSID[this.paytype])
  135. }
  136. let res = await this.$http
  137. .post('/user/order/queryOrderStatus', params, {
  138. headers: {
  139. token: this.token
  140. }
  141. })
  142. let response = res.data
  143. if (response.code === 0 && response.data) {
  144. this.t1 = null
  145. this.t1 && clearInterval(this.t1)
  146. this.$router.replace({
  147. name: 'payresult',
  148. params: {
  149. isSuccess: 'success'
  150. }
  151. })
  152. }
  153. }
  154. },
  155. async getCode () {
  156. let {orderId, orderType} = this.$route.params
  157. if (!orderId || (!orderType && orderType !== 0)) {
  158. return this.$toast.show('error', '获取订单信息失败')
  159. }
  160. if (this.paytype !== 'paypal') {
  161. let params = {
  162. orderId: orderId,
  163. orderType: Number(orderType)
  164. }
  165. let res = await this.$http
  166. .post(`/order/pay/${this.paytype}`, params, {
  167. headers: {
  168. token: this.token
  169. }
  170. })
  171. let response = res.data
  172. if (response.code !== 0) {
  173. return this.$toast.show('error', '获取支付二维码失败', () => {
  174. this.t1 = null
  175. this.t1 && clearInterval(this.t1)
  176. })
  177. }
  178. this.response = response.data
  179. this.inverRequest()
  180. } else {
  181. this.t1 = null
  182. this.t1 && clearInterval(this.t1)
  183. this.$toast.show('warn', '正在跳转至paypal支付链接,请稍等')
  184. }
  185. }
  186. },
  187. beforeDestroy () {
  188. clearInterval(this.t1)
  189. this.t1 = null
  190. }
  191. }
  192. </script>
  193. <style lang="scss" scoped>
  194. $theme-color: #1fe4dc;
  195. .pay-layout {
  196. width: 1030px;
  197. min-height: 74vh;
  198. margin: 25px auto;
  199. .pay-header {
  200. width: 100%;
  201. margin-bottom: 50px;
  202. display: flex;
  203. justify-content: space-between;
  204. align-items: center;
  205. .h-left {
  206. display: flex;
  207. justify-content: space-between;
  208. align-items: center;
  209. .h-line {
  210. width: 1px;
  211. height: 20px;
  212. background: #000;
  213. margin: 0 10px;
  214. display: inline-block;
  215. }
  216. span {
  217. font-size: 20px;
  218. color: #2d2d2d;
  219. }
  220. }
  221. .h-right {
  222. font-size: 14px;
  223. color: #2d2d2d;
  224. }
  225. }
  226. .pay-con {
  227. background: #f4f4f4;
  228. padding: 40px;
  229. display: flex;
  230. justify-content: space-between;
  231. margin-bottom: 80px;
  232. .pay-left {
  233. .top,
  234. .mid,
  235. .bottom {
  236. display: flex;
  237. margin-bottom: 50px;
  238. .attr {
  239. font-size: 14px;
  240. color: #2d2d2d;
  241. }
  242. .val {
  243. display: flex;
  244. align-items: center;
  245. margin-left: 20px;
  246. .tag {
  247. height: 100%;
  248. font-size: 0;
  249. margin-right: 50px;
  250. display: flex;
  251. align-items: center;
  252. border: 1px solid #f4f4f4;
  253. position: relative;
  254. .year {
  255. width: 52px;
  256. height: 48px;
  257. line-height: 48px;
  258. text-align: center;
  259. display: inline-block;
  260. background: #ededed;
  261. color: #777777;
  262. font-size: 14px;
  263. flex-shrink: 0;
  264. }
  265. .price {
  266. background: #fff;
  267. height: 48px;
  268. width: 160px;
  269. line-height: 48px;
  270. display: inline-block;
  271. font-size: 18px;
  272. color: #ff0000;
  273. text-align: center;
  274. .per {
  275. font-size: 12px;
  276. margin-left: 20px;
  277. color: #777777;
  278. }
  279. }
  280. img {
  281. position: absolute;
  282. bottom: 0;
  283. right: 0;
  284. width: 14px;
  285. }
  286. }
  287. .tag-active {
  288. border: 1px solid $theme-color;
  289. box-sizing: border-box;
  290. }
  291. }
  292. .body {
  293. margin-left: 20px;
  294. .pay-tag {
  295. cursor: pointer;
  296. border: 1px solid #e7e7e7;
  297. width: 200px;
  298. line-height: 36px;
  299. height: 36px;
  300. margin-bottom: 20px;
  301. position: relative;
  302. span {
  303. margin-left: 36px;
  304. display: inline-block;
  305. text-align: center;
  306. padding-left: 60px;
  307. }
  308. img {
  309. position: absolute;
  310. }
  311. .t-icon {
  312. width: 36px;
  313. height: 36px;
  314. padding: 6px;
  315. left: 0;
  316. border-right: 1px solid #e7e7e7;
  317. }
  318. .t-click {
  319. right: 0;
  320. bottom: 0;
  321. display: none;
  322. }
  323. }
  324. .paypal-con{
  325. position: relative;
  326. .form-con{
  327. opacity: 0;
  328. input[type='text']{
  329. width: 1px;
  330. height: 1px;
  331. position: absolute;
  332. top: 0;
  333. opacity: 0;
  334. left: 0;
  335. }
  336. input[type='submit']{
  337. width: 100%;
  338. position: absolute;
  339. top: 0;
  340. left: 0;
  341. opacity: 0;
  342. height: 100%;
  343. }
  344. }
  345. }
  346. .tag-active {
  347. border: 1px solid $theme-color;
  348. span {
  349. color: #000;
  350. }
  351. .t-icon {
  352. border-right: 1px solid $theme-color;
  353. }
  354. .t-click {
  355. display: inline-block;
  356. }
  357. }
  358. }
  359. .price-detail{
  360. margin-left: 6px;
  361. text-align: center;
  362. position: relative;
  363. width: 160px;
  364. top: -15px;
  365. .price{
  366. font-size: 30px;
  367. color: #ff0000;
  368. margin: 0 0 0 8px;
  369. text-align: left;
  370. padding: 0;
  371. margin-bottom: 24px;
  372. }
  373. .sao{
  374. font-size: 14px;
  375. color: #2d2d2d;
  376. margin-bottom: 5px;
  377. }
  378. .dec{
  379. color: #2d2d2d;
  380. font-size: 12px;
  381. margin-top: 10px;
  382. }
  383. img{
  384. width: 130px;
  385. box-shadow: 0 0 10px rgba(0,0,0,0.2);
  386. height: 130px;
  387. }
  388. .scanicon{
  389. position: absolute;
  390. left: 180px;
  391. width: 200px;
  392. top: 30px;
  393. height: auto;
  394. box-shadow:none;
  395. }
  396. }
  397. }
  398. .bottom {
  399. margin-bottom: 0;
  400. }
  401. .mid{
  402. margin-bottom: 20px;
  403. }
  404. }
  405. .pay-right {
  406. text-align: center;
  407. border-left: 1px solid #e5e5e5;
  408. padding-left: 28px;
  409. .p-title{
  410. font-size: 20px;
  411. color: #777777;
  412. }
  413. .pay-icon{
  414. margin-top: 20px;
  415. img{
  416. margin: 15px 0;
  417. }
  418. p{
  419. color: #969696;
  420. font-size: 14px;
  421. }
  422. }
  423. .pay-detail{
  424. height: 28px;
  425. margin: 90px 0 20px;
  426. cursor: pointer;
  427. line-height: 28px;
  428. font-size: 14px;
  429. color: #777777;
  430. width: 128px;
  431. border: 1px solid #e5e5e5;
  432. }
  433. }
  434. }
  435. .pay-bottom{
  436. color: #969696;
  437. font-size: 12px;
  438. text-align: center;
  439. margin-top: 20px;
  440. }
  441. }
  442. </style>