confirm_pay.vue 19 KB

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