index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <div class="payment">
  3. <Header></Header>
  4. <section class="section">
  5. <div class="container">
  6. <div class="section__header">
  7. <div class="icon">
  8. <i class="img el-icon-bank-card"></i>
  9. </div>
  10. <div class="title">支付中心</div>
  11. </div>
  12. <div class="section__body">
  13. <div class="order-msg">
  14. <div class="order-msg__header" v-if="orderSn">
  15. <!-- <div class="icon">✔</div> -->
  16. <!-- <div class="title">订单提交成功!订单编号:20220305100636</div> -->
  17. <div class="title">订单编号:{{ orderSn }}</div>
  18. <!-- <div class="desc">订单详情▼</div> -->
  19. </div>
  20. <div class="order-msg__body">
  21. <div
  22. class="goods_item"
  23. v-for="(goodsItem, goodsIndex) in checkGoodsList"
  24. :key="goodsIndex"
  25. >
  26. 商品名称:{{ goodsItem.goodsName }}
  27. <span>应付金额:{{ goodsItem.standPrice | toFixed }}元</span>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="payment-way">
  32. <ul>
  33. <li :class="{ active: radio == 1 }">
  34. <el-radio v-model="radio" label="1">
  35. <img src="@/assets/wep.png" alt="" />
  36. </el-radio>
  37. </li>
  38. <!-- <li :class="{ active: radio == 2 }">
  39. <el-radio v-model="radio" label="2">
  40. <img src="@/assets/unp.png" alt="" />
  41. </el-radio>
  42. </li> -->
  43. </ul>
  44. </div>
  45. <div class="payment-btn">
  46. 应付金额:
  47. <div class="price">{{ total | toFixed }}</div>
  48. <el-button type="danger" class="btn" id="pay" @click="pay"
  49. >立即支付</el-button
  50. >
  51. </div>
  52. </div>
  53. </div>
  54. </section>
  55. <el-dialog
  56. title="请使用微信扫码支付"
  57. :visible.sync="qrCodeShow"
  58. width="348px"
  59. center
  60. :close-on-click-modal="false"
  61. :close-on-press-escape="false"
  62. :before-close="closePay"
  63. class="qrcode"
  64. >
  65. <div class="qrcode__body">
  66. <div class="img" @click="refreshCode">
  67. <img
  68. :src="lastTime <= 0 ? require('@/assets/qrcode.png') : urlBase64"
  69. alt=""
  70. />
  71. </div>
  72. <p v-if="lastTime > 0">
  73. 距离二维码过期还剩<span>{{ lastTime }}</span
  74. >秒
  75. </p>
  76. <p v-else>二维码已过期,点击图片重新获取二维码</p>
  77. <p>过期后请刷新重新获取二维码</p>
  78. <p>客服电话:020-12345678</p>
  79. </div>
  80. </el-dialog>
  81. <ToolBar></ToolBar>
  82. <Footer></Footer>
  83. </div>
  84. </template>
  85. <script>
  86. import Footer from "@/components/footer/index";
  87. import Header from "@/components/header/index";
  88. import ToolBar from "@/components/toolbar/index";
  89. import { mapGetters, mapMutations } from "vuex";
  90. export default {
  91. name: "Payment",
  92. components: {
  93. Footer,
  94. Header,
  95. ToolBar,
  96. },
  97. data() {
  98. return {
  99. lastTime: 60,
  100. radio: "1",
  101. qrCodeShow: false,
  102. total: 0,
  103. urlBase64: "",
  104. orderSn: "",
  105. checkOrderTimer: null,
  106. loading: null,
  107. countTimer: null,
  108. isBK: "",
  109. };
  110. },
  111. computed: {
  112. ...mapGetters(["checkGoodsList"]),
  113. },
  114. beforeDestroy() {
  115. clearInterval(this.countTimer);
  116. clearInterval(this.checkOrderTimer);
  117. },
  118. mounted() {
  119. console.log(this.checkGoodsList);
  120. this.isBK = this.$route.query.isBK;
  121. if (this.checkGoodsList.length <= 0 && !this.$route.params.orderSn) {
  122. this.$router.back(-1);
  123. return;
  124. } else {
  125. if (this.$route.params.orderSn) {
  126. this.orderSn = this.$route.params.orderSn;
  127. this.total = this.$route.params.total;
  128. } else if (this.checkGoodsList.length > 0) {
  129. this.caculate();
  130. }
  131. }
  132. },
  133. methods: {
  134. ...mapMutations(["setCheckGoodsList"]),
  135. refreshCode() {
  136. if (this.lastTime > 0) {
  137. return;
  138. }
  139. this.$request
  140. .orderResumePCOrder({ orderSn: this.orderSn })
  141. .then((res) => {
  142. this.loading.close();
  143. this.urlBase64 = res.data.urlBase64;
  144. this.orderSn = res.data.orderSn;
  145. this.checkOrderTimer = setInterval(() => {
  146. this.orderPayStatus();
  147. }, 2000);
  148. this.lastTime = 60;
  149. this.countTimer = setInterval(() => {
  150. if (this.lastTime <= 0) {
  151. clearInterval(this.countTimer);
  152. clearInterval(this.checkOrderTimer);
  153. return;
  154. }
  155. this.lastTime--;
  156. }, 1000);
  157. })
  158. .catch((err) => {
  159. // this.loading.close();
  160. });
  161. },
  162. closePay() {
  163. console.log(999);
  164. this.$confirm("确定离开支付页面吗", "提示", {
  165. confirmButtonText: "确定",
  166. cancelButtonText: "取消",
  167. })
  168. .then((_) => {
  169. this.qrCodeShow = false;
  170. this.$router.back(-1);
  171. })
  172. .catch((_) => {});
  173. },
  174. caculate() {
  175. this.total = 0;
  176. this.checkGoodsList.forEach((item) => {
  177. this.total += item.standPrice;
  178. console.log(this.total);
  179. });
  180. },
  181. pay() {
  182. if (this.radio == 1) {
  183. //微信
  184. this.loading = this.$loading({
  185. lock: true,
  186. text: "支付中",
  187. spinner: "el-icon-loading",
  188. background: "rgba(0, 0, 0, 0)",
  189. target: document.querySelector(".section__body"),
  190. });
  191. if (this.orderSn) {
  192. //订单继续支付
  193. this.orderResumePCOrder();
  194. } else {
  195. //购物车进入支付
  196. this.orderPlacePcOrder();
  197. }
  198. } else {
  199. //银联
  200. }
  201. },
  202. orderPlacePcOrder() {
  203. this.$request
  204. .orderPlacePcOrder({ goodsList: this.checkGoodsList })
  205. .then((res) => {
  206. this.loading.close();
  207. console.log(res);
  208. this.urlBase64 = res.data.urlBase64;
  209. this.orderSn = res.data.orderSn;
  210. this.qrCodeShow = true;
  211. this.checkOrderTimer = setInterval(() => {
  212. this.orderPayStatus();
  213. }, 2000);
  214. this.lastTime = 60;
  215. this.countTimer = setInterval(() => {
  216. if (this.lastTime <= 0) {
  217. clearInterval(this.countTimer);
  218. clearInterval(this.checkOrderTimer);
  219. return;
  220. }
  221. this.lastTime--;
  222. }, 1000);
  223. })
  224. .catch((err) => {
  225. this.loading.close();
  226. setTimeout(() => {
  227. if (err.code == 510) {
  228. this.$confirm(err.msg + "。点击确定跳转待支付订单列表", "提示", {
  229. confirmButtonText: "确定",
  230. cancelButtonText: "取消",
  231. })
  232. .then((_) => {
  233. this.$router.push({
  234. path: "/person-center/my-order",
  235. });
  236. })
  237. .catch((_) => {});
  238. // this.qrCodeShow = true;
  239. } else {
  240. this.$message({
  241. type: "warning",
  242. message: err.msg,
  243. });
  244. }
  245. }, 500);
  246. });
  247. },
  248. orderResumePCOrder() {
  249. this.$request
  250. .orderResumePCOrder({ orderSn: this.orderSn })
  251. .then((res) => {
  252. this.loading.close();
  253. this.urlBase64 = res.data.urlBase64;
  254. this.orderSn = res.data.orderSn;
  255. this.qrCodeShow = true;
  256. this.checkOrderTimer = setInterval(() => {
  257. this.orderPayStatus();
  258. }, 2000);
  259. this.lastTime = 60;
  260. this.countTimer = setInterval(() => {
  261. if (this.lastTime <= 0) {
  262. clearInterval(this.countTimer);
  263. clearInterval(this.checkOrderTimer);
  264. return;
  265. }
  266. this.lastTime--;
  267. }, 1000);
  268. })
  269. .catch((err) => {
  270. // this.loading.close();
  271. });
  272. },
  273. orderPayStatus() {
  274. this.$request
  275. .orderPayStatus(this.orderSn)
  276. .then((res) => {
  277. if (res.data) {
  278. this.setCheckGoodsList([]);
  279. clearInterval(this.checkOrderTimer);
  280. if (this.isBK) {
  281. this.$router.replace({
  282. path: "/payment-success",
  283. name: "支付成功",
  284. params: {
  285. orderSn: this.orderSn,
  286. total: this.total,
  287. isBK: this.isBK,
  288. goodsId: this.checkGoodsList[0].learnGoodsId,
  289. gradeId: this.checkGoodsList[0].learnGradeId,
  290. orderGoodsId: this.checkGoodsList[0].learnOrderGoodsId,
  291. },
  292. });
  293. } else {
  294. this.$router.replace({
  295. path: "/payment-success",
  296. name: "支付成功",
  297. params: {
  298. orderSn: this.orderSn,
  299. total: this.total,
  300. },
  301. });
  302. }
  303. }
  304. })
  305. .catch((err) => {});
  306. },
  307. },
  308. };
  309. </script>
  310. <!-- Add "scoped" attribute to limit CSS to this component only -->
  311. <style scoped lang="scss">
  312. .payment {
  313. .section {
  314. &__header {
  315. height: 80px;
  316. background: #ebf3ff;
  317. display: flex;
  318. align-items: center;
  319. padding: 0 20px;
  320. .icon {
  321. width: 40px;
  322. height: 40px;
  323. background: #3f8dfd;
  324. box-shadow: 0px 0px 9px 1px rgba(63, 141, 253, 0.3);
  325. border-radius: 50%;
  326. text-align: center;
  327. line-height: 40px;
  328. .img {
  329. vertical-align: middle;
  330. display: inline-block;
  331. color: #fff;
  332. font-size: 24px;
  333. }
  334. }
  335. .title {
  336. margin-left: 20px;
  337. flex: 1;
  338. font-size: 30px;
  339. font-family: Microsoft YaHei;
  340. font-weight: 400;
  341. color: #333333;
  342. }
  343. }
  344. &__body {
  345. .order-msg {
  346. border-bottom: 2px solid #eee;
  347. &__header {
  348. display: flex;
  349. align-items: center;
  350. padding: 0 20px;
  351. height: 40px;
  352. .icon {
  353. color: #fff;
  354. width: 24px;
  355. height: 24px;
  356. line-height: 24px;
  357. border-radius: 50%;
  358. text-align: center;
  359. background: rgba(52, 199, 89, 1);
  360. }
  361. .title {
  362. flex: 1;
  363. margin-left: 10px;
  364. }
  365. }
  366. &__body {
  367. padding-left: 50px;
  368. .goods_item {
  369. margin: 16px 0;
  370. span {
  371. margin-left: 20px;
  372. }
  373. }
  374. }
  375. }
  376. .payment-way {
  377. border-bottom: 2px solid #eee;
  378. ul {
  379. li {
  380. margin: 24px 0;
  381. width: 100%;
  382. background: #fafbfc;
  383. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  384. border-radius: 16px;
  385. height: 80px;
  386. border-radius: 16px;
  387. display: flex;
  388. align-items: center;
  389. padding: 0 20px;
  390. &.active {
  391. background: #f2f7fc;
  392. border: 1px solid #3f8dfd;
  393. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  394. }
  395. /deep/ .el-radio__label {
  396. vertical-align: middle;
  397. }
  398. }
  399. }
  400. }
  401. .payment-btn {
  402. margin: 24px 0;
  403. display: flex;
  404. align-items: center;
  405. .price {
  406. font-size: 24px;
  407. font-family: Microsoft YaHei;
  408. font-weight: 400;
  409. color: #ff3b30;
  410. }
  411. .btn {
  412. cursor: pointer;
  413. margin-left: 40px;
  414. width: 120px;
  415. height: 40px;
  416. padding: 0;
  417. background-color: #ff3b30;
  418. border-radius: 20px;
  419. text-align: center;
  420. line-height: 40px;
  421. color: #fff;
  422. font-size: 16px;
  423. &:hover {
  424. background-color: #f78989;
  425. }
  426. }
  427. }
  428. }
  429. }
  430. .qrcode {
  431. &__body {
  432. .img {
  433. cursor: pointer;
  434. margin: 0 auto;
  435. width: 180px;
  436. height: 180px;
  437. img {
  438. width: 100%;
  439. height: 100%;
  440. }
  441. }
  442. p {
  443. margin: 5px 0;
  444. text-align: center;
  445. font-size: 14px;
  446. font-family: Microsoft YaHei;
  447. font-weight: 400;
  448. color: #333333;
  449. line-height: 24px;
  450. span {
  451. color: #ff3b30;
  452. }
  453. }
  454. }
  455. }
  456. }
  457. </style>