confirm_pay.vue 15 KB

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