DeviceModal.vue
3.69 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<template>
<BasicModal
v-bind="$attrs"
width="55rem"
@register="register"
:title=getTitle
@visible-change="handleVisibleChange"
>
<div class="step-form-form">
<a-steps :current="current">
<a-step title="填写设备信息" />
<a-step title="确认转账信息" />
<a-step title="完成" />
</a-steps>
</div>
<div class="mt-5">
<DeviceStep1 @next="handleStep1Next" v-show="current === 0" />
<DeviceStep2
@prev="handleStepPrev"
@next="handleStep2Next"
v-show="current === 1"
v-if="initStep2"
/>
<DeviceStep3 v-show="current === 2" @redo="handleRedo" v-if="initStep3" />
</div>
</BasicModal>
</template>
<script lang="ts">
import {defineComponent, ref, nextTick, computed, unref, reactive, toRefs} from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, FormSchema, useForm } from '/@/components/Form';
import DeviceStep1 from "/@/views/device/step/DeviceStep1.vue";
import DeviceStep2 from "/@/views/device/step/DeviceStep2.vue";
import DeviceStep3 from "/@/views/device/step/DeviceStep3.vue";
import { Steps } from "ant-design-vue";
const schemas: FormSchema[] = [
{
field: 'field1',
component: 'Input',
label: '字段1',
colProps: {
span: 24,
},
defaultValue: '111',
},
{
field: 'field2',
component: 'Input',
label: '字段2',
colProps: {
span: 24,
},
},
];
export default defineComponent({
name:'DeviceModal',
components: { BasicModal, BasicForm, DeviceStep1, DeviceStep2, DeviceStep3,
[Steps.name]: Steps,
[Steps.Step.name]: Steps.Step, },
props: {
userData: { type: Object },
},
setup(props) {
const state = reactive({
initStep2: false,
initStep3: false,
});
const current = ref(0);
const isUpdate = ref(true);
const modelRef = ref({});
const getTitle = computed(() => (!unref(isUpdate) ? '新增设备' : '编辑设备'));
const [
registerForm,
{
// setFieldsValue,
// setProps
},
] = useForm({
labelWidth: 120,
schemas,
showActionButtonGroup: false,
actionColOptions: {
span: 24,
},
});
const [register] = useModalInner((data) => {
isUpdate.value = !!data?.isUpdate;
data && onDataReceive(data);
});
function handleStepPrev() {
current.value--;
}
function handleStep1Next(step1Values: any) {
current.value++;
state.initStep2 = true;
console.log(step1Values);
}
function handleStep2Next(step2Values: any) {
current.value++;
state.initStep3 = true;
console.log(step2Values);
}
function handleRedo() {
current.value = 0;
state.initSetp2 = false;
state.initSetp3 = false;
}
function onDataReceive(data) {
console.log('Data Received', data);
// 方式1;
// setFieldsValue({
// field2: data.data,
// field1: data.info,
// });
// // 方式2
modelRef.value = { field2: data.data, field1: data.info };
// setProps({
// model:{ field2: data.data, field1: data.info }
// })
}
function handleVisibleChange(v) {
v && props.userData && nextTick(() => onDataReceive(props.userData));
}
return { register, schemas, registerForm, model: modelRef, getTitle,handleVisibleChange,
current, ...toRefs(state), handleStepPrev, handleStep1Next, handleStep2Next, handleRedo};
},
});
</script>