wupengfei
11 小时以前 b331f884097a2dc5086c8cf043c8c8f52e7640fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<template>
  <ProDialog
    title="钱包充值"
    v-model="visible"
    @close="onDialogClose"
    destroy-on-close
    draggable
    :width="700"
  >
    <ProForm :model="form" ref="dialogForm" label-width="120px">
      <ProFormItemV2 label="钱包通道:" prop="access" :check-rules="[{ message: '请选择钱包通道' }]">
        <ProFormSelect
          v-model="form.access"
          :valueEnum="EnumEnterpriseWalletAccessText"
          placeholder="请选择钱包通道"
        >
        </ProFormSelect>
      </ProFormItemV2>
      <ProFormItemV2
        label="充值金额:"
        prop="amount"
        :check-rules="[{ message: '请输入充值金额' }]"
      >
        <ProFormInputNumber
          placeholder="请输入充值金额"
          v-model.trim="form.amount"
          :controls="false"
          :min="0"
        ></ProFormInputNumber>
      </ProFormItemV2>
      <ProFormItemV2 label="备注" prop="remark">
        <ProFormTextArea placeholder="请输入备注" v-model="form.remark"></ProFormTextArea>
      </ProFormItemV2>
    </ProForm>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emit('onCancel')">取消</el-button>
        <el-button type="primary" @click="handleConfirm">确认</el-button>
      </span>
    </template>
  </ProDialog>
  <AlipayWalletRecharge v-bind="dialogAlipayWalletProps" />
</template>
 
<script setup lang="ts">
import { FormInstance } from 'element-plus';
import {
  ProDialog,
  ProForm,
  ProFormInputNumber,
  ProFormItemV2,
  ProFormTextArea,
  useFormDialog,
  ProFormSelect,
} from '@bole-core/components';
import * as enterpriseWalletServices from '@/services/api/enterpriseWallet';
import AlipayWalletRecharge from './AlipayWalletRecharge.vue';
import { EnumEnterpriseWalletAccessText } from '@/constants';
 
defineOptions({
  name: 'RechargeEnterpriseWalletDialog',
});
 
type Form = {
  title?: string;
  amount: number;
  remark: string;
  access: EnumEnterpriseWalletAccess;
};
 
const visible = defineModel({ type: Boolean });
 
const form = defineModel<Form>('form');
 
const emit = defineEmits<{
  (e: 'onConfirm'): void;
  (e: 'onCancel'): void;
}>();
 
const dialogForm = ref<FormInstance>();
 
const { dialogProps: dialogAlipayWalletProps, handleAdd: handleAlipayWalletAdd } = useFormDialog({
  defaultFormParams: {
    alipayUrl: '',
  },
});
 
async function rechargeEnterpriseWallet() {
  try {
    let params: API.RechargeEnterpriseWalletCommand = {
      access: form.value.access,
      amount: form.value.amount,
      remark: form.value.remark,
    };
    let res = await enterpriseWalletServices.rechargeEnterpriseWallet(params);
    if (res) {
      handleAlipayWalletAdd({
        alipayUrl: res.payUrl,
      });
    }
  } catch (error) {}
}
 
function onDialogClose() {
  if (!dialogForm.value) return;
  dialogForm.value.resetFields();
}
 
function handleConfirm() {
  if (!dialogForm.value) return;
  dialogForm.value.validate((valid) => {
    if (valid) {
      rechargeEnterpriseWallet();
      emit('onConfirm');
    } else {
      return;
    }
  });
}
</script>