DirectPayDialog.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <CommonDialog v-model:show="show" title="升级付款" :showDivider="false" :showCloseButton="false">
  3. <FlexCol gap="gap.lg" padding="padding.md" width="600rpx">
  4. <template v-if="uploadStep === 'form'">
  5. <Text textAlign="center" text="选择支付方式" fontConfig="contentSpeicalText" />
  6. <Height :height="10" />
  7. <FlexCol gap="gap.md">
  8. <BoxMid direction="row" justify="space-between">
  9. <FlexRow align="center">
  10. <Icon icon="wechat" size="40" />
  11. <Text text="微信支付" fontConfig="lightImportantTitle" :fontSize="42" />
  12. </FlexRow>
  13. <CheckBox :modelValue="payMethod == 'wechat'" shape="round" @update="payMethod = 'wechat'" />
  14. </BoxMid>
  15. </FlexCol>
  16. <FlexRow justify="space-around" gap="gap.md">
  17. <FrameButton text="取消" @click="show = false" width="220rpx" />
  18. <FrameButton primary text="支付" @click="handleSubmitPay" width="220rpx" />
  19. </FlexRow>
  20. </template>
  21. <template v-else-if="uploadStep === 'finished'">
  22. <Result
  23. status="success"
  24. title="感谢您的贡献!"
  25. description="村社升级已经生效啦"
  26. />
  27. <FlexRow justify="space-around" gap="gap.md">
  28. <FrameButton primary text="完成" @click="handleFinish" width="220rpx" />
  29. </FlexRow>
  30. </template>
  31. </FlexCol>
  32. </CommonDialog>
  33. </template>
  34. <script setup lang="ts">
  35. import { ref } from "vue";
  36. import { toast } from "@/components/dialog/CommonRoot";
  37. import { showError } from "@/common/composeabe/ErrorDisplay";
  38. import { useAuthStore } from "@/store/auth";
  39. import CommonDialog from "@/common/components/CommonDialog.vue";
  40. import FrameButton from "@/common/components/FrameButton.vue";
  41. import FlexCol from "@/components/layout/FlexCol.vue";
  42. import FlexRow from "@/components/layout/FlexRow.vue";
  43. import Height from "@/components/layout/space/Height.vue";
  44. import Text from "@/components/basic/Text.vue";
  45. import Result from "@/components/feedback/Result.vue";
  46. import BoxMid from "@/common/components/box/BoxMid.vue";
  47. import TreeApi from "@/api/light/TreeApi";
  48. import CheckBox from "@/components/form/CheckBox.vue";
  49. import type { UpgradeOrderConfirm } from "@/api/light/TreeApi";
  50. import Icon from "@/components/basic/Icon.vue";
  51. const emit = defineEmits(['success']);
  52. const authStore = useAuthStore();
  53. const show = ref(false);
  54. const uploadStep = ref<'form' | 'finished'>('form');
  55. const payMethod = ref('wechat');
  56. const orderId = ref<number>(0);
  57. async function handleSubmitPay() {
  58. if (!orderId.value) {
  59. showError('缺少必要参数');
  60. return;
  61. }
  62. switch (payMethod.value) {
  63. case 'wechat':
  64. try {
  65. const payInfo: UpgradeOrderConfirm = await TreeApi.upgradePay(orderId.value);
  66. if (payInfo && payInfo.pay) {
  67. uni.requestPayment({
  68. provider: 'wxpay',
  69. appId: payInfo.pay.appId,
  70. timeStamp: payInfo.pay.timeStamp,
  71. nonceStr: payInfo.pay.nonceStr,
  72. package: payInfo.pay.package,
  73. signType: payInfo.pay.signType,
  74. paySign: payInfo.pay.paySign,
  75. success: () => {
  76. uploadStep.value = 'finished';
  77. },
  78. fail: (err) => {
  79. toast(`支付失败: ${err.errMsg}`);
  80. },
  81. });
  82. }
  83. } catch (err) {
  84. showError('支付接口调用失败');
  85. }
  86. break;
  87. default:
  88. throw new Error('未知支付方式');
  89. }
  90. }
  91. function handleFinish() {
  92. emit('success');
  93. show.value = false;
  94. }
  95. defineExpose({
  96. open(id: number) {
  97. orderId.value = id;
  98. uploadStep.value = 'form';
  99. show.value = true;
  100. },
  101. openSuccess() {
  102. show.value = true;
  103. uploadStep.value = 'finished';
  104. },
  105. });
  106. </script>