pay.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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;
  53. this.companyUserId=options.companyUserId;
  54. },
  55. onShareAppMessage(res) {
  56. return {
  57. title: '御君方-收款',
  58. path: `/pages_user/user/pay?companyId=`+this.companyId+"&companyUserId="+this.companyUserId
  59. }
  60. },
  61. methods: {
  62. testMoney(e){
  63. let that = this;
  64. let price = e.detail.value
  65. if (price.indexOf(".") == 0) {
  66. //'首位小数点情况'
  67. price = price.replace(/[^$#$]/g, "0.");
  68. price = price.replace(/\.{2,}/g, ".");
  69. }
  70. price = price.match(/^\d*(\.?\d{0,2})/g)[0] || null;
  71. //重新赋值给input
  72. this.$nextTick(() => {
  73. this.money = price;
  74. });
  75. },
  76. pay(){
  77. if(this.money==null){
  78. uni.showToast({
  79. icon:'none',
  80. title: "请输入支付金额"
  81. });
  82. return;
  83. }
  84. uni.login({
  85. success: res => {
  86. console.log(res)
  87. this.payment(res.code);
  88. }
  89. });
  90. },
  91. payment(code){
  92. var data = {payMoney:this.money,remark:this.desc,code:code,companyId:this.companyId,companyUserId:this.companyUserId};
  93. var that=this;
  94. uni.showLoading();
  95. payment(data).then(
  96. res => {
  97. if(res.code==200){
  98. console.log(res);
  99. var result=JSON.parse(res.result);
  100. uni.requestPayment({
  101. provider: 'wxpay',
  102. timeStamp: result.timeStamp,
  103. nonceStr: result.nonceStr,
  104. package: result.package,
  105. signType: result.signType,
  106. paySign: result.paySign,
  107. success: function(res) {
  108. uni.hideLoading();
  109. uni.redirectTo({
  110. url:"./success"
  111. })
  112. },
  113. fail: function(err) {
  114. uni.showToast({
  115. icon:'none',
  116. title:'fail:' + JSON.stringify(err),
  117. });
  118. console.log('fail:' + JSON.stringify(err));
  119. uni.hideLoading();
  120. }
  121. });
  122. // uni.requestPayment({
  123. // provider: 'wxpay',
  124. // timeStamp: res.result.timeStamp,
  125. // nonceStr: res.result.nonceStr,
  126. // package: res.result.packageValue,
  127. // signType: res.result.signType,
  128. // paySign: res.result.paySign,
  129. // success: function(res) {
  130. // uni.hideLoading();
  131. // uni.showToast({
  132. // icon:'success',
  133. // title: "支付成功",
  134. // });
  135. // uni.navigateTo({
  136. // url:'./success'
  137. // })
  138. // },
  139. // fail: function(err) {
  140. // console.log('fail:' + JSON.stringify(err));
  141. // uni.hideLoading();
  142. // }
  143. // });
  144. }else{
  145. uni.showToast({
  146. icon:'none',
  147. title: res.msg,
  148. });
  149. }
  150. },
  151. rej => {}
  152. );
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss">
  158. page{
  159. height: 100%;
  160. background-color: #f0eff4;
  161. }
  162. .content{
  163. height: 100%;
  164. display: flex;
  165. flex-direction: column;
  166. .top{
  167. flex:1;
  168. padding: 20rpx;
  169. .inner{
  170. width: 100%;
  171. display: flex;
  172. flex-direction: column;
  173. align-items: flex-start;
  174. justify-content: center;
  175. .pay{
  176. width: 100%;
  177. box-shadow: 1px 1px 5px #e6e6e6;
  178. background: #FFFFFF;
  179. border-radius: 5upx;
  180. display: flex;
  181. flex-direction: column;
  182. align-items: flex-start;
  183. .title{
  184. display: flex;
  185. flex-direction: column;
  186. align-items: flex-start;
  187. width: 100%;
  188. background-color: #f7f7f7;
  189. padding: 30rpx 0rpx;
  190. .name{
  191. padding: 15rpx 30rpx;
  192. font-size: 32rpx;
  193. }
  194. .desc{
  195. color: #989898;
  196. padding: 15rpx 30rpx;
  197. font-size: 25rpx;
  198. }
  199. }
  200. .pay-money
  201. {
  202. padding: 30rpx 0rpx;
  203. width: 100%;
  204. background: #FFFFFF;
  205. border-radius: 5upx;
  206. display: flex;
  207. flex-direction: column;
  208. align-items: flex-start;
  209. .pay-money-title{
  210. padding: 15rpx 30rpx;
  211. font-size: 32rpx;
  212. }
  213. .money{
  214. font-size: 42rpx;
  215. padding: 15rpx 30rpx;
  216. display: flex;
  217. flex-direction: row;
  218. align-items: flex-start;
  219. input{
  220. margin-left: 15rpx;
  221. }
  222. }
  223. .desc{
  224. width: 100%;
  225. padding: 30rpx 30rpx;
  226. border-top: 1rpx solid #e6e6e6;
  227. }
  228. textarea {
  229. height:50rpx;
  230. line-height: 50rpx;
  231. }
  232. }
  233. }
  234. }
  235. .btn-box{
  236. padding: 30rpx 0rpx;
  237. height: 121upx;
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. .btn{
  242. width: 91.73%;
  243. height: 88upx;
  244. line-height: 88upx;
  245. font-size: 30upx;
  246. font-family: PingFang SC;
  247. font-weight: bold;
  248. color: #FFFFFF;
  249. text-align: center;
  250. background: #2BC7B9;
  251. border-radius: 44upx;
  252. }
  253. }
  254. }
  255. .ad{
  256. margin: 0rpx 0rpx 60rpx;
  257. }
  258. }
  259. </style>