confirm_pay.vue 17 KB

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