pay.vue 6.9 KB

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