confirm_pay.vue 17 KB

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