confirm_pay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 self = this
  117. let list = self.shoppingCartList
  118. for(let i=0;i<list.length;i++){
  119. let item = list[i];
  120. if(item.goodsType==1){
  121. if(item.templateType=='class'){
  122. delete item.gradObj.goodsList
  123. let goodsInputData = {
  124. type:'class',
  125. gradeId:item.gradObj.gradeId,
  126. gradeJson:JSON.stringify(item.gradObj)
  127. }
  128. item.goodsInputData = goodsInputData
  129. }
  130. if(item.templateType=='apply'){
  131. let goodsInputData = {
  132. type:'apply',
  133. applyAreasJson:JSON.stringify(item.applyAreas),
  134. examDateJson:JSON.stringify(item.examDate)
  135. }
  136. item.goodsInputData = goodsInputData
  137. }
  138. }
  139. }
  140. let data = {goodsList:list}
  141. this.$api.placeSmallOrder(data).then(res => {
  142. console.log(res,'res')
  143. if(res.data.code==200){
  144. uni.setStorageSync('updateCart',1) //提醒刷新购物车
  145. if(this.totalPrice == 0) { //免费商品
  146. uni.redirectTo({
  147. url: `/pages2/order/confirm_success?sn=${res.data.data.orderSn}&isBk=${self.isBK}`
  148. });
  149. } else {
  150. let data = res.data.data
  151. uni.showLoading({
  152. title:'支付中',
  153. mask:true,
  154. })
  155. uni.requestPayment({
  156. provider: data.provider,
  157. nonceStr: data.nonceStr,
  158. package: data.package,
  159. signType: data.signType,
  160. paySign: data.sign,
  161. timeStamp: String(data.timeStamp),
  162. success: function (res) {
  163. uni.hideLoading()
  164. self.btnNo = false
  165. uni.redirectTo({
  166. url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${self.isBK}`
  167. });
  168. console.log('success:' + JSON.stringify(res));
  169. },
  170. fail: function (err) {
  171. uni.hideLoading()
  172. self.btnNo = false
  173. console.log('fail:' + JSON.stringify(err));
  174. }
  175. });
  176. }
  177. }else if(res.data.code == 510){ //有未支付订单
  178. self.hasPaying = true;
  179. self.btnNo = false
  180. this.modalMsg = res.data.msg;
  181. this.showConfirmButton = true;
  182. this.confirmText = "跳转到【我的订单】\n查看未支付订单";
  183. this.showModal = true;
  184. } else if(res.data.code == 511) { //511 重复购买
  185. self.hasPaying = false;
  186. self.btnNo = false
  187. this.modalMsg = res.data.msg;
  188. this.showConfirmButton = true;
  189. this.showModal = true;
  190. if(this.fromCart) {
  191. console.log(this.fromCart)
  192. this.confirmText = "返回购物车";
  193. } else {
  194. let type = '';
  195. if(this.shoppingCartList.length == 1) {
  196. type = this.shoppingCartList[0].goodsType
  197. } else {
  198. type = this.shoppingCartList[0].goodsType;
  199. if(this.shoppingCartList.find(item => item.goodsType != type)) {
  200. type = 3;
  201. }
  202. }
  203. this.confirmText = (type == 1 || type == 6) ? "继续选课" : type == 2 ? "继续选题" : type == 3 ? "继续选购" :"";
  204. }
  205. } else {
  206. self.hasPaying = false;
  207. self.btnNo = false
  208. this.showConfirmButton = false;
  209. this.modalMsg = res.data.msg;
  210. this.showModal = true;
  211. }
  212. });
  213. },
  214. modalCancel() {
  215. this.showModal = false;
  216. },
  217. modalConfirm() {
  218. if(this.hasPaying) {
  219. uni.navigateTo({
  220. url:'/pages2/order/index?current=0'
  221. })
  222. } else {
  223. if(this.fromCart) {
  224. uni.navigateTo({
  225. url:'/pages4/shopping/shoppingCart'
  226. })
  227. } else {
  228. uni.switchTab({
  229. url:'/pages/course/index'
  230. })
  231. }
  232. }
  233. },
  234. getOpenid(code){
  235. let self = this
  236. this.$api.wxOpenid({code:code}).then(res => {
  237. if(res.data.code==200){
  238. self.postOrder()
  239. }
  240. });
  241. },
  242. pay(){
  243. let self = this
  244. this.btnNo = true
  245. // #ifdef MP-WEIXIN
  246. uni.login({
  247. provider: 'weixin',
  248. success: function(loginRes) {
  249. console.log(loginRes,69)
  250. self.getOpenid(loginRes.code)
  251. }
  252. });
  253. // #endif
  254. // #ifdef H5
  255. // https://www.xyyxt.net/?ask_type=h.xyyxt.net
  256. // location.replace(
  257. // "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6f48f721d18244eb" +
  258. // "&redirect_uri=" +
  259. // encodeURIComponent('https://www.xyyxt.net/?ask_type=h.xyyxt.net') +
  260. // "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
  261. // )
  262. // #endif
  263. },
  264. radioChange(e) {
  265. // console.log(e);
  266. },
  267. // 选中任一radio时,由radio-group触发
  268. radioGroupChange(e) {
  269. // console.log(e);
  270. },
  271. cMenu(index){
  272. this.menuIndex = index;
  273. },
  274. change(index){
  275. this.current = index;
  276. }
  277. },
  278. onReachBottom() {},
  279. computed: { ...mapGetters(['userInfo','shoppingCartList']) }
  280. };
  281. </script>
  282. <style >
  283. ::-webkit-scrollbar{
  284. width: 0;
  285. height: 0;
  286. color: transparent
  287. }
  288. page{
  289. background-color: #EAEEF1;
  290. }
  291. </style>
  292. <style lang="scss" scoped>
  293. .txt_left_pay{
  294. display: flex;
  295. align-items: center;
  296. height: 64rpx;
  297. font-size: 24rpx;
  298. color: #666666;
  299. }
  300. .pay_icon{
  301. width: 64rpx;
  302. height: 64rpx;
  303. margin-right: 10rpx;
  304. }
  305. .box3{
  306. width: 100%;
  307. height: 886rpx;
  308. background: #FFFFFF;
  309. // border-radius: 16rpx;
  310. margin-top: 16rpx;
  311. padding: 32rpx 32rpx 0rpx 32rpx;
  312. }
  313. .tip{
  314. font-size: 24rpx;
  315. color: #999999;
  316. height: 40rpx;
  317. line-height: 40rpx;
  318. }
  319. .txt_right_sn{
  320. font-size: 30rpx;
  321. font-weight: bold;
  322. color: #666666;
  323. }
  324. .txt_right_price{
  325. font-size: 32rpx;
  326. font-weight: bold;
  327. color: #FF2D55;
  328. }
  329. .txt_left{
  330. font-size: 28rpx;
  331. color: #666666;
  332. }
  333. .txt_right{
  334. text-align: right;
  335. color: #333333;
  336. font-weight: bold;
  337. width: 75%;
  338. }
  339. .list_title {
  340. display: flex;
  341. justify-content: space-between;
  342. }
  343. .list_item{
  344. display: flex;
  345. justify-content: space-between;
  346. height: 110rpx;
  347. align-items: center;
  348. }
  349. .title2{
  350. font-size: 32rpx;
  351. font-weight: bold;
  352. color: #333333;
  353. // height: 80rpx;
  354. // line-height: 80rpx;
  355. // margin-left: 30rpx;
  356. margin-bottom: 32rpx;
  357. }
  358. .box2{
  359. width: 100%;
  360. background: #FFFFFF;
  361. // border-radius: 16rpx;
  362. padding: 32rpx 32rpx 0rpx 32rpx;
  363. .right_con {
  364. width: 450rpx;
  365. }
  366. .priceTag{
  367. font-size: 28rpx;
  368. font-family: PingFang SC;
  369. font-weight: bold;
  370. color: #FC3F3F;
  371. margin-top: 6rpx;
  372. margin-bottom: 16rpx;
  373. }
  374. .info_right {
  375. height: 110rpx;
  376. line-height: 110rpx;
  377. border-top: 1rpx solid #F2F2F2;
  378. }
  379. }
  380. .box1_t2{
  381. font-size: 24rpx;
  382. color: #999999;
  383. text-align: center;
  384. }
  385. .box1_t1{
  386. font-size: 30rpx;
  387. font-weight: bold;
  388. color: #333333;
  389. height: 70rpx;
  390. display: flex;
  391. align-items: center;
  392. justify-content: center;
  393. }
  394. .box1{
  395. width: 100%;
  396. height: 120rpx;
  397. background: #FFFFFF;
  398. border-radius: 16rpx;
  399. }
  400. .bottomBtn{
  401. position: fixed;
  402. bottom: 0;
  403. width: 100%;
  404. height: 98rpx;
  405. background: linear-gradient(0deg, #015EEA, #00C0FA);
  406. color: #FFFFFF;
  407. text-align: center;
  408. line-height: 98rpx;
  409. font-weight: bold;
  410. font-size: 30rpx;
  411. border-radius: 0;
  412. }
  413. .bottomBox{
  414. position: fixed;
  415. bottom: 0;
  416. width: 100%;
  417. left: 0;
  418. height: 132rpx ;
  419. background-color: #FFFFFF;
  420. display: flex;
  421. justify-content: space-between;
  422. align-items: center;
  423. box-sizing: unset;
  424. box-shadow: 0px -2px 6px 0px rgba(0,0,0,0.1000);
  425. >view{
  426. margin: 0 30rpx;
  427. }
  428. .sums {
  429. display: flex;
  430. }
  431. .all_sum {
  432. font-size: 28rpx;
  433. font-weight: 500;
  434. color: #303030;
  435. }
  436. .priceTag {
  437. font-size: 32rpx;
  438. font-weight: 800;
  439. color: #FC3F3F;
  440. }
  441. .btn2{
  442. width: 232rpx;
  443. height: 92rpx;
  444. background: #FC3F3F;
  445. border-radius: 120rpx;
  446. text-align: center;
  447. line-height: 92rpx;
  448. color: #fff;
  449. }
  450. }
  451. </style>