index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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" v-else>
  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. <Class-time-tip :gradeId="goodsItem.gradeId"></Class-time-tip>
  29. </div>
  30. </div>
  31. </div>
  32. <div class="payment-way">
  33. <ul>
  34. <li :class="{ active: radio == 1 }">
  35. <el-radio v-model="radio" label="1">
  36. <img src="@/assets/wep.png" alt="" />
  37. </el-radio>
  38. </li>
  39. <!-- <li :class="{ active: radio == 2 }">
  40. <el-radio v-model="radio" label="2">
  41. <img src="@/assets/unp.png" alt="" />
  42. </el-radio>
  43. </li> -->
  44. </ul>
  45. </div>
  46. <div class="payment-btn">
  47. 应付金额:
  48. <div class="price">{{ total | toFixed }}</div>
  49. <el-button type="danger" class="btn" id="pay" @click="pay"
  50. >立即支付</el-button
  51. >
  52. </div>
  53. </div>
  54. </div>
  55. </section>
  56. <el-dialog
  57. title="请使用微信扫码支付"
  58. :visible.sync="qrCodeShow"
  59. width="348px"
  60. center
  61. :close-on-click-modal="false"
  62. :close-on-press-escape="false"
  63. :before-close="closePay"
  64. class="qrcode"
  65. >
  66. <div class="qrcode__body">
  67. <div class="img" @click="refreshCode">
  68. <img
  69. :src="lastTime <= 0 ? require('@/assets/qrcode.png') : urlBase64"
  70. alt=""
  71. />
  72. </div>
  73. <p v-if="lastTime > 0">
  74. 距离二维码过期还剩<span>{{ lastTime }}</span
  75. >秒
  76. </p>
  77. <p v-else>二维码已过期,点击图片重新获取二维码</p>
  78. <p>过期后请刷新重新获取二维码</p>
  79. <p>客服电话:020-87085982</p>
  80. </div>
  81. </el-dialog>
  82. <updateUserInfo ref="updateUserInfo"></updateUserInfo>
  83. <ToolBar></ToolBar>
  84. <Footer></Footer>
  85. </div>
  86. </template>
  87. <script>
  88. import updateUserInfo from "./updateUserInfo.vue";
  89. import Footer from "@/components/footer/index";
  90. import Header from "@/components/header/index";
  91. import ToolBar from "@/components/toolbar/index";
  92. import ClassTimeTip from "@/components/common/ClassTimeTip.vue";
  93. import { mapGetters, mapMutations } from "vuex";
  94. export default {
  95. name: "Payment",
  96. components: {
  97. Footer,
  98. Header,
  99. ToolBar,
  100. ClassTimeTip,
  101. updateUserInfo
  102. },
  103. data() {
  104. return {
  105. lastTime: 60,
  106. radio: "1",
  107. qrCodeShow: false,
  108. total: 0,
  109. urlBase64: "",
  110. orderSn: "",
  111. checkOrderTimer: null,
  112. loading: null,
  113. countTimer: null,
  114. checkGoodsList: [],
  115. isBK: ""
  116. };
  117. },
  118. computed: {},
  119. beforeDestroy() {
  120. clearInterval(this.countTimer);
  121. clearInterval(this.checkOrderTimer);
  122. },
  123. mounted() {
  124. console.log(this.$route, "this.$route.params");
  125. this.isBK = this.$route.query.isBK;
  126. let checkGoodsList = localStorage.getItem("checkGoodsList");
  127. if (!this.$tools.isLogin()) {
  128. this.setCurrentRouter(this.$route);
  129. this.$router.push({
  130. path: "/login"
  131. });
  132. return;
  133. }
  134. if (!checkGoodsList && !this.$route.params.orderSn) {
  135. this.$router.push({ path: "/person-center/my-order" });
  136. return;
  137. } else {
  138. if (this.$route.params.orderSn) {
  139. this.orderSn = this.$route.params.orderSn;
  140. this.total = this.$route.params.total;
  141. this.orderGoodsList();
  142. } else if (checkGoodsList) {
  143. this.checkGoodsList = JSON.parse(checkGoodsList);
  144. this.caculate();
  145. }
  146. }
  147. },
  148. methods: {
  149. ...mapMutations(["setCurrentRouter"]),
  150. refreshCode() {
  151. if (this.lastTime > 0) {
  152. return;
  153. }
  154. this.$request
  155. .orderResumePCOrder({ orderSn: this.orderSn })
  156. .then(res => {
  157. this.loading.close();
  158. this.urlBase64 = res.data.urlBase64;
  159. this.orderSn = res.data.orderSn;
  160. this.checkOrderTimer = setInterval(() => {
  161. this.orderPayStatus();
  162. }, 2000);
  163. this.lastTime = 60;
  164. this.countTimer = setInterval(() => {
  165. if (this.lastTime <= 0) {
  166. clearInterval(this.countTimer);
  167. clearInterval(this.checkOrderTimer);
  168. return;
  169. }
  170. this.lastTime--;
  171. }, 1000);
  172. })
  173. .catch(err => {
  174. // this.loading.close();
  175. });
  176. },
  177. closePay() {
  178. console.log(999);
  179. this.$confirm("确定离开支付页面吗", "提示", {
  180. confirmButtonText: "确定",
  181. cancelButtonText: "取消"
  182. })
  183. .then(_ => {
  184. this.qrCodeShow = false;
  185. this.$router.back(-1);
  186. })
  187. .catch(_ => {});
  188. },
  189. caculate() {
  190. this.total = 0;
  191. this.checkGoodsList.forEach(item => {
  192. this.total += item.standPrice;
  193. });
  194. },
  195. orderGoodsList() {
  196. this.$request
  197. .orderGoodsList({
  198. orderSn: this.orderSn
  199. })
  200. .then(res => {
  201. this.checkGoodsList = res.rows;
  202. });
  203. },
  204. verify() {
  205. return new Promise((resolve, reject) => {
  206. for (let i = 0; i < this.checkGoodsList.length; i++) {
  207. if (
  208. this.checkGoodsList[i].educationName == "继续教育" &&
  209. (this.checkGoodsList[i].projectName == "建造师" ||
  210. this.checkGoodsList[i].projectName == "造价师") &&
  211. this.checkGoodsList[i].businessName == "二级" &&
  212. (!this.$store.state.userInfo.realname ||
  213. !this.$store.state.userInfo.idCard)
  214. ) {
  215. this.$confirm("请完善学员姓名、身份证", "提示", {
  216. confirmButtonText: "确定",
  217. cancelButtonText: "取消",
  218. type: "warning"
  219. })
  220. .then(() => {
  221. this.$refs.updateUserInfo.openBox(1);
  222. })
  223. .catch(() => {});
  224. reject();
  225. }
  226. if (
  227. this.checkGoodsList[i].educationName == "继续教育" &&
  228. this.checkGoodsList[i].projectName == "施工现场专业人员" &&
  229. this.checkGoodsList[i].businessName == "七大员" &&
  230. this.checkGoodsList[i].sevenYear != "2021" &&
  231. this.checkGoodsList[i].sevenYear != "2022" &&
  232. (!this.$store.state.userInfo.realname ||
  233. !this.$store.state.userInfo.idCard ||
  234. !this.$store.state.userInfo.companyName ||
  235. !this.$store.state.userInfo.eduLevel ||
  236. !this.$store.state.userInfo.sex)
  237. ) {
  238. this.$confirm(
  239. "请完善学员姓名、身份证、性别、公司名称、教育层次",
  240. "提示",
  241. {
  242. confirmButtonText: "确定",
  243. cancelButtonText: "取消",
  244. type: "warning"
  245. }
  246. )
  247. .then(() => {
  248. this.$refs.updateUserInfo.openBox(2);
  249. })
  250. .catch(() => {});
  251. reject();
  252. }
  253. }
  254. resolve();
  255. });
  256. },
  257. async pay() {
  258. try {
  259. await this.verify();
  260. } catch (_) {
  261. return;
  262. }
  263. if (this.radio == 1) {
  264. //微信
  265. this.loading = this.$loading({
  266. lock: true,
  267. text: "支付中",
  268. spinner: "el-icon-loading",
  269. background: "rgba(0, 0, 0, 0)",
  270. target: document.querySelector(".section__body")
  271. });
  272. if (this.orderSn) {
  273. //订单继续支付
  274. this.orderResumePCOrder();
  275. } else {
  276. //购物车进入支付
  277. this.orderPlacePcOrder();
  278. }
  279. } else {
  280. //银联
  281. }
  282. },
  283. orderPlacePcOrder() {
  284. this.$request
  285. .orderPlacePcOrder({ goodsList: this.checkGoodsList })
  286. .then(res => {
  287. this.loading.close();
  288. localStorage.removeItem("checkGoodsList");
  289. console.log(res);
  290. //0元商品
  291. if (this.total == 0) {
  292. this.orderSn = res.data.orderSn;
  293. if (this.isBK) {
  294. this.$router.replace({
  295. path: "/payment-success",
  296. name: "支付成功",
  297. params: {
  298. orderSn: this.orderSn,
  299. total: this.total,
  300. isBK: this.isBK,
  301. goodsId: this.checkGoodsList[0].learnGoodsId,
  302. gradeId: this.checkGoodsList[0].learnGradeId,
  303. orderGoodsId: this.checkGoodsList[0].learnOrderGoodsId
  304. },
  305. query: {
  306. orderSn: this.orderSn,
  307. isBK: this.isBK,
  308. goodsId: this.checkGoodsList[0].learnGoodsId,
  309. gradeId: this.checkGoodsList[0].learnGradeId,
  310. orderGoodsId: this.checkGoodsList[0].learnOrderGoodsId
  311. }
  312. });
  313. } else {
  314. this.$router.replace({
  315. path: "/payment-success",
  316. name: "支付成功",
  317. params: {
  318. goodsId: this.checkGoodsList[0].goodsId,
  319. gradeId: this.checkGoodsList[0].gradeId,
  320. orderGoodsId: this.checkGoodsList[0].orderGoodsId,
  321. orderSn: this.orderSn,
  322. total: this.total
  323. },
  324. query: {
  325. goodsId: this.checkGoodsList[0].goodsId,
  326. gradeId: this.checkGoodsList[0].gradeId,
  327. orderGoodsId: this.checkGoodsList[0].orderGoodsId,
  328. orderSn: this.orderSn
  329. }
  330. });
  331. }
  332. return;
  333. } else {
  334. this.urlBase64 = res.data.urlBase64;
  335. this.orderSn = res.data.orderSn;
  336. this.qrCodeShow = true;
  337. this.checkOrderTimer = setInterval(() => {
  338. this.orderPayStatus();
  339. }, 2000);
  340. this.lastTime = 60;
  341. this.countTimer = setInterval(() => {
  342. if (this.lastTime <= 0) {
  343. clearInterval(this.countTimer);
  344. clearInterval(this.checkOrderTimer);
  345. return;
  346. }
  347. this.lastTime--;
  348. }, 1000);
  349. }
  350. })
  351. .catch(err => {
  352. this.loading.close();
  353. setTimeout(() => {
  354. if (err.code == 510) {
  355. this.$confirm(err.msg + "。点击确定跳转待支付订单列表", "提示", {
  356. confirmButtonText: "确定",
  357. cancelButtonText: "取消"
  358. })
  359. .then(_ => {
  360. this.$router.push({
  361. path: "/person-center/my-order"
  362. });
  363. })
  364. .catch(_ => {});
  365. // this.qrCodeShow = true;
  366. } else {
  367. this.$message({
  368. type: "warning",
  369. message: err.msg
  370. });
  371. }
  372. }, 500);
  373. });
  374. },
  375. orderResumePCOrder() {
  376. this.$request
  377. .orderResumePCOrder({ orderSn: this.orderSn })
  378. .then(res => {
  379. this.loading.close();
  380. this.urlBase64 = res.data.urlBase64;
  381. this.orderSn = res.data.orderSn;
  382. this.qrCodeShow = true;
  383. this.checkOrderTimer = setInterval(() => {
  384. this.orderPayStatus();
  385. }, 2000);
  386. this.lastTime = 60;
  387. this.countTimer = setInterval(() => {
  388. if (this.lastTime <= 0) {
  389. clearInterval(this.countTimer);
  390. clearInterval(this.checkOrderTimer);
  391. return;
  392. }
  393. this.lastTime--;
  394. }, 1000);
  395. })
  396. .catch(err => {
  397. // this.loading.close();
  398. });
  399. },
  400. orderPayStatus() {
  401. this.$request
  402. .orderPayStatus(this.orderSn)
  403. .then(res => {
  404. if (res.data) {
  405. clearInterval(this.checkOrderTimer);
  406. console.log(1);
  407. if (this.isBK) {
  408. console.log(2);
  409. this.$router.replace({
  410. path: "/payment-success",
  411. name: "支付成功",
  412. params: {
  413. orderSn: this.orderSn,
  414. total: this.total,
  415. isBK: this.isBK,
  416. goodsId: this.checkGoodsList[0].learnGoodsId,
  417. gradeId: this.checkGoodsList[0].learnGradeId,
  418. orderGoodsId: this.checkGoodsList[0].learnOrderGoodsId
  419. },
  420. query: {
  421. orderSn: this.orderSn,
  422. isBK: this.isBK,
  423. goodsId: this.checkGoodsList[0].learnGoodsId,
  424. gradeId: this.checkGoodsList[0].learnGradeId,
  425. orderGoodsId: this.checkGoodsList[0].learnOrderGoodsId
  426. }
  427. });
  428. } else {
  429. console.log(3);
  430. this.$router.replace({
  431. path: "/payment-success",
  432. name: "支付成功",
  433. params: {
  434. goodsId: this.checkGoodsList[0].goodsId,
  435. gradeId: this.checkGoodsList[0].gradeId,
  436. orderGoodsId: this.checkGoodsList[0].orderGoodsId,
  437. orderSn: this.orderSn,
  438. total: this.total
  439. },
  440. query: {
  441. goodsId: this.checkGoodsList[0].goodsId,
  442. gradeId: this.checkGoodsList[0].gradeId,
  443. orderGoodsId: this.checkGoodsList[0].orderGoodsId,
  444. orderSn: this.orderSn
  445. }
  446. });
  447. }
  448. console.log(this.checkGoodsList);
  449. }
  450. })
  451. .catch(err => {
  452. console.log(err, "err");
  453. });
  454. }
  455. }
  456. };
  457. </script>
  458. <!-- Add "scoped" attribute to limit CSS to this component only -->
  459. <style scoped lang="scss">
  460. .payment {
  461. .section {
  462. &__header {
  463. height: 80px;
  464. background: #ebf3ff;
  465. display: flex;
  466. align-items: center;
  467. padding: 0 20px;
  468. .icon {
  469. width: 40px;
  470. height: 40px;
  471. background: #3f8dfd;
  472. box-shadow: 0px 0px 9px 1px rgba(63, 141, 253, 0.3);
  473. border-radius: 50%;
  474. text-align: center;
  475. line-height: 40px;
  476. .img {
  477. vertical-align: middle;
  478. display: inline-block;
  479. color: #fff;
  480. font-size: 24px;
  481. }
  482. }
  483. .title {
  484. margin-left: 20px;
  485. flex: 1;
  486. font-size: 30px;
  487. font-family: Microsoft YaHei;
  488. font-weight: 400;
  489. color: #333333;
  490. }
  491. }
  492. &__body {
  493. .order-msg {
  494. border-bottom: 2px solid #eee;
  495. &__header {
  496. display: flex;
  497. align-items: center;
  498. padding: 0 20px;
  499. height: 40px;
  500. .icon {
  501. color: #fff;
  502. width: 24px;
  503. height: 24px;
  504. line-height: 24px;
  505. border-radius: 50%;
  506. text-align: center;
  507. background: rgba(52, 199, 89, 1);
  508. }
  509. .title {
  510. flex: 1;
  511. margin-left: 10px;
  512. }
  513. }
  514. &__body {
  515. padding-left: 50px;
  516. .goods_item {
  517. margin: 16px 0;
  518. span {
  519. margin-left: 20px;
  520. }
  521. }
  522. }
  523. }
  524. .payment-way {
  525. border-bottom: 2px solid #eee;
  526. ul {
  527. li {
  528. margin: 24px 0;
  529. width: 100%;
  530. background: #fafbfc;
  531. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  532. border-radius: 16px;
  533. height: 80px;
  534. border-radius: 16px;
  535. display: flex;
  536. align-items: center;
  537. padding: 0 20px;
  538. &.active {
  539. background: #f2f7fc;
  540. border: 1px solid #3f8dfd;
  541. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  542. }
  543. /deep/ .el-radio__label {
  544. vertical-align: middle;
  545. }
  546. }
  547. }
  548. }
  549. .payment-btn {
  550. margin: 24px 0;
  551. display: flex;
  552. align-items: center;
  553. .price {
  554. font-size: 24px;
  555. font-family: Microsoft YaHei;
  556. font-weight: 400;
  557. color: #ff3b30;
  558. }
  559. .btn {
  560. cursor: pointer;
  561. margin-left: 40px;
  562. width: 120px;
  563. height: 40px;
  564. padding: 0;
  565. background-color: #ff3b30;
  566. border-radius: 20px;
  567. text-align: center;
  568. line-height: 40px;
  569. color: #fff;
  570. font-size: 16px;
  571. &:hover {
  572. background-color: #f78989;
  573. }
  574. }
  575. }
  576. }
  577. }
  578. .qrcode {
  579. &__body {
  580. .img {
  581. cursor: pointer;
  582. margin: 0 auto;
  583. width: 180px;
  584. height: 180px;
  585. img {
  586. width: 100%;
  587. height: 100%;
  588. }
  589. }
  590. p {
  591. margin: 5px 0;
  592. text-align: center;
  593. font-size: 14px;
  594. font-family: Microsoft YaHei;
  595. font-weight: 400;
  596. color: #333333;
  597. line-height: 24px;
  598. span {
  599. color: #ff3b30;
  600. }
  601. }
  602. }
  603. }
  604. }
  605. </style>