pay-zfb.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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.shopLogoUrl ? shopInfo.shopLogoUrl : '/static/images/error.jpeg'"
  11. mode=""></image>
  12. <h4 class="shopName">{{ shopInfo ? shopInfo.shopName : "" }}</h4>
  13. </view>
  14. <view class="login-contont">
  15. <view class="uInput">
  16. <u-input placeholder="请输入金额" border="bottom" :fontSize="40" type="digit" v-model="price"
  17. :customStyle="inpustyle" @input="handlePriceChange">
  18. <span slot="prefix" style="font-size: 30px">¥</span>
  19. </u-input>
  20. </view>
  21. <view class="pay-info" v-if="voucherRadio">
  22. <text>抵扣代金券后,实付金额</text>
  23. <text class="price"> {{ payment }}</text>
  24. </view>
  25. <view class="login-contont-button">
  26. <button class="btn" @tap="Pay">立即支付</button>
  27. <view style="padding: 0 30rpx">
  28. <view class="cell-item">
  29. <u-cell-group :border="false">
  30. <u-cell title="代金券折扣" :border="false" isLink @tap="voucher">
  31. <template slot="value">
  32. <text style="color: orange;">{{ CellText }}</text>
  33. </template>
  34. </u-cell>
  35. </u-cell-group>
  36. </view>
  37. <view class="tip">
  38. 支付成功后,次日将有随机奖励红包以及店铺代金券,可抵现金花,AI天枢云小程序领取
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 绑定手机号弹窗 -->
  45. <u-popup :show="showPhone" mode="center" round="20">
  46. <view class="popup">
  47. <view class="header">
  48. <h4>绑定手机号</h4>
  49. <p class="tip">提示:首次登录请绑定手机号</p>
  50. </view>
  51. <view class="main">
  52. <view class="input-item">
  53. <u-input placeholder="请输入手机号" type="number" v-model="phone" :adjustPosition="true" />
  54. </view>
  55. <view class="input-item">
  56. <u-input placeholder="验证码" v-model="yzm" :adjustPosition="true">
  57. <template slot="suffix">
  58. <u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
  59. <text class="yzm-btn" @tap="getCode">{{ tips ? tips : "发送验证码" }}</text>
  60. </template>
  61. </u-input>
  62. </view>
  63. </view>
  64. <view class="footer">
  65. <u-button type="primary" class="btn" text="确定" @tap="submitOk"></u-button>
  66. </view>
  67. </view>
  68. </u-popup>
  69. <u-popup :show="showPopup" mode="bottom" :round="20">
  70. <view class="coupon-popup">
  71. <view class="popup-header">
  72. <text class="title">店铺代金券</text>
  73. <u-icon name="close" size="22" @tap="showPopup = false" />
  74. </view>
  75. <view class="coupon-list">
  76. <u-radio-group v-model="voucherRadio" placement="column" @change="groupChange" iconSize="30"
  77. size="40">
  78. <view class="coupon-item" :class="item.status === 0 ? 'disabled' : 'active'"
  79. v-for="(item, index) in couponList" :key="index" @tap="selectCoupon(index)">
  80. <view class="left">
  81. <view class="tag" :class="item.voucherType === 1 ? 'independent' : 'chain'">
  82. {{ item.voucherType === 1 ? '独立券' : item.voucherType === 2 ? '连锁券' : '联合券' }}
  83. </view>
  84. <view class="price">
  85. <text class="yen">¥</text>
  86. <text class="num">{{ item.amount }}</text>
  87. <text class="tip">{{ item.voucherRule == 1 ? '无门槛' : '满' + item.minOrderAmount + '减'
  88. +
  89. item.discountAmount }}</text>
  90. </view>
  91. <view class="info">
  92. <text>{{ item.createTime }}</text>
  93. <!-- <text>{{ item.scope }}</text> -->
  94. </view>
  95. </view>
  96. <view class="right">
  97. <u-radio :name="item.id" iconSize="30" />
  98. </view>
  99. </view>
  100. </u-radio-group>
  101. </view>
  102. </view>
  103. </u-popup>
  104. </view>
  105. </template>
  106. <script>
  107. import api from "@/api/index.js";
  108. import { requestConfig } from "@/app.config.js";
  109. export default {
  110. data() {
  111. return {
  112. showPhone: false,
  113. showPopup: false,
  114. requestConfig: requestConfig,
  115. code: "",
  116. userInfo: {},
  117. inpustyle: {
  118. fontWeight: "bold",
  119. fontSize: "40px",
  120. },
  121. phone: "",
  122. yzm: "",
  123. tips: null,
  124. price: "",
  125. shopId: "",
  126. storeId: "",
  127. shopInfo: {},
  128. zfbInfo: {},
  129. localUserInfo: null,
  130. couponList: [],
  131. couponId: "",
  132. CellText: "暂无代金券",
  133. payment: "",
  134. voucherRadio: false,
  135. };
  136. },
  137. onLoad(options) {
  138. this.zfbInfo = options;
  139. this.uid = options.uid || "";
  140. this.shopId = options.shopId || "";
  141. this.storeId = options.storeId || "";
  142. // 读取本地支付宝用户信息
  143. let info = uni.getStorageSync("aliPayUserInfo");
  144. if (info) {
  145. this.localUserInfo = JSON.parse(info);
  146. }
  147. // 登录逻辑
  148. if (this.localUserInfo) {
  149. this.getShopInfo();
  150. this.getVoucher();
  151. this.getPhoneBind();
  152. } else {
  153. if (this.zfbInfo.auth_code) {
  154. this.getInfo();
  155. } else {
  156. uni.$u.toast("授权信息失效,请重新进入");
  157. }
  158. }
  159. },
  160. methods: {
  161. // 输入金额时自动重置代金券计算
  162. handlePriceChange() {
  163. this.payment = "";
  164. this.couponId = "";
  165. this.voucherRadio = false;
  166. this.CellText = this.couponList.length
  167. ? `可使用${this.couponList.length}个`
  168. : "暂无代金券";
  169. },
  170. // 选择代金券
  171. groupChange(e) {
  172. this.showPopup = false;
  173. let target = this.couponList.find((item) => item.id === e);
  174. if (!target) return;
  175. if (target.voucherRule === 1) {
  176. this.CellText = `- ¥${target.amount}`;
  177. } else {
  178. this.CellText = `满${target.minOrderAmount}减${target.discountAmount}`;
  179. }
  180. let pay = Number(this.price) - Number(target.amount || 0);
  181. this.payment = pay > 0 ? pay.toFixed(2) : "0.01";
  182. this.voucherRadio = true;
  183. },
  184. // 获取可用代金券
  185. getVoucher() {
  186. if (!this.storeId) return;
  187. api.availableList({
  188. storeId: this.storeId,
  189. }).then((res) => {
  190. if (res.code == 200) {
  191. this.couponList = res.data.filter((item) => item.applyAllProducts !== 0);
  192. if (this.couponList.length > 0) {
  193. this.CellText = `可使用${this.couponList.length}个`;
  194. } else {
  195. this.CellText = "暂无代金券";
  196. }
  197. }
  198. });
  199. },
  200. // 打开代金券选择
  201. voucher() {
  202. if (!this.price || Number(this.price) <= 0) {
  203. return uni.$u.toast("请输入正确的支付金额!");
  204. }
  205. if (this.couponList.length === 0) {
  206. return uni.$u.toast("暂无可用代金券");
  207. }
  208. this.showPopup = true;
  209. },
  210. // 检查是否绑定手机号
  211. getPhoneBind() {
  212. api.checkBindPhone().then((res1) => {
  213. // this.showPhone = res1.code !== 200 || res1.data.bindPhoneStatus === 0;
  214. }).catch(() => {
  215. this.showPhone = true;
  216. });
  217. },
  218. // 支付宝授权登录
  219. getInfo() {
  220. uni.showLoading({ title: "登录中..." });
  221. api.weChatH5Login({
  222. code: this.zfbInfo.auth_code,
  223. grant_type: "ali",
  224. }).then((res) => {
  225. uni.hideLoading();
  226. if (res.code == 200) {
  227. this.userInfo = res.data;
  228. uni.setStorageSync("token", this.userInfo.access_token)
  229. uni.setStorageSync("aliPayUserInfo", JSON.stringify(this.userInfo))
  230. // localStorage.setItem("token", this.userInfo.access_token);
  231. // localStorage.setItem("aliPayUserInfo", JSON.stringify(this.userInfo));
  232. this.getShopInfo();
  233. this.getVoucher();
  234. this.getPhoneBind();
  235. uni.hideLoading();
  236. } else {
  237. uni.$u.toast("登录失败,请重试");
  238. uni.hideLoading();
  239. }
  240. }).catch(() => {
  241. uni.hideLoading();
  242. uni.$u.toast("登录异常");
  243. });
  244. },
  245. // 支付
  246. Pay() {
  247. if (!this.price || Number(this.price) <= 0) {
  248. return uni.$u.toast("请输入支付金额");
  249. }
  250. if (!this.shopInfo || !this.shopInfo.shopId) {
  251. return uni.$u.toast("店铺信息异常");
  252. }
  253. uni.showLoading({ title: "支付中..." });
  254. let payAmount = this.payment || this.price;
  255. api.payOrder({
  256. shopType: this.shopInfo.shopType,
  257. shopUserId: this.shopInfo.shopUserId,
  258. shopId: this.shopInfo.shopId,
  259. payAmount: Number(payAmount).toFixed(2),
  260. payWay: 7,
  261. }).then((pay) => {
  262. uni.hideLoading();
  263. if (pay.code == 200) {
  264. let url = `alipays://platformapi/startapp?appId=20000067&url=${encodeURIComponent(pay.data.result)}`;
  265. window.location.href = url;
  266. } else {
  267. uni.$u.toast(pay.msg);
  268. }
  269. }).catch((err) => {
  270. uni.hideLoading();
  271. uni.$u.toast("支付请求失败");
  272. });
  273. },
  274. // 获取店铺信息
  275. getShopInfo() {
  276. if (!this.shopId) return;
  277. api.getStoreInfoByScan({
  278. shopId: this.shopId,
  279. }).then((res) => {
  280. if (res.code == 200) {
  281. this.shopInfo = res.data;
  282. } else {
  283. uni.$u.toast(res.msg);
  284. }
  285. });
  286. },
  287. restLogin() {
  288. api.weChatH5Login({
  289. grant_type: "pwd",
  290. phone: this.phone,
  291. password: 123456,
  292. }).then((res) => {
  293. if (res.code == 200) {
  294. this.userInfo = res.data;
  295. uni.setStorageSync("token", this.userInfo.access_token)
  296. uni.setStorageSync("aliPayUserInfo", JSON.stringify(this.userInfo));
  297. this.getPhoneBind()
  298. }
  299. })
  300. },
  301. // 绑定手机号提交(支付宝浏览器完美修复版)
  302. submitOk() {
  303. // 防重复提交
  304. if (this.isSubmitting) return;
  305. this.isSubmitting = true;
  306. if (!this.phone) return uni.$u.toast("请输入手机号");
  307. if (!this.yzm) return uni.$u.toast("请输入验证码");
  308. // 支付宝浏览器核心修复:延迟请求
  309. setTimeout(() => {
  310. uni.showLoading({ title: "正在绑定中..." });
  311. let params = {
  312. mobile: this.phone,
  313. code: this.yzm,
  314. password: "123456",
  315. confirmPassword: "123456",
  316. type: 0,
  317. };
  318. api.bindH5Phone(params).then((res) => {
  319. uni.hideLoading();
  320. this.isSubmitting = false;
  321. if (res.code == 200) {
  322. uni.$u.toast("绑定成功");
  323. this.showPhone = false;
  324. this.restLogin();
  325. } else {
  326. uni.$u.toast(res.msg || "绑定失败");
  327. }
  328. }).catch((err) => {
  329. uni.hideLoading();
  330. this.isSubmitting = false;
  331. console.error("绑定错误:", err);
  332. uni.$u.toast("绑定失败,请重试");
  333. });
  334. }, 200);
  335. },
  336. codeChange(text) {
  337. this.tips = text;
  338. },
  339. // 获取验证码(支付宝终极修复版)
  340. async getCode() {
  341. if (!this.$refs.uCode.canGetCode) return;
  342. if (!this.phone) return uni.$u.toast("请输入手机号");
  343. api.sendSms({ phone: this.phone, type: 0 }).then((res) => {
  344. if (res.code == 200) {
  345. uni.$u.toast("验证码已发送");
  346. this.$refs.uCode.start();
  347. } else {
  348. uni.$u.toast(res.msg || "发送失败");
  349. }
  350. }).catch((err) => {
  351. alert(JSON.stringify(err));
  352. uni.hideLoading();
  353. uni.$u.toast("发送失败");
  354. });
  355. },
  356. }
  357. };
  358. </script>
  359. <style lang="scss" scoped>
  360. .info {
  361. font-size: 24rpx;
  362. color: #999;
  363. line-height: 1.6;
  364. }
  365. .right {
  366. padding-left: 20rpx;
  367. }
  368. .tag {
  369. font-size: 22rpx;
  370. color: #fff;
  371. padding: 4rpx 12rpx;
  372. border-radius: 6rpx;
  373. margin-bottom: 12rpx;
  374. }
  375. .login-main {
  376. background: url("../../static/images/payBack.png");
  377. background-size: cover;
  378. width: 100%;
  379. height: 100vh;
  380. }
  381. .main {
  382. width: 100%;
  383. background: #fff;
  384. height: calc(100% - 270rpx);
  385. border-radius: 40rpx 40rpx 0 0;
  386. }
  387. .login-main-content {
  388. display: flex;
  389. align-items: center;
  390. padding: 30rpx 30rpx 0;
  391. .img {
  392. width: 44rpx;
  393. height: 44rpx;
  394. border-radius: 50%;
  395. margin-right: 20rpx;
  396. }
  397. .shopName {
  398. font-size: 36rpx;
  399. font-weight: bold;
  400. color: #333;
  401. }
  402. }
  403. .login-contont {
  404. padding: 40rpx 30rpx;
  405. }
  406. .uInput {
  407. border-bottom: 0.5px solid #eee;
  408. padding: 10rpx 0;
  409. }
  410. .pay-info {
  411. padding: 20rpx 0;
  412. font-size: 26rpx;
  413. color: #666;
  414. .price {
  415. color: orange;
  416. font-size: 40rpx;
  417. margin-left: 10rpx;
  418. }
  419. }
  420. .yen {
  421. font-size: 28rpx;
  422. color: #ff4d4f;
  423. }
  424. .num {
  425. font-size: 44rpx;
  426. font-weight: bold;
  427. color: #ff4d4f;
  428. margin: 0 10rpx;
  429. }
  430. .login-contont-button {
  431. text-align: center;
  432. .btn {
  433. width: 100%;
  434. height: 90rpx;
  435. background: linear-gradient(152deg, #6f9dfd 0%, #1b71f2 100%);
  436. border-radius: 44rpx;
  437. color: #fff;
  438. font-size: 32rpx;
  439. border: none;
  440. margin-top: 30rpx;
  441. }
  442. }
  443. .cell-item {
  444. background: #fff7f6;
  445. margin-top: 40rpx;
  446. border-radius: 12rpx;
  447. }
  448. .tip {
  449. margin-top: 20rpx;
  450. font-size: 26rpx;
  451. color: #999;
  452. line-height: 1.5;
  453. }
  454. .popup {
  455. padding: 30rpx;
  456. .header {
  457. text-align: center;
  458. margin-bottom: 30rpx;
  459. }
  460. .input-item {
  461. margin-bottom: 30rpx;
  462. }
  463. .footer {
  464. margin-top: 60rpx;
  465. }
  466. .yzm-btn {
  467. color: #00d36d;
  468. font-size: 28rpx;
  469. }
  470. }
  471. .independent {
  472. width: 70rpx;
  473. background: #5c8dff;
  474. }
  475. .chain {
  476. width: 70rpx;
  477. background: #ff7d00;
  478. }
  479. .left {
  480. flex: 1;
  481. }
  482. .coupon-popup {
  483. padding: 30rpx;
  484. height: 1000rpx;
  485. box-sizing: border-box;
  486. }
  487. .popup-header {
  488. display: flex;
  489. justify-content: space-between;
  490. align-items: center;
  491. font-size: 32rpx;
  492. font-weight: bold;
  493. margin-bottom: 30rpx;
  494. }
  495. .coupon-list {
  496. height: calc(100% - 100rpx);
  497. overflow-y: auto;
  498. }
  499. .coupon-item {
  500. background: #fff;
  501. border-radius: 16rpx;
  502. padding: 24rpx;
  503. margin-bottom: 20rpx;
  504. display: flex;
  505. justify-content: space-between;
  506. align-items: center;
  507. border: 2rpx solid #eee;
  508. }
  509. .coupon-item.active {
  510. // border-color: #ff4d4f;
  511. background: #fffbf4;
  512. }
  513. .coupon-item.disabled {
  514. opacity: 0.5;
  515. }
  516. ::v-deep .u-cell__title {
  517. flex: none !important;
  518. }
  519. </style>