confirm_pay.vue 15 KB

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