pay.vue 7.5 KB

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