payBox.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <template>
  2. <div>
  3. <el-dialog title="选择支付方式" :visible.sync="dialogPay" width="878px" class="dialog_pay" @closed="goBack">
  4. <div>
  5. <el-form label-width="106px" style="padding-left:140px;">
  6. <el-form-item label="支付金额">
  7. <span class="col_red">¥ {{money}}</span>
  8. </el-form-item>
  9. <el-form-item label="打赏课程" v-if="from === 'course'">
  10. <span class="col_red">{{pay_sn}}</span>
  11. </el-form-item>
  12. <el-form-item label="赞赏用户" v-if="from === 'micro'">
  13. <span class="col_red">{{pay_sn}}</span>
  14. </el-form-item>
  15. <el-form-item label="付费文章" v-if="from === 'notice'">
  16. <span class="col_red">{{pay_sn}}</span>
  17. </el-form-item>
  18. <el-form-item label="支付流水号" v-if="from === 'pay'">
  19. <span>{{pay_sn}}</span>
  20. </el-form-item>
  21. <el-form-item label="支付方式" class="spe" style="min-height:60px;">
  22. <div class="flex pay_way" style="flex-wrap:wrap;">
  23. <div style="margin-bottom:10px;" class="flex flex-a-c flex-j-c way" @click="changeIndex(item)"
  24. :class="[item.value==pay_select?'border_spe':'']" v-for="(item,index) in pay_way" :key="index">
  25. <div class="radio_button" :class="[item.value==pay_select?'radio':'']"></div>
  26. <img src="~/assets/images/icon/coin.png" style="margin-right:5px;width:28px;height:28px;"
  27. v-if="item.value==3">
  28. <img src="~/assets/images/icon/wechat_pay.png" style="margin-right:5px;"
  29. v-if="item.value==28||item.value==57 || item.value==50">
  30. <img src="~/assets/images/icon/ali_pay.png" style="margin-right:5px;"
  31. v-if="item.value==2||item.value==29||item.value ==85">
  32. {{item.name}}
  33. </div>
  34. </div>
  35. </el-form-item>
  36. </el-form>
  37. <div class="btn_wrap flex">
  38. <el-button class="flex flex-a-c flex-j-c" @click="dialogPay=false">关闭</el-button>
  39. <el-button type="primary" class="flex flex-a-c flex-j-c" style="margin-left:56px;" v-if="from === 'notice'"
  40. @click="payNoticeMoney">立即支付
  41. </el-button>
  42. <el-button type="primary" class="flex flex-a-c flex-j-c" style="margin-left:56px;" v-if="!from || from === 'pay'"
  43. @click="payMoney">立即支付
  44. </el-button>
  45. <el-button type="primary" class="flex flex-a-c flex-j-c" style="margin-left:56px;" v-if="from === 'course'"
  46. @click="payPost">立即打赏
  47. </el-button>
  48. <el-button type="primary" class="flex flex-a-c flex-j-c" style="margin-left:56px;" v-if="from === 'micro'"
  49. @click="payMicroPost">立即赞赏
  50. </el-button>
  51. </div>
  52. </div>
  53. </el-dialog>
  54. <el-dialog title="提示" :visible.sync="show_qrcode" width="450px" class="dialog_qr" :close-on-click-modal="false" @closed="goBack">
  55. <div class="qr_content" v-show="!show_pay_status">
  56. <div style="margin-bottom: 25px;">请在2小时内完成支付</div>
  57. <div class="qr_code m-auto">
  58. <canvas id="qrccode-canvas2"></canvas>
  59. </div>
  60. <div style="margin-bottom: 34px;">{{pay_select == 85?'支付宝扫码支付':'微信扫码支付' }}</div>
  61. </div>
  62. <div class="pay-status-box" v-show="show_pay_status && pay_success">
  63. <div><i class="el-icon-success"></i></div>
  64. <p class="pay-tips">支付成功</p>
  65. <el-button type="primary" plain @click="toUrl('order')">查看订单列表</el-button>
  66. </div>
  67. <div class="pay-status-box" v-show="show_pay_status && !pay_success">
  68. <div><i class="el-icon-error"></i></div>
  69. <p class="pay-tips">支付失败</p>
  70. <el-button type="danger" plain @click="toUrl('order')">查看订单列表</el-button>
  71. </div>
  72. </el-dialog>
  73. <el-dialog title="请输入余额支付密码" :visible.sync="popupSpecs" width="878px" class="dialog_pay" @closed="goBack">
  74. <el-form>
  75. <el-form-item label="余额支付密码" class="flex flex-j-c">
  76. <el-input v-model="balancePwd" type="password" placeholder="请输入密码"></el-input>
  77. </el-form-item>
  78. </el-form>
  79. <div style="margin-top:50px;" class="flex flex-j-c">
  80. <el-button class="flex flex-a-c flex-j-c" @click="popupSpecs=false">关闭</el-button>
  81. <el-button type="primary" class="flex flex-a-c flex-j-c" style="margin-left:56px;" @click="getVerifyPassword">
  82. 立即支付
  83. </el-button>
  84. </div>
  85. </el-dialog>
  86. </div>
  87. </template>
  88. <script>
  89. import QRCode from "qrcode";
  90. var canvas = "";
  91. export default {
  92. name: "payBox",
  93. props: {
  94. orderPayId: Number,
  95. money: String,
  96. pay_sn: String,
  97. order_pay_id: Number,
  98. pay_way: Array,
  99. from: String,
  100. noJump: {
  101. type: Boolean,
  102. default: false
  103. },
  104. rewardTypes: Number,
  105. trick_id: Number
  106. },
  107. data() {
  108. return {
  109. interval: null,
  110. balancePwd: "",
  111. popupSpecs: false,
  112. show_qrcode: false,
  113. pay_select: 1,
  114. pay_name: "",
  115. dialogPay: false,
  116. show_pay_status: false,
  117. pay_success: false,
  118. };
  119. },
  120. methods: {
  121. showPay() {
  122. if (this.interval) {
  123. clearInterval(this.interval);
  124. }
  125. this.dialogPay = true;
  126. },
  127. toUrl(url, params) {
  128. if(!this.from) {
  129. this.goBack();
  130. return
  131. }
  132. this.$router.push(this.fun.getUrl(url, params));
  133. },
  134. createQrc(_url) {
  135. // this.init()
  136. this.$nextTick(function () {
  137. // DOM操作
  138. canvas = document.getElementById("qrccode-canvas2");
  139. QRCode.toCanvas(canvas, _url, error => {
  140. if (error) {
  141. console.log(error);
  142. }
  143. });
  144. });
  145. },
  146. goBack() {
  147. this.show_qrcode = false;
  148. this.popupSpecs = false;
  149. this.balancePwd = "";
  150. if (this.interval) {
  151. clearInterval(this.interval);
  152. }
  153. if (this.from === "pay" && !this.noJump) {
  154. this.$router.push(this.fun.getUrl("order"));
  155. } else {
  156. this.dialogPay = false;
  157. this.$emit("paySuccess", true);
  158. }
  159. // this.$router.go(-1)
  160. },
  161. // 微社区打赏支付
  162. payMicroPost() {
  163. if (this.pay_select != 3 && this.pay_select != 2 && this.pay_select != 6) {
  164. this.$message.error("PC端目前不支持该付款方式,请在移动端支付");
  165. return
  166. }
  167. let url = "plugin.micro-communities.api.reward-log.index";
  168. let json = {
  169. pay_method: this.pay_select,
  170. amount: this.money,
  171. pay_name: this.pay_name,
  172. };
  173. if (this.rewardTypes == 0) {
  174. // 帖子打赏
  175. json.trick_id = this.trick_id;
  176. } else {
  177. // 评论打赏
  178. url = "plugin.micro-communities.api.reward-log.commentPay";
  179. json.comment_id = this.trick_id;
  180. }
  181. this.fun
  182. .$get(url, json, "..")
  183. .then(response => {
  184. if (response.result == 1) {
  185. if (this.pay_select == 3) {
  186. if (this.need_password) {
  187. this.popupSpecs = true;
  188. this.balancePwd = "";
  189. } else {
  190. this.dialogPay = false;
  191. this.$message.success(response.msg);
  192. this.$emit("paySuccess", true);
  193. }
  194. } else if (this.pay_select == 2) {
  195. // 支付宝
  196. window.location.href = response.data;
  197. // window.open(response.data, "_blank");
  198. } else if (this.pay_select == 6) {
  199. // 微信
  200. window.location.href = response.data;
  201. } else {
  202. this.$message.error("PC端目前不支持该付款方式,请在移动端支付");
  203. }
  204. } else {
  205. this.$message.error(response.msg);
  206. }
  207. });
  208. },
  209. // 课程打赏支付
  210. payPost() {
  211. if (this.pay_select != 3 && this.pay_select != 2 && this.pay_select != 6) {
  212. this.$message.error("PC端目前不支持该付款方式,请在移动端支付");
  213. return
  214. }
  215. let json = {
  216. pay_method: this.pay_select,
  217. amount: this.money,
  218. pay_name: this.pay_name,
  219. goods_id: this.order_pay_id // 商品id
  220. };
  221. this.fun
  222. .$get("plugin.video-demand.api.lecturer-reward.run-reward-pay", json, "..")
  223. .then(response => {
  224. if (response.result == 1) {
  225. if (this.pay_select == 3) {
  226. if (this.need_password) {
  227. this.popupSpecs = true;
  228. this.balancePwd = "";
  229. } else {
  230. this.dialogPay = false;
  231. this.$message.success(response.msg);
  232. this.$emit("paySuccess", true);
  233. }
  234. } else if (this.pay_select == 2) {
  235. // 支付宝
  236. window.location.href = response.data;
  237. // window.open(response.data, "_blank");
  238. } else if (this.pay_select == 6) {
  239. // 微信
  240. window.location.href = response.data;
  241. } else {
  242. this.$message.error("PC端目前不支持该付款方式,请在移动端支付");
  243. }
  244. } else {
  245. this.$message.error(response.msg);
  246. }
  247. });
  248. },
  249. // 付费文章
  250. payNoticeMoney() {
  251. if (this.pay_select != 3 && this.pay_select != 2 && this.pay_select != 6) {
  252. this.$message.error("PC端目前不支持该付款方式,请在移动端支付");
  253. return
  254. }
  255. let json = {
  256. pay_id: this.pay_select,
  257. money: this.money,
  258. pay_name: this.pay_name,
  259. id: this.order_pay_id, // 文章id
  260. art: 'pay'
  261. };
  262. this.fun
  263. .$get("plugin.article-pay.api.index.orderPay", json, "..")
  264. .then(response => {
  265. if (response.result == 1) {
  266. if (this.pay_select == 3) {
  267. if (this.need_password) {
  268. this.popupSpecs = true;
  269. this.balancePwd = "";
  270. } else {
  271. this.dialogPay = false;
  272. this.$message.success(response.msg);
  273. this.$emit("paySuccess", true);
  274. }
  275. } else if (this.pay_select == 2) {
  276. // 支付宝
  277. window.location.href = response.data;
  278. // window.open(response.data, "_blank");
  279. } else if (this.pay_select == 6) {
  280. // 微信
  281. window.location.href = response.data;
  282. } else {
  283. this.$message.error("PC端目前不支持该付款方式,请在移动端支付");
  284. }
  285. } else {
  286. this.$message.error(response.msg);
  287. }
  288. });
  289. },
  290. // 商城订单付费
  291. payMoney() {
  292. if (this.pay_select == 3) {
  293. if (this.need_password) {
  294. this.popupSpecs = true;
  295. this.balancePwd = "";
  296. } else {
  297. this.balancePay();
  298. }
  299. } else if (this.pay_select == 2) {
  300. this.aliPayOrder();
  301. } else if (this.pay_select == 17) {
  302. this.payNoMoney();
  303. } else if (this.pay_select == 29) {
  304. this.getwechatPayAili();
  305. } else if (this.pay_select == 28) {
  306. this.getwechatPay();
  307. } else if (this.pay_select == 57) {
  308. this.pcweixin();
  309. } else if (this.pay_select == 85){
  310. this.Otherleshua_Alipay();
  311. } else {
  312. this.$message.error('PC端暂不支持该支付方式!')
  313. }
  314. },
  315. changeIndex(item) {
  316. if (item.need_password) {
  317. this.need_password = item.need_password;
  318. }
  319. this.pay_select = item.value;
  320. this.pay_name = item.name;
  321. },
  322. balancePay(password) {
  323. let json = {
  324. order_pay_id: this.order_pay_id
  325. };
  326. if (!this.fun.isTextEmpty(password)) {
  327. json = {
  328. order_pay_id: this.order_pay_id,
  329. payment_password: password
  330. };
  331. }
  332. this.fun
  333. .$get("order.credit-merge-pay.credit2", json, "")
  334. .then(response => {
  335. if (response.result == 1) {
  336. this.$message.success(response.msg);
  337. this.dialogPay = false;
  338. this.$emit("paySuccess", true);
  339. } else {
  340. this.$message.error(response.msg);
  341. }
  342. });
  343. },
  344. aliPayOrder() {
  345. let payUrl = "order.merge-pay.alipay";
  346. this.fun
  347. .$get(
  348. payUrl,
  349. {
  350. order_pay_id: this.order_pay_id
  351. },
  352. "支付中"
  353. )
  354. .then(response => {
  355. if (response.result == 1) {
  356. window.location.href = response.data;
  357. this.$message.success(response.msg);
  358. } else {
  359. this.$message.error(response.msg);
  360. }
  361. });
  362. },
  363. payNoMoney() {
  364. let payUrl = "order.mergePay.COD";
  365. this.fun
  366. .$get(
  367. payUrl,
  368. {
  369. order_pay_id: this.order_pay_id
  370. },
  371. "支付中"
  372. )
  373. .then(response => {
  374. if (response.result == 1) {
  375. this.$message.success(response.msg);
  376. this.show_pay_status = true;
  377. this.pay_success = true;
  378. } else {
  379. this.$message.error(response.msg);
  380. }
  381. });
  382. },
  383. // 乐刷支付宝
  384. Otherleshua_Alipay(){
  385. let payUrl = "order.merge-pay.leshua-alipay";
  386. this.fun
  387. .$get(
  388. payUrl,
  389. {
  390. order_pay_id: this.order_pay_id
  391. },
  392. "支付中"
  393. )
  394. .then(response => {
  395. if (response.result == 1) {
  396. console.log(response.data.pay_msg.link,'ddddd')
  397. this.createQrc(response.data.pay_msg.link);
  398. this.show_qrcode = true;
  399. if (this.orderPayId) {
  400. this.interval = setInterval(() => {
  401. this.getOrderStatus();
  402. }, 3000);
  403. }
  404. // window.location.href = response.data.data.rc_Result;
  405. // this.$message.success(response.msg);
  406. } else {
  407. this.$message.error(response.msg);
  408. }
  409. });
  410. },
  411. //汇聚阿里支付
  412. getwechatPayAili() {
  413. let payUrl = "order.merge-pay.alipay-pay-hj";
  414. this.fun
  415. .$get(
  416. payUrl,
  417. {
  418. order_pay_id: this.order_pay_id
  419. },
  420. "支付中"
  421. )
  422. .then(response => {
  423. if (response.result == 1) {
  424. window.location.href = response.data.data.rc_Result;
  425. this.$message.success(response.msg);
  426. } else {
  427. this.$message.error(response.msg);
  428. }
  429. });
  430. },
  431. getOrderStatus() {
  432. this.fun
  433. .$get(
  434. 'payment.pc-scan.index',
  435. {
  436. order_ids: this.orderPayId
  437. },
  438. )
  439. .then(response => {
  440. if (response.result == 1) {
  441. if (response.data.pay_status) {
  442. // if (response.data.redirect) {
  443. // setTimeout(() => {
  444. // window.location.href = response.data.redirect
  445. // }, 3000);
  446. // }
  447. clearInterval(this.interval);
  448. this.show_pay_status = true;
  449. this.pay_success = true;
  450. }
  451. } else {
  452. clearInterval(this.interval);
  453. this.show_pay_status = true;
  454. this.pay_success = false;
  455. this.$message.error(response.msg);
  456. }
  457. });
  458. },
  459. pcweixin() {
  460. let payUrl = "order.merge-pay.wechat-native";
  461. this.fun
  462. .$get(
  463. payUrl,
  464. {
  465. order_pay_id: this.order_pay_id
  466. },
  467. "加载中"
  468. )
  469. .then(response => {
  470. if (response.result == 1) {
  471. this.createQrc(response.data.code_url);
  472. this.show_qrcode = true;
  473. if (this.orderPayId) {
  474. this.interval = setInterval(() => {
  475. this.getOrderStatus();
  476. }, 3000);
  477. }
  478. } else {
  479. this.$message.error(response.msg);
  480. }
  481. });
  482. },
  483. // 第三方支付 微信支付-汇聚
  484. getwechatPay() {
  485. let payUrl = "order.merge-pay.wechat-pay-hj";
  486. this.fun
  487. .$get(
  488. payUrl,
  489. {
  490. order_pay_id: this.order_pay_id
  491. },
  492. "加载中"
  493. )
  494. .then(response => {
  495. if (response.result == 1) {
  496. this.createQrc(response.data.data.rc_Result);
  497. this.show_qrcode = true;
  498. } else {
  499. this.$message.error(response.msg);
  500. }
  501. });
  502. },
  503. getVerifyPassword() {
  504. this.fun
  505. .$get("payment.password.check", {password: this.balancePwd}, "")
  506. .then(response => {
  507. if (response.result == 1) {
  508. this.balancePay(this.balancePwd);
  509. this.popupSpecs = false;
  510. } else {
  511. this.$message.error(response.msg);
  512. this.popupSpecs = false;
  513. this.dialogPay = false;
  514. }
  515. });
  516. }
  517. }
  518. };
  519. </script>
  520. <style lang="scss" rel="stylesheet/scss" scoped>
  521. .dialog_pay {
  522. :deep(.el-input) {
  523. width: 336px;
  524. height: 42px;
  525. }
  526. :deep(.el-dialog__body) {
  527. padding: 40px 0 30px 0;
  528. }
  529. :deep(.el-dialog__header) {
  530. border-bottom: solid 1px #f2f2f2;
  531. }
  532. :deep(.el-form-item__label) {
  533. text-align: left !important;
  534. }
  535. :deep(.el-form-item__label) {
  536. text-align: left !important;
  537. font-size: 16px;
  538. }
  539. }
  540. .pay_way {
  541. flex-wrap: wrap;
  542. .way {
  543. cursor: pointer;
  544. min-width: 120px;
  545. min-height: 60px;
  546. border-radius: 5px;
  547. border: solid 1px #cacaca;
  548. margin: 10px;
  549. padding: 0 10px;
  550. .radio_button {
  551. margin-right: 10px;
  552. border-radius: 50%;
  553. width: 10px;
  554. height: 10px;
  555. background-color: #e1e1e1;
  556. }
  557. }
  558. }
  559. .border_spe {
  560. border: solid 1px var(--color) !important;
  561. }
  562. .radio {
  563. background-color: var(--color) !important;
  564. }
  565. .btn_wrap {
  566. margin-top: 50px;
  567. padding-left: 270px;
  568. .el-button {
  569. width: 134px;
  570. height: 43px;
  571. border-radius: 4px;
  572. font-size: 16px;
  573. }
  574. }
  575. .dialog_qr {
  576. :deep(.el-dialog__header) {
  577. padding: 0;
  578. height: 56px;
  579. background-color: #f5f8fa;
  580. display: flex;
  581. align-items: center;
  582. justify-content: center;
  583. }
  584. :deep(.el-dialog__body) {
  585. padding: 0;
  586. }
  587. }
  588. .qr_content {
  589. padding-top: 33px;
  590. padding-bottom: 27px;
  591. text-align: center;
  592. .qr_code {
  593. width: 220px;
  594. height: 220px;
  595. margin-bottom: 20px;
  596. #qrccode-canvas2 {
  597. width: 220px !important;
  598. height: 220px !important;
  599. }
  600. }
  601. }
  602. .pay-status-box {
  603. text-align: center;
  604. padding-bottom: 20px;
  605. i {
  606. font-size: 80px;
  607. color: var(--color);
  608. margin: 10px auto;
  609. }
  610. .el-icon-error {
  611. color: $red;
  612. }
  613. .pay-tips {
  614. font-size: 16px;
  615. font-weight: bold;
  616. margin: 10px auto 20px auto;
  617. }
  618. }
  619. </style>