Sanakey
2024-09-14 abcc94512041409b4e1d4f56e51a442f9c762f09
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<template>
  <BasicModal
    v-bind="$attrs"
    @register="register"
    title="添加跟进"
    @visible-change="handleVisibleChange"
    @ok="handleSubmit"
  >
    <div :class="'pt-3px pr-3px '+ prefixCls">
<!--      <div>-->
<!--        <ApiSelect-->
<!--          :api="optionsListApi"-->
<!--          :allow-clear="false"-->
<!--          :bordered="false"-->
<!--          v-model:value="currentFollowUpType"-->
<!--          optionFilterProp="label"-->
<!--          resultField="list"-->
<!--          labelField="name"-->
<!--          valueField="id"-->
<!--          label="跟进类型"-->
<!--          style="width: 120px"-->
<!--          @change="handleFollowUpTypeChange"-->
<!--        />-->
<!--      </div>-->
      <BasicForm @register="registerForm1"></BasicForm>
      <div class="edit-wrap mb-10px">
        <BasicForm @register="registerForm2" :model="modelRef">
          <template #textBtnArray>
            <a-button v-for="item in textArray" class="mr-10px mb-10px" @click="addText(item)">
              {{ item }}
            </a-button>
          </template>
          <template #uploadFile="{ model, field }">
            <div class="flex flex-justify-between">
              <Upload
                v-model:file-list="model[field]"
                action=""
                list-type="text"
                @remove="removeFile"
                class="upload-list-inline"
                :showUploadList="{ showDownloadIcon: false,showRemoveIcon: true }"
              >
                <a-button type="primary" sharp="circle">
                  <template #icon>
                    <PaperClipOutlined />
                  </template>
                  上传附件
                </a-button>
              </Upload>
            </div>
          </template>
        </BasicForm>
      </div>
      <BasicForm @register="registerForm3"></BasicForm>
    </div>
  </BasicModal>
</template>
<script lang="ts" setup>
import {ref, nextTick, h, unref} from 'vue';
import {BasicModal, useModalInner} from '@/components/Modal';
import {ApiSelect, BasicForm, useForm} from '@/components/Form';
import {schemas1,schemas2,schemas3} from './followUpFormData';
 
import {PlusOutlined, MinusOutlined,PaperClipOutlined} from '@ant-design/icons-vue';
import {TreeSelect, Upload} from "ant-design-vue";
import {optionsListApi} from "@/api/demo/select";
const prefixCls = 'new-follow-up';
const props = defineProps({
  userData: {type: Object},
});
const modelRef = ref({});
const [registerForm1,{validate:validate1}] = useForm({
  schemas:schemas1,
  showActionButtonGroup: false,
});
const [registerForm2,{validate:validate2,setFieldsValue:setFieldsValue2,getFieldsValue:getFieldsValue2}] = useForm({
  schemas:schemas2,
  showActionButtonGroup: false,
});
const [registerForm3,{validate:validate3}] = useForm({
  schemas:schemas3,
  showActionButtonGroup: false,
});
 
const [register,{ setModalProps, closeModal }] = useModalInner((data) => {
  Logger.log('useModalInner data...', data);
  data && onDataReceive(data);
  setModalProps({
    // width: 800,
    destroyOnClose: true,
  });
});
 
let textArray = ref(['1','2']);
function addText(item) {
  let text = getFieldsValue2()['followUpContent']?.trim() || '';
  Logger.log('addText... text', text);
  setFieldsValue2({
    followUpContent: text? `${text}${item}` : item,
  });
}
 
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));
}
 
// let currentFollowUpType = ref('1');
// function handleFollowUpTypeChange(value: any) {
//   Logger.log('handleFollowUpTypeChange...', value);
// }
 
function removeFile(file: any) {
  Logger.log('remove file...', file);
}
 
async function handleSubmit() {
  try {
    const [values1, values2,values3] = await Promise.all([validate1(), validate2(),validate3()]);
    Logger.log('submit values1', values1);
    Logger.log('submit values2', values2);
    Logger.log('submit values3', values3);
    setModalProps({ confirmLoading: true });
    // TODO custom api
    // console.log(values);
    closeModal();
  } finally {
    setModalProps({ confirmLoading: false });
  }
}
</script>
 
<style lang="less">
.new-follow-up{
  .edit-wrap{
    border: 1px solid #eee;
    padding: 10px;
    border-radius: 5px;
  }
  // 子元素激活时父容器边框变色
  .edit-wrap:focus-within  {
    border-color: #1890ff;
  }
}
 
</style>