index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. params: {
  284. orderSn: this.orderSn,
  285. total: this.total,
  286. isBK: this.isBK,
  287. goodsId: this.checkGoodsList[0].learnGoodsId,
  288. gradeId: this.checkGoodsList[0].learnGradeId,
  289. orderGoodsId: this.checkGoodsList[0].learnOrderGoodsId,
  290. },
  291. });
  292. } else {
  293. this.$router.replace({
  294. path: "/payment-success",
  295. params: {
  296. orderSn: this.orderSn,
  297. total: this.total,
  298. },
  299. });
  300. }
  301. }
  302. })
  303. .catch((err) => {});
  304. },
  305. },
  306. };
  307. </script>
  308. <!-- Add "scoped" attribute to limit CSS to this component only -->
  309. <style scoped lang="scss">
  310. .payment {
  311. .section {
  312. &__header {
  313. height: 80px;
  314. background: #ebf3ff;
  315. display: flex;
  316. align-items: center;
  317. padding: 0 20px;
  318. .icon {
  319. width: 40px;
  320. height: 40px;
  321. background: #3f8dfd;
  322. box-shadow: 0px 0px 9px 1px rgba(63, 141, 253, 0.3);
  323. border-radius: 50%;
  324. text-align: center;
  325. line-height: 40px;
  326. .img {
  327. vertical-align: middle;
  328. display: inline-block;
  329. color: #fff;
  330. font-size: 24px;
  331. }
  332. }
  333. .title {
  334. margin-left: 20px;
  335. flex: 1;
  336. font-size: 30px;
  337. font-family: Microsoft YaHei;
  338. font-weight: 400;
  339. color: #333333;
  340. }
  341. }
  342. &__body {
  343. .order-msg {
  344. border-bottom: 2px solid #eee;
  345. &__header {
  346. display: flex;
  347. align-items: center;
  348. padding: 0 20px;
  349. height: 40px;
  350. .icon {
  351. color: #fff;
  352. width: 24px;
  353. height: 24px;
  354. line-height: 24px;
  355. border-radius: 50%;
  356. text-align: center;
  357. background: rgba(52, 199, 89, 1);
  358. }
  359. .title {
  360. flex: 1;
  361. margin-left: 10px;
  362. }
  363. }
  364. &__body {
  365. padding-left: 50px;
  366. .goods_item {
  367. margin: 16px 0;
  368. span {
  369. margin-left: 20px;
  370. }
  371. }
  372. }
  373. }
  374. .payment-way {
  375. border-bottom: 2px solid #eee;
  376. ul {
  377. li {
  378. margin: 24px 0;
  379. width: 100%;
  380. background: #fafbfc;
  381. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  382. border-radius: 16px;
  383. height: 80px;
  384. border-radius: 16px;
  385. display: flex;
  386. align-items: center;
  387. padding: 0 20px;
  388. &.active {
  389. background: #f2f7fc;
  390. border: 1px solid #3f8dfd;
  391. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  392. }
  393. /deep/ .el-radio__label {
  394. vertical-align: middle;
  395. }
  396. }
  397. }
  398. }
  399. .payment-btn {
  400. margin: 24px 0;
  401. display: flex;
  402. align-items: center;
  403. .price {
  404. font-size: 24px;
  405. font-family: Microsoft YaHei;
  406. font-weight: 400;
  407. color: #ff3b30;
  408. }
  409. .btn {
  410. cursor: pointer;
  411. margin-left: 40px;
  412. width: 120px;
  413. height: 40px;
  414. padding: 0;
  415. background-color: #ff3b30;
  416. border-radius: 20px;
  417. text-align: center;
  418. line-height: 40px;
  419. color: #fff;
  420. font-size: 16px;
  421. &:hover {
  422. background-color: #f78989;
  423. }
  424. }
  425. }
  426. }
  427. }
  428. .qrcode {
  429. &__body {
  430. .img {
  431. cursor: pointer;
  432. margin: 0 auto;
  433. width: 180px;
  434. height: 180px;
  435. img {
  436. width: 100%;
  437. height: 100%;
  438. }
  439. }
  440. p {
  441. margin: 5px 0;
  442. text-align: center;
  443. font-size: 14px;
  444. font-family: Microsoft YaHei;
  445. font-weight: 400;
  446. color: #333333;
  447. line-height: 24px;
  448. span {
  449. color: #ff3b30;
  450. }
  451. }
  452. }
  453. }
  454. }
  455. </style>