pay.vue 6.7 KB

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