pay.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="app">
  3. <view class="price-box">
  4. <text>支付金额</text>
  5. <text class="price">{{price / 100.0}}</text>
  6. </view>
  7. <view class="pay-type-list">
  8. <view class="type-item b-b" @click="changePayType(1)">
  9. <text class="icon yticon icon-weixinzhifu"></text>
  10. <view class="con">
  11. <text class="tit">微信支付</text>
  12. <text>推荐使用微信支付</text>
  13. </view>
  14. <label class="radio">
  15. <radio value="" color="#fa436a" :checked='payType == 1' />
  16. </radio>
  17. </label>
  18. </view>
  19. <!-- <view class="type-item b-b">-->
  20. <!-- <text class="icon yticon icon-alipay"></text>-->
  21. <!-- <view class="con">-->
  22. <!-- <text class="tit">支付宝(敬请期待)</text>-->
  23. <!-- </view>-->
  24. <!-- <label class="radio">-->
  25. <!-- <radio disabled="true" value="" color="#fa436a" :checked='payType == 2' />-->
  26. <!-- </radio>-->
  27. <!-- </label>-->
  28. <!-- </view>-->
  29. <!-- <view class="type-item" @click="changePayType(3)">-->
  30. <!-- <text class="icon yticon icon-erjiye-yucunkuan"></text>-->
  31. <!-- <view class="con">-->
  32. <!-- <text class="tit">线下支付(到付)</text>-->
  33. <!-- </view>-->
  34. <!-- <label class="radio">-->
  35. <!-- <radio value="" color="#fa436a" :checked='payType == 3' />-->
  36. <!-- </radio>-->
  37. <!-- </label>-->
  38. <!-- </view>-->
  39. </view>
  40. <text :disabled="submiting" class="mix-btn" @click="confirm">确认支付</text>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. payType: 1,
  48. price: 0,
  49. orderNo: '',
  50. submiting: false
  51. };
  52. },
  53. computed: {
  54. },
  55. onLoad(options) {
  56. this.price = options.price
  57. this.orderNo = options.orderno
  58. },
  59. methods: {
  60. //选择支付方式
  61. changePayType(type) {
  62. this.payType = type;
  63. },
  64. //确认支付
  65. confirm: async function() {
  66. const that = this
  67. if (that.payType === 1) {
  68. that.submiting = true
  69. that.$api.request('get', 'order/app/wxPrepay', {
  70. orderId : that.orderNo
  71. }, failres => {
  72. that.submiting = false
  73. that.$api.msg(failres.msg)
  74. }).then(prepayRes => {
  75. that.submiting = false
  76. //#ifdef MP-WEIXIN
  77. const payParam = {
  78. appId: prepayRes.data.appId,
  79. nonceStr: prepayRes.data.nonceStr,
  80. package: prepayRes.data.packageValue,
  81. timeStamp: prepayRes.data.timeStamp,
  82. signType: prepayRes.data.signType,
  83. paySign: prepayRes.data.paySign,
  84. }
  85. //#endif
  86. //#ifdef APP-PLUS
  87. const payParam = {
  88. appid: prepayRes.data.appId,
  89. noncestr: prepayRes.data.nonceStr,
  90. package: prepayRes.data.packageValue,
  91. partnerid: prepayRes.data.partnerId,
  92. prepayid: prepayRes.data.prepayId,
  93. timestamp: parseInt(prepayRes.data.timeStamp),
  94. sign: prepayRes.data.sign,
  95. signType: 'MD5'
  96. }
  97. //#endif
  98. //#ifdef MP-WEIXIN || APP-PLUS
  99. uni.requestPayment({
  100. provider: 'wxpay',
  101. //#ifdef MP-WEIXIN
  102. ...payParam,
  103. //#endif
  104. //#ifdef APP-PLUS
  105. orderInfo: payParam,
  106. //#endif
  107. success: function(res) {
  108. uni.redirectTo({
  109. url: '/pages/pay/success'
  110. })
  111. },
  112. fail: function(res) {
  113. console.log("支付过程失败");
  114. that.$api.msg(JSON.stringify(res))
  115. },
  116. complete: function(res) {
  117. console.log("支付过程结束")
  118. }
  119. });
  120. //#endif
  121. //#ifdef H5
  122. that.$jweixin.chooseWXPay({
  123. nonceStr: prepayRes.data.nonceStr,
  124. timestamp: prepayRes.data.timeStamp,
  125. package: prepayRes.data.packageValue,
  126. signType: prepayRes.data.signType,
  127. paySign: prepayRes.data.paySign,
  128. success: (e) => {
  129. //支付成功
  130. uni.redirectTo({
  131. url: '/pages/pay/success'
  132. })
  133. },
  134. fail: function(res) {
  135. console.log("支付过程失败");
  136. that.$api.msg(JSON.stringify(res))
  137. },
  138. complete: function(res) {
  139. console.log("支付过程结束")
  140. }
  141. })
  142. //#endif
  143. })
  144. } else if (that.payType === 3) {
  145. that.submiting = true
  146. that.$api.request('get', '/offlinePrepay', {
  147. orderNo : that.orderNo
  148. }, failres => {
  149. that.submiting = false
  150. that.$api.msg(failres.msg)
  151. }).then(res => {
  152. uni.redirectTo({
  153. url: '/pages/pay/success'
  154. })
  155. })
  156. }
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang='scss'>
  162. .app {
  163. width: 100%;
  164. }
  165. .price-box {
  166. background-color: #fff;
  167. height: 265upx;
  168. display: flex;
  169. flex-direction: column;
  170. justify-content: center;
  171. align-items: center;
  172. font-size: 28upx;
  173. color: #909399;
  174. .price {
  175. font-size: 50upx;
  176. color: #303133;
  177. margin-top: 12upx;
  178. &:before {
  179. content: '¥';
  180. font-size: 40upx;
  181. }
  182. }
  183. }
  184. .pay-type-list {
  185. margin-top: 20upx;
  186. background-color: #fff;
  187. padding-left: 60upx;
  188. .type-item {
  189. height: 120upx;
  190. padding: 20upx 0;
  191. display: flex;
  192. justify-content: space-between;
  193. align-items: center;
  194. padding-right: 60upx;
  195. font-size: 30upx;
  196. position: relative;
  197. }
  198. .icon {
  199. width: 100upx;
  200. font-size: 52upx;
  201. }
  202. .icon-erjiye-yucunkuan {
  203. color: #fe8e2e;
  204. }
  205. .icon-weixinzhifu {
  206. color: #36cb59;
  207. }
  208. .icon-alipay {
  209. color: #01aaef;
  210. }
  211. .tit {
  212. font-size: $font-lg;
  213. color: $font-color-dark;
  214. margin-bottom: 4upx;
  215. }
  216. .con {
  217. flex: 1;
  218. display: flex;
  219. flex-direction: column;
  220. font-size: $font-sm;
  221. color: $font-color-light;
  222. }
  223. }
  224. .mix-btn {
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. width: 630upx;
  229. height: 80upx;
  230. margin: 80upx auto 30upx;
  231. font-size: $font-lg;
  232. color: #fff;
  233. background-color: $base-color;
  234. border-radius: 10upx;
  235. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  236. }
  237. </style>