pay-zfb.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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('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. },
  234. };
  235. </script>
  236. <style lang="scss">
  237. .shopName {
  238. font-weight: bold;
  239. font-size: 36rpx;
  240. color: #333333;
  241. }
  242. /* 修改加载提示框的遮罩层 z-index */
  243. .uni-loading__mask {
  244. z-index: 10076;
  245. }
  246. /* 修改加载提示框本身的 z-index */
  247. .uni-loading {
  248. z-index: 10076;
  249. }
  250. .yzm {
  251. font-weight: 500;
  252. font-size: 28rpx;
  253. color: #00D36D;
  254. }
  255. .popup {
  256. height: 300px;
  257. padding: 20px;
  258. .footer {
  259. margin-top: 150rpx;
  260. .btn {
  261. width: 100%;
  262. background: linear-gradient(275deg, #01CF6C 0%, #07E278 100%);
  263. border-radius: 46rpx;
  264. border: none;
  265. }
  266. }
  267. .main {
  268. margin-top: 20rpx;
  269. }
  270. .header {
  271. margin-bottom: 20rpx;
  272. text-align: center;
  273. .tip {
  274. margin-top: 20rpx;
  275. font-weight: 500;
  276. font-size: 26rpx;
  277. color: #FF8B2F;
  278. }
  279. }
  280. }
  281. .u-radio-group--row {
  282. justify-content: center;
  283. }
  284. .radioText {
  285. font-weight: 500;
  286. font-size: 24rpx;
  287. color: #999999;
  288. line-height: 34rpx;
  289. text-align: left;
  290. font-style: normal;
  291. }
  292. .login-main {
  293. width: 100%;
  294. display: flex;
  295. flex-direction: column;
  296. /* justify-content: space-between; */
  297. align-items: center;
  298. height: 100vh;
  299. }
  300. .login-contont-button {
  301. text-align: center;
  302. .btn {
  303. margin-top: 20px;
  304. width: 95%;
  305. height: 90rpx;
  306. background: linear-gradient(275deg, #01cf6c 0%, #07e278 100%);
  307. border-radius: 44rpx;
  308. color: #fff;
  309. }
  310. }
  311. .login-contont {
  312. width: 90%;
  313. height: 50%;
  314. .uInput {
  315. padding: 10px 0px;
  316. border-bottom: 0.5px solid #97979740;
  317. }
  318. .login-contont-info {
  319. text-align: center;
  320. .text {
  321. margin-top: 10px;
  322. font-weight: 500;
  323. font-size: 28rpx;
  324. color: #999999;
  325. line-height: 40rpx;
  326. font-style: normal;
  327. }
  328. }
  329. }
  330. .radio {
  331. text-align: center;
  332. margin-top: 10px;
  333. }
  334. .login-main-content {
  335. background: url("../../static/images/payBack.png") no-repeat;
  336. background-size: 100% 100%;
  337. text-align: center;
  338. width: 100%;
  339. height: 120px;
  340. .img {
  341. margin-top: 70px;
  342. width: 80px;
  343. height: 80px;
  344. border-radius: 50%;
  345. }
  346. }
  347. </style>