confirm_pay.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <template>
  2. <view>
  3. <nav-bar title="订单支付"></nav-bar>
  4. <view>
  5. <view>
  6. <view class="box2">
  7. <view class="title2">支付信息</view>
  8. <!-- <view style="padding:10rpx 30rpx;" v-for="(item,index) in shoppingCartList" :key="index">
  9. <view class="list_title">
  10. <view class="txt_left">商品名称</view>
  11. <view class="txt_right">{{item.goodsName}}</view>
  12. </view>
  13. <view class="list_item">
  14. <view class="txt_left">应付金额</view>
  15. <view class="txt_right_price">¥ {{item.standPrice}}</view>
  16. </view>
  17. </view> -->
  18. <view
  19. v-for="(item, index) in shoppingCartList"
  20. :key="index"
  21. style="
  22. display: flex;
  23. justify-content: space-between;
  24. margin-bottom: 32rpx;
  25. "
  26. >
  27. <image
  28. :src="$method.splitImgHost(item.coverUrl)"
  29. style="height: 120rpx; width: 204rpx; border-radius: 16rpx"
  30. ></image>
  31. <view class="right_con" style="margin-left: 20rpx">
  32. <view style="color: #333333; font-size: 30rpx; font-weight: bold">
  33. {{ item.goodsName }}
  34. </view>
  35. <view class="priceTag"> ¥ {{ item.standPrice }} </view>
  36. <Class-time-tip
  37. v-if="item.gradObj && item.gradObj.gradeId"
  38. :classInfo="item.gradObj"
  39. ></Class-time-tip>
  40. </view>
  41. </view>
  42. <view class="info_right">
  43. <!-- <u-line color="#D6D6DB" /> -->
  44. <view class="list_item">
  45. <view class="txt_left">应付总金额</view>
  46. <view class="txt_right_price">¥ {{ totalPrice }}</view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="box3">
  51. <view class="title2">支付方式</view>
  52. <view>
  53. <u-radio-group v-model="value" @change="radioGroupChange">
  54. <view class="list_item">
  55. <view class="txt_left_pay"
  56. ><image src="/static/wepay.png" class="pay_icon"></image
  57. >微信支付</view
  58. >
  59. <view
  60. ><u-radio @change="radioChange" name="wepay"></u-radio
  61. ></view>
  62. </view>
  63. <view class="list_item" v-if="false">
  64. <view class="txt_left_pay"
  65. ><image src="/static/unipay.png" class="pay_icon"></image
  66. >云闪付</view
  67. >
  68. <view
  69. ><u-radio @change="radioChange" name="unipay"></u-radio
  70. ></view>
  71. </view>
  72. </u-radio-group>
  73. </view>
  74. <u-line color="#D6D6DB" />
  75. </view>
  76. </view>
  77. </view>
  78. <view class="bottomBox safeArea">
  79. <view class="sums">
  80. <text class="all_sum">总金额:</text>
  81. <text class="priceTag">¥ {{ totalPrice }}</text>
  82. </view>
  83. <view style="display: flex; color: #ffffff; align-items: center">
  84. <button class="btn2" @click="pay()" :disabled="btnNo">确认支付</button>
  85. </view>
  86. </view>
  87. <u-modal
  88. v-model="showModal"
  89. :confirm-text="confirmText"
  90. cancel-text="知道了"
  91. cancel-color="#666666"
  92. confirm-color="rgba(0, 122, 255, 1);"
  93. :show-confirm-button="showConfirmButton"
  94. :show-cancel-button="true"
  95. :content="modalMsg"
  96. @cancel="modalCancel()"
  97. @confirm="modalConfirm()"
  98. ref="uModal"
  99. ></u-modal>
  100. </view>
  101. </template>
  102. <script>
  103. import { mapGetters, mapActions } from "vuex";
  104. import { getQueryString } from "../../common/navTo";
  105. import ClassTimeTip from "../../components/common/ClassTimeTip.vue";
  106. export default {
  107. data() {
  108. return {
  109. showModal: false,
  110. modalMsg: "",
  111. list: [
  112. {
  113. name: "网课",
  114. },
  115. {
  116. name: "题库通",
  117. },
  118. ],
  119. array: [
  120. "全部",
  121. "建设工程施工管理",
  122. "机电全科",
  123. "机电工程管理与实",
  124. "机电全科",
  125. "全科",
  126. ],
  127. current: 0,
  128. menuIndex: 0,
  129. value: "wepay",
  130. btnNo: false,
  131. isBK: "",
  132. fromCart: "",
  133. hasPaying: false,
  134. showConfirmButton: false,
  135. confirmText: "",
  136. options: {},
  137. };
  138. },
  139. onPullDownRefresh() {},
  140. onLoad(option) {
  141. this.fromCart = option.fromCart;
  142. this.isBK = option.isBK;
  143. this.options = option;
  144. },
  145. onShow() {
  146. // #ifdef H5
  147. this.authorize();
  148. // #endif
  149. },
  150. methods: {
  151. ...mapActions(["getUserInfo"]),
  152. authorize() {
  153. if (location.search.includes("code")) {
  154. const code = getQueryString("code");
  155. this.$store.commit("setShoppingCartList", {
  156. shoppingCartList: uni.getStorageSync("shopList"),
  157. });
  158. uni.setStorageSync("h5_code", code);
  159. this.OfficialLogin(code);
  160. } else {
  161. // 没有code,就重定向到地址https://www.xyyxt.net?ask_type=https://api.xyyxt.net/pages2/order/confirm_pay 去获取code,授权后就会把code带上然后访问域名
  162. // ?fromCart=&code=061F5a1w3aolh03SLe1w3sMsCF4F5a16&state=STATE
  163. this.$api.checkBindGzh().then((res) => {
  164. if (!res.data.data && process.env.NODE_ENV !== "development") {
  165. uni.setStorageSync("shopList", this.shoppingCartList);
  166. const url = window.location.host + "/pages2/order/confirm_pay";
  167. // 跳自己授权
  168. if (this.config.gzhSelfLicense) {
  169. this.$api.getWxConfig().then((res) => {
  170. location.replace(
  171. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${
  172. res.data.data.gzhAppId
  173. }&redirect_uri=${encodeURIComponent(
  174. "https://" + url
  175. )}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
  176. );
  177. });
  178. } else {
  179. location.replace("https://www.xyyxt.net/?ask_type=" + url);
  180. }
  181. }
  182. });
  183. }
  184. },
  185. OfficialLogin(code) {
  186. this.$api
  187. .OfficialLogin({
  188. code,
  189. })
  190. .then((res) => {
  191. if (res.data.code !== 200) {
  192. this.$u.toast(res.data.msg);
  193. }
  194. });
  195. },
  196. async postOrder() {
  197. let list = this.shoppingCartList;
  198. let keys = [];
  199. for (let i = 0; i < list.length; i++) {
  200. let item = list[i];
  201. if (item.erJianErZao) {
  202. keys.push("realname", "idCard");
  203. }
  204. if (item.jjShiGongYuan) {
  205. keys.push("sex", "companyName", "eduLevel");
  206. }
  207. if (item.goodsType == 1) {
  208. if (item.templateType == "class") {
  209. delete item.gradObj.goodsList;
  210. let goodsInputData = {
  211. type: "class",
  212. gradeId: item.gradObj.gradeId,
  213. gradeJson: JSON.stringify(item.gradObj),
  214. };
  215. item.goodsInputData = goodsInputData;
  216. }
  217. if (item.templateType == "apply") {
  218. let goodsInputData = {
  219. type: "apply",
  220. applyAreasJson: JSON.stringify(item.applyAreas),
  221. examDateJson: JSON.stringify(item.examDate),
  222. };
  223. item.goodsInputData = goodsInputData;
  224. }
  225. }
  226. if (this.options.distributionCode) {
  227. item.distributionLinkCode = this.options.linkCode;
  228. item.distributionCode = this.options.distributionCode;
  229. }
  230. }
  231. // 二建 && 七大员 需要先完善信息
  232. if (keys.length) {
  233. if (!this.userInfo) await this.getUserInfo();
  234. if (keys.some((key) => !this.userInfo[key])) {
  235. this.btnNo = false;
  236. uni.showModal({
  237. title: "提示",
  238. content: "请先完善个人信息!",
  239. success: (res) => {
  240. if (res.confirm) {
  241. this.$navTo.togo("/pages2/verify/info_fill", {
  242. keys: keys.toString(),
  243. });
  244. }
  245. },
  246. });
  247. return;
  248. }
  249. }
  250. let data = { goodsList: list };
  251. // 邀请码
  252. if (this.sac) {
  253. data["shareActivityCode"] = this.sac;
  254. }
  255. // #ifdef MP-WEIXIN
  256. this.$api.placeSmallOrder(data).then((res) => {
  257. this.orderResult(res);
  258. });
  259. // #endif
  260. // #ifdef H5
  261. data["url"] = location.href;
  262. this.$api.placeGzhOrder(data).then((res) => {
  263. console.log(res, "h5支付res");
  264. this.orderResult(res);
  265. });
  266. // #endif
  267. },
  268. orderResult(res) {
  269. if (res.data.code == 200) {
  270. uni.setStorageSync("updateCart", 1); //提醒刷新购物车
  271. if (this.totalPrice == 0) {
  272. //免费商品
  273. uni.redirectTo({
  274. url: `/pages2/order/confirm_success?sn=${res.data.data.orderSn}&isBk=${this.isBK}`,
  275. });
  276. } else {
  277. let data = res.data.data;
  278. uni.showLoading({
  279. title: "支付中",
  280. mask: true,
  281. });
  282. // #ifdef MP-WEIXIN
  283. uni.requestPayment({
  284. provider: data.provider,
  285. nonceStr: data.nonceStr,
  286. package: data.package,
  287. signType: data.signType,
  288. paySign: data.sign,
  289. timeStamp: String(data.timeStamp),
  290. success: (res) => {
  291. uni.hideLoading();
  292. this.btnNo = false;
  293. uni.redirectTo({
  294. url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${this.isBK}`,
  295. });
  296. console.log("success:" + JSON.stringify(res));
  297. },
  298. fail: (err) => {
  299. uni.hideLoading();
  300. this.btnNo = false;
  301. console.log("fail:" + JSON.stringify(err));
  302. },
  303. });
  304. // #endif
  305. // #ifdef H5
  306. this.h5_wxpay(data);
  307. // #endif
  308. }
  309. } else if (res.data.code == 510) {
  310. //有未支付订单
  311. this.hasPaying = true;
  312. this.btnNo = false;
  313. this.modalMsg = res.data.msg;
  314. this.showConfirmButton = true;
  315. this.confirmText = "跳转到【我的订单】\n查看未支付订单";
  316. this.showModal = true;
  317. } else if (res.data.code == 511) {
  318. //511 重复购买
  319. this.hasPaying = false;
  320. this.btnNo = false;
  321. this.modalMsg = res.data.msg;
  322. this.showConfirmButton = true;
  323. this.showModal = true;
  324. if (this.fromCart) {
  325. console.log(this.fromCart);
  326. this.confirmText = "返回购物车";
  327. } else {
  328. let type = "";
  329. if (this.shoppingCartList.length == 1) {
  330. type = this.shoppingCartList[0].goodsType;
  331. } else {
  332. type = this.shoppingCartList[0].goodsType;
  333. if (this.shoppingCartList.find((item) => item.goodsType != type)) {
  334. type = 3;
  335. }
  336. }
  337. this.confirmText =
  338. type == 1 || type == 6
  339. ? "继续选课"
  340. : type == 2
  341. ? "继续选题"
  342. : type == 3 || type == 8
  343. ? "继续选购"
  344. : "";
  345. }
  346. } else {
  347. this.hasPaying = false;
  348. this.btnNo = false;
  349. this.showConfirmButton = false;
  350. this.modalMsg = res.data.msg;
  351. this.showModal = true;
  352. }
  353. },
  354. h5_wxpay(data) {
  355. console.log("====调起支付状态", data);
  356. let self = this;
  357. function onBridgeReady() {
  358. // 加载框
  359. WeixinJSBridge.invoke(
  360. "getBrandWCPayRequest",
  361. {
  362. appId: data.appId, // 公众号名称,由商户传入
  363. timeStamp: data.timeStamp, // 时间戳,自1970年以来的秒数
  364. nonceStr: data.nonceStr, // 随机串
  365. package: data.package,
  366. signType: data.signType, // 微信签名方式:
  367. paySign: data.paySign, // 微信签名
  368. },
  369. function (res) {
  370. // 判断支付状态
  371. console.log("支付状态", res, "this:", this, self);
  372. if (res.err_msg === "get_brand_wcpay_request:ok") {
  373. self.$u.toast("支付成功");
  374. uni.hideLoading();
  375. self.btnNo = false;
  376. uni.redirectTo({
  377. url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${self.isBK}`,
  378. });
  379. } else if (res.err_msg === "get_brand_wcpay_request:cancel") {
  380. self.$u.toast("取消支付");
  381. } else {
  382. uni.hideLoading();
  383. self.btnNo = false;
  384. self.$u.toast("支付失败");
  385. }
  386. }
  387. );
  388. }
  389. if (typeof WeixinJSBridge === "undefined") {
  390. if (document.addEventListener) {
  391. document.addEventListener(
  392. "WeixinJSBridgeReady",
  393. onBridgeReady,
  394. false
  395. );
  396. } else if (document.attachEvent) {
  397. document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
  398. document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
  399. }
  400. } else {
  401. onBridgeReady();
  402. }
  403. },
  404. modalCancel() {
  405. this.showModal = false;
  406. },
  407. modalConfirm() {
  408. if (this.hasPaying) {
  409. uni.navigateTo({
  410. url: "/pages2/order/index?current=0",
  411. });
  412. } else {
  413. if (this.fromCart) {
  414. uni.navigateTo({
  415. url: "/pages4/shopping/shoppingCart",
  416. });
  417. } else {
  418. if (this.shoppingCartList[0].goodsType == 8) {
  419. uni.reLaunch({
  420. url: "/pages/information/index",
  421. });
  422. return;
  423. }
  424. uni.switchTab({
  425. url: "/pages/course/index",
  426. });
  427. }
  428. }
  429. },
  430. getOpenid(code) {
  431. let self = this;
  432. this.$api.wxOpenid({ code: code }).then((res) => {
  433. if (res.data.code == 200) {
  434. self.postOrder();
  435. }
  436. });
  437. },
  438. pay() {
  439. let self = this;
  440. this.btnNo = true;
  441. // #ifdef MP-WEIXIN
  442. uni.login({
  443. provider: "weixin",
  444. success: function (loginRes) {
  445. self.getOpenid(loginRes.code);
  446. },
  447. });
  448. // #endif
  449. // #ifdef H5
  450. // 在首页已经请求过接口/gzh_login 提交code了
  451. this.postOrder();
  452. // #endif
  453. },
  454. radioChange(e) {
  455. // console.log(e);
  456. },
  457. // 选中任一radio时,由radio-group触发
  458. radioGroupChange(e) {
  459. // console.log(e);
  460. },
  461. cMenu(index) {
  462. this.menuIndex = index;
  463. },
  464. change(index) {
  465. this.current = index;
  466. },
  467. },
  468. onReachBottom() {},
  469. computed: {
  470. ...mapGetters(["userInfo", "shoppingCartList", "sac", "config"]),
  471. totalPrice() {
  472. return this.shoppingCartList.reduce(
  473. (a, b) => a + Number(b.standPrice),
  474. 0
  475. );
  476. },
  477. },
  478. components: { ClassTimeTip },
  479. };
  480. </script>
  481. <style>
  482. ::-webkit-scrollbar {
  483. width: 0;
  484. height: 0;
  485. color: transparent;
  486. }
  487. page {
  488. background-color: #eaeef1;
  489. }
  490. </style>
  491. <style lang="scss" scoped>
  492. .txt_left_pay {
  493. display: flex;
  494. align-items: center;
  495. height: 64rpx;
  496. font-size: 24rpx;
  497. color: #666666;
  498. }
  499. .pay_icon {
  500. width: 64rpx;
  501. height: 64rpx;
  502. margin-right: 10rpx;
  503. }
  504. .box3 {
  505. width: 100%;
  506. height: 886rpx;
  507. background: #ffffff;
  508. // border-radius: 16rpx;
  509. margin-top: 16rpx;
  510. padding: 32rpx 32rpx 0rpx 32rpx;
  511. }
  512. .tip {
  513. font-size: 24rpx;
  514. color: #999999;
  515. height: 40rpx;
  516. line-height: 40rpx;
  517. }
  518. .txt_right_sn {
  519. font-size: 30rpx;
  520. font-weight: bold;
  521. color: #666666;
  522. }
  523. .txt_right_price {
  524. font-size: 32rpx;
  525. font-weight: bold;
  526. color: #ff2d55;
  527. }
  528. .txt_left {
  529. font-size: 28rpx;
  530. color: #666666;
  531. }
  532. .txt_right {
  533. text-align: right;
  534. color: #333333;
  535. font-weight: bold;
  536. width: 75%;
  537. }
  538. .list_title {
  539. display: flex;
  540. justify-content: space-between;
  541. }
  542. .list_item {
  543. display: flex;
  544. justify-content: space-between;
  545. height: 110rpx;
  546. align-items: center;
  547. }
  548. .title2 {
  549. font-size: 32rpx;
  550. font-weight: bold;
  551. color: #333333;
  552. // height: 80rpx;
  553. // line-height: 80rpx;
  554. // margin-left: 30rpx;
  555. margin-bottom: 32rpx;
  556. }
  557. .box2 {
  558. width: 100%;
  559. background: #ffffff;
  560. // border-radius: 16rpx;
  561. padding: 32rpx 32rpx 0rpx 32rpx;
  562. .right_con {
  563. width: 450rpx;
  564. }
  565. .priceTag {
  566. font-size: 28rpx;
  567. font-family: PingFang SC;
  568. font-weight: bold;
  569. color: #fc3f3f;
  570. margin-top: 6rpx;
  571. margin-bottom: 10rpx;
  572. }
  573. .info_right {
  574. height: 110rpx;
  575. line-height: 110rpx;
  576. border-top: 1rpx solid #f2f2f2;
  577. }
  578. }
  579. .box1_t2 {
  580. font-size: 24rpx;
  581. color: #999999;
  582. text-align: center;
  583. }
  584. .box1_t1 {
  585. font-size: 30rpx;
  586. font-weight: bold;
  587. color: #333333;
  588. height: 70rpx;
  589. display: flex;
  590. align-items: center;
  591. justify-content: center;
  592. }
  593. .box1 {
  594. width: 100%;
  595. height: 120rpx;
  596. background: #ffffff;
  597. border-radius: 16rpx;
  598. }
  599. .bottomBtn {
  600. position: fixed;
  601. bottom: 0;
  602. width: 100%;
  603. height: 98rpx;
  604. background: linear-gradient(0deg, #015eea, #00c0fa);
  605. color: #ffffff;
  606. text-align: center;
  607. line-height: 98rpx;
  608. font-weight: bold;
  609. font-size: 30rpx;
  610. border-radius: 0;
  611. }
  612. .bottomBox {
  613. position: fixed;
  614. bottom: 0;
  615. width: 100%;
  616. left: 0;
  617. height: 132rpx;
  618. background-color: #ffffff;
  619. display: flex;
  620. justify-content: space-between;
  621. align-items: center;
  622. box-sizing: unset;
  623. box-shadow: 0px -2px 6px 0px rgba(0, 0, 0, 0.1);
  624. > view {
  625. margin: 0 30rpx;
  626. }
  627. .sums {
  628. display: flex;
  629. }
  630. .all_sum {
  631. font-size: 28rpx;
  632. font-weight: 500;
  633. color: #303030;
  634. }
  635. .priceTag {
  636. font-size: 32rpx;
  637. font-weight: 800;
  638. color: #fc3f3f;
  639. }
  640. .btn2 {
  641. width: 232rpx;
  642. height: 92rpx;
  643. background: #fc3f3f;
  644. border-radius: 120rpx;
  645. text-align: center;
  646. line-height: 92rpx;
  647. color: #fff;
  648. }
  649. }
  650. </style>