courseOrderPayment.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. };
  84. var that=this;
  85. uni.showLoading();
  86. payment(data).then(
  87. res => {
  88. if(res.code==200){
  89. if(res.isPay==1){
  90. uni.redirectTo({
  91. url:"/pages_order/courseOrderPaySuccess?orderId="+that.order.orderId
  92. })
  93. }
  94. else{
  95. if(res.type=="tz"){
  96. uni.setStorageSync("ztPayUrl",res.data.body.url)
  97. uni.redirectTo({
  98. url:"/pages_order/tzPay"
  99. })
  100. }
  101. if(res.type=="yb"){
  102. var payData=JSON.parse(res.data.pay_info)
  103. console.log(payData)
  104. uni.requestPayment({
  105. provider: 'wxpay',
  106. timeStamp: payData.timeStamp,
  107. nonceStr: payData.nonceStr,
  108. package: payData.package,
  109. signType: payData.signType,
  110. paySign: payData.paySign,
  111. success: function(res) {
  112. console.log(that.order.orderId)
  113. uni.hideLoading();
  114. uni.redirectTo({
  115. url:"./courseOrderPaySuccess?orderId="+that.order.orderId
  116. })
  117. },
  118. fail: function(err) {
  119. uni.showToast({
  120. icon:'none',
  121. title:'fail:' + JSON.stringify(err),
  122. });
  123. uni.hideLoading();
  124. }
  125. });
  126. }
  127. else if(res.type=="hf"){
  128. var payData=JSON.parse(res.data.pay_info)
  129. console.log(payData)
  130. uni.requestPayment({
  131. provider: 'wxpay',
  132. timeStamp: payData.timeStamp,
  133. nonceStr: payData.nonceStr,
  134. package: payData.package,
  135. signType: payData.signType,
  136. paySign: payData.paySign,
  137. success: function(res) {
  138. console.log(that.order.orderId)
  139. uni.hideLoading();
  140. uni.redirectTo({
  141. url:"./courseOrderPaySuccess?orderId="+that.order.orderId
  142. })
  143. },
  144. fail: function(err) {
  145. uni.showToast({
  146. icon:'none',
  147. title:'fail:' + JSON.stringify(err),
  148. });
  149. uni.hideLoading();
  150. }
  151. });
  152. }
  153. else if(res.type=="wx"){
  154. uni.requestPayment({
  155. provider: 'wxpay',
  156. timeStamp: res.data.timeStamp,
  157. nonceStr: res.data.nonceStr,
  158. package: res.data.packageValue,
  159. signType: res.data.signType,
  160. paySign: res.data.paySign,
  161. success: function(res) {
  162. console.log(that.order.orderId)
  163. uni.hideLoading();
  164. uni.redirectTo({
  165. url:"./courseOrderPaySuccess?orderId="+that.order.orderId
  166. })
  167. },
  168. fail: function(err) {
  169. uni.showToast({
  170. icon:'none',
  171. title:'fail:' + JSON.stringify(err),
  172. });
  173. uni.hideLoading();
  174. }
  175. });
  176. }
  177. }
  178. }else{
  179. uni.showToast({
  180. icon:'none',
  181. title: res.msg,
  182. });
  183. }
  184. },
  185. rej => {}
  186. );
  187. }
  188. }
  189. }
  190. </script>
  191. <style lang="scss">
  192. .inner-box{
  193. padding: 20upx 20upx 300upx;
  194. .time-price{
  195. box-sizing: border-box;
  196. padding: 50upx 0upx;
  197. background: #FFFFFF;
  198. border-radius: 16upx;
  199. display: flex;
  200. flex-direction: column;
  201. align-items: center;
  202. .time{
  203. font-size: 32upx;
  204. font-family: PingFang SC;
  205. font-weight: 500;
  206. color: #222222;
  207. line-height: 1;
  208. text-align: center;
  209. }
  210. .desc{
  211. margin: 30upx 0upx 15upx;
  212. font-size: 26upx;
  213. font-family: PingFang SC;
  214. color: #999999;
  215. line-height: 1;
  216. text-align: center;
  217. }
  218. .price-box{
  219. display: flex;
  220. align-items: flex-end;
  221. margin-top: 28upx;
  222. .unit{
  223. font-size: 32upx;
  224. font-family: PingFang SC;
  225. font-weight: bold;
  226. color: #FF6633;
  227. line-height: 1.3;
  228. margin-right: 10upx;
  229. }
  230. .num{
  231. font-size: 56upx;
  232. font-family: PingFang SC;
  233. font-weight: bold;
  234. color: #FF6633;
  235. line-height: 1;
  236. }
  237. }
  238. }
  239. .order-info{
  240. margin-top: 20upx;
  241. background: #FFFFFF;
  242. border-radius: 16upx;
  243. padding: 40upx 30upx;
  244. .title{
  245. font-size: 30upx;
  246. font-family: PingFang SC;
  247. font-weight: bold;
  248. color: #222222;
  249. line-height: 1;
  250. }
  251. .item{
  252. margin-top: 40upx;
  253. display: flex;
  254. align-items: center;
  255. justify-content: space-between;
  256. .label{
  257. font-size: 26upx;
  258. font-family: PingFang SC;
  259. font-weight: 500;
  260. color: #666666;
  261. line-height: 1;
  262. }
  263. .text{
  264. font-size: 26upx;
  265. font-family: PingFang SC;
  266. font-weight: 500;
  267. color: #222222;
  268. line-height: 32upx;
  269. }
  270. .cont-text{
  271. font-size: 26upx;
  272. font-family: PingFang SC;
  273. font-weight: 500;
  274. color: #666666;
  275. .bold{
  276. color: #111111;
  277. }
  278. }
  279. .sn-box{
  280. display: flex;
  281. align-items: center;
  282. .copy-btn{
  283. width: 58upx;
  284. height: 32upx;
  285. line-height: 32upx;
  286. text-align: center;
  287. font-size: 22upx;
  288. font-family: PingFang SC;
  289. font-weight: 500;
  290. color: #222222;
  291. background: #F5F5F5;
  292. border-radius: 4upx;
  293. margin-left: 24upx;
  294. }
  295. }
  296. }
  297. .line{
  298. width: 100%;
  299. height: 1px;
  300. background: #F0F0F0;
  301. margin-top: 30upx;
  302. }
  303. }
  304. }
  305. .btn-box{
  306. z-index: 9999;
  307. width: 100%;
  308. padding: 30rpx 30upx 0rpx;
  309. position: fixed;
  310. bottom: 0;
  311. left: 0;
  312. box-sizing: border-box;
  313. background-color: #ffffff;
  314. display: flex;
  315. flex-direction: column;
  316. align-items: center;
  317. justify-content: center;
  318. .btn{
  319. margin-bottom: 20rpx;
  320. width: 100%;
  321. height: 88upx;
  322. line-height: 88upx;
  323. text-align: center;
  324. font-size: 34upx;
  325. font-family: PingFang SC;
  326. font-weight: 400;
  327. color: #FFFFFF;
  328. background: #C39A58;
  329. border-radius: 10upx;
  330. position: relative;
  331. }
  332. .btn1{
  333. margin-bottom: 20rpx;
  334. width: 100%;
  335. height: 88upx;
  336. line-height: 88upx;
  337. text-align: center;
  338. font-size: 34upx;
  339. font-family: PingFang SC;
  340. font-weight: 400;
  341. color: #C39A58;
  342. border: 1rpx solid #C39A58;
  343. border-radius: 10upx;
  344. position: relative;
  345. .share-btn {
  346. top:0rpx;
  347. left:0rpx;
  348. position: absolute;
  349. width: 100%;
  350. height: 88upx;
  351. display: flex;
  352. opacity: 0;
  353. }
  354. }
  355. }
  356. </style>