courseOrderPayment.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <view>
  3. <view class="inner-box" v-if="order!=null">
  4. <!-- 时间、价格 -->
  5. <view class="time-price">
  6. <text class="time">订单金额</text>
  7. <view class="price-box">
  8. <text class="unit">¥</text>
  9. <text class="num" >{{order.payMoney.toFixed(2)}}</text>
  10. </view>
  11. </view>
  12. <!-- 订单详情查看 -->
  13. <view class="order-info">
  14. <view class="title">订单信息</view>
  15. <view class="item">
  16. <text class="label">订单编号</text>
  17. <view class="sn-box">
  18. <text class="text">{{order.orderSn}}</text>
  19. <view class="copy-btn" @click="copyTest(order.orderSn)">复制</view>
  20. </view>
  21. </view>
  22. <view class="item">
  23. <text class="label">下单时间</text>
  24. <text class="text">{{order.createTime}}</text>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 底部按钮 -->
  29. <view class="btn-box">
  30. <view class="btn" v-if="order!=null" @click="payOrder()">立即支付</view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import {getCourseOrderById,payment} from '@/api/courseOrder.js'
  36. export default {
  37. data() {
  38. return {
  39. payMethod:null,
  40. orderId:null,
  41. order:null,
  42. }
  43. },
  44. onLoad(option) {
  45. this.orderId=option.orderId;
  46. this.payMethod=option.payMethod;
  47. },
  48. onShow() {
  49. this.getCourseOrderById();
  50. },
  51. methods: {
  52. copyTest(text) {
  53. // 复制方法
  54. uni.setClipboardData({
  55. data:text,
  56. success:()=>{
  57. uni.showToast({
  58. title:'内容已成功复制到剪切板',
  59. icon:'none'
  60. })
  61. }
  62. });
  63. },
  64. getCourseOrderById(){
  65. var data={orderId:this.orderId};
  66. console.log(data)
  67. getCourseOrderById(data).then(
  68. res => {
  69. if(res.code==200){
  70. this.order=res.order
  71. if(this.payMethod!=null&&this.payMethod=='app'){
  72. this.payOrder();
  73. }
  74. }else{
  75. }
  76. },
  77. rej => {}
  78. );
  79. },
  80. payOrder(){
  81. var data = {
  82. orderId:this.orderId,
  83. appId: getApp().globalData.appId
  84. };
  85. var that=this;
  86. uni.showLoading();
  87. payment(data).then(
  88. res => {
  89. if(res.code==200){
  90. if(res.isPay==1){
  91. uni.redirectTo({
  92. url:"/pages_order/courseOrderPaySuccess?orderId="+that.order.orderId
  93. })
  94. }
  95. else{
  96. if(res.type=="tz"){
  97. uni.setStorageSync("ztPayUrl",res.data.body.url)
  98. uni.redirectTo({
  99. url:"/pages_order/tzPay"
  100. })
  101. }
  102. if(res.type=="yb"){
  103. var payData=JSON.parse(res.data.pay_info)
  104. console.log(payData)
  105. uni.requestPayment({
  106. provider: 'wxpay',
  107. timeStamp: payData.timeStamp,
  108. nonceStr: payData.nonceStr,
  109. package: payData.package,
  110. signType: payData.signType,
  111. paySign: payData.paySign,
  112. success: function(res) {
  113. console.log(that.order.orderId)
  114. uni.hideLoading();
  115. uni.redirectTo({
  116. url:"./courseOrderPaySuccess?orderId="+that.order.orderId
  117. })
  118. },
  119. fail: function(err) {
  120. uni.showToast({
  121. icon:'none',
  122. title:'fail:' + JSON.stringify(err),
  123. });
  124. uni.hideLoading();
  125. }
  126. });
  127. }
  128. else if(res.type=="hf"){
  129. var payData=JSON.parse(res.data.pay_info)
  130. console.log(payData)
  131. uni.requestPayment({
  132. provider: 'wxpay',
  133. timeStamp: payData.timeStamp,
  134. nonceStr: payData.nonceStr,
  135. package: payData.package,
  136. signType: payData.signType,
  137. paySign: payData.paySign,
  138. success: function(res) {
  139. console.log(that.order.orderId)
  140. uni.hideLoading();
  141. uni.redirectTo({
  142. url:"./courseOrderPaySuccess?orderId="+that.order.orderId
  143. })
  144. },
  145. fail: function(err) {
  146. uni.showToast({
  147. icon:'none',
  148. title:'fail:' + JSON.stringify(err),
  149. });
  150. uni.hideLoading();
  151. }
  152. });
  153. }
  154. else if(res.type=="wx"){
  155. uni.requestPayment({
  156. provider: 'wxpay',
  157. timeStamp: res.data.timeStamp,
  158. nonceStr: res.data.nonceStr,
  159. package: res.data.packageValue,
  160. signType: res.data.signType,
  161. paySign: res.data.paySign,
  162. success: function(res) {
  163. console.log(that.order.orderId)
  164. uni.hideLoading();
  165. uni.redirectTo({
  166. url:"./courseOrderPaySuccess?orderId="+that.order.orderId
  167. })
  168. },
  169. fail: function(err) {
  170. uni.showToast({
  171. icon:'none',
  172. title:'fail:' + JSON.stringify(err),
  173. });
  174. uni.hideLoading();
  175. }
  176. });
  177. }
  178. }
  179. }else{
  180. uni.showToast({
  181. icon:'none',
  182. title: res.msg,
  183. });
  184. this.$reLoginCheck(res.msg)
  185. }
  186. },
  187. rej => {}
  188. );
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang="scss">
  194. .inner-box{
  195. padding: 20upx 20upx 300upx;
  196. .time-price{
  197. box-sizing: border-box;
  198. padding: 50upx 0upx;
  199. background: #FFFFFF;
  200. border-radius: 16upx;
  201. display: flex;
  202. flex-direction: column;
  203. align-items: center;
  204. .time{
  205. font-size: 32upx;
  206. font-family: PingFang SC;
  207. font-weight: 500;
  208. color: #222222;
  209. line-height: 1;
  210. text-align: center;
  211. }
  212. .desc{
  213. margin: 30upx 0upx 15upx;
  214. font-size: 26upx;
  215. font-family: PingFang SC;
  216. color: #999999;
  217. line-height: 1;
  218. text-align: center;
  219. }
  220. .price-box{
  221. display: flex;
  222. align-items: flex-end;
  223. margin-top: 28upx;
  224. .unit{
  225. font-size: 32upx;
  226. font-family: PingFang SC;
  227. font-weight: bold;
  228. color: #FF6633;
  229. line-height: 1.3;
  230. margin-right: 10upx;
  231. }
  232. .num{
  233. font-size: 56upx;
  234. font-family: PingFang SC;
  235. font-weight: bold;
  236. color: #FF6633;
  237. line-height: 1;
  238. }
  239. }
  240. }
  241. .order-info{
  242. margin-top: 20upx;
  243. background: #FFFFFF;
  244. border-radius: 16upx;
  245. padding: 40upx 30upx;
  246. .title{
  247. font-size: 30upx;
  248. font-family: PingFang SC;
  249. font-weight: bold;
  250. color: #222222;
  251. line-height: 1;
  252. }
  253. .item{
  254. margin-top: 40upx;
  255. display: flex;
  256. align-items: center;
  257. justify-content: space-between;
  258. .label{
  259. font-size: 26upx;
  260. font-family: PingFang SC;
  261. font-weight: 500;
  262. color: #666666;
  263. line-height: 1;
  264. }
  265. .text{
  266. font-size: 26upx;
  267. font-family: PingFang SC;
  268. font-weight: 500;
  269. color: #222222;
  270. line-height: 32upx;
  271. }
  272. .cont-text{
  273. font-size: 26upx;
  274. font-family: PingFang SC;
  275. font-weight: 500;
  276. color: #666666;
  277. .bold{
  278. color: #111111;
  279. }
  280. }
  281. .sn-box{
  282. display: flex;
  283. align-items: center;
  284. .copy-btn{
  285. width: 58upx;
  286. height: 32upx;
  287. line-height: 32upx;
  288. text-align: center;
  289. font-size: 22upx;
  290. font-family: PingFang SC;
  291. font-weight: 500;
  292. color: #222222;
  293. background: #F5F5F5;
  294. border-radius: 4upx;
  295. margin-left: 24upx;
  296. }
  297. }
  298. }
  299. .line{
  300. width: 100%;
  301. height: 1px;
  302. background: #F0F0F0;
  303. margin-top: 30upx;
  304. }
  305. }
  306. }
  307. .btn-box{
  308. z-index: 9999;
  309. width: 100%;
  310. padding: 30rpx 30upx 0rpx;
  311. position: fixed;
  312. bottom: 0;
  313. left: 0;
  314. box-sizing: border-box;
  315. background-color: #ffffff;
  316. display: flex;
  317. flex-direction: column;
  318. align-items: center;
  319. justify-content: center;
  320. .btn{
  321. margin-bottom: 20rpx;
  322. width: 100%;
  323. height: 88upx;
  324. line-height: 88upx;
  325. text-align: center;
  326. font-size: 34upx;
  327. font-family: PingFang SC;
  328. font-weight: 400;
  329. color: #FFFFFF;
  330. background: #2583EB;
  331. border-radius: 10upx;
  332. position: relative;
  333. }
  334. .btn1{
  335. margin-bottom: 20rpx;
  336. width: 100%;
  337. height: 88upx;
  338. line-height: 88upx;
  339. text-align: center;
  340. font-size: 34upx;
  341. font-family: PingFang SC;
  342. font-weight: 400;
  343. color: #2583EB;
  344. border: 1rpx solid #2583EB;
  345. border-radius: 10upx;
  346. position: relative;
  347. .share-btn {
  348. top:0rpx;
  349. left:0rpx;
  350. position: absolute;
  351. width: 100%;
  352. height: 88upx;
  353. display: flex;
  354. opacity: 0;
  355. }
  356. }
  357. }
  358. </style>