pay.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. import { loginByMiniApp} from '@/api/user'
  32. export default {
  33. data() {
  34. return {
  35. companyUserId:null,
  36. companyId:null,
  37. desc:"",
  38. money:null,
  39. wxPay: true,
  40. }
  41. },
  42. onLoad: function(options) {
  43. // if (options.hasOwnProperty('q') && options.q) {
  44. // // 通过下面这步解码,可以拿到url的值
  45. // const url = decodeURIComponent(options.q)
  46. // this.url=url;
  47. // // // 对url中携带的参数提取处理
  48. // const obj = this.utils.urlToObj(url)
  49. // console.log(obj)
  50. // this.companyId=obj.companyId;
  51. // this.companyUserId=obj.companyUserId;
  52. // }
  53. this.companyId=options.companyId;
  54. this.companyUserId=options.companyUserId;
  55. this.gologin()
  56. },
  57. onShareAppMessage(res) {
  58. return {
  59. title: '康年臻选-收款',
  60. path: `/pages_user/user/pay?companyId=`+this.companyId+"&companyUserId="+this.companyUserId
  61. }
  62. },
  63. methods: {
  64. gologin(){
  65. let provider = 'weixin'
  66. uni.login({
  67. provider: provider,
  68. success: async loginRes => {
  69. console.log(loginRes)
  70. uni.getUserInfo({
  71. provider: provider,
  72. success: (infoRes)=> {
  73. uni.showToast({
  74. title: '处理中...',
  75. icon: 'loading'
  76. });
  77. loginByMiniApp({
  78. code: loginRes.code,
  79. encryptedData:infoRes.encryptedData,
  80. iv:infoRes.iv,
  81. appId:wx.getAccountInfoSync().miniProgram.appId,
  82. }).then(res=>{
  83. uni.hideLoading();
  84. if (res.code == 200) {
  85. } else {
  86. uni.showToast({
  87. title: res.msg,
  88. icon: 'none'
  89. });
  90. }
  91. }).catch(err=>{
  92. uni.hideLoading();
  93. uni.showToast({
  94. icon:'none',
  95. title: "登录失败,请重新登录",
  96. });
  97. });
  98. }
  99. });
  100. }
  101. })
  102. },
  103. testMoney(e){
  104. let that = this;
  105. let price = e.detail.value
  106. if (price.indexOf(".") == 0) {
  107. //'首位小数点情况'
  108. price = price.replace(/[^$#$]/g, "0.");
  109. price = price.replace(/\.{2,}/g, ".");
  110. }
  111. price = price.match(/^\d*(\.?\d{0,2})/g)[0] || null;
  112. //重新赋值给input
  113. this.$nextTick(() => {
  114. this.money = price;
  115. });
  116. },
  117. pay(){
  118. if(this.money==null){
  119. uni.showToast({
  120. icon:'none',
  121. title: "请输入支付金额"
  122. });
  123. return;
  124. }
  125. this.payment();
  126. // this.utils.isLogin().then(res => {
  127. // if(res){
  128. // uni.navigateTo({
  129. // url: url
  130. // })
  131. // }
  132. // })
  133. // uni.login({
  134. // success: res => {
  135. // console.log(res)
  136. // }
  137. // });
  138. },
  139. payment(){
  140. var data = {payMoney:this.money,remark:this.desc,companyId:this.companyId,companyUserId:this.companyUserId};
  141. var that=this;
  142. uni.showLoading();
  143. payment(data).then(
  144. res => {
  145. if(res.code==200){
  146. console.log(res);
  147. uni.requestPayment({
  148. provider: 'wxpay',
  149. timeStamp: res.result.timeStamp,
  150. nonceStr: res.result.nonceStr,
  151. package: res.result.packageValue,
  152. signType: res.result.signType,
  153. paySign: res.result.paySign,
  154. success: function(res) {
  155. uni.hideLoading();
  156. uni.showToast({
  157. icon:'success',
  158. title: "支付成功",
  159. });
  160. uni.navigateTo({
  161. url:'./success'
  162. })
  163. },
  164. fail: function(err) {
  165. console.log('fail:' + JSON.stringify(err));
  166. uni.hideLoading();
  167. }
  168. });
  169. }else{
  170. uni.showToast({
  171. icon:'none',
  172. title: res.msg,
  173. });
  174. }
  175. },
  176. rej => {}
  177. );
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="scss">
  183. page{
  184. height: 100%;
  185. background-color: #f0eff4;
  186. }
  187. .content{
  188. height: 100%;
  189. display: flex;
  190. flex-direction: column;
  191. .top{
  192. flex:1;
  193. padding: 20rpx;
  194. .inner{
  195. width: 100%;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: flex-start;
  199. justify-content: center;
  200. .pay{
  201. width: 100%;
  202. box-shadow: 1px 1px 5px #e6e6e6;
  203. background: #FFFFFF;
  204. border-radius: 5upx;
  205. display: flex;
  206. flex-direction: column;
  207. align-items: flex-start;
  208. .title{
  209. display: flex;
  210. flex-direction: column;
  211. align-items: flex-start;
  212. width: 100%;
  213. background-color: #f7f7f7;
  214. padding: 30rpx 0rpx;
  215. .name{
  216. padding: 15rpx 30rpx;
  217. font-size: 32rpx;
  218. }
  219. .desc{
  220. color: #989898;
  221. padding: 15rpx 30rpx;
  222. font-size: 25rpx;
  223. }
  224. }
  225. .pay-money
  226. {
  227. padding: 30rpx 0rpx;
  228. width: 100%;
  229. background: #FFFFFF;
  230. border-radius: 5upx;
  231. display: flex;
  232. flex-direction: column;
  233. align-items: flex-start;
  234. .pay-money-title{
  235. padding: 15rpx 30rpx;
  236. font-size: 32rpx;
  237. }
  238. .money{
  239. font-size: 42rpx;
  240. padding: 15rpx 30rpx;
  241. display: flex;
  242. flex-direction: row;
  243. align-items: flex-start;
  244. input{
  245. margin-left: 15rpx;
  246. }
  247. }
  248. .desc{
  249. width: 100%;
  250. padding: 30rpx 30rpx;
  251. border-top: 1rpx solid #e6e6e6;
  252. }
  253. textarea {
  254. height:50rpx;
  255. line-height: 50rpx;
  256. }
  257. }
  258. }
  259. }
  260. .btn-box{
  261. padding: 30rpx 0rpx;
  262. height: 121upx;
  263. display: flex;
  264. align-items: center;
  265. justify-content: center;
  266. .btn{
  267. width: 91.73%;
  268. height: 88upx;
  269. line-height: 88upx;
  270. font-size: 30upx;
  271. font-family: PingFang SC;
  272. font-weight: bold;
  273. color: #FFFFFF;
  274. text-align: center;
  275. background: #2BC7B9;
  276. border-radius: 44upx;
  277. }
  278. }
  279. }
  280. .ad{
  281. margin: 0rpx 0rpx 60rpx;
  282. }
  283. }
  284. </style>