index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <div class="pay-wrap" v-loading="loading">
  3. <div class="item-block">
  4. <div class="payment-detail">
  5. <div class="payment-media">
  6. <el-row>
  7. <el-col :span="4">
  8. <div class="media-left"><i class="el-icon-circle-check ns-text-color"></i></div>
  9. </el-col>
  10. <el-col :span="16">
  11. <div class="media-body">
  12. <el-row>
  13. <el-col :span="12">
  14. <div class="payment-text">您的订单已提交成功,正在等待处理!</div>
  15. <div>
  16. <span>应付金额:</span>
  17. <span class="payment-money ns-text-color">¥{{ payInfo.pay_money }}元</span>
  18. </div>
  19. </el-col>
  20. <el-col :span="12"></el-col>
  21. </el-row>
  22. </div>
  23. </el-col>
  24. <el-col :span="4">
  25. <div class="media-right">
  26. <div class="el-button--text" @click="orderOpen ? (orderOpen = false) : (orderOpen = true)">
  27. 订单信息
  28. <i :class="orderOpen ? 'rotate' : ''" class="el-icon-arrow-down"></i>
  29. </div>
  30. </div>
  31. </el-col>
  32. </el-row>
  33. </div>
  34. <div class="order-info" v-if="orderOpen">
  35. <el-row>
  36. <el-col :span="4" class="order-info-left"></el-col>
  37. <el-col :span="20">
  38. <div class="line"></div>
  39. <div class="order-item">
  40. <div class="item-label">交易单号:</div>
  41. <div class="item-value">{{ payInfo.out_trade_no }}</div>
  42. </div>
  43. <div class="order-item">
  44. <div class="item-label">订单内容:</div>
  45. <div class="item-value">{{ payInfo.pay_detail }}</div>
  46. </div>
  47. <div class="order-item">
  48. <div class="item-label">订单金额:</div>
  49. <div class="item-value">¥{{ payInfo.pay_money }}</div>
  50. </div>
  51. <div class="order-item">
  52. <div class="item-label">创建时间:</div>
  53. <div class="item-value">{{ $timeStampTurnTime(payInfo.create_time) }}</div>
  54. </div>
  55. </el-col>
  56. </el-row>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="item-block">
  61. <div class="block-text">支付方式</div>
  62. <div class="pay-type-list" v-if="payTypeList.length">
  63. <div class="pay-type-item" v-for="(item, index) in payTypeList" :key="index"
  64. :class="payIndex == index ? 'active' : ''" @click="payIndex = index">
  65. {{ item.name }}
  66. </div>
  67. <div class="clear"></div>
  68. </div>
  69. <div class="no-pay-type" v-else>
  70. <p>商家未配置支付方式</p>
  71. </div>
  72. </div>
  73. <div class="item-block" v-if="payTypeList.length">
  74. <div class="order-submit"><el-button type="primary" class="el-button--primary" @click="pay">立即支付</el-button></div>
  75. <div class="clear"></div>
  76. </div>
  77. <el-dialog title="请确认支付是否完成" :visible.sync="dialogVisible" width="23%" top="30vh" class="confirm-pay-wrap">
  78. <div class="info-wrap">
  79. <i class="el-message-box__status el-icon-warning"></i>
  80. <span>完成支付前请根据您的情况点击下面的按钮</span>
  81. </div>
  82. <span slot="footer" class="dialog-footer">
  83. <el-button @click="goIndex" size="small">返回首页</el-button>
  84. <el-button type="primary" @click="goOrderList" size="small">已完成支付</el-button>
  85. </span>
  86. </el-dialog>
  87. <!-- 微信支付弹框 -->
  88. <el-dialog title="请用微信扫码支付" :visible.sync="openQrcode" width="300px" center>
  89. <div class="wechatpay-box"><img :src="payQrcode" /></div>
  90. </el-dialog>
  91. </div>
  92. </template>
  93. <script>
  94. import {
  95. getPayInfo,
  96. getPayType,
  97. checkPayStatus,
  98. pay
  99. } from '@/api/pay';
  100. import Config from '@/plugins/config';
  101. export default {
  102. name: 'pay',
  103. components: {},
  104. data: () => {
  105. return {
  106. orderOpen: false,
  107. outTradeNo: '',
  108. payInfo: {
  109. pay_money: 0
  110. },
  111. payIndex: 0,
  112. payTypeList: [{
  113. name: '支付宝支付',
  114. icon: 'iconzhifubaozhifu-',
  115. type: 'alipay'
  116. },
  117. {
  118. name: '微信支付',
  119. icon: 'iconweixinzhifu',
  120. type: 'wechatpay'
  121. }
  122. ],
  123. payUrl: '',
  124. timer: null,
  125. payQrcode: '',
  126. openQrcode: false,
  127. loading: true,
  128. test: null,
  129. dialogVisible: false
  130. };
  131. },
  132. created() {
  133. if (!this.$route.query.code) {
  134. this.$router.push({
  135. path: '/'
  136. });
  137. return;
  138. }
  139. this.outTradeNo = this.$route.query.code;
  140. this.getPayInfo();
  141. this.getPayType();
  142. },
  143. methods: {
  144. getPayInfo() {
  145. getPayInfo({
  146. out_trade_no: this.outTradeNo,
  147. forceLogin: true
  148. })
  149. .then(res => {
  150. const {
  151. code,
  152. message,
  153. data
  154. } = res;
  155. if (data) {
  156. this.payInfo = res.data;
  157. }
  158. this.loading = false;
  159. })
  160. .catch(err => {
  161. this.loading = false;
  162. this.$message.error({
  163. message: err.message,
  164. duration: 2000,
  165. onClose: () => {
  166. this.$router.push({
  167. path: '/member/order_list'
  168. });
  169. }
  170. });
  171. });
  172. },
  173. getPayType() {
  174. getPayType({})
  175. .then(res => {
  176. const {
  177. code,
  178. message,
  179. data
  180. } = res;
  181. if (code >= 0) {
  182. if (res.data.pay_type == '') {
  183. this.payTypeList = [];
  184. } else {
  185. this.payTypeList.forEach((val, key) => {
  186. if (res.data.pay_type.indexOf(val.type) == -1) {
  187. this.payTypeList.splice(key, 1);
  188. }
  189. });
  190. }
  191. }
  192. })
  193. .catch(err => {
  194. this.$message.error(err.message);
  195. });
  196. },
  197. checkPayStatus() {
  198. this.timer = setInterval(() => {
  199. checkPayStatus({
  200. out_trade_no: this.outTradeNo
  201. })
  202. .then(res => {
  203. const {
  204. code,
  205. message,
  206. data
  207. } = res;
  208. if (code >= 0) {
  209. if (code == 0) {
  210. if (data.pay_status == 2) {
  211. clearInterval(this.timer);
  212. this.dialogVisible = false;
  213. this.$router.push({
  214. path: '/pay/result?code=' + this.payInfo.out_trade_no
  215. });
  216. }
  217. } else {
  218. clearInterval(this.timer);
  219. }
  220. }
  221. })
  222. .catch(err => {
  223. clearInterval(this.timer);
  224. this.$router.push({
  225. path: '/'
  226. });
  227. });
  228. }, 2000);
  229. },
  230. pay() {
  231. var payType = this.payTypeList[this.payIndex];
  232. if (!payType) return;
  233. let return_url = encodeURIComponent(Config.webDomain + '/pay/result?code=' + this.outTradeNo);
  234. pay({
  235. out_trade_no: this.payInfo.out_trade_no,
  236. pay_type: payType.type,
  237. app_type: 'pc',
  238. return_url
  239. })
  240. .then(res => {
  241. const {
  242. code,
  243. message,
  244. data
  245. } = res;
  246. if (code >= 0) {
  247. this.checkPayStatus();
  248. switch (payType.type) {
  249. case 'alipay':
  250. this.payUrl = res.data.data;
  251. window.open(this.payUrl)
  252. this.open();
  253. break;
  254. case 'wechatpay':
  255. this.payQrcode = res.data.qrcode;
  256. this.openQrcode = true;
  257. break;
  258. }
  259. } else {
  260. this.$message({
  261. message: message,
  262. type: 'warning'
  263. });
  264. }
  265. })
  266. .catch(err => {
  267. this.$message.error(err.message);
  268. });
  269. },
  270. open() {
  271. this.dialogVisible = true;
  272. },
  273. goIndex() {
  274. clearInterval(this.timer);
  275. this.dialogVisible = false;
  276. this.$router.push({
  277. path: '/'
  278. });
  279. },
  280. goOrderList() {
  281. clearInterval(this.timer);
  282. this.dialogVisible = false;
  283. this.$router.push({
  284. path: '/member/order_list'
  285. });
  286. }
  287. }
  288. };
  289. </script>
  290. <style lang="scss" scoped>
  291. .pay-wrap {
  292. width: 1210px;
  293. margin: 20px auto;
  294. }
  295. .clear {
  296. clear: both;
  297. }
  298. .item-block {
  299. padding: 0 15px 1px;
  300. margin: 10px 0;
  301. border-radius: 0;
  302. border: none;
  303. background: #ffffff;
  304. .block-text {
  305. border-color: #eeeeee;
  306. color: $ns-text-color-black;
  307. padding: 7px 0;
  308. border-bottom: 1px;
  309. }
  310. }
  311. .media-left {
  312. text-align: center;
  313. i {
  314. font-size: 65px;
  315. }
  316. }
  317. .payment-detail {
  318. padding: 30px 0;
  319. transition: 2s;
  320. }
  321. .media-right {
  322. text-align: center;
  323. line-height: 65px;
  324. cursor: pointer;
  325. i.rotate {
  326. transform: rotate(180deg);
  327. transition: 0.3s;
  328. }
  329. }
  330. .payment-text {
  331. font-size: 20px;
  332. }
  333. .payment-time {
  334. font-size: 12px;
  335. line-height: 65px;
  336. color: #999;
  337. }
  338. //支付方式
  339. .order-submit {
  340. float: right;
  341. padding: 10px;
  342. }
  343. .pay-type-list {
  344. padding: 20px 0;
  345. }
  346. .no-pay-type {
  347. padding: 30px 0;
  348. text-align: center;
  349. }
  350. .pay-type-item {
  351. display: inline-block;
  352. border: 2px solid #eeeeee;
  353. padding: 5px 20px;
  354. margin-right: 20px;
  355. cursor: pointer;
  356. }
  357. .pay-type-item.active {
  358. border-color: $base-color;
  359. }
  360. .mobile-wrap {
  361. width: 300px;
  362. }
  363. .order-info {
  364. .order-item {
  365. padding: 1px 0;
  366. .item-label {
  367. display: inline-block;
  368. width: 100px;
  369. }
  370. .item-value {
  371. display: inline-block;
  372. }
  373. }
  374. .line {
  375. width: 100%;
  376. height: 1px;
  377. background: #f2f2f2;
  378. margin: 20px 0 10px 0;
  379. }
  380. .order-info-left {
  381. height: 1px;
  382. }
  383. }
  384. .wechatpay-box {
  385. text-align: center;
  386. img {
  387. width: 80%;
  388. }
  389. }
  390. .confirm-pay-wrap {
  391. .el-dialog__body {
  392. padding: 10px 15px;
  393. }
  394. .info-wrap {
  395. i {
  396. position: initial;
  397. vertical-align: middle;
  398. transform: initial;
  399. }
  400. span {
  401. vertical-align: middle;
  402. padding: 0 10px;
  403. }
  404. }
  405. }
  406. </style>
  407. <style lang="scss">
  408. .confirm-pay-wrap {
  409. .el-dialog__body {
  410. padding: 10px 15px;
  411. }
  412. .el-dialog__footer {
  413. padding-top: 0;
  414. padding-bottom: 10px;
  415. }
  416. }
  417. </style>