pay.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. var result=JSON.parse(res.result);
  99. uni.requestPayment({
  100. provider: 'wxpay',
  101. timeStamp: result.timeStamp,
  102. nonceStr: result.nonceStr,
  103. package: result.package,
  104. signType: result.signType,
  105. paySign: result.paySign,
  106. success: function(res) {
  107. uni.hideLoading();
  108. uni.redirectTo({
  109. url:"./success"
  110. })
  111. },
  112. fail: function(err) {
  113. uni.showToast({
  114. icon:'none',
  115. title:'fail:' + JSON.stringify(err),
  116. });
  117. console.log('fail:' + JSON.stringify(err));
  118. uni.hideLoading();
  119. }
  120. });
  121. // uni.requestPayment({
  122. // provider: 'wxpay',
  123. // timeStamp: res.result.timeStamp,
  124. // nonceStr: res.result.nonceStr,
  125. // package: res.result.packageValue,
  126. // signType: res.result.signType,
  127. // paySign: res.result.paySign,
  128. // success: function(res) {
  129. // uni.hideLoading();
  130. // uni.showToast({
  131. // icon:'success',
  132. // title: "支付成功",
  133. // });
  134. // uni.navigateTo({
  135. // url:'./success'
  136. // })
  137. // },
  138. // fail: function(err) {
  139. // console.log('fail:' + JSON.stringify(err));
  140. // uni.hideLoading();
  141. // }
  142. // });
  143. }else{
  144. uni.showToast({
  145. icon:'none',
  146. title: res.msg,
  147. });
  148. }
  149. },
  150. rej => {}
  151. );
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss">
  157. page{
  158. height: 100%;
  159. background-color: #f0eff4;
  160. }
  161. .content{
  162. height: 100%;
  163. display: flex;
  164. flex-direction: column;
  165. .top{
  166. flex:1;
  167. padding: 20rpx;
  168. .inner{
  169. width: 100%;
  170. display: flex;
  171. flex-direction: column;
  172. align-items: flex-start;
  173. justify-content: center;
  174. .pay{
  175. width: 100%;
  176. box-shadow: 1px 1px 5px #e6e6e6;
  177. background: #FFFFFF;
  178. border-radius: 5upx;
  179. display: flex;
  180. flex-direction: column;
  181. align-items: flex-start;
  182. .title{
  183. display: flex;
  184. flex-direction: column;
  185. align-items: flex-start;
  186. width: 100%;
  187. background-color: #f7f7f7;
  188. padding: 30rpx 0rpx;
  189. .name{
  190. padding: 15rpx 30rpx;
  191. font-size: 32rpx;
  192. }
  193. .desc{
  194. color: #989898;
  195. padding: 15rpx 30rpx;
  196. font-size: 25rpx;
  197. }
  198. }
  199. .pay-money
  200. {
  201. padding: 30rpx 0rpx;
  202. width: 100%;
  203. background: #FFFFFF;
  204. border-radius: 5upx;
  205. display: flex;
  206. flex-direction: column;
  207. align-items: flex-start;
  208. .pay-money-title{
  209. padding: 15rpx 30rpx;
  210. font-size: 32rpx;
  211. }
  212. .money{
  213. font-size: 42rpx;
  214. padding: 15rpx 30rpx;
  215. display: flex;
  216. flex-direction: row;
  217. align-items: flex-start;
  218. input{
  219. margin-left: 15rpx;
  220. }
  221. }
  222. .desc{
  223. width: 100%;
  224. padding: 30rpx 30rpx;
  225. border-top: 1rpx solid #e6e6e6;
  226. }
  227. textarea {
  228. height:50rpx;
  229. line-height: 50rpx;
  230. }
  231. }
  232. }
  233. }
  234. .btn-box{
  235. padding: 30rpx 0rpx;
  236. height: 121upx;
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. .btn{
  241. width: 91.73%;
  242. height: 88upx;
  243. line-height: 88upx;
  244. font-size: 30upx;
  245. font-family: PingFang SC;
  246. font-weight: bold;
  247. color: #FFFFFF;
  248. text-align: center;
  249. background: #2BC7B9;
  250. border-radius: 44upx;
  251. }
  252. }
  253. }
  254. .ad{
  255. margin: 0rpx 0rpx 60rpx;
  256. }
  257. }
  258. </style>