pay.vue 8.5 KB

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