pay.vue 6.6 KB

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