confirm_pay.vue 16 KB

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