confirm_pay.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. // 二建 && 七大员 需要先完善信息
  197. async checkNeedInfo() {
  198. let keys = [];
  199. this.shoppingCartList.forEach((item) => {
  200. if (item.erJianErZao) {
  201. keys.push("realname", "idCard");
  202. }
  203. if (item.jjShiGongYuan) {
  204. keys.push("realname", "idCard", "sex", "companyName", "eduLevel");
  205. }
  206. });
  207. if (keys.length) {
  208. if (!this.userInfo) await this.getUserInfo();
  209. if (keys.some((key) => !this.userInfo[key])) {
  210. uni.showModal({
  211. title: "提示",
  212. content: "请先完善个人信息!",
  213. success: (res) => {
  214. if (res.confirm) {
  215. uni.navigateTo({
  216. url:
  217. "/pages2/verify/info_fill?keys=" +
  218. Array.from(new Set(keys)).toString(),
  219. });
  220. }
  221. },
  222. });
  223. return false;
  224. }
  225. }
  226. return true;
  227. },
  228. async postOrder() {
  229. let list = this.shoppingCartList;
  230. for (let i = 0; i < list.length; i++) {
  231. let item = list[i];
  232. if (item.goodsType == 1) {
  233. if (item.templateType == "class") {
  234. delete item.gradObj.goodsList;
  235. let goodsInputData = {
  236. type: "class",
  237. gradeId: item.gradObj.gradeId,
  238. gradeJson: JSON.stringify(item.gradObj),
  239. };
  240. item.goodsInputData = goodsInputData;
  241. }
  242. if (item.templateType == "apply") {
  243. let goodsInputData = {
  244. type: "apply",
  245. applyAreasJson: JSON.stringify(item.applyAreas),
  246. examDateJson: JSON.stringify(item.examDate),
  247. };
  248. item.goodsInputData = goodsInputData;
  249. }
  250. }
  251. if (this.options.distributionCode) {
  252. item.distributionLinkCode = this.options.linkCode;
  253. item.distributionCode = this.options.distributionCode;
  254. }
  255. }
  256. let data = { goodsList: list };
  257. // 邀请码
  258. if (this.sac) {
  259. data["shareActivityCode"] = this.sac;
  260. }
  261. // #ifdef MP-WEIXIN
  262. this.$api.placeSmallOrder(data).then((res) => {
  263. this.orderResult(res);
  264. });
  265. // #endif
  266. // #ifdef H5
  267. data["url"] = location.href;
  268. this.$api.placeGzhOrder(data).then((res) => {
  269. console.log(res, "h5支付res");
  270. this.orderResult(res);
  271. });
  272. // #endif
  273. },
  274. orderResult(res) {
  275. if (res.data.code == 200) {
  276. uni.setStorageSync("updateCart", 1); //提醒刷新购物车
  277. if (this.totalPrice == 0) {
  278. //免费商品
  279. uni.redirectTo({
  280. url: `/pages2/order/confirm_success?sn=${res.data.data.orderSn}&isBk=${this.isBK}`,
  281. });
  282. } else {
  283. let data = res.data.data;
  284. uni.showLoading({
  285. title: "支付中",
  286. mask: true,
  287. });
  288. // #ifdef MP-WEIXIN
  289. uni.requestPayment({
  290. provider: data.provider,
  291. nonceStr: data.nonceStr,
  292. package: data.package,
  293. signType: data.signType,
  294. paySign: data.sign,
  295. timeStamp: String(data.timeStamp),
  296. success: (res) => {
  297. uni.hideLoading();
  298. this.btnNo = false;
  299. uni.redirectTo({
  300. url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${this.isBK}`,
  301. });
  302. console.log("success:" + JSON.stringify(res));
  303. },
  304. fail: (err) => {
  305. uni.hideLoading();
  306. this.btnNo = false;
  307. console.log("fail:" + JSON.stringify(err));
  308. },
  309. });
  310. // #endif
  311. // #ifdef H5
  312. this.h5_wxpay(data);
  313. // #endif
  314. }
  315. } else if (res.data.code == 510) {
  316. //有未支付订单
  317. this.hasPaying = true;
  318. this.btnNo = false;
  319. this.modalMsg = res.data.msg;
  320. this.showConfirmButton = true;
  321. this.confirmText = "跳转到【我的订单】\n查看未支付订单";
  322. this.showModal = true;
  323. } else if (res.data.code == 511) {
  324. //511 重复购买
  325. this.hasPaying = false;
  326. this.btnNo = false;
  327. this.modalMsg = res.data.msg;
  328. this.showConfirmButton = true;
  329. this.showModal = true;
  330. if (this.fromCart) {
  331. console.log(this.fromCart);
  332. this.confirmText = "返回购物车";
  333. } else {
  334. let type = "";
  335. if (this.shoppingCartList.length == 1) {
  336. type = this.shoppingCartList[0].goodsType;
  337. } else {
  338. type = this.shoppingCartList[0].goodsType;
  339. if (this.shoppingCartList.find((item) => item.goodsType != type)) {
  340. type = 3;
  341. }
  342. }
  343. this.confirmText =
  344. type == 1 || type == 6
  345. ? "继续选课"
  346. : type == 2
  347. ? "继续选题"
  348. : type == 3 || type == 8
  349. ? "继续选购"
  350. : "";
  351. }
  352. } else {
  353. this.hasPaying = false;
  354. this.btnNo = false;
  355. this.showConfirmButton = false;
  356. this.modalMsg = res.data.msg;
  357. this.showModal = true;
  358. }
  359. },
  360. h5_wxpay(data) {
  361. console.log("====调起支付状态", data);
  362. let self = this;
  363. function onBridgeReady() {
  364. // 加载框
  365. WeixinJSBridge.invoke(
  366. "getBrandWCPayRequest",
  367. {
  368. appId: data.appId, // 公众号名称,由商户传入
  369. timeStamp: data.timeStamp, // 时间戳,自1970年以来的秒数
  370. nonceStr: data.nonceStr, // 随机串
  371. package: data.package,
  372. signType: data.signType, // 微信签名方式:
  373. paySign: data.paySign, // 微信签名
  374. },
  375. function (res) {
  376. // 判断支付状态
  377. console.log("支付状态", res, "this:", this, self);
  378. if (res.err_msg === "get_brand_wcpay_request:ok") {
  379. self.$u.toast("支付成功");
  380. uni.hideLoading();
  381. self.btnNo = false;
  382. uni.redirectTo({
  383. url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${self.isBK}`,
  384. });
  385. } else if (res.err_msg === "get_brand_wcpay_request:cancel") {
  386. self.$u.toast("取消支付");
  387. } else {
  388. uni.hideLoading();
  389. self.btnNo = false;
  390. self.$u.toast("支付失败");
  391. }
  392. }
  393. );
  394. }
  395. if (typeof WeixinJSBridge === "undefined") {
  396. if (document.addEventListener) {
  397. document.addEventListener(
  398. "WeixinJSBridgeReady",
  399. onBridgeReady,
  400. false
  401. );
  402. } else if (document.attachEvent) {
  403. document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
  404. document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
  405. }
  406. } else {
  407. onBridgeReady();
  408. }
  409. },
  410. modalCancel() {
  411. this.showModal = false;
  412. },
  413. modalConfirm() {
  414. if (this.hasPaying) {
  415. uni.navigateTo({
  416. url: "/pages2/order/index?current=0",
  417. });
  418. } else {
  419. if (this.fromCart) {
  420. uni.navigateTo({
  421. url: "/pages4/shopping/shoppingCart",
  422. });
  423. } else {
  424. if (this.shoppingCartList[0].goodsType == 8) {
  425. uni.reLaunch({
  426. url: "/pages/information/index",
  427. });
  428. return;
  429. }
  430. uni.switchTab({
  431. url: "/pages/course/index",
  432. });
  433. }
  434. }
  435. },
  436. getOpenid(code) {
  437. let self = this;
  438. this.$api.wxOpenid({ code: code }).then((res) => {
  439. if (res.data.code == 200) {
  440. self.postOrder();
  441. }
  442. });
  443. },
  444. async pay() {
  445. if (!(await this.checkNeedInfo())) {
  446. return;
  447. }
  448. let self = this;
  449. this.btnNo = true;
  450. // #ifdef MP-WEIXIN
  451. uni.login({
  452. provider: "weixin",
  453. success: function (loginRes) {
  454. self.getOpenid(loginRes.code);
  455. },
  456. });
  457. // #endif
  458. // #ifdef H5
  459. // 在首页已经请求过接口/gzh_login 提交code了
  460. this.postOrder();
  461. // #endif
  462. },
  463. radioChange(e) {
  464. // console.log(e);
  465. },
  466. // 选中任一radio时,由radio-group触发
  467. radioGroupChange(e) {
  468. // console.log(e);
  469. },
  470. cMenu(index) {
  471. this.menuIndex = index;
  472. },
  473. change(index) {
  474. this.current = index;
  475. },
  476. },
  477. onReachBottom() {},
  478. computed: {
  479. ...mapGetters(["userInfo", "shoppingCartList", "sac", "config"]),
  480. totalPrice() {
  481. return this.shoppingCartList.reduce(
  482. (a, b) => a + Number(b.standPrice),
  483. 0
  484. );
  485. },
  486. },
  487. components: { ClassTimeTip },
  488. };
  489. </script>
  490. <style>
  491. ::-webkit-scrollbar {
  492. width: 0;
  493. height: 0;
  494. color: transparent;
  495. }
  496. page {
  497. background-color: #eaeef1;
  498. }
  499. </style>
  500. <style lang="scss" scoped>
  501. .txt_left_pay {
  502. display: flex;
  503. align-items: center;
  504. height: 64rpx;
  505. font-size: 24rpx;
  506. color: #666666;
  507. }
  508. .pay_icon {
  509. width: 64rpx;
  510. height: 64rpx;
  511. margin-right: 10rpx;
  512. }
  513. .box3 {
  514. width: 100%;
  515. height: 886rpx;
  516. background: #ffffff;
  517. // border-radius: 16rpx;
  518. margin-top: 16rpx;
  519. padding: 32rpx 32rpx 0rpx 32rpx;
  520. }
  521. .tip {
  522. font-size: 24rpx;
  523. color: #999999;
  524. height: 40rpx;
  525. line-height: 40rpx;
  526. }
  527. .txt_right_sn {
  528. font-size: 30rpx;
  529. font-weight: bold;
  530. color: #666666;
  531. }
  532. .txt_right_price {
  533. font-size: 32rpx;
  534. font-weight: bold;
  535. color: #ff2d55;
  536. }
  537. .txt_left {
  538. font-size: 28rpx;
  539. color: #666666;
  540. }
  541. .txt_right {
  542. text-align: right;
  543. color: #333333;
  544. font-weight: bold;
  545. width: 75%;
  546. }
  547. .list_title {
  548. display: flex;
  549. justify-content: space-between;
  550. }
  551. .list_item {
  552. display: flex;
  553. justify-content: space-between;
  554. height: 110rpx;
  555. align-items: center;
  556. }
  557. .title2 {
  558. font-size: 32rpx;
  559. font-weight: bold;
  560. color: #333333;
  561. // height: 80rpx;
  562. // line-height: 80rpx;
  563. // margin-left: 30rpx;
  564. margin-bottom: 32rpx;
  565. }
  566. .box2 {
  567. width: 100%;
  568. background: #ffffff;
  569. // border-radius: 16rpx;
  570. padding: 32rpx 32rpx 0rpx 32rpx;
  571. .right_con {
  572. width: 450rpx;
  573. }
  574. .priceTag {
  575. font-size: 28rpx;
  576. font-family: PingFang SC;
  577. font-weight: bold;
  578. color: #fc3f3f;
  579. margin-top: 6rpx;
  580. margin-bottom: 10rpx;
  581. }
  582. .info_right {
  583. height: 110rpx;
  584. line-height: 110rpx;
  585. border-top: 1rpx solid #f2f2f2;
  586. }
  587. }
  588. .box1_t2 {
  589. font-size: 24rpx;
  590. color: #999999;
  591. text-align: center;
  592. }
  593. .box1_t1 {
  594. font-size: 30rpx;
  595. font-weight: bold;
  596. color: #333333;
  597. height: 70rpx;
  598. display: flex;
  599. align-items: center;
  600. justify-content: center;
  601. }
  602. .box1 {
  603. width: 100%;
  604. height: 120rpx;
  605. background: #ffffff;
  606. border-radius: 16rpx;
  607. }
  608. .bottomBtn {
  609. position: fixed;
  610. bottom: 0;
  611. width: 100%;
  612. height: 98rpx;
  613. background: linear-gradient(0deg, #015eea, #00c0fa);
  614. color: #ffffff;
  615. text-align: center;
  616. line-height: 98rpx;
  617. font-weight: bold;
  618. font-size: 30rpx;
  619. border-radius: 0;
  620. }
  621. .bottomBox {
  622. position: fixed;
  623. bottom: 0;
  624. width: 100%;
  625. left: 0;
  626. height: 132rpx;
  627. background-color: #ffffff;
  628. display: flex;
  629. justify-content: space-between;
  630. align-items: center;
  631. box-sizing: unset;
  632. box-shadow: 0px -2px 6px 0px rgba(0, 0, 0, 0.1);
  633. > view {
  634. margin: 0 30rpx;
  635. }
  636. .sums {
  637. display: flex;
  638. }
  639. .all_sum {
  640. font-size: 28rpx;
  641. font-weight: 500;
  642. color: #303030;
  643. }
  644. .priceTag {
  645. font-size: 32rpx;
  646. font-weight: 800;
  647. color: #fc3f3f;
  648. }
  649. .btn2 {
  650. width: 232rpx;
  651. height: 92rpx;
  652. background: #fc3f3f;
  653. border-radius: 120rpx;
  654. text-align: center;
  655. line-height: 92rpx;
  656. color: #fff;
  657. }
  658. }
  659. </style>