index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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">
  67. <img :src="urlBase64" alt="" />
  68. </div>
  69. <!-- <p>距离二维码过期还剩<span>60</span>秒</p>
  70. <p>过期后请刷新重新获取二维码</p>
  71. <p>客服电话:020-12345678</p> -->
  72. </div>
  73. </el-dialog>
  74. <ToolBar></ToolBar>
  75. <Footer></Footer>
  76. </div>
  77. </template>
  78. <script>
  79. import Footer from "@/components/footer/index";
  80. import Header from "@/components/header/index";
  81. import ToolBar from "@/components/toolbar/index";
  82. import { mapGetters, mapMutations } from "vuex";
  83. export default {
  84. name: "Payment",
  85. components: {
  86. Footer,
  87. Header,
  88. ToolBar,
  89. },
  90. data() {
  91. return {
  92. radio: "1",
  93. qrCodeShow: false,
  94. total: 0,
  95. urlBase64: "",
  96. orderSn: "",
  97. checkOrderTimer: null,
  98. loading: null,
  99. };
  100. },
  101. computed: {
  102. ...mapGetters(["checkGoodsList"]),
  103. },
  104. beforeDestroy() {
  105. clearInterval(this.checkOrderTimer);
  106. },
  107. mounted() {
  108. console.log(this.checkGoodsList);
  109. if (this.checkGoodsList.length <= 0 && !this.$route.params.orderSn) {
  110. this.$router.back(-1);
  111. return;
  112. } else {
  113. if (this.$route.params.orderSn) {
  114. this.orderSn = this.$route.params.orderSn;
  115. this.total = this.$route.params.total;
  116. } else if (this.checkGoodsList.length > 0) {
  117. this.caculate();
  118. }
  119. }
  120. },
  121. methods: {
  122. ...mapMutations(["setCheckGoodsList"]),
  123. closePay() {
  124. console.log(999);
  125. this.$confirm("确定离开支付页面吗", "提示", {
  126. confirmButtonText: "确定",
  127. cancelButtonText: "取消",
  128. })
  129. .then((_) => {
  130. this.qrCodeShow = false;
  131. this.$router.back(-1);
  132. })
  133. .catch((_) => {});
  134. },
  135. caculate() {
  136. this.total = 0;
  137. this.checkGoodsList.forEach((item) => {
  138. this.total += item.standPrice;
  139. console.log(this.total);
  140. });
  141. },
  142. pay() {
  143. if (this.radio == 1) {
  144. //微信
  145. this.loading = this.$loading({
  146. lock: true,
  147. text: "支付中",
  148. spinner: "el-icon-loading",
  149. background: "rgba(0, 0, 0, 0)",
  150. target: document.querySelector(".section__body"),
  151. });
  152. if (this.orderSn) {
  153. //订单继续支付
  154. this.orderResumePCOrder();
  155. } else {
  156. //购物车进入支付
  157. this.orderPlacePcOrder();
  158. }
  159. } else {
  160. //银联
  161. }
  162. },
  163. orderPlacePcOrder() {
  164. this.$request
  165. .orderPlacePcOrder({ goodsList: this.checkGoodsList })
  166. .then((res) => {
  167. this.loading.close();
  168. console.log(res);
  169. this.urlBase64 = res.data.urlBase64;
  170. this.orderSn = res.data.orderSn;
  171. this.qrCodeShow = true;
  172. this.checkOrderTimer = setInterval(() => {
  173. this.orderPayStatus();
  174. }, 2000);
  175. })
  176. .catch((err) => {
  177. this.loading.close();
  178. if (err.code == 510) {
  179. this.$confirm(err.msg + "。点击确定跳转待支付订单列表", "提示", {
  180. confirmButtonText: "确定",
  181. cancelButtonText: "取消",
  182. })
  183. .then((_) => {
  184. this.$router.push({
  185. path: "/person-center/my-order",
  186. });
  187. })
  188. .catch((_) => {});
  189. // this.qrCodeShow = true;
  190. } else {
  191. this.$message({
  192. type: "warning",
  193. message: err.msg,
  194. });
  195. }
  196. });
  197. },
  198. orderResumePCOrder() {
  199. this.$request
  200. .orderResumePCOrder({ orderSn: this.orderSn })
  201. .then((res) => {
  202. this.loading.close();
  203. this.urlBase64 = res.data.urlBase64;
  204. this.orderSn = res.data.orderSn;
  205. this.qrCodeShow = true;
  206. this.checkOrderTimer = setInterval(() => {
  207. this.orderPayStatus();
  208. }, 2000);
  209. })
  210. .catch((err) => {
  211. this.loading.close();
  212. });
  213. },
  214. orderPayStatus() {
  215. this.$request
  216. .orderPayStatus(this.orderSn)
  217. .then((res) => {
  218. if (res.data) {
  219. this.setCheckGoodsList([]);
  220. clearInterval(this.checkOrderTimer);
  221. this.$router.replace({
  222. path: "/payment-success",
  223. name: "支付成功",
  224. params: {
  225. orderSn: this.orderSn,
  226. total: this.total,
  227. },
  228. });
  229. }
  230. })
  231. .catch((err) => {});
  232. },
  233. },
  234. };
  235. </script>
  236. <!-- Add "scoped" attribute to limit CSS to this component only -->
  237. <style scoped lang="scss">
  238. .payment {
  239. .section {
  240. &__header {
  241. height: 80px;
  242. background: #ebf3ff;
  243. display: flex;
  244. align-items: center;
  245. padding: 0 20px;
  246. .icon {
  247. width: 40px;
  248. height: 40px;
  249. background: #3f8dfd;
  250. box-shadow: 0px 0px 9px 1px rgba(63, 141, 253, 0.3);
  251. border-radius: 50%;
  252. text-align: center;
  253. line-height: 40px;
  254. .img {
  255. vertical-align: middle;
  256. display: inline-block;
  257. color: #fff;
  258. font-size: 24px;
  259. }
  260. }
  261. .title {
  262. margin-left: 20px;
  263. flex: 1;
  264. font-size: 30px;
  265. font-family: Microsoft YaHei;
  266. font-weight: 400;
  267. color: #333333;
  268. }
  269. }
  270. &__body {
  271. .order-msg {
  272. border-bottom: 2px solid #eee;
  273. &__header {
  274. display: flex;
  275. align-items: center;
  276. padding: 0 20px;
  277. height: 40px;
  278. .icon {
  279. color: #fff;
  280. width: 24px;
  281. height: 24px;
  282. line-height: 24px;
  283. border-radius: 50%;
  284. text-align: center;
  285. background: rgba(52, 199, 89, 1);
  286. }
  287. .title {
  288. flex: 1;
  289. margin-left: 10px;
  290. }
  291. }
  292. &__body {
  293. padding-left: 50px;
  294. .goods_item {
  295. margin: 16px 0;
  296. span {
  297. margin-left: 20px;
  298. }
  299. }
  300. }
  301. }
  302. .payment-way {
  303. border-bottom: 2px solid #eee;
  304. ul {
  305. li {
  306. margin: 24px 0;
  307. width: 100%;
  308. background: #fafbfc;
  309. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  310. border-radius: 16px;
  311. height: 80px;
  312. border-radius: 16px;
  313. display: flex;
  314. align-items: center;
  315. padding: 0 20px;
  316. &.active {
  317. background: #f2f7fc;
  318. border: 1px solid #3f8dfd;
  319. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  320. }
  321. /deep/ .el-radio__label {
  322. vertical-align: middle;
  323. }
  324. }
  325. }
  326. }
  327. .payment-btn {
  328. margin: 24px 0;
  329. display: flex;
  330. align-items: center;
  331. .price {
  332. font-size: 24px;
  333. font-family: Microsoft YaHei;
  334. font-weight: 400;
  335. color: #ff3b30;
  336. }
  337. .btn {
  338. cursor: pointer;
  339. margin-left: 40px;
  340. width: 120px;
  341. height: 40px;
  342. padding: 0;
  343. background-color: #ff3b30;
  344. border-radius: 20px;
  345. text-align: center;
  346. line-height: 40px;
  347. color: #fff;
  348. font-size: 16px;
  349. &:hover {
  350. background-color: #f78989;
  351. }
  352. }
  353. }
  354. }
  355. }
  356. .qrcode {
  357. &__body {
  358. .img {
  359. margin: 0 auto;
  360. width: 180px;
  361. height: 180px;
  362. img {
  363. width: 100%;
  364. height: 100%;
  365. }
  366. }
  367. p {
  368. margin: 5px 0;
  369. text-align: center;
  370. font-size: 14px;
  371. font-family: Microsoft YaHei;
  372. font-weight: 400;
  373. color: #333333;
  374. line-height: 24px;
  375. span {
  376. color: #ff3b30;
  377. }
  378. }
  379. }
  380. }
  381. }
  382. </style>