pay.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. <view class="inner">
  5. <view class="pay">
  6. <view class="title">
  7. <text class="name">付款给 倍力优</text>
  8. <text class="desc">微信收款</text>
  9. </view>
  10. <view class="pay-money">
  11. <view class="pay-money-title">支付金额</view>
  12. <view class="money">
  13. <text class="fh">¥</text>
  14. <input v-model="money" class="uni-input" @input="testMoney" type="digit" focus />
  15. </view>
  16. <textarea class="desc" placeholder="请填写备注说明" maxlength="20" v-model="desc" />
  17. </view>
  18. </view>
  19. </view>
  20. <view class="btn-box">
  21. <view class="btn" @click="pay()">确认支付</view>
  22. </view>
  23. </view>
  24. <view class="ad">
  25. <ad unit-id="adunit-a018415a6deb69e8"></ad>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import {payment} from '@/api/payment'
  31. export default {
  32. data() {
  33. return {
  34. companyUserId:null,
  35. companyId:null,
  36. desc:"",
  37. money:null,
  38. wxPay: true,
  39. }
  40. },
  41. onLoad: function(options) {
  42. // if (options.hasOwnProperty('q') && options.q) {
  43. // // 通过下面这步解码,可以拿到url的值
  44. // const url = decodeURIComponent(options.q)
  45. // this.url=url;
  46. // // // 对url中携带的参数提取处理
  47. // const obj = this.utils.urlToObj(url)
  48. // console.log(obj)
  49. // this.companyId=obj.companyId;
  50. // this.companyUserId=obj.companyUserId;
  51. // }
  52. this.companyId=options.companyId; this.companyUserId=options.companyUserId;
  53. },
  54. onShareAppMessage(res) {
  55. return {
  56. title: '云联融智-收款',
  57. path: `/pages_user/user/pay?companyId=`+this.companyId+"&companyUserId="+this.companyUserId
  58. }
  59. },
  60. methods: {
  61. testMoney(e){
  62. let that = this;
  63. let price = e.detail.value
  64. if (price.indexOf(".") == 0) {
  65. //'首位小数点情况'
  66. price = price.replace(/[^$#$]/g, "0.");
  67. price = price.replace(/\.{2,}/g, ".");
  68. }
  69. price = price.match(/^\d*(\.?\d{0,2})/g)[0] || null;
  70. //重新赋值给input
  71. this.$nextTick(() => {
  72. this.money = price;
  73. });
  74. },
  75. pay(){
  76. if(this.money==null){
  77. uni.showToast({
  78. icon:'none',
  79. title: "请输入支付金额"
  80. });
  81. return;
  82. }
  83. uni.login({
  84. success: res => {
  85. console.log(res)
  86. this.payment(res.code);
  87. }
  88. });
  89. },
  90. payment(code){
  91. var data = {payMoney:this.money,remark:this.desc,code:code,companyId:this.companyId,companyUserId:this.companyUserId};
  92. var that=this;
  93. uni.showLoading();
  94. payment(data).then(
  95. res => {
  96. if(res.code==200){
  97. console.log(res);
  98. uni.requestPayment({
  99. provider: 'wxpay',
  100. timeStamp: res.result.timeStamp,
  101. nonceStr: res.result.nonceStr,
  102. // package: res.result.packageValue,
  103. package: res.result.packageStr,
  104. signType: res.result.signType,
  105. paySign: res.result.paySign,
  106. success: function(res) {
  107. uni.hideLoading();
  108. uni.showToast({
  109. icon:'success',
  110. title: "支付成功",
  111. });
  112. uni.navigateTo({
  113. url:'./success'
  114. })
  115. },
  116. fail: function(err) {
  117. console.log('fail:' + JSON.stringify(err));
  118. uni.hideLoading();
  119. }
  120. });
  121. }else{
  122. uni.showToast({
  123. icon:'none',
  124. title: res.msg,
  125. });
  126. }
  127. },
  128. rej => {}
  129. );
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss">
  135. page{
  136. height: 100%;
  137. background-color: #f0eff4;
  138. }
  139. .content{
  140. height: 100%;
  141. display: flex;
  142. flex-direction: column;
  143. .top{
  144. flex:1;
  145. padding: 20rpx;
  146. .inner{
  147. width: 100%;
  148. display: flex;
  149. flex-direction: column;
  150. align-items: flex-start;
  151. justify-content: center;
  152. .pay{
  153. width: 100%;
  154. box-shadow: 1px 1px 5px #e6e6e6;
  155. background: #FFFFFF;
  156. border-radius: 5upx;
  157. display: flex;
  158. flex-direction: column;
  159. align-items: flex-start;
  160. .title{
  161. display: flex;
  162. flex-direction: column;
  163. align-items: flex-start;
  164. width: 100%;
  165. background-color: #f7f7f7;
  166. padding: 30rpx 0rpx;
  167. .name{
  168. padding: 15rpx 30rpx;
  169. font-size: 32rpx;
  170. }
  171. .desc{
  172. color: #989898;
  173. padding: 15rpx 30rpx;
  174. font-size: 25rpx;
  175. }
  176. }
  177. .pay-money
  178. {
  179. padding: 30rpx 0rpx;
  180. width: 100%;
  181. background: #FFFFFF;
  182. border-radius: 5upx;
  183. display: flex;
  184. flex-direction: column;
  185. align-items: flex-start;
  186. .pay-money-title{
  187. padding: 15rpx 30rpx;
  188. font-size: 32rpx;
  189. }
  190. .money{
  191. font-size: 42rpx;
  192. padding: 15rpx 30rpx;
  193. display: flex;
  194. flex-direction: row;
  195. align-items: flex-start;
  196. input{
  197. margin-left: 15rpx;
  198. }
  199. }
  200. .desc{
  201. width: 100%;
  202. padding: 30rpx 30rpx;
  203. border-top: 1rpx solid #e6e6e6;
  204. }
  205. textarea {
  206. height:50rpx;
  207. line-height: 50rpx;
  208. }
  209. }
  210. }
  211. }
  212. .btn-box{
  213. padding: 30rpx 0rpx;
  214. height: 121upx;
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. .btn{
  219. width: 91.73%;
  220. height: 88upx;
  221. line-height: 88upx;
  222. font-size: 30upx;
  223. font-family: PingFang SC;
  224. font-weight: bold;
  225. color: #FFFFFF;
  226. text-align: center;
  227. background: #018C39;
  228. border-radius: 44upx;
  229. }
  230. }
  231. }
  232. .ad{
  233. margin: 0rpx 0rpx 60rpx;
  234. }
  235. }
  236. </style>