confirm_pay.vue 17 KB

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