pay.vue 6.9 KB

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