pay-zfb.vue 9.7 KB

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