Ben Lin
2024-07-02 2069d53e9be24adec3c8d6717fd7317555bd9a52
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
137
138
139
140
141
142
143
144
145
<!--
 * @Description: file content
 * @Author: Ben Lin
 * @version: 
 * @Date: 2024-06-26 22:54:42
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-27 22:14:51
-->
<template>
  <BasicModal
    width="800px"
    :height="600"
    v-bind="$attrs"
    @register="register"
    :title="title"
    @ok="handleSubmit"
  >
    <div class="step-form-form">
      <Steps :current="current">
        <Steps.Step title="选择客户" />
        <Steps.Step title="添加工艺路线" />
        <Steps.Step title="完成" />
      </Steps>
    </div>
    <div class="mt-5">
      <Step1 @next="handleStep1Next" v-show="current === 0" />
      <Step2
        @prev="handleStepPrev"
        @next="handleStep2Next"
        v-show="current === 1"
        v-if="state.initStep2"
      />
      <Step3 v-show="current === 2" @redo="handleRedo" v-if="state.initStep3" />
    </div>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref, reactive } from 'vue';
  import Step1 from './Step1.vue';
  import Step2 from './Step2.vue';
  import Step3 from './Step3.vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { Steps } from 'ant-design-vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { isNullOrUnDef } from '/@/utils/is';
  import { useMessage } from '/@/hooks/web/useMessage';
 
  defineOptions({ name: 'StepModal' });
 
  const emit = defineEmits(['success']);
  const { createErrorModal } = useMessage();
  const { t } = useI18n();
  const title = ref('');
  const current = ref(0);
  const step1Values = ref({});
  const step2Values = ref({});
 
  const state = reactive({
    initStep2: false,
    initStep3: false,
  });
 
  const [register, { setModalProps, closeModal }] = useModalInner((data) => {
    setModalProps({ confirmLoading: false, okText: '保存提交' });
    data && onDataReceive(data);
  });
 
  /**
   * @description: 打开模态窗口时接收数据方法
   * @param {*} data
   * @return {*}
   */
  async function onDataReceive(data) {
    console.log('Data Received', data);
    title.value = data?.title;
  }
 
  /**
   * @description: 步骤完成后提交方法
   * @return {*}
   */
  async function handleSubmit() {
    try {
      if (isNullOrUnDef(step1Values.value['CUST_CODE'])) {
        createErrorModal({
          title: t('sys.api.errorTip'),
          content: '步骤1未完成,请完成再保存提交',
        });
        return;
      }
      if (isNullOrUnDef(step2Values.value['ROT_CODE'])) {
        createErrorModal({
          title: t('sys.api.errorTip'),
          content: '步骤2未完成,请完成再保存提交',
        });
        return;
      }
      closeModal();
      emit('success', { ...step1Values.value, ...step2Values.value });
    } finally {
      setModalProps({ confirmLoading: false });
    }
  }
 
  function handleStep1Next(Values: any) {
    current.value++;
    state.initStep2 = true;
    console.log(Values);
    step1Values.value = Values;
  }
 
  function handleStepPrev() {
    current.value--;
    if(current.value == 1){
      step2Values.value = '';
    }
    if(current.value == 0){
      step1Values.value = '';
    }
  }
 
  function handleStep2Next(Values: any) {
    current.value++;
    state.initStep3 = true;
    console.log(Values);
    step2Values.value = Values;
  }
 
  function handleRedo() {
    current.value = 0;
    state.initStep2 = false;
    state.initStep3 = false;
  }
</script>
<style lang="less" scoped>
  .step-form-content {
    padding: 24px;
    background-color: @component-background;
  }
 
  .step-form-form {
    width: 750px;
    margin: 0 auto;
  }
</style>