pay-zfb.vue 9.0 KB

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