pay.vue 8.5 KB

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