pay.vue 7.7 KB

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