pay-zfb.vue 9.1 KB

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