pay-zfb.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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">提示:首次登陆请绑定于机号,连续奖励21次红包,最高可免单</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('aliPayUserInfo');
  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('aliPayUserInfo');
  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('aliPayUserInfo', 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.hideLoading();
  168. uni.$u.toast(pay.data.msg);
  169. }
  170. } else {
  171. uni.$u.toast('创建线下支付订单失败!');
  172. }
  173. },
  174. validateInput(e, num) {
  175. const inputTypeNum = /[^\d]/g //数字
  176. switch (num) {
  177. case 1:
  178. //要写nextTick 不然无效
  179. this.$nextTick(() => {
  180. this.listData.integral = e.replace(inputTypeNum, '');
  181. })
  182. break;
  183. }
  184. },
  185. async getShopInfo() {
  186. let res = await axios.get(
  187. `${requestConfig.BaseUrl}user/app/v1/store/getStoreInfoByScan?shopId=${this.zfbInfo.shopId}`, {
  188. headers: {
  189. 'token': `${this.userInfo.token}`
  190. }
  191. });
  192. if (res.data.code == 200) {
  193. this.shopInfo = res.data.data
  194. } else {
  195. uni.$u.toast(res.data.msg);
  196. }
  197. },
  198. async submitOk() {
  199. if (this.phone == "") {
  200. uni.$u.toast('请输入手机号');
  201. } else if (this.yzm == "") {
  202. uni.$u.toast('请输入验证码');
  203. }
  204. const res = await axios.post(
  205. `${requestConfig.BaseUrl}user/app/v1/user/bindPhone?
  206. phone=${this.phone}
  207. &code=${this.yzm}
  208. &alipayUserId=${this.userInfo.alipayUserId}
  209. `
  210. );
  211. if (res.data.code == 200) {
  212. uni.$u.toast('绑定手机号成功');
  213. this.userInfo = res.data.data
  214. this.showPhone = false
  215. this.getShopInfo()
  216. }
  217. },
  218. codeChange(text) {
  219. this.tips = text;
  220. },
  221. async getCode() {
  222. if (this.$refs.uCode.canGetCode) {
  223. const res = await axios.post(
  224. `${requestConfig.BaseUrl}third/app/v1/third/getSMSCode?phone=${this.phone}`
  225. );
  226. uni.showLoading({
  227. title: '正在获取验证码'
  228. })
  229. setTimeout(() => {
  230. uni.hideLoading();
  231. uni.$u.toast('验证码已发送');
  232. this.$refs.uCode.start();
  233. }, 2000);
  234. } else {
  235. uni.$u.toast('倒计时结束后再发送');
  236. }
  237. },
  238. },
  239. };
  240. </script>
  241. <style lang="scss">
  242. .shopName {
  243. font-weight: bold;
  244. font-size: 36rpx;
  245. color: #333333;
  246. }
  247. /* 修改加载提示框的遮罩层 z-index */
  248. .uni-loading__mask {
  249. z-index: 10076;
  250. }
  251. /* 修改加载提示框本身的 z-index */
  252. .uni-loading {
  253. z-index: 10076;
  254. }
  255. .yzm {
  256. font-weight: 500;
  257. font-size: 28rpx;
  258. color: #00D36D;
  259. }
  260. .popup {
  261. height: 300px;
  262. padding: 20px;
  263. .footer {
  264. margin-top: 150rpx;
  265. .btn {
  266. width: 100%;
  267. background: linear-gradient(275deg, #01CF6C 0%, #07E278 100%);
  268. border-radius: 46rpx;
  269. border: none;
  270. }
  271. }
  272. .main {
  273. margin-top: 20rpx;
  274. }
  275. .header {
  276. margin-bottom: 20rpx;
  277. text-align: center;
  278. .tip {
  279. margin-top: 20rpx;
  280. font-weight: 500;
  281. font-size: 26rpx;
  282. color: #FF8B2F;
  283. }
  284. }
  285. }
  286. .u-radio-group--row {
  287. justify-content: center;
  288. }
  289. .radioText {
  290. font-weight: 500;
  291. font-size: 24rpx;
  292. color: #999999;
  293. line-height: 34rpx;
  294. text-align: left;
  295. font-style: normal;
  296. }
  297. .login-main {
  298. width: 100%;
  299. display: flex;
  300. flex-direction: column;
  301. /* justify-content: space-between; */
  302. align-items: center;
  303. height: 100vh;
  304. }
  305. .login-contont-button {
  306. text-align: center;
  307. .btn {
  308. margin-top: 20px;
  309. width: 95%;
  310. height: 90rpx;
  311. background: linear-gradient(275deg, #01cf6c 0%, #07e278 100%);
  312. border-radius: 44rpx;
  313. color: #fff;
  314. }
  315. }
  316. .login-contont {
  317. width: 90%;
  318. height: 50%;
  319. .uInput {
  320. padding: 10px 0px;
  321. border-bottom: 0.5px solid #97979740;
  322. }
  323. .login-contont-info {
  324. text-align: center;
  325. .text {
  326. margin-top: 10px;
  327. font-weight: 500;
  328. font-size: 28rpx;
  329. color: #999999;
  330. line-height: 40rpx;
  331. font-style: normal;
  332. }
  333. }
  334. }
  335. .radio {
  336. text-align: center;
  337. margin-top: 10px;
  338. }
  339. .login-main-content {
  340. background: url("../../static/images/payBack.png") no-repeat;
  341. background-size: 100% 100%;
  342. text-align: center;
  343. width: 100%;
  344. height: 120px;
  345. .img {
  346. margin-top: 70px;
  347. width: 80px;
  348. height: 80px;
  349. border-radius: 50%;
  350. }
  351. }
  352. </style>