pay.vue 5.4 KB

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