<template>
	<view>
		<template v-if="getSchema.component === componentType.collapse"> 
			<uni-section :title="getSchema.name" type="line" :borderBottom="true"> 
				<uni-card v-show="cardShow" :is-shadow="false" is-full :border="false"> 
					
					<view v-for="(child, index) in getSchema.layout" :key="getSchema.key+index"> 
						<template v-for="(schema, idx) in child.children" :key="schema.key">
							<SimpleFormItem :formApi="formApi"
								:schema="schema"
								:refreshFieldObj="refreshFieldObj" 
								v-show="getIfShow(schema, formModel[schema.field])"
								v-model ="formModel[schema.field]" 
							/>
						</template> 
					</view>
				
				</uni-card> 
				<template v-slot:right>
					<view class="card-title-box iconfont" :class="cardShow?'icon-shouqi':'icon-zhankai'" @click="()=>{cardShow=!cardShow}"></view>
				</template>
			</uni-section>
		</template>
		<template v-if="getSchema.component === componentType.tableLayout"> 
			<uni-section :title="getSchema.name" type="line" :borderBottom="true" v-show="getIsShow(getSchema,'')"> 
				<view v-for="(child, index) in getSchema.layout" :key="getSchema.key+index"> 
				<template v-for="(schema, idx) in child.children" :key="schema.key">
							<SimpleFormItem :formApi="formApi"
								:schema="schema"
								:refreshFieldObj="refreshFieldObj" 
								v-show="getIfShow(schema, formModel[schema.field])"
								v-model ="formModel[schema.field]" 
							/>
						</template> 
					</view>
			</uni-section>
		</template>
		<template v-if="getSchema.component === componentType.tab">
			<uni-tab :data="getSchema.layout" v-model="activeRef" v-bind="getComponentsProps" />
			<!-- <component :is="componentMap.get(getSchema.component)" :data="getSchema.layout" v-model="activeRef" v-bind="getComponentsProps"></component> -->
			<view v-for="(child, index) in getSchema.layout"  :key="getSchema.key+index">
				<view v-show="activeRef === index">
					<template v-for="(schema, idx) in child.children" :key="schema.key">
						<SimpleFormItem :formApi="formApi"
							:schema="schema"
							:refreshFieldObj="refreshFieldObj" 
							v-show="getIfShow(schema, formModel[schema.field])"
							v-model ="formModel[schema.field]"
						/>
					</template>
				</view>
			</view>
		</template>
		<template v-else-if="getSchema.component === componentType.segmented">
			<uni-segmented-control style-type="text"
				:current="activeRef"
				:values="getSchema.layout.map((x) => x.name)"
				@clickItem="(e) => (activeRef = e.currentIndex)"
				v-bind="getComponentsProps"
			/> 
			<view v-for="(child, index) in getSchema.layout" :key="getSchema.key+index">
				<view v-show="activeRef === index">
					<template v-for="(schema, idx) in child.children" :key="schema.key"> 
						<SimpleFormItem :formApi="formApi"
							:schema="schema"
							:refreshFieldObj="refreshFieldObj" 
							v-show="getIfShow(schema, formModel[schema.field])"
							v-model ="formModel[schema.field]"
						/>
					</template>
				</view>
			</view>
		</template>
		<template v-else-if="[componentType.subForm,componentType.sunForm,componentType.singleForm].includes(getSchema.component)"> 
			<uni-sub-form :schema="getSchema" v-model="formModel[getSchema.field]" :formApi="formApi" :disabled="getDisabled"/>
			 
		</template>
		<template v-else-if="getSchema.component === componentType.formView||getSchema.component === componentType.customComp">
		<!-- 暂时不支持 -->
		 </template>
		<template v-else-if="getSchema.component.includes('Date')">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
			<uni-date-year v-if="getComponentsProps.formatType=='year'||getComponentsProps.formatType=='month'" :disabled="getDisabled" 
					v-bind="getComponentsProps"
					v-model="formModel[getSchema.field]"></uni-date-year>
				<uni-datetime-picker v-else
					:disabled="getDisabled"
					v-bind="getComponentsProps"
					v-model="formModel[getSchema.field]"
					v-model:startTime="formModel[getSchema.startTimeField]"
					v-model:endTime="formModel[getSchema.endTimeField]"
				/> 
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.timeRange">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-time-picker :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" 
				v-model="formModel[getSchema.field]" 
				v-model:sTime="formModel[getSchema.startTimeField]"
				v-model:eTime="formModel[getSchema.endTimeField]"/>
			</uni-forms-item>
		</template>
		
		<template v-else-if="getSchema.component === componentType.input">  
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field"> 
				<view v-if='getSchema.componentProps.scan'>
				<uni-easyinput :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"  suffixIcon="ant-design:scan-outlined" @iconClick="scanClick(getSchema.field)" /></view>
				<view v-else><uni-easyinput :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"/></view>
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.checkbox || getSchema.component === componentType.radio">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-data-checkbox :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>

		<template v-else-if="getSchema.component === componentType.inputNumber">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-number-box :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>

		<template v-else-if="getSchema.component === componentType.associatePicker">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-associate-picker :mainKey="tableName" :index="index" :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>

		<template v-else-if="getSchema.component === componentType.select">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-data-select :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.TreeSelect">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-select-tree :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.labelComp">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-label-component :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.TreeChecked">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-checked-tree :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>

		<template v-else-if="getSchema.component === componentType.cascader">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-data-cascader :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.slider">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				 <custom-slider :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" /> 			 
			</uni-forms-item> 
		</template>
		<template v-else-if="getSchema.component === componentType.divider">
			<uni-divider :schema="getSchema" v-bind="getComponentsProps" />
		</template>

		<template v-else-if="getSchema.component === componentType.switch">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<custom-switch :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
				<!-- <uni-switch :schema="getSchema" :disabled="disabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" /> -->
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.Opinion">
			<uni-forms-item :label="getSchema.label">
				<OpinionVue :value="getSchema.defaultValue" />
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.autoCode">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-auto-code :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.editor"> 
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-editorbox :schema="getSchema" :disabled="getDisabled" :editorkey="getSchema.key" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>
    <template v-else-if="getSchema.component === componentType.rate">
    	<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
    		<uni-rate :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
    	</uni-forms-item>
    </template>
    <template v-else-if="getSchema.component === componentType.image"> 
    	<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field"> 
				<uni-file-picker :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"/>
    	</uni-forms-item>
    </template>
    <template v-else-if="getSchema.component === componentType.organization">
    	<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
    		<uni-organization :title="getSchema.label" :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"  />
    	</uni-forms-item>
    </template>
    <template v-else-if="getSchema.component === componentType.user">
    	<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
    		<uni-user :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"  />
    	</uni-forms-item>
    </template>
		<template v-else-if="getSchema.component === componentType.role">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-role :schema="getSchema" :key="tableName?null:refreshFieldObj[getSchema.field]" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"  />
			</uni-forms-item>
		</template>
    <template v-else-if="getSchema.component === componentType.computation || getSchema.component === componentType.moneyChinese">
    	<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
    		<uni-computation :isMoney="getSchema.component === componentType.moneyChinese" :index="index" :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
    	</uni-forms-item>
    </template>
		<template v-else-if="getSchema.component === componentType.color">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-color-picker :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.qrcode">
			<uni-forms-item :label="getSchema.label" >
				<uni-qrcode  :schema="getSchema"  v-bind="getComponentsProps" />
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.barcode">
			<uni-forms-item :label="getSchema.label" >
				<uni-barcode  :schema="getSchema"  v-bind="getComponentsProps" :codekey="getSchema.key"/>
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.title">
			<uni-title  :schema="getSchema" v-bind="getComponentsProps" />
		</template>
		<template v-else-if="getSchema.component === componentType.map"> 
			<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-select-map :index="index" :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"/>
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.upload">
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" 
			:rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
				<uni-file-picker :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"/>
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.file">
			<uni-forms-item :label="getSchema.label"  > 
				<uni-file  :schema="getSchema" v-bind="getComponentsProps" />
			</uni-forms-item>
		</template>
    <template v-else-if="getSchema.component === componentType.associatePopup || getSchema.component === componentType.multiplePopup">
    	<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
    		<uni-associate-popup :key="tableName?null:refreshFieldObj[getSchema.field]" :mainKey="tableName" :index="index" :isMultiple="getSchema.component === componentType.multiplePopup" :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"/>
    	</uni-forms-item>
    </template>
    <template v-else-if="getSchema.component === componentType.info">
    	<uni-forms-item :label="getSchema.label" :required="getSchema.required"
			 :rules="getSchema.rules" :name="tableName?tableName+'['+index+']'+'['+getSchema.field+']':getSchema.field">
    		<uni-info :schema="getSchema" :disabled="true" v-bind="getComponentsProps" v-model="formModel[getSchema.field]"/>
    	</uni-forms-item>
    </template>
    <template v-else-if="getSchema.component === componentType.button">
    	<uni-forms-item :label="getSchema.label" >
    		<custom-button :mainKey="tableName" :index="index" :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" />
    	</uni-forms-item>
    </template>
		<template v-else-if="getSchema.component === componentType.text"> 
			<view :style="{
						margin:'10px 0',
			      fontFamily: getComponentsProps.fontFamily,
			      fontSize: getComponentsProps.fontSize + 'px',
			      fontWeight: getComponentsProps.fontWeight,
			      color: getComponentsProps.color,
			      fontStyle: getComponentsProps.fontStyle,
						align:getComponentsProps.align
			    }"
			  >
			    {{ getSchema.defaultValue }}</view
			  >
		</template>

		 <template v-else-if="getSchema.component === componentType.iframe">
		 <uni-forms-item :label="getSchema.label" >
				<web-view :src="getSchema.url" style="height:200px;position: relative;"></web-view>
    	</uni-forms-item>
    </template>
		<template v-else-if="getSchema.component ===  componentType.aiAnswer">
		 <uni-forms-item :label="getSchema.label" >
				<ai-answer />
			</uni-forms-item>
		</template>
   
    <template v-else-if="getSchema.component === componentType.signature">
    	<uni-forms-item :label="getSchema.label" :required="getSchema.required"
    	 :rules="getSchema.required?signRules:[]" :name="getSchema.field">
    		<uni-signature :schema="getSchema" :disabled="getDisabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
    	</uni-forms-item>
    </template>
		<template v-else-if="getSchema.component === componentType.customModal">
			<uni-forms-item :label="getSchema.label" > 
				<custom-modal :schema="getSchema" :title="getSchema.name" :disabled="getDisabled" v-bind="getComponentsProps" :mainformModel="formModel" /> 
			</uni-forms-item>
		</template>
		<template v-else-if="getSchema.component === componentType.customDrawer">
			<uni-forms-item :label="getSchema.label" > 
				<custom-drawer :schema="getSchema" :title="getSchema.name" :disabled="getDisabled" v-bind="getComponentsProps"  /> 
			</uni-forms-item>
		</template>
	<!-- 	<template v-else>
			<uni-forms-item :label="getSchema.label" :required="getSchema.required" :rules="getSchema.rules" :name="getSchema.field">
				<component :is="componentMap.get(getSchema.component)" :schema="getSchema" :disabled="disabled" v-bind="getComponentsProps" v-model="formModel[getSchema.field]" />
			</uni-forms-item>
		</template> -->
	</view>
</template>

<script setup>
import { inject, computed, onMounted, watch, ref } from 'vue';
import { upperFirst } from '../../utils/helper/index.js';
import { isFunction } from '../../utils/helper/utils.js';
import { componentMap } from './componentMap.js';
import { componentType, datasourceTypeEnum, fetchComponents } from './types/form.js';
import { getIsShow, getIfShow } from './utils/utils.js';
import { getDicDetailList } from '@/common/api/system/dictionary/index.js';
import { requestMagicApi } from '@/common/api/magic-api/index.js';
import { useUserStore } from '../../common/store/user';
import Switch from '../../uni_modules/uni-switch/components/uni-switch/uni-switch'
import OpinionVue from './components/Opinion.vue'; 
import SimpleFormItem from './SimpleFormItem.vue'; 
const userStore = useUserStore();

const props = defineProps(['schema', 'modelValue', 'formApi','tableName','index','refreshFieldObj']);
const emit = defineEmits(['update:modelValue']);
const injectFormModel = inject('formModel');
const formModel =props.tableName?props.modelValue: injectFormModel;
const formProps = inject('formProps');
const disabled = inject('disabled');
const isFilter=inject('isFilter'); //来自筛选
const isCustomForm = inject('isCustomForm', false);

const activeRef = ref(0);
const cardShow = ref(true);
const getSchema = computed(() => {
	return props.schema;
});

const getDisabled = computed(() => {
	//如果是查看默认使用 全局disabled
	//ruguo 不是查看  组件覆盖全局
	return (isFilter.value?false: disabled.value) || (isFilter.value?false:props.schema.dynamicDisabled);
});

onMounted(() => {
	const { component } = props.schema;

	//判断组件是否为 远程组件
	if (fetchComponents.includes(component)) {
		//fetch();
	}
});

watch(
	() => props.schema.params,
	() => {
		fetch();
	},
	{ deep: true }
);

const getComponentsProps = computed(() => {
	let { componentProps = {}, events } = props.schema;
	//如果是函数
	if (isFunction(componentProps)) {
		componentProps = componentProps({ schema: props.schema, formModel, formApi: props.formApi }) || {};
		return componentProps;
	}
 
	//如果有配置事件
	if (events) {
		for (const eventKey in events) {
			
			try {
				const event = new Function('schema', 'formModel', 'formActionType','eventData', `${events[eventKey]}`);
				componentProps['on' + upperFirst(eventKey)] = function (e) {
			
					event(props.schema, injectFormModel.value, props.formApi,e);
				};
			} catch (error) {
				//console.log('error', error);
			}
		}
	}
	return componentProps;
});
 
  const checkSign = (_, value, data, callback) => { 
    if (typeof value === 'string' && JSON.parse(value)) {
      const values = Object.values(JSON.parse(value)); 
      const hasNoSign = values.some((item) => !item);
      return hasNoSign ? callback(`${props.schema.label}是必填项`) : true;
    }
    return true;
  };

  const signRules = computed(() => { 
    const rules = { validateFunction: checkSign };
    return [...getSchema.value.rules, rules];
  });
// 移动端扫描
function scanClick(field){
	// #ifdef H5
  uni.showModal({
    title: "提示",
    content: "抱歉H5界面暂不支持扫码功能",
    showCancel: false,
    confirmText: "确定",
  });
  // #endif
  // #ifdef MP-WEIXIN
  uni.scanCode({
    success: (res) => {
      let result = res.result;
			formModel.value[field] = result;
    },
  });
  // #endif
  // #ifdef APP-PLUS
  uni.scanCode({
    success: (res) => {
      let result = res.result;
      formModel.value[field] = result;
    },
  });
  // #endif
}
async function fetch() {
	const { componentProps = {}, component } = props.schema;
	const { datasourceType, params } = componentProps;
	
	//如果是远程组件 根据配置 请求后端 获取数据  插入到 localdata 属性
	//uni-ui 组件 都是使用 localdata 作为数据集
	//如果是数据字典
	if (datasourceType === datasourceTypeEnum.Dic) {
		const { data } = await getDicDetailList(params);
		componentProps.localdata = data.map((item) => {
			return {
				text: item.name,
				value: item.id
			};
		});
	}
	if (datasourceType === datasourceTypeEnum.Api) {
		const { apiConfig } = componentProps;

		const queryParam = {};
		const headerParam = {};
		const bodyParams = {};
		for (const param of apiConfig.apiParams) {
			//queryString
			if (param.key === `1` && param.tableInfo) {
				for (const query of param.tableInfo) {
					queryParam[query.name] = getParamsValue(query);
				}
			}
			//header
			if (param.key === `2` && param.tableInfo) {
				for (const head of param.tableInfo) {
					headerParam[head.name] = getParamsValue(head, true);
				}
			}
			//body
			if (param.key === `3` && param.tableInfo) {
				for (const body of param.tableInfo) {
					bodyParams[body.name] = getParamsValue(body);
				}
			}
		}

		const { data } = await requestMagicApi({
			url: apiConfig.path,
			method: apiConfig.method,
			query: queryParam,
			header: headerParam,
			body: bodyParams
		});

		componentProps.localdata = data;
		console.log(data, 'requestMagicApi');
	}
}

function getParamsValue(params, isHeaders = false) {
	let value;
	if (params.bindType === 'value') {
		value = params.value;
	} else if (params.bindType === 'data') {
		const paramsArr = params.value?.split('-');
		if (paramsArr[0] === '3') {
			//当前信息
			value = isHeaders ? userStore.getUserInfo[paramsArr[1]] : userStore.getUserInfo[paramsArr[1]];
		} else {
			if (!formModel) return;
			const headerValue = isCustomForm ? formModel[paramsArr[0]] : formModel[camelCaseString(paramsArr[0])];
			value = isHeaders ? headerValue : headerValue;
		}
	}

	return value;
}

/**
 * 范围组件change 事件
 */
// function rangeComponentsChange(e) {
// 	const { componentProps = {} } = props.schema;
// 	if()

// }
</script>

<style>
	 
	.card-title-box.iconfont{
		font-size: 12px;
		    background: #E7EBF2;
		    border-radius: 50%;
		    padding: 5px;
		    color: #253954;
	}
</style>
