confirm_pay.vue 15 KB

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