pay-zfb.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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" @click="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 @click="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="确定" @click="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" @click="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" @click="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. {
  132. "amount": 2,
  133. "applyAllProducts": 1,
  134. "applyProductIds": [],
  135. "bizType": 14,
  136. "claimTime": "2026-04-11 09:56:51",
  137. "createTime": "2026-04-11 09:56:51",
  138. "discountAmount": null,
  139. "endTime": "2026-04-30 10:33:38",
  140. "id": "2042783907267350530",
  141. "isApply": 0,
  142. "minOrderAmount": null,
  143. "orderNo": "",
  144. "productIds": [],
  145. "ruleDisplay": "无门槛",
  146. "startTime": "2026-04-10 10:33:26",
  147. "status": 1,
  148. "storeCount": 1,
  149. "storeId": "2018881434293329922",
  150. "storeList": [
  151. {
  152. "isCreator": 1,
  153. "storeId": "2018881434293329922",
  154. "storeName": "医药one店",
  155. "voucherId": "2042068417733718017"
  156. }
  157. ],
  158. "storeName": "",
  159. "unApplyReason": "",
  160. "updateTime": "2026-04-11 09:56:47",
  161. "useTime": null,
  162. "userId": "1965353825816576001",
  163. "voucherId": "2042068417733718017",
  164. "voucherName": "2元代金券",
  165. "voucherRule": 1,
  166. "voucherType": 3,
  167. "voucherTypeDesc": "联合券"
  168. },
  169. {
  170. "amount": 2,
  171. "applyAllProducts": 1,
  172. "applyProductIds": [],
  173. "bizType": 14,
  174. "claimTime": "2026-04-11 09:56:50",
  175. "createTime": "2026-04-11 09:56:50",
  176. "discountAmount": null,
  177. "endTime": "2026-04-16 21:21:31",
  178. "id": "2042783902674587650",
  179. "isApply": 0,
  180. "minOrderAmount": null,
  181. "orderNo": "",
  182. "productIds": [],
  183. "ruleDisplay": "无门槛",
  184. "startTime": "2026-04-07 15:14:37",
  185. "status": 1,
  186. "storeCount": 1,
  187. "storeId": "2018881434293329922",
  188. "storeList": [
  189. {
  190. "isCreator": 1,
  191. "storeId": "2018881434293329922",
  192. "storeName": "医药one店",
  193. "voucherId": "2042139544933875713"
  194. }
  195. ],
  196. "storeName": "",
  197. "unApplyReason": "",
  198. "updateTime": "2026-04-11 09:56:46",
  199. "useTime": null,
  200. "userId": "1965353825816576001",
  201. "voucherId": "2042139544933875713",
  202. "voucherName": "联合券",
  203. "voucherRule": 1,
  204. "voucherType": 3,
  205. "voucherTypeDesc": "联合券"
  206. }
  207. ],
  208. couponId: "",
  209. CellText: "暂无代金券",
  210. payment: "",
  211. voucherRadio: false,
  212. };
  213. },
  214. onLoad(options) {
  215. this.zfbInfo = options;
  216. this.uid = options.uid || "";
  217. this.shopId = options.shopId || "";
  218. this.storeId = options.storeId || "";
  219. // 读取本地支付宝用户信息
  220. let info = localStorage.getItem("aliPayUserInfo");
  221. if (info) {
  222. this.localUserInfo = JSON.parse(info);
  223. }
  224. // 登录逻辑
  225. if (this.localUserInfo) {
  226. this.getShopInfo();
  227. this.getVoucher();
  228. this.getPhoneBind();
  229. } else {
  230. if (this.zfbInfo.auth_code) {
  231. this.getInfo();
  232. } else {
  233. uni.$u.toast("授权信息失效,请重新进入");
  234. }
  235. }
  236. },
  237. methods: {
  238. // 输入金额时自动重置代金券计算
  239. handlePriceChange() {
  240. this.payment = "";
  241. this.couponId = "";
  242. this.voucherRadio = false;
  243. this.CellText = this.couponList.length
  244. ? `可使用${this.couponList.length}个`
  245. : "暂无代金券";
  246. },
  247. // 选择代金券
  248. groupChange(e) {
  249. this.showPopup = false;
  250. let target = this.couponList.find((item) => item.id === e);
  251. if (!target) return;
  252. if (target.voucherRule === 1) {
  253. this.CellText = `- ¥${target.amount}`;
  254. } else {
  255. this.CellText = `满${target.minOrderAmount}减${target.discountAmount}`;
  256. }
  257. let pay = Number(this.price) - Number(target.amount || 0);
  258. this.payment = pay > 0 ? pay.toFixed(2) : "0.01";
  259. this.voucherRadio = true;
  260. },
  261. // 获取可用代金券
  262. getVoucher() {
  263. if (!this.storeId) return;
  264. api.availableList({
  265. storeId: this.storeId,
  266. }).then((res) => {
  267. if (res.code == 200) {
  268. this.couponList = res.data.filter((item) => item.applyAllProducts !== 0);
  269. if (this.couponList.length > 0) {
  270. this.CellText = `可使用${this.couponList.length}个`;
  271. } else {
  272. this.CellText = "暂无代金券";
  273. }
  274. }
  275. });
  276. },
  277. // 打开代金券选择
  278. voucher() {
  279. if (!this.price || Number(this.price) <= 0) {
  280. return uni.$u.toast("请输入正确的支付金额!");
  281. }
  282. if (this.couponList.length === 0) {
  283. return uni.$u.toast("暂无可用代金券");
  284. }
  285. this.showPopup = true;
  286. },
  287. // 检查是否绑定手机号
  288. getPhoneBind() {
  289. api.checkBindPhone().then((res1) => {
  290. // this.showPhone = res1.code !== 200 || res1.data.bindPhoneStatus === 0;
  291. }).catch(() => {
  292. this.showPhone = true;
  293. });
  294. },
  295. // 支付宝授权登录
  296. async getInfo() {
  297. uni.showLoading({ title: "登录中..." });
  298. api.weChatH5Login({
  299. code: this.zfbInfo.auth_code,
  300. grant_type: "ali",
  301. }).then((res) => {
  302. uni.hideLoading();
  303. if (res.code == 200) {
  304. this.userInfo = res.data;
  305. localStorage.setItem("token", this.userInfo.access_token);
  306. localStorage.setItem("aliPayUserInfo", JSON.stringify(this.userInfo));
  307. this.getShopInfo();
  308. this.getVoucher();
  309. this.getPhoneBind();
  310. uni.hideLoading();
  311. } else {
  312. uni.$u.toast("登录失败,请重试");
  313. uni.hideLoading();
  314. }
  315. }).catch(() => {
  316. uni.hideLoading();
  317. uni.$u.toast("登录异常");
  318. });
  319. },
  320. // 支付
  321. async Pay() {
  322. if (!this.price || Number(this.price) <= 0) {
  323. return uni.$u.toast("请输入支付金额");
  324. }
  325. if (!this.shopInfo || !this.shopInfo.shopId) {
  326. return uni.$u.toast("店铺信息异常");
  327. }
  328. uni.showLoading({ title: "支付中..." });
  329. let payAmount = this.payment || this.price;
  330. api.payOrder({
  331. shopType: this.shopInfo.shopType,
  332. shopUserId: this.shopInfo.shopUserId,
  333. shopId: this.shopInfo.shopId,
  334. payAmount: Number(payAmount).toFixed(2),
  335. payWay: 7,
  336. }).then((pay) => {
  337. uni.hideLoading();
  338. if (pay.code == 200) {
  339. let url = `alipays://platformapi/startapp?appId=20000067&url=${encodeURIComponent(pay.data.result)}`;
  340. window.location.href = url;
  341. } else {
  342. uni.$u.toast(pay.msg);
  343. }
  344. }).catch((err) => {
  345. uni.hideLoading();
  346. uni.$u.toast("支付请求失败");
  347. });
  348. },
  349. // 获取店铺信息
  350. async getShopInfo() {
  351. if (!this.shopId) return;
  352. api.getStoreInfoByScan({
  353. shopId: this.shopId,
  354. }).then((res) => {
  355. if (res.code == 200) {
  356. this.shopInfo = res.data;
  357. } else {
  358. uni.$u.toast(res.msg);
  359. }
  360. });
  361. },
  362. restLogin() {
  363. api.weChatH5Login({
  364. grant_type: "pwd",
  365. phone: this.phone,
  366. password: 123456,
  367. }).then((res) => {
  368. if (res.code == 200) {
  369. this.userInfo = res.data;
  370. localStorage.setItem("token", this.userInfo.access_token);
  371. localStorage.setItem("aliPayUserInfo", JSON.stringify(this.userInfo));
  372. this.getPhoneBind()
  373. }
  374. }).catch((err) => {
  375. });
  376. },
  377. // 绑定手机号提交
  378. async submitOk() {
  379. if (!this.phone) return uni.$u.toast("请输入手机号");
  380. if (!this.yzm) return uni.$u.toast("请输入验证码");
  381. uni.showLoading({ title: "正在绑定中..." });
  382. api.bindH5Phone({
  383. mobile: this.phone,
  384. code: this.yzm,
  385. password: 123456,
  386. confirmPassword: 123456,
  387. type: 0,
  388. }).then((res) => {
  389. if (res.code == 200) {
  390. uni.$u.toast("绑定成功");
  391. this.showPhone = false;
  392. this.restLogin()
  393. uni.hideLoading();
  394. } else {
  395. uni.$u.toast(res.msg);
  396. }
  397. }).catch((err) => {
  398. uni.$u.toast(err.data.msg);
  399. });
  400. },
  401. codeChange(text) {
  402. this.tips = text;
  403. },
  404. // 获取验证码
  405. async getCode() {
  406. if (!this.$refs.uCode.canGetCode) return;
  407. if (!this.phone) return uni.$u.toast("请输入手机号");
  408. api.sendSms({ phone: this.phone, type: 0 }).then((res) => {
  409. if (res.code == 200) {
  410. uni.$u.toast("验证码已发送");
  411. this.$refs.uCode.start();
  412. } else {
  413. uni.$u.toast(res.msg || "发送失败");
  414. }
  415. }).catch(() => {
  416. uni.hideLoading();
  417. uni.$u.toast("发送失败");
  418. });
  419. },
  420. },
  421. };
  422. </script>
  423. <style lang="scss" scoped>
  424. .info {
  425. font-size: 24rpx;
  426. color: #999;
  427. line-height: 1.6;
  428. }
  429. .right {
  430. padding-left: 20rpx;
  431. }
  432. .tag {
  433. font-size: 22rpx;
  434. color: #fff;
  435. padding: 4rpx 12rpx;
  436. border-radius: 6rpx;
  437. margin-bottom: 12rpx;
  438. }
  439. .login-main {
  440. background: url("../../static/images/payBack.png");
  441. background-size: cover;
  442. width: 100%;
  443. height: 100vh;
  444. }
  445. .main {
  446. width: 100%;
  447. background: #fff;
  448. height: calc(100% - 270rpx);
  449. border-radius: 40rpx 40rpx 0 0;
  450. }
  451. .login-main-content {
  452. display: flex;
  453. align-items: center;
  454. padding: 30rpx 30rpx 0;
  455. .img {
  456. width: 44rpx;
  457. height: 44rpx;
  458. border-radius: 50%;
  459. margin-right: 20rpx;
  460. }
  461. .shopName {
  462. font-size: 36rpx;
  463. font-weight: bold;
  464. color: #333;
  465. }
  466. }
  467. .login-contont {
  468. padding: 40rpx 30rpx;
  469. }
  470. .uInput {
  471. border-bottom: 0.5px solid #eee;
  472. padding: 10rpx 0;
  473. }
  474. .pay-info {
  475. padding: 20rpx 0;
  476. font-size: 26rpx;
  477. color: #666;
  478. .price {
  479. color: orange;
  480. font-size: 40rpx;
  481. margin-left: 10rpx;
  482. }
  483. }
  484. .yen {
  485. font-size: 28rpx;
  486. color: #ff4d4f;
  487. }
  488. .num {
  489. font-size: 44rpx;
  490. font-weight: bold;
  491. color: #ff4d4f;
  492. margin: 0 10rpx;
  493. }
  494. .login-contont-button {
  495. text-align: center;
  496. .btn {
  497. width: 100%;
  498. height: 90rpx;
  499. background: linear-gradient(152deg, #6f9dfd 0%, #1b71f2 100%);
  500. border-radius: 44rpx;
  501. color: #fff;
  502. font-size: 32rpx;
  503. border: none;
  504. margin-top: 30rpx;
  505. }
  506. }
  507. .cell-item {
  508. background: #fff7f6;
  509. margin-top: 40rpx;
  510. border-radius: 12rpx;
  511. }
  512. .tip {
  513. margin-top: 20rpx;
  514. font-size: 26rpx;
  515. color: #999;
  516. line-height: 1.5;
  517. }
  518. .popup {
  519. padding: 30rpx;
  520. .header {
  521. text-align: center;
  522. margin-bottom: 30rpx;
  523. }
  524. .input-item {
  525. margin-bottom: 30rpx;
  526. }
  527. .footer {
  528. margin-top: 60rpx;
  529. }
  530. .yzm-btn {
  531. color: #00d36d;
  532. font-size: 28rpx;
  533. }
  534. }
  535. .independent {
  536. width: 70rpx;
  537. background: #5c8dff;
  538. }
  539. .chain {
  540. width: 70rpx;
  541. background: #ff7d00;
  542. }
  543. .left {
  544. flex: 1;
  545. }
  546. .coupon-popup {
  547. padding: 30rpx;
  548. height: 1000rpx;
  549. box-sizing: border-box;
  550. }
  551. .popup-header {
  552. display: flex;
  553. justify-content: space-between;
  554. align-items: center;
  555. font-size: 32rpx;
  556. font-weight: bold;
  557. margin-bottom: 30rpx;
  558. }
  559. .coupon-list {
  560. height: calc(100% - 100rpx);
  561. overflow-y: auto;
  562. }
  563. .coupon-item {
  564. background: #fff;
  565. border-radius: 16rpx;
  566. padding: 24rpx;
  567. margin-bottom: 20rpx;
  568. display: flex;
  569. justify-content: space-between;
  570. align-items: center;
  571. border: 2rpx solid #eee;
  572. }
  573. .coupon-item.active {
  574. // border-color: #ff4d4f;
  575. background: #fffbf4;
  576. }
  577. .coupon-item.disabled {
  578. opacity: 0.5;
  579. }
  580. ::v-deep .u-cell__title {
  581. flex: none !important;
  582. }
  583. </style>