confirm_pay.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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 v-for="(item,index) in shoppingCartList" :key="index" style="display: flex;justify-content: space-between; margin-bottom: 32rpx;">
  19. <image :src="$method.splitImgHost(item.coverUrl)" style="height: 120rpx;width: 204rpx;border-radius: 16rpx;"></image>
  20. <view class="right_con" style="margin-left: 20rpx;">
  21. <view style="color: #333333;font-size: 30rpx;font-weight: bold;">
  22. {{item.goodsName}}
  23. </view>
  24. <view class="priceTag">
  25. ¥ {{item.standPrice}}
  26. </view>
  27. </view>
  28. </view>
  29. <view class="info_right" >
  30. <!-- <u-line color="#D6D6DB" /> -->
  31. <view class="list_item">
  32. <view class="txt_left">应付总金额</view>
  33. <view class="txt_right_price">¥ {{totalPrice}}</view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="box3">
  38. <view class="title2">支付方式</view>
  39. <view>
  40. <u-radio-group v-model="value" @change="radioGroupChange">
  41. <view class="list_item">
  42. <view class="txt_left_pay"><image src="/static/wepay.png" class="pay_icon"></image>微信支付</view>
  43. <view ><u-radio @change="radioChange" name="wepay"></u-radio></view>
  44. </view>
  45. <view class="list_item" v-if="false">
  46. <view class="txt_left_pay"><image src="/static/unipay.png" class="pay_icon"></image>云闪付</view>
  47. <view ><u-radio @change="radioChange" name="unipay"></u-radio></view>
  48. </view>
  49. </u-radio-group>
  50. </view>
  51. <u-line color="#D6D6DB" />
  52. </view>
  53. </view>
  54. </view>
  55. <view class="bottomBox safeArea">
  56. <view class="sums">
  57. <text class="all_sum">总金额:</text>
  58. <text class="priceTag">¥ {{totalPrice}}</text>
  59. </view>
  60. <view style="display: flex;color: #FFFFFF;align-items: center;">
  61. <!-- <view class="btn2" @click="pay()">确认支付</view> -->
  62. <button class="btn2" @click="pay()" :disabled="btnNo">确认支付</button>
  63. </view>
  64. </view>
  65. <!-- <button class="bottomBtn" @click="pay()" :disabled="btnNo">确认支付</button> -->
  66. <u-modal v-model="showModal" :confirm-text="confirmText" cancel-text="知道了" cancel-color="#666666" confirm-color="rgba(0, 122, 255, 1);" :show-confirm-button="showConfirmButton" :show-cancel-button="true" :content="modalMsg" @cancel="modalCancel()" @confirm="modalConfirm()" ref="uModal" ></u-modal>
  67. </view>
  68. </template>
  69. <script>
  70. import { mapGetters } from 'vuex';
  71. export default {
  72. components: {
  73. },
  74. data() {
  75. return {
  76. showModal:false,
  77. modalMsg:'',
  78. list:[
  79. {
  80. name: '网课'
  81. },
  82. {
  83. name: '题库通'
  84. }
  85. ],
  86. array:['全部','建设工程施工管理','机电全科','机电工程管理与实','机电全科','全科'],
  87. current:0,
  88. menuIndex:0,
  89. value:'wepay',
  90. btnNo:false,
  91. isBK:'',
  92. fromCart:'',
  93. hasPaying:false,
  94. showConfirmButton:false,
  95. totalPrice:0,
  96. confirmText:''
  97. };
  98. },
  99. onPullDownRefresh(){
  100. },
  101. onLoad(option) {
  102. let self = this
  103. this.fromCart = option.fromCart;
  104. console.log(self.shoppingCartList,6)
  105. let list = self.shoppingCartList
  106. this.isBK = option.isBK
  107. for(let i=0;i<list.length;i++){
  108. this.totalPrice+=Number(list[i].standPrice)
  109. }
  110. console.log(this.isBK == '1')
  111. },
  112. onShow() {
  113. },
  114. methods: {
  115. postOrder(){
  116. let list = this.shoppingCartList
  117. for(let i=0;i<list.length;i++){
  118. let item = list[i];
  119. if(item.goodsType==1){
  120. if(item.templateType=='class'){
  121. delete item.gradObj.goodsList
  122. let goodsInputData = {
  123. type:'class',
  124. gradeId:item.gradObj.gradeId,
  125. gradeJson:JSON.stringify(item.gradObj)
  126. }
  127. item.goodsInputData = goodsInputData
  128. }
  129. if(item.templateType=='apply'){
  130. let goodsInputData = {
  131. type:'apply',
  132. applyAreasJson:JSON.stringify(item.applyAreas),
  133. examDateJson:JSON.stringify(item.examDate)
  134. }
  135. item.goodsInputData = goodsInputData
  136. }
  137. }
  138. }
  139. let data = {goodsList:list}
  140. // #ifdef MP-WEIXIN
  141. this.$api.placeSmallOrder(data).then(res => {
  142. console.log(res,'res')
  143. this.orderResult(res)
  144. });
  145. // #endif
  146. // #ifdef H5
  147. data['url'] = location.href
  148. this.$api.placeGzhOrder(data).then(res => {
  149. console.log(res,'res')
  150. this.orderResult(res)
  151. });
  152. // #endif
  153. },
  154. orderResult(res) {
  155. if(res.data.code==200){
  156. uni.setStorageSync('updateCart',1) //提醒刷新购物车
  157. if(this.totalPrice == 0) { //免费商品
  158. uni.redirectTo({
  159. url: `/pages2/order/confirm_success?sn=${res.data.data.orderSn}&isBk=${this.isBK}`
  160. });
  161. } else {
  162. let data = res.data.data
  163. uni.showLoading({
  164. title:'支付中',
  165. mask:true,
  166. })
  167. // #ifdef MP-WEIXIN
  168. uni.requestPayment({
  169. provider: data.provider,
  170. nonceStr: data.nonceStr,
  171. package: data.package,
  172. signType: data.signType,
  173. paySign: data.sign,
  174. timeStamp: String(data.timeStamp),
  175. success: (res) => {
  176. uni.hideLoading()
  177. this.btnNo = false
  178. uni.redirectTo({
  179. url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${this.isBK}`
  180. });
  181. console.log('success:' + JSON.stringify(res));
  182. },
  183. fail: (err) => {
  184. uni.hideLoading()
  185. this.btnNo = false
  186. console.log('fail:' + JSON.stringify(err));
  187. }
  188. });
  189. // #endif
  190. // #ifdef H5
  191. this.h5_wxpay(data)
  192. // #endif
  193. }
  194. }else if(res.data.code == 510){ //有未支付订单
  195. this.hasPaying = true;
  196. this.btnNo = false
  197. this.modalMsg = res.data.msg;
  198. this.showConfirmButton = true;
  199. this.confirmText = "跳转到【我的订单】\n查看未支付订单";
  200. this.showModal = true;
  201. } else if(res.data.code == 511) { //511 重复购买
  202. this.hasPaying = false;
  203. this.btnNo = false
  204. this.modalMsg = res.data.msg;
  205. this.showConfirmButton = true;
  206. this.showModal = true;
  207. if(this.fromCart) {
  208. console.log(this.fromCart)
  209. this.confirmText = "返回购物车";
  210. } else {
  211. let type = '';
  212. if(this.shoppingCartList.length == 1) {
  213. type = this.shoppingCartList[0].goodsType
  214. } else {
  215. type = this.shoppingCartList[0].goodsType;
  216. if(this.shoppingCartList.find(item => item.goodsType != type)) {
  217. type = 3;
  218. }
  219. }
  220. this.confirmText = (type == 1 || type == 6) ? "继续选课" : type == 2 ? "继续选题" : type == 3 ? "继续选购" :"";
  221. }
  222. } else {
  223. this.hasPaying = false;
  224. this.btnNo = false
  225. this.showConfirmButton = false;
  226. this.modalMsg = res.data.msg;
  227. this.showModal = true;
  228. }
  229. },
  230. h5_wxpay(data) {
  231. function onBridgeReady() {
  232. // 加载框
  233. WeixinJSBridge.invoke(
  234. 'getBrandWCPayRequest', {
  235. 'appId': data.appId, // 公众号名称,由商户传入
  236. 'timeStamp': data.timeStamp, // 时间戳,自1970年以来的秒数
  237. 'nonceStr': data.nonceStr, // 随机串
  238. 'package': data.package,
  239. 'signType': data.signType, // 微信签名方式:
  240. 'paySign': data.paySign // 微信签名
  241. },
  242. function(res) {
  243. // 判断支付状态
  244. console.log('支付状态',res)
  245. if (res.err_msg === 'get_brand_wcpay_request:ok') {
  246. this.$u.toast('支付成功')
  247. uni.hideLoading()
  248. this.btnNo = false
  249. uni.redirectTo({
  250. url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${this.isBK}`
  251. });
  252. } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
  253. this.$u.toast('取消支付')
  254. } else {
  255. uni.hideLoading()
  256. this.btnNo = false
  257. this.$u.toast('支付失败')
  258. }
  259. }
  260. )
  261. }
  262. if (typeof WeixinJSBridge === 'undefined') {
  263. if (document.addEventListener) {
  264. document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
  265. } else if (document.attachEvent) {
  266. document.attachEvent('WeixinJSBridgeReady', onBridgeReady)
  267. document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
  268. }
  269. } else {
  270. onBridgeReady()
  271. }
  272. },
  273. modalCancel() {
  274. this.showModal = false;
  275. },
  276. modalConfirm() {
  277. if(this.hasPaying) {
  278. uni.navigateTo({
  279. url:'/pages2/order/index?current=0'
  280. })
  281. } else {
  282. if(this.fromCart) {
  283. uni.navigateTo({
  284. url:'/pages4/shopping/shoppingCart'
  285. })
  286. } else {
  287. uni.switchTab({
  288. url:'/pages/course/index'
  289. })
  290. }
  291. }
  292. },
  293. getOpenid(code){
  294. let self = this
  295. this.$api.wxOpenid({code:code}).then(res => {
  296. if(res.data.code==200){
  297. self.postOrder()
  298. }
  299. });
  300. },
  301. pay(){
  302. let self = this
  303. this.btnNo = true
  304. // #ifdef MP-WEIXIN
  305. uni.login({
  306. provider: 'weixin',
  307. success: function(loginRes) {
  308. console.log(loginRes,69)
  309. self.getOpenid(loginRes.code)
  310. }
  311. });
  312. // #endif
  313. // #ifdef H5
  314. // 在首页已经请求过接口/gzh_login 提交code了
  315. this.postOrder()
  316. // #endif
  317. },
  318. radioChange(e) {
  319. // console.log(e);
  320. },
  321. // 选中任一radio时,由radio-group触发
  322. radioGroupChange(e) {
  323. // console.log(e);
  324. },
  325. cMenu(index){
  326. this.menuIndex = index;
  327. },
  328. change(index){
  329. this.current = index;
  330. }
  331. },
  332. onReachBottom() {},
  333. computed: { ...mapGetters(['userInfo','shoppingCartList']) }
  334. };
  335. </script>
  336. <style >
  337. ::-webkit-scrollbar{
  338. width: 0;
  339. height: 0;
  340. color: transparent
  341. }
  342. page{
  343. background-color: #EAEEF1;
  344. }
  345. </style>
  346. <style lang="scss" scoped>
  347. .txt_left_pay{
  348. display: flex;
  349. align-items: center;
  350. height: 64rpx;
  351. font-size: 24rpx;
  352. color: #666666;
  353. }
  354. .pay_icon{
  355. width: 64rpx;
  356. height: 64rpx;
  357. margin-right: 10rpx;
  358. }
  359. .box3{
  360. width: 100%;
  361. height: 886rpx;
  362. background: #FFFFFF;
  363. // border-radius: 16rpx;
  364. margin-top: 16rpx;
  365. padding: 32rpx 32rpx 0rpx 32rpx;
  366. }
  367. .tip{
  368. font-size: 24rpx;
  369. color: #999999;
  370. height: 40rpx;
  371. line-height: 40rpx;
  372. }
  373. .txt_right_sn{
  374. font-size: 30rpx;
  375. font-weight: bold;
  376. color: #666666;
  377. }
  378. .txt_right_price{
  379. font-size: 32rpx;
  380. font-weight: bold;
  381. color: #FF2D55;
  382. }
  383. .txt_left{
  384. font-size: 28rpx;
  385. color: #666666;
  386. }
  387. .txt_right{
  388. text-align: right;
  389. color: #333333;
  390. font-weight: bold;
  391. width: 75%;
  392. }
  393. .list_title {
  394. display: flex;
  395. justify-content: space-between;
  396. }
  397. .list_item{
  398. display: flex;
  399. justify-content: space-between;
  400. height: 110rpx;
  401. align-items: center;
  402. }
  403. .title2{
  404. font-size: 32rpx;
  405. font-weight: bold;
  406. color: #333333;
  407. // height: 80rpx;
  408. // line-height: 80rpx;
  409. // margin-left: 30rpx;
  410. margin-bottom: 32rpx;
  411. }
  412. .box2{
  413. width: 100%;
  414. background: #FFFFFF;
  415. // border-radius: 16rpx;
  416. padding: 32rpx 32rpx 0rpx 32rpx;
  417. .right_con {
  418. width: 450rpx;
  419. }
  420. .priceTag{
  421. font-size: 28rpx;
  422. font-family: PingFang SC;
  423. font-weight: bold;
  424. color: #FC3F3F;
  425. margin-top: 6rpx;
  426. margin-bottom: 16rpx;
  427. }
  428. .info_right {
  429. height: 110rpx;
  430. line-height: 110rpx;
  431. border-top: 1rpx solid #F2F2F2;
  432. }
  433. }
  434. .box1_t2{
  435. font-size: 24rpx;
  436. color: #999999;
  437. text-align: center;
  438. }
  439. .box1_t1{
  440. font-size: 30rpx;
  441. font-weight: bold;
  442. color: #333333;
  443. height: 70rpx;
  444. display: flex;
  445. align-items: center;
  446. justify-content: center;
  447. }
  448. .box1{
  449. width: 100%;
  450. height: 120rpx;
  451. background: #FFFFFF;
  452. border-radius: 16rpx;
  453. }
  454. .bottomBtn{
  455. position: fixed;
  456. bottom: 0;
  457. width: 100%;
  458. height: 98rpx;
  459. background: linear-gradient(0deg, #015EEA, #00C0FA);
  460. color: #FFFFFF;
  461. text-align: center;
  462. line-height: 98rpx;
  463. font-weight: bold;
  464. font-size: 30rpx;
  465. border-radius: 0;
  466. }
  467. .bottomBox{
  468. position: fixed;
  469. bottom: 0;
  470. width: 100%;
  471. left: 0;
  472. height: 132rpx ;
  473. background-color: #FFFFFF;
  474. display: flex;
  475. justify-content: space-between;
  476. align-items: center;
  477. box-sizing: unset;
  478. box-shadow: 0px -2px 6px 0px rgba(0,0,0,0.1000);
  479. >view{
  480. margin: 0 30rpx;
  481. }
  482. .sums {
  483. display: flex;
  484. }
  485. .all_sum {
  486. font-size: 28rpx;
  487. font-weight: 500;
  488. color: #303030;
  489. }
  490. .priceTag {
  491. font-size: 32rpx;
  492. font-weight: 800;
  493. color: #FC3F3F;
  494. }
  495. .btn2{
  496. width: 232rpx;
  497. height: 92rpx;
  498. background: #FC3F3F;
  499. border-radius: 120rpx;
  500. text-align: center;
  501. line-height: 92rpx;
  502. color: #fff;
  503. }
  504. }
  505. </style>