schangxiang@126.com
2025-05-20 b5904672914f1088841208b4084fc7619576fa2e
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import {
  ref,
  onMounted,
  reactive,
  computed,
  Ref,
  watch,
  SetupContext,
  h,
} from 'vue'
import { injectModel } from '@/libs/Provider/Provider'
import { $EntityName$Drawer } from '../Models/$EntityName$Drawer'
import { ElMessage } from 'element-plus'
import isEqual from 'lodash/isEqual'
import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox'
import { cloneDeep } from 'lodash'
// ÒýÈ빫¹²Ñ¡ÏîÅäÖÃ
import { 
  FILTER_MODE_OPTIONS_STRING, 
  FILTER_MODE_OPTIONS_NUM,
  FILTER_MODE_OPTIONS_BOOL
} from '@/components/DyFormForHighQuery/DyFormForHighQueryOptions';
import { 
  BOOLEAN_OPTIONS
} from '@/utils/commonOptionConstants';
 
export const use$EntityName$QueryDrawer = (props: any, ctx?: any) => {
  const $PageMenuInstanceName$Drawer = injectModel<$EntityName$Drawer>('$EntityName$Drawer')
  /**
   * ÓÃÀ´¶Ô±ÈµÄ³õʼ»¯Êý¾Ý
   */
  const initiateData: Ref<Record<string, any>> = ref({})
  const formData = ref<Record<string, any>>({})
  // ref
  const formRef = ref()
 
  const disabled = ref(false)
 
  const current = computed(() => {
    return props.row || null
  })
 
  const inputNumber = (attrs) => {
    return (
      <el-input-number
        min="1"
        step="1"
        precision="0"
        {...attrs}
      ></el-input-number>
    )
  }
 
    const datePickerRange = (attrs) => {
    return (
      <el-date-picker
        type="daterange"
        value-format="YYYY-MM-DD HH:mm:ss"
        start-placeholder="¿ªÊ¼ÈÕÆÚ"
        end-placeholder="½áÊøÈÕÆÚ"
        {...attrs}
      ></el-date-picker>
    )
  }
 
  const dateTimePickerRange = (attrs) => {
    return (
      <el-date-picker
        type="datetimerange"
        value-format="YYYY-MM-DD HH:mm:ss"
        start-placeholder="¿ªÊ¼ÈÕÆÚ"
        end-placeholder="½áÊøÈÕÆÚ"
        {...attrs}
      ></el-date-picker>
    )
  }
 
  const visible = computed({
    get() {
      return props.modelValue
    },
    set(val) {
      ctx.emit('update:modelValue', val)
    },
  })
  /**
   * ¸ß¼¶²éѯµÄform×Ö¶Î
   */
  const formItems = reactive([
    $PageAddFormAttributes_Query$
  ])
  /**
   * Ð£ÑéÊÇ·ñÓÐÊý¾Ý±ä»¯
   */
  const checkIsEqualObject = () => {
    const data = {
      formData: formData.value,
    }
    const check = isEqual(initiateData.value, data)
    return check
  }
  /**
 * »ñÈ¡±íµ¥Êý¾Ý - ÓÅ»¯°æ
 */
const commonGetFormData = () => {
  const data = {};
  
  // ±éÀú±íµ¥ÅäÖÃÊÕ¼¯Êý¾Ý
  formItems.forEach(item => {
    // ÊÕ¼¯»ù´¡×Ö¶Î
    data[item.prop] = formData.value[item.prop] || '';
    
    // ÊÕ¼¯¹ýÂËģʽ×Ö¶Î
    if (item.highSelectAttrs && item.highSelectAttrs.prop) {
      const filterModeProp = item.highSelectAttrs.prop;
      data[filterModeProp] = formData.value[filterModeProp] || '';
    }
  });
  
  return data;
}
  const onClose = (done: () => void) => {
    if (visible.value) {
      visible.value = false
      const data =commonGetFormData();
      ctx.emit('close', data)
    }
  }
  /**
   * È·Èϲéѯ
   */
  const onConfirmQuery = async () => {
    const data =commonGetFormData();
    ctx.emit('confirmQuery', data)
  }
  /** 
   * ÖØÖù«¹²select²éѯ 
   */ 
  const onResetForHighSelect = () => {  
      // ±éÀúËùÓÐ±íµ¥×ֶΠ 
      formItems.forEach(item => {  
        // ¼ì²é×Ö¶ÎÊÇ·ñÓи߼¶²éѯµÄ¹ýÂËģʽÅäÖà 
        if (item.highSelectAttrs && item.highSelectAttrs.prop) {  
          const filterModeProp = item.highSelectAttrs.prop;  
          const options = item.highSelectAttrs.options || [];  
      
          // Èç¹û´æÔÚÑ¡ÏÔòÉèÖÃΪµÚÒ»¸öÑ¡ÏîµÄÖµ  
          if (options.length > 0) {  
            // ¼ÙÉèÑ¡Ïî¸ñʽΪ { value, label } »òÀàËÆ½á¹¹  
            const firstValue = options[0].value !== undefined ? options[0].value : options[0];  
            formData.value[filterModeProp] = firstValue;  
          }  
        }  
      });  
  }  
    /**
    * ÖØÖòéѯ - ÓÅ»¯°æ
    */
    const onReset = async () => {
        // 1. Çå¿ÕËùÓлù´¡×ֶΣ¨²»°üº¬¹ýÂËģʽ×ֶΣ©
        const baseFields = formItems.reduce((acc, item) => {
        acc[item.prop] = '';
        return acc;
        }, {});
  
        // 2. Ó¦Óûù´¡×ֶγõʼֵ
        formData.value = { ...baseFields };
  
        // 3. Ê¹ÓÃÔ­Óз½·¨ÖØÖùýÂËģʽ×Ö¶Î
        onResetForHighSelect(); // ±£ÁôÔ­Óз½·¨µ÷ÓÃ
  
        // 4. Ïò¸¸×é¼þ·¢ËÍ×Ô¶¨Òåʼþ
        ctx.emit('restQuery');
    }
 
  const updateCheckData = () => {
    initiateData.value = {
      formData: {
        ...formData.value,
      },
    }
  }
  const updateFormItemOptions = (propName: string, enumData: any[]) => {
    const item = formItems.find((item) => item.prop === propName)
    if (item && enumData) {
      item.options = enumData.map((item) => ({
        label: item.description,
        value: item.value,
      }))
    }
  }
  /**
   * Í¨Óòéѯö¾Ù
   */
  const commonQueryEnumForFrom = async () => {
    $CommonQueryEnumForFrom$
  }
  commonQueryEnumForFrom()
  onResetForHighSelect();//ÖØÖù«¹²select²éѯ 
  /**
   * µ¯´°´ò¿ª»ñÈ¡ÏêÇé
   */
  const onOpen = async () => {
    disabled.value = false
    updateCheckData()
  }
 
  watch(() => current.value, onOpen)
 
  return {
    formItems,
    formData,
    visible,
    formRef,
    onOpen,
    onClose,
    onConfirmQuery,
    onReset,
  }
}