confirm_pay.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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
  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. uni.switchTab({
  394. url: "/pages/course/index",
  395. });
  396. }
  397. }
  398. },
  399. getOpenid(code) {
  400. let self = this;
  401. this.$api.wxOpenid({ code: code }).then((res) => {
  402. if (res.data.code == 200) {
  403. self.postOrder();
  404. }
  405. });
  406. },
  407. pay() {
  408. let self = this;
  409. this.btnNo = true;
  410. // #ifdef MP-WEIXIN
  411. uni.login({
  412. provider: "weixin",
  413. success: function (loginRes) {
  414. console.log(loginRes, 69);
  415. self.getOpenid(loginRes.code);
  416. },
  417. });
  418. // #endif
  419. // #ifdef H5
  420. // 在首页已经请求过接口/gzh_login 提交code了
  421. this.postOrder();
  422. // #endif
  423. },
  424. radioChange(e) {
  425. // console.log(e);
  426. },
  427. // 选中任一radio时,由radio-group触发
  428. radioGroupChange(e) {
  429. // console.log(e);
  430. },
  431. cMenu(index) {
  432. this.menuIndex = index;
  433. },
  434. change(index) {
  435. this.current = index;
  436. },
  437. },
  438. onReachBottom() {},
  439. computed: {
  440. ...mapGetters(["userInfo", "shoppingCartList", "sac", "config"]),
  441. totalPrice() {
  442. return this.shoppingCartList.reduce(
  443. (a, b) => a + Number(b.standPrice),
  444. 0
  445. );
  446. },
  447. },
  448. components: { ClassTimeTip },
  449. };
  450. </script>
  451. <style>
  452. ::-webkit-scrollbar {
  453. width: 0;
  454. height: 0;
  455. color: transparent;
  456. }
  457. page {
  458. background-color: #eaeef1;
  459. }
  460. </style>
  461. <style lang="scss" scoped>
  462. .txt_left_pay {
  463. display: flex;
  464. align-items: center;
  465. height: 64rpx;
  466. font-size: 24rpx;
  467. color: #666666;
  468. }
  469. .pay_icon {
  470. width: 64rpx;
  471. height: 64rpx;
  472. margin-right: 10rpx;
  473. }
  474. .box3 {
  475. width: 100%;
  476. height: 886rpx;
  477. background: #ffffff;
  478. // border-radius: 16rpx;
  479. margin-top: 16rpx;
  480. padding: 32rpx 32rpx 0rpx 32rpx;
  481. }
  482. .tip {
  483. font-size: 24rpx;
  484. color: #999999;
  485. height: 40rpx;
  486. line-height: 40rpx;
  487. }
  488. .txt_right_sn {
  489. font-size: 30rpx;
  490. font-weight: bold;
  491. color: #666666;
  492. }
  493. .txt_right_price {
  494. font-size: 32rpx;
  495. font-weight: bold;
  496. color: #ff2d55;
  497. }
  498. .txt_left {
  499. font-size: 28rpx;
  500. color: #666666;
  501. }
  502. .txt_right {
  503. text-align: right;
  504. color: #333333;
  505. font-weight: bold;
  506. width: 75%;
  507. }
  508. .list_title {
  509. display: flex;
  510. justify-content: space-between;
  511. }
  512. .list_item {
  513. display: flex;
  514. justify-content: space-between;
  515. height: 110rpx;
  516. align-items: center;
  517. }
  518. .title2 {
  519. font-size: 32rpx;
  520. font-weight: bold;
  521. color: #333333;
  522. // height: 80rpx;
  523. // line-height: 80rpx;
  524. // margin-left: 30rpx;
  525. margin-bottom: 32rpx;
  526. }
  527. .box2 {
  528. width: 100%;
  529. background: #ffffff;
  530. // border-radius: 16rpx;
  531. padding: 32rpx 32rpx 0rpx 32rpx;
  532. .right_con {
  533. width: 450rpx;
  534. }
  535. .priceTag {
  536. font-size: 28rpx;
  537. font-family: PingFang SC;
  538. font-weight: bold;
  539. color: #fc3f3f;
  540. margin-top: 6rpx;
  541. margin-bottom: 10rpx;
  542. }
  543. .info_right {
  544. height: 110rpx;
  545. line-height: 110rpx;
  546. border-top: 1rpx solid #f2f2f2;
  547. }
  548. }
  549. .box1_t2 {
  550. font-size: 24rpx;
  551. color: #999999;
  552. text-align: center;
  553. }
  554. .box1_t1 {
  555. font-size: 30rpx;
  556. font-weight: bold;
  557. color: #333333;
  558. height: 70rpx;
  559. display: flex;
  560. align-items: center;
  561. justify-content: center;
  562. }
  563. .box1 {
  564. width: 100%;
  565. height: 120rpx;
  566. background: #ffffff;
  567. border-radius: 16rpx;
  568. }
  569. .bottomBtn {
  570. position: fixed;
  571. bottom: 0;
  572. width: 100%;
  573. height: 98rpx;
  574. background: linear-gradient(0deg, #015eea, #00c0fa);
  575. color: #ffffff;
  576. text-align: center;
  577. line-height: 98rpx;
  578. font-weight: bold;
  579. font-size: 30rpx;
  580. border-radius: 0;
  581. }
  582. .bottomBox {
  583. position: fixed;
  584. bottom: 0;
  585. width: 100%;
  586. left: 0;
  587. height: 132rpx;
  588. background-color: #ffffff;
  589. display: flex;
  590. justify-content: space-between;
  591. align-items: center;
  592. box-sizing: unset;
  593. box-shadow: 0px -2px 6px 0px rgba(0, 0, 0, 0.1);
  594. > view {
  595. margin: 0 30rpx;
  596. }
  597. .sums {
  598. display: flex;
  599. }
  600. .all_sum {
  601. font-size: 28rpx;
  602. font-weight: 500;
  603. color: #303030;
  604. }
  605. .priceTag {
  606. font-size: 32rpx;
  607. font-weight: 800;
  608. color: #fc3f3f;
  609. }
  610. .btn2 {
  611. width: 232rpx;
  612. height: 92rpx;
  613. background: #fc3f3f;
  614. border-radius: 120rpx;
  615. text-align: center;
  616. line-height: 92rpx;
  617. color: #fff;
  618. }
  619. }
  620. </style>