pay-zfb.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <view class="login-main">
  3. <view style="width: 100%; height: 220px">
  4. <view class="login-main-content">
  5. <image class="img" :src="shopInfo?shopInfo.store_logo_url:''" mode=""></image>
  6. <h4 class="shopName">{{shopInfo?shopInfo.store_name:""}}</h4>
  7. </view>
  8. </view>
  9. <view class="login-contont">
  10. <view class="uInput">
  11. <u-input placeholder="请输入金额" border="bottom" :fontSize="40" type="digit"
  12. @change="validateInput($event,1)" v-model="price" :customStyle="inpustyle">
  13. <span slot="prefix" style="font-size: 30px">¥</span>
  14. </u-input>
  15. </view>
  16. <view class="login-contont-button">
  17. <button class="btn" @click="Pay">立即支付</button>
  18. <view style="margin-top: 20rpx; font-size: 26rpx">
  19. 支付成功后,次日有奖励红包,农商直采小程序领取
  20. </view>
  21. </view>
  22. </view>
  23. <u-popup :zIndex="200" :overlayStyle={zIndex:200} :show="showPhone" @close="close" @open="open"
  24. :safeAreaInsetTop="true" round="20">
  25. <view class="popup">
  26. <view class="header">
  27. <h4>绑定手机号</h4>
  28. <p class="tip">注意:首次登录,需绑定手机号才可成功领取农商网红包</p>
  29. </view>
  30. <view class="main">
  31. <view style="height: 70rpx">
  32. <u--input placeholder="请输入手机号" type="number" border="surround" v-model="phone"
  33. style="background: #F4F4F4;height:100%" />
  34. </view>
  35. <view style="margin-top: 20px;height: 70rpx">
  36. <u--input placeholder="验证码" border="surround" v-model="yzm"
  37. style="background: #F4F4F4;height:100%">
  38. <template slot="suffix">
  39. <u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
  40. <text class="yzm" @tap="getCode">{{tips?tips:'发送验证码'}}</text>
  41. </template>
  42. </u--input>
  43. </view>
  44. </view>
  45. <view class="footer">
  46. <u-button type="primary" class="btn" text="确定" @click="submitOk"></u-button>
  47. </view>
  48. </view>
  49. </u-popup>
  50. </view>
  51. </template>
  52. <script>
  53. import ap from "../../static/zfb.js"
  54. import {
  55. requestConfig
  56. } from "@/app.config.js";
  57. import axios from "axios";
  58. export default {
  59. data() {
  60. return {
  61. ap: ap,
  62. showPhone: false,
  63. requestConfig: requestConfig,
  64. code: "",
  65. appid: "",
  66. value: "",
  67. userInfo: {},
  68. inpustyle: {
  69. fontWeight: "bold",
  70. fontSize: "40px",
  71. },
  72. phone: "",
  73. yzm: "",
  74. tips: null,
  75. price: null,
  76. shopId: "",
  77. shopInfo: {},
  78. zfbInfo: {},
  79. shopId: "",
  80. localUserInfo: {}
  81. };
  82. },
  83. onLoad(options) {
  84. this.zfbInfo = options
  85. this.shopId = options.shopId
  86. let info = localStorage.getItem('userInfo');
  87. this.localUserInfo = JSON.parse(info)
  88. if (this.localUserInfo) {
  89. this.vidTokenExist()
  90. } else {
  91. this.getShopInfo();
  92. this.getInfo();
  93. }
  94. },
  95. methods: {
  96. async vidTokenExist() {
  97. let res = await axios.get(
  98. `${requestConfig.BaseUrl}user/app/v1/user/vidTokenExist`, {
  99. headers: {
  100. 'token': `${this.localUserInfo.token}`
  101. }
  102. });
  103. if (res.data.code == 200) {
  104. this.userInfo = this.localUserInfo;
  105. this.getShopInfo();
  106. } else {
  107. uni.$u.toast('登录已过期,请重新登录!');
  108. localStorage.removeItem('userInfo');
  109. setTimeout(() => {
  110. uni.redirectTo({
  111. url: '/pages/index/index?shopId=' + this.shopId
  112. })
  113. }, 1000)
  114. }
  115. },
  116. async getInfo() {
  117. const res = await axios.post(
  118. `${requestConfig.BaseUrl}user/app/v1/user/alipayLogin?code=${this.zfbInfo.auth_code}`
  119. );
  120. if (res.data.code == 200) {
  121. this.userInfo = res.data.data;
  122. localStorage.setItem('userInfo', JSON.stringify(this.userInfo))
  123. if (this.userInfo.bindPhoneStatus == 0) {
  124. this.showPhone = true
  125. } else {
  126. this.showPhone = false
  127. this.getShopInfo()
  128. }
  129. } else {
  130. uni.$u.toast('获取登录信息失败!');
  131. }
  132. },
  133. async Pay() {
  134. uni.showLoading({
  135. title: '支付中'
  136. });
  137. if (!this.price) {
  138. uni.$u.toast('请输入支付金额!');
  139. }
  140. let res = await axios.get(`${requestConfig.BaseUrl}order/app/v1/buyer/order/createOfflineOrder
  141. ?shopId=${this.zfbInfo.shopId}&price=${this.price}`, {
  142. headers: {
  143. 'token': `${this.userInfo.token}`
  144. }
  145. });
  146. if (res.data.code == 200) {
  147. let data = {
  148. "orderId": res.data.data, //订单id
  149. "orderType": 11, //订单类型 -1--其他 2-司机保证金 3-商品交易 11-线下交易
  150. "payKinds": 1, //支付类型 0-微信 1-支付宝
  151. "payMeth": 7 //5-微信小程序支付 6-微信H5支付 7-支付宝app支付
  152. }
  153. const pay = await axios.post(`${requestConfig.BaseUrl}order/app/v1/buyer/order/offlineOrderPay
  154. `, data, {
  155. headers: {
  156. 'Token': `${this.userInfo.token}`
  157. }
  158. });
  159. if (pay.data.code == 200) {
  160. uni.hideLoading();
  161. window.location.href =
  162. // pay.data.data.result
  163. `alipays://platformapi/startapp?appId=20000067&url=${encodeURIComponent(pay.data.data.result)}`
  164. // window.close(); // 关闭当前页面
  165. // ap.popWindow()
  166. } else {
  167. uni.$u.toast('支付失败!');
  168. }
  169. } else {
  170. uni.$u.toast('创建线下支付订单失败!');
  171. }
  172. },
  173. validateInput(e, num) {
  174. const inputTypeNum = /[^\d]/g //数字
  175. switch (num) {
  176. case 1:
  177. //要写nextTick 不然无效
  178. this.$nextTick(() => {
  179. this.listData.integral = e.replace(inputTypeNum, '');
  180. })
  181. break;
  182. }
  183. },
  184. async getShopInfo() {
  185. let res = await axios.get(
  186. `${requestConfig.BaseUrl}user/app/v1/store/getStoreInfoByScan?shopId=${this.zfbInfo.shopId}`, {
  187. headers: {
  188. 'token': `${this.userInfo.token}`
  189. }
  190. });
  191. if (res.data.code == 200) {
  192. this.shopInfo = res.data.data
  193. } else {
  194. uni.$u.toast(res.data.msg);
  195. }
  196. },
  197. async submitOk() {
  198. if (this.phone == "") {
  199. uni.$u.toast('请输入手机号');
  200. } else if (this.yzm == "") {
  201. uni.$u.toast('请输入验证码');
  202. }
  203. const res = await axios.post(
  204. `${requestConfig.BaseUrl}user/app/v1/user/bindPhone?phone=${this.phone}&code=${this.yzm}&alipayUserId=${this.userInfo.alipayUserId}`
  205. );
  206. if (res.data.code == 200) {
  207. uni.$u.toast('绑定手机号成功');
  208. this.userInfo = res.data.data
  209. this.showPhone = false
  210. this.getShopInfo()
  211. }
  212. },
  213. codeChange(text) {
  214. this.tips = text;
  215. },
  216. async getCode() {
  217. if (this.$refs.uCode.canGetCode) {
  218. const res = await axios.post(
  219. `${requestConfig.BaseUrl}third/app/v1/third/getSMSCode?phone=${this.phone}`
  220. );
  221. uni.showLoading({
  222. title: '正在获取验证码'
  223. })
  224. setTimeout(() => {
  225. uni.hideLoading();
  226. uni.$u.toast('验证码已发送');
  227. this.$refs.uCode.start();
  228. }, 2000);
  229. } else {
  230. uni.$u.toast('倒计时结束后再发送');
  231. }
  232. },
  233. // async Pay() {
  234. // uni.showLoading({
  235. // title: '支付中'
  236. // });
  237. // // uni.hideLoading();
  238. // // window.open(`${requestConfig.redirectOpen}pages/index/paySuccess`)
  239. // if (!this.price) {
  240. // uni.$u.toast('请输入支付金额!');
  241. // }
  242. // let res = await axios.get(`${requestConfig.BaseUrl}order/app/v1/buyer/order/createOfflineOrder
  243. // ?shopId=${this.shopId}&price=${this.price}`, {
  244. // headers: {
  245. // 'token': `${this.userInfo.token}`
  246. // }
  247. // });
  248. // if (res.data.code == 200) {
  249. // //post请求
  250. // let data = {
  251. // "orderId": res.data.data, //订单id
  252. // "orderType": 11, //订单类型 -1--其他 2-司机保证金 3-商品交易 4-线下交易
  253. // "payKinds": 0, //支付类型 0-微信 1-支付宝
  254. // "payMeth": 6 //5-微信小程序支付 6-微信H5支付 7-支付宝app支付
  255. // }
  256. // const pay = await axios.post(`${requestConfig.BaseUrl}order/app/v1/buyer/order/offlineOrderPay
  257. // `, data, {
  258. // headers: {
  259. // 'Token': `${this.userInfo.token}`
  260. // }
  261. // });
  262. // if (pay.data.code == 200) {
  263. // let res = JSON.parse(pay.data.data.result)
  264. // console.log(res);
  265. // WeixinJSBridge.invoke(
  266. // "getBrandWCPayRequest", {
  267. // // 公众号名称,由商户传入
  268. // appId: res.appId,
  269. // // 时间戳,自1970年以来的秒数
  270. // timeStamp: res.timeStamp,
  271. // // 随机串
  272. // nonceStr: res.nonceStr,
  273. // package: res.package,
  274. // // 微信签名方式:
  275. // signType: res.signType,
  276. // // 微信签名
  277. // paySign: res.paySign,
  278. // },
  279. // function(res) {
  280. // if (res.err_msg == "get_brand_wcpay_request:ok") {
  281. // // 使用以上方式判断前端返回,
  282. // // 微信团队郑重提示:
  283. // uni.hideLoading();
  284. // window.location.href = requestConfig.redirectOpen
  285. // // res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  286. // } else {
  287. // uni.hideLoading();
  288. // uni.$u.toast('支付失败!');
  289. // }
  290. // }
  291. // );
  292. // } else {
  293. // uni.hideLoading();
  294. // uni.$u.toast('支付失败!');
  295. // }
  296. // }
  297. // },
  298. },
  299. };
  300. </script>
  301. <style lang="scss">
  302. .shopName {
  303. font-weight: bold;
  304. font-size: 36rpx;
  305. color: #333333;
  306. }
  307. /* 修改加载提示框的遮罩层 z-index */
  308. .uni-loading__mask {
  309. z-index: 10076;
  310. }
  311. /* 修改加载提示框本身的 z-index */
  312. .uni-loading {
  313. z-index: 10076;
  314. }
  315. .yzm {
  316. font-weight: 500;
  317. font-size: 28rpx;
  318. color: #00D36D;
  319. }
  320. .popup {
  321. height: 300px;
  322. padding: 20px;
  323. .footer {
  324. margin-top: 150rpx;
  325. .btn {
  326. width: 100%;
  327. background: linear-gradient(275deg, #01CF6C 0%, #07E278 100%);
  328. border-radius: 46rpx;
  329. border: none;
  330. }
  331. }
  332. .main {
  333. margin-top: 20rpx;
  334. }
  335. .header {
  336. margin-bottom: 20rpx;
  337. text-align: center;
  338. .tip {
  339. margin-top: 20rpx;
  340. font-weight: 500;
  341. font-size: 26rpx;
  342. color: #FF8B2F;
  343. }
  344. }
  345. }
  346. .u-radio-group--row {
  347. justify-content: center;
  348. }
  349. .radioText {
  350. font-weight: 500;
  351. font-size: 24rpx;
  352. color: #999999;
  353. line-height: 34rpx;
  354. text-align: left;
  355. font-style: normal;
  356. }
  357. .login-main {
  358. width: 100%;
  359. display: flex;
  360. flex-direction: column;
  361. /* justify-content: space-between; */
  362. align-items: center;
  363. height: 100vh;
  364. }
  365. .login-contont-button {
  366. text-align: center;
  367. .btn {
  368. margin-top: 20px;
  369. width: 95%;
  370. height: 90rpx;
  371. background: linear-gradient(275deg, #01cf6c 0%, #07e278 100%);
  372. border-radius: 44rpx;
  373. color: #fff;
  374. }
  375. }
  376. .login-contont {
  377. width: 90%;
  378. height: 50%;
  379. .uInput {
  380. padding: 10px 0px;
  381. border-bottom: 0.5px solid #97979740;
  382. }
  383. .login-contont-info {
  384. text-align: center;
  385. .text {
  386. margin-top: 10px;
  387. font-weight: 500;
  388. font-size: 28rpx;
  389. color: #999999;
  390. line-height: 40rpx;
  391. font-style: normal;
  392. }
  393. }
  394. }
  395. .radio {
  396. text-align: center;
  397. margin-top: 10px;
  398. }
  399. .login-main-content {
  400. background: url("../../static/images/payBack.png") no-repeat;
  401. background-size: 100% 100%;
  402. text-align: center;
  403. width: 100%;
  404. height: 120px;
  405. .img {
  406. margin-top: 70px;
  407. width: 80px;
  408. height: 80px;
  409. border-radius: 50%;
  410. }
  411. }
  412. </style>