confirm_pay.vue 16 KB

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