pay.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 { loginPay } from '@/api/user.js'
  31. import {paymentByWxaCode} from '@/api/companyUser.js'
  32. export default {
  33. data() {
  34. return {
  35. companyUserId:null,
  36. companyId:null,
  37. desc:"",
  38. money:null,
  39. wxPay: true,
  40. isLogin: false
  41. }
  42. },
  43. onLoad: function(options) {
  44. // if (options.hasOwnProperty('q') && options.q) {
  45. // // 通过下面这步解码,可以拿到url的值
  46. // const url = decodeURIComponent(options.q)
  47. // this.url=url;
  48. // // // 对url中携带的参数提取处理
  49. // const obj = this.utils.urlToObj(url)
  50. // console.log(obj)
  51. // this.companyId=obj.companyId;
  52. // this.companyUserId=obj.companyUserId;
  53. // }
  54. this.companyId=options.companyId;
  55. this.companyUserId=options.companyUserId;
  56. },
  57. onShareAppMessage(res) {
  58. return {
  59. title: '泰安泰医堂中医医院-收款',
  60. path: `/pages_user/user/pay?companyId=`+this.companyId+"&companyUserId="+this.companyUserId
  61. }
  62. },
  63. onShow() {
  64. this.$isLogin().then(res => {
  65. if (res) {
  66. this.isLogin = true
  67. } else {
  68. this.isLogin = false
  69. this.goLogin()
  70. }
  71. });
  72. },
  73. methods: {
  74. testMoney(e){
  75. let that = this;
  76. let price = e.detail.value
  77. if (price.indexOf(".") == 0) {
  78. //'首位小数点情况'
  79. price = price.replace(/[^$#$]/g, "0.");
  80. price = price.replace(/\.{2,}/g, ".");
  81. }
  82. price = price.match(/^\d*(\.?\d{0,2})/g)[0] || null;
  83. //重新赋值给input
  84. this.$nextTick(() => {
  85. this.money = price;
  86. });
  87. },
  88. pay(){
  89. if(!this.isLogin) {
  90. this.goLogin(1)
  91. return
  92. }
  93. if(this.money==null){
  94. uni.showToast({
  95. icon:'none',
  96. title: "请输入支付金额"
  97. });
  98. return;
  99. }
  100. this.payment();
  101. },
  102. payment(){
  103. var data = {payMoney:this.money,remark:this.desc,companyId:this.companyId,companyUserId:this.companyUserId,appId: getApp().globalData.appId};
  104. var that=this;
  105. uni.showLoading();
  106. paymentByWxaCode(data).then(
  107. res => {
  108. if(res.code==200){
  109. console.log(res);
  110. uni.requestPayment({
  111. provider: 'wxpay',
  112. timeStamp: res.result.timeStamp,
  113. nonceStr: res.result.nonceStr,
  114. package: res.result.packageValue,
  115. signType: res.result.signType,
  116. paySign: res.result.paySign,
  117. success: function(res) {
  118. uni.hideLoading();
  119. uni.showToast({
  120. icon:'success',
  121. title: "支付成功",
  122. });
  123. uni.navigateTo({
  124. url:'./success'
  125. })
  126. },
  127. fail: function(err) {
  128. console.log('fail:' + JSON.stringify(err));
  129. uni.hideLoading();
  130. }
  131. });
  132. }else{
  133. uni.showToast({
  134. icon:'none',
  135. title: res.msg,
  136. });
  137. }
  138. },
  139. rej => {}
  140. );
  141. },
  142. goLogin(type) {
  143. let provider = 'weixin'
  144. uni.login({
  145. provider: provider,
  146. success: async loginRes => {
  147. console.log(loginRes)
  148. uni.getUserInfo({
  149. provider: provider,
  150. success: (infoRes)=> {
  151. uni.showToast({
  152. title: '处理中...',
  153. icon: 'loading'
  154. });
  155. loginPay({
  156. code: loginRes.code,
  157. encryptedData:infoRes.encryptedData,
  158. iv:infoRes.iv,
  159. appId: getApp().globalData.appId
  160. }).then(res=>{
  161. uni.hideLoading();
  162. if (res.code == 200) {
  163. this.isLogin = true
  164. uni.setStorageSync('userHistoryApp',res.user.historyApp);
  165. uni.setStorageSync('AppToken',res.token);
  166. uni.setStorageSync('userId',res.user.userId);
  167. uni.setStorageSync('avatar',res.user.avatar);
  168. uni.setStorageSync('nickName',res.user.nickName);
  169. if(type==1) {
  170. this.pay()
  171. }
  172. uni.$emit('refreshIM');
  173. } else {
  174. this.isLogin = false
  175. uni.showToast({
  176. title: res.msg,
  177. icon: 'none'
  178. });
  179. }
  180. }).catch(err=>{
  181. uni.hideLoading();
  182. uni.showToast({
  183. icon:'none',
  184. title: "登录失败,请重新登录",
  185. });
  186. });
  187. }
  188. });
  189. }
  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: #078C9D;
  289. border-radius: 44upx;
  290. }
  291. }
  292. }
  293. .ad{
  294. margin: 0rpx 0rpx 60rpx;
  295. }
  296. }
  297. </style>