payment copy.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <Navbar title="支付方式" fixed border autoBack @leftClick="leftClick">
  5. <template #right>
  6. <navMenu :options="{ icon: 'icon-home', text: '主页' }" />
  7. </template>
  8. </Navbar>
  9. <view class="content">
  10. <view class="cont">
  11. <view class="payable_price">
  12. {{ symbol.symbol }}
  13. <text>{{ Moneyhtml(payInfo.totalAmt) }}</text>
  14. </view>
  15. <view class="logistics_step" v-if="type != 'package'">
  16. <trans _t="请在" />
  17. <text class="step_time">{{
  18. useGlobal().$format(payInfo.enddate || "")
  19. }}</text>
  20. <trans _t="取消付款提示" />
  21. </view>
  22. <view class="wallet_pay">
  23. <!-- <view class="wallet_title">
  24. <trans _t="用余额支付" />
  25. <view class="tag">
  26. <trans _t="推荐" />
  27. </view>
  28. </view>
  29. <view class="wallet_content">
  30. <view class="wallet_top">
  31. <up-radio-group v-model="radioValue" activeColor="var(--black)">
  32. <up-radio name="wallet">
  33. <template #label>
  34. <view style="display:flex;align-items:center;">
  35. <view class="wallet_img">
  36. <image src="../../static/shop/balance.png" class="_img"></image>
  37. </view>
  38. <view class="payment_text">
  39. <view class="payment_title">
  40. <trans _t="钱包" />
  41. </view>
  42. <view class="wallet_amount">{{ symbol.symbol }}&nbsp;{{ Moneyhtml(userInfo.money) }}</view>
  43. </view>
  44. </view>
  45. </template>
  46. </up-radio>
  47. </up-radio-group>
  48. </view>
  49. <view class="wallet_bottom" v-if="differenceMoney < 0">
  50. <view class="bottom_left">
  51. <trans _t="余额不足需充值" />
  52. <text class="money">¥{{ Math.abs(differenceMoney) }}</text>
  53. </view>
  54. <view class="bottom_right" @click="toRecharge">
  55. <trans _t="充值" />
  56. </view>
  57. </view>
  58. </view> -->
  59. <view
  60. class="wallet_content"
  61. v-for="(item, index) in bankList"
  62. :key="index"
  63. >
  64. <view class="wallet_top">
  65. <up-radio-group v-model="radioValue" activeColor="var(--black)">
  66. <up-radio :name="item.name">
  67. <template #label>
  68. <view style="display: flex; align-items: center">
  69. <view class="wallet_img">
  70. <image
  71. :src="`../../static/shop/${item.icon}`"
  72. class="_img"
  73. ></image>
  74. </view>
  75. <view class="payment_text">
  76. <view class="payment_title">
  77. <trans :_t="item.title" />
  78. </view>
  79. </view>
  80. </view>
  81. </template>
  82. </up-radio>
  83. </up-radio-group>
  84. </view>
  85. </view>
  86. <!-- <DropInPay :oid="oid" ref="dropInPayRef"></DropInPay> -->
  87. </view>
  88. <couponModel
  89. :item="couponList"
  90. @change="changeId"
  91. v-if="type == 'package'"
  92. />
  93. </view>
  94. <view class="footer">
  95. <view class="handling_fee">
  96. <trans _t="手续费" />&nbsp;:&nbsp;{{ symbol.symbol }}&nbsp;0
  97. </view>
  98. <view class="amount">
  99. <text>{{ symbol.symbol }}&nbsp;</text>
  100. <text>{{ Moneyhtml(payInfo.totalAmt) }}</text>
  101. </view>
  102. <view class="footer_btn" @click="openPassword">
  103. <trans _t="支付" />
  104. <text>{{ symbol.symbol }}</text>
  105. <text>{{ Moneyhtml(payInfo.totalAmt) }}</text>
  106. </view>
  107. </view>
  108. </view>
  109. <successModel ref="successModels" @open="handleSuccessModelOpen">
  110. <template #footer v-if="type == 'service'">
  111. <view></view>
  112. </template>
  113. </successModel>
  114. </view>
  115. <PasswordModal ref="passwordModal" @complete="completePassword" />
  116. <!-- #ifdef H5 -->
  117. <SplitCardPay
  118. ref="splitCardPayModalRef"
  119. :paramsObj="paramsObj"
  120. @on-success="handleAairwallexSuccess"
  121. />
  122. <GooglePayModal
  123. ref="googlePayRef"
  124. :paramsObj="paramsObj"
  125. @success="handleAairwallexSuccess"
  126. />
  127. <ApplePayModal
  128. ref="applePayModalRef"
  129. :paramsObj="paramsObj"
  130. @on-success="handleAairwallexSuccess"
  131. />
  132. <!-- #endif -->
  133. <!-- #ifdef APP-PLUS -->
  134. <cardPaymentApp
  135. ref="cardpaymentAppRef"
  136. :paramsObj="paramsObj"
  137. @on-success="handleAairwallexSuccess"
  138. />
  139. <googlePaymentApp ref="googlepaymentAppRef" :paramsObj="paramsObj" />
  140. <!-- #endif -->
  141. </Theme>
  142. </template>
  143. <script setup>
  144. import Navbar from "@/components/navbar";
  145. import navMenu from "@/components/nav_menu";
  146. import { onLoad } from "@dcloudio/uni-app";
  147. import { ref, nextTick, computed, onMounted } from "vue";
  148. import {
  149. SHOP_PAY_INFO,
  150. SHOP_SUBMIT_PAY,
  151. SHOP_PACKAGES_PAY,
  152. SHOP_GET_CANCOUPON,
  153. } from "@/api";
  154. import { useSystemStore, useUserStore, useTabbarStore } from "@/store";
  155. import { useGlobal, Toast, Moneyhtml, query } from "@/utils";
  156. import PasswordModal from "@/components/passwordModal";
  157. // #ifdef H5
  158. import SplitCardPay from "@/components/paymentModal/splitCardPay";
  159. import GooglePayModal from "@/components/paymentModal/googlePay";
  160. import ApplePayModal from "@/components/paymentModal/applePay";
  161. // #endif
  162. // #ifdef APP-PLUS
  163. import cardPaymentApp from "@/components/paymentModal/cardPayment_app";
  164. import googlePaymentApp from "@/components/paymentModal/googlePayment_app";
  165. // #endif
  166. // import DropInPay from "@/components/paymentModal/dropInPay"
  167. import successModel from "./components/successModel";
  168. import couponModel from "./components/couponModel";
  169. const useSystem = useSystemStore();
  170. const useUser = useUserStore();
  171. const useTabbar = useTabbarStore();
  172. const oid = ref("");
  173. const payInfo = ref({});
  174. const radioValue = ref("airwallex");
  175. const successModels = ref(null);
  176. const cardpaymentAppRef = ref(null);
  177. const googlepaymentAppRef = ref(null);
  178. const symbol = computed(() => useSystem.getSymbol);
  179. const userInfo = computed(() => useUser.getuserInfo);
  180. const differenceMoney = computed(() => {
  181. let infoPrice = Number(userInfo.value.money);
  182. let payPrice = Number(payInfo.value.totalAmt);
  183. if (infoPrice > payPrice || infoPrice == payPrice) {
  184. return 0;
  185. } else {
  186. return infoPrice - payPrice;
  187. }
  188. });
  189. const totalAmt = computed(() => {
  190. if (type.value === "package" && payInfo.value.couponId) {
  191. return payInfo.value.totalAmt - (checkDate.value.money || 0) < 0
  192. ? 0.01
  193. : payInfo.value.totalAmt - (checkDate.value.money || 0);
  194. }
  195. return payInfo.value.totalAmt || 0;
  196. });
  197. const bankList = [
  198. {
  199. name: "airwallex",
  200. title: "银行卡",
  201. icon: "bank_card.png",
  202. },
  203. // #ifndef APP-PLUS
  204. {
  205. name: "google",
  206. title: "Google支付",
  207. icon: "google.png",
  208. },
  209. // #endif
  210. ];
  211. if (useGlobal().$adjustPosition) {
  212. const applePayConf = {
  213. name: "apple",
  214. title: "Apple支付",
  215. icon: "applepay.png",
  216. };
  217. const i = bankList.findIndex((item) => item.name == applePayConf.name);
  218. i < 0 && bankList.push(applePayConf);
  219. }
  220. const issubnum = ref(0);
  221. const isPage = ref("");
  222. const type = ref("");
  223. const couponList = ref([]);
  224. const checkDate = ref(null);
  225. const passwordModal = ref(null);
  226. const cardPayModalRef = ref(null);
  227. const splitCardPayModalRef = ref(null);
  228. const applePayModalRef = ref(null);
  229. const googlePayRef = ref(null);
  230. const paramsObj = ref(null);
  231. // const dropInPayRef = ref(null);
  232. const openPassword = () => {
  233. const isShipping = type.value === "package";
  234. paramsObj.value = {
  235. [isShipping ? "id" : "oid"]: oid.value,
  236. type: type.value,
  237. };
  238. if (isShipping && payInfo.value.couponId) {
  239. paramsObj.value.couponId = payInfo.value.couponId;
  240. }
  241. if (radioValue.value == "wallet") {
  242. if (userInfo.value.setpaypass) {
  243. passwordModal.value && passwordModal.value.open();
  244. } else {
  245. uni.navigateTo({ url: "/pages/setting/account-safety" });
  246. }
  247. return;
  248. }
  249. // if (radioValue.value == 'airwallex') return cardPayModalRef.value && cardPayModalRef.value.open();
  250. // #ifdef H5
  251. if (radioValue.value == "airwallex")
  252. return splitCardPayModalRef.value && splitCardPayModalRef.value.open();
  253. if (radioValue.value == "google")
  254. return googlePayRef.value && googlePayRef.value.open();
  255. if (radioValue.value == "apple")
  256. return applePayModalRef.value && applePayModalRef.value.open();
  257. // #endif
  258. // #ifdef APP-PLUS
  259. if (radioValue.value == "airwallex")
  260. return (
  261. cardpaymentAppRef.value && cardpaymentAppRef.value.open(paramsObj.value)
  262. );
  263. if (radioValue.value == "google")
  264. return googlepaymentAppRef.value && googlepaymentAppRef.value.open();
  265. // #endif
  266. };
  267. const completePassword = (password) => {
  268. paySubmit(password);
  269. };
  270. const paySubmit = async (password) => {
  271. try {
  272. const isShipping = type.value === "package";
  273. const params = {
  274. type: type.value,
  275. payType: radioValue.value,
  276. paypass: password,
  277. [isShipping ? "id" : "oid"]: oid.value,
  278. };
  279. if (isShipping && payInfo.value.couponId) {
  280. params.couponId = payInfo.value.couponId;
  281. }
  282. const res = await SHOP_PACKAGES_PAY(params);
  283. useUser.getUserInfo();
  284. passwordModal.value && passwordModal.value.close();
  285. useTabbar.getPageCur("shop");
  286. successModels.value && successModels.value.open();
  287. // setTimeout(() => {
  288. // uni.$emit('on-open')
  289. // uni.navigateBack()
  290. // }, 1000)
  291. } catch (error) {
  292. Toast(error.msg);
  293. }
  294. };
  295. // #ifdef H5
  296. const handleAairwallexSuccess = (dataInfo) => {
  297. switch (radioValue.value) {
  298. case "airwallex":
  299. // cardPayModalRef.value && cardPayModalRef.value.close();
  300. splitCardPayModalRef.value && splitCardPayModalRef.value.close();
  301. break;
  302. case "google":
  303. googlePayRef.value && googlePayRef.value.close();
  304. break;
  305. case "apple":
  306. applePayModalRef.value && applePayModalRef.value.close();
  307. break;
  308. default:
  309. break;
  310. }
  311. useTabbar.getPageCur("shop");
  312. successModels.value && successModels.value.open();
  313. };
  314. // #endif
  315. // #ifdef APP-PLUS
  316. const handleAairwallexSuccess = (dataInfo) => {
  317. console.log("----- on-success dataInfo ----", dataInfo);
  318. switch (radioValue.value) {
  319. case "airwallex":
  320. cardpaymentAppRef.value && cardpaymentAppRef.value.close();
  321. break;
  322. case "google":
  323. googlepaymentAppRef.value && googlepaymentAppRef.value.open();
  324. break;
  325. case "apple":
  326. break;
  327. default:
  328. break;
  329. }
  330. useTabbar.getPageCur("shop");
  331. successModels.value && successModels.value.open();
  332. };
  333. // #endif
  334. const toRecharge = () => {
  335. uni.navigateTo({ url: "/pages/bank/recharge" });
  336. };
  337. const leftClick = () => {
  338. if (isPage.value == "order") {
  339. uni.switchTab({ url: "/pages/order/index" });
  340. useTabbar.getPageCur("shop");
  341. } else {
  342. uni.navigateBack();
  343. }
  344. };
  345. onLoad((options) => {
  346. oid.value = options.oid;
  347. isPage.value = options.page || "";
  348. type.value = options.type || "";
  349. if (type.value == "package") {
  350. payInfo.value.totalAmt = options.money || 0;
  351. nextTick(() => {
  352. getCoupon(options.money);
  353. });
  354. } else {
  355. nextTick(() => {
  356. getPayInfo();
  357. // dropInPayRef.value && dropInPayRef.value.onMount()
  358. });
  359. }
  360. });
  361. function handleSuccessModelOpen() {
  362. if (type.value == "service") {
  363. setTimeout(() => {
  364. uni.navigateBack({
  365. success: () => {
  366. uni.$emit("on-service-open");
  367. },
  368. });
  369. }, 1000);
  370. }
  371. }
  372. const getPayInfo = async () => {
  373. try {
  374. const res = await SHOP_PAY_INFO({
  375. oid: oid.value,
  376. type: type.value,
  377. couponId: payInfo.value.couponId,
  378. });
  379. payInfo.value = res.data;
  380. } catch (error) {}
  381. };
  382. const getCoupon = async (money) => {
  383. try {
  384. const res = await SHOP_GET_CANCOUPON(money);
  385. couponList.value = res.data || [];
  386. } catch (error) {}
  387. };
  388. const changeId = (id, data) => {
  389. if (id) {
  390. payInfo.value.couponId = id;
  391. checkDate.value = data;
  392. } else {
  393. delete payInfo.value.couponId;
  394. checkDate.value = null;
  395. }
  396. getPayInfo();
  397. };
  398. onMounted(() => {
  399. // walletRef.value.appendChild('1231232')
  400. // #ifdef APP-PLUS
  401. // #endif
  402. });
  403. </script>
  404. <style lang="less" scoped>
  405. @import url("@/style.less");
  406. .wrap {
  407. min-height: 100vh;
  408. background-color: var(--bg);
  409. .flex();
  410. flex-direction: column;
  411. overflow: hidden;
  412. .content {
  413. flex-grow: 1;
  414. .flex();
  415. flex-direction: column;
  416. height: calc(100vh - 44px);
  417. overflow: hidden scroll;
  418. .cont {
  419. flex-grow: 1;
  420. overflow: hidden scroll;
  421. .payable_price {
  422. color: var(--text);
  423. .size(48rpx);
  424. font-weight: 700;
  425. line-height: 60rpx;
  426. padding-top: 24rpx;
  427. text-align: center;
  428. }
  429. .logistics_step {
  430. color: var(--text-01);
  431. .size(28rpx);
  432. line-height: 40rpx;
  433. padding: 32rpx 24rpx 0;
  434. .step_time {
  435. margin: 0 8rpx;
  436. display: inline-block;
  437. color: var(--text);
  438. font-weight: 700;
  439. }
  440. }
  441. .wallet_pay {
  442. margin: 24rpx;
  443. padding: 24rpx;
  444. border-radius: 16rpx;
  445. background-color: var(--light);
  446. .wallet_title {
  447. .ver();
  448. .size(36rpx);
  449. font-weight: 700;
  450. height: 60rpx;
  451. color: var(--text);
  452. .tag {
  453. background-color: var(--danger);
  454. border-radius: 8rpx;
  455. color: var(--light);
  456. .size(24rpx);
  457. font-weight: 500;
  458. line-height: 40rpx;
  459. margin-left: 8rpx;
  460. padding: 0 8rpx;
  461. }
  462. }
  463. .wallet_content {
  464. margin-top: 24rpx;
  465. .wallet_top {
  466. /deep/ .u-radio-group {
  467. flex: none;
  468. .u-radio__icon-wrap {
  469. margin-right: 0;
  470. }
  471. }
  472. .ver();
  473. .wallet_img {
  474. width: 72rpx;
  475. height: 72rpx;
  476. margin: 0 24rpx;
  477. ._img {
  478. width: inherit;
  479. height: inherit;
  480. }
  481. }
  482. .payment_text {
  483. .ver(flex-end);
  484. color: var(--text);
  485. .size();
  486. font-weight: 500;
  487. .wallet_amount {
  488. margin-left: 8rpx;
  489. font-weight: 700;
  490. }
  491. }
  492. }
  493. .wallet_bottom {
  494. margin-top: 16rpx;
  495. padding: 16rpx 24rpx;
  496. background-color: var(--bg);
  497. border-radius: 8rpx;
  498. .flex_position(space-between);
  499. .bottom_left {
  500. color: var(--text-02);
  501. .size(24rpx);
  502. margin-right: 16rpx;
  503. .money {
  504. color: var(--primary);
  505. }
  506. }
  507. .bottom_right {
  508. height: 64rpx;
  509. background-color: var(--black);
  510. color: var(--light);
  511. border-radius: 16rpx;
  512. padding: 16rpx 30rpx;
  513. .flex_center();
  514. .size(24rpx);
  515. line-height: 1;
  516. }
  517. }
  518. }
  519. }
  520. }
  521. .footer {
  522. padding: 0 24rpx 24rpx;
  523. background-color: var(--bg);
  524. .handling_fee {
  525. color: var(--text-01);
  526. .size(28rpx);
  527. line-height: 60rpx;
  528. text-align: center;
  529. }
  530. .amount {
  531. color: var(--red);
  532. .size(48rpx);
  533. font-weight: 700;
  534. line-height: 80rpx;
  535. text-align: center;
  536. }
  537. &_btn {
  538. background-color: var(--black);
  539. color: var(--light);
  540. padding: 16rpx 30rpx;
  541. height: 96rpx;
  542. .flex_center();
  543. border-radius: 16rpx;
  544. font-weight: 700;
  545. .size(28rpx);
  546. column-gap: 8rpx;
  547. }
  548. }
  549. }
  550. }
  551. </style>