<template>

<a-spin :spinning="confirmLoading">
    <a-form ref="formRef" class="antd-modal-form" :labelCol="labelCol" :wrapperCol="wrapperCol">
      <a-row>
        <a-col :span="24">
          <a-form-item label="问题项目" v-bind="validateInfos.pbItem">
	          <a-textarea v-model:value="formData.pbItem"  :disabled="disabled"></a-textarea>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="问题示例" v-bind="validateInfos.pbExample">
	          <a-textarea v-model:value="formData.pbExample"  :disabled="disabled"></a-textarea>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="改进建议" v-bind="validateInfos.pbAdvise">
	          <a-textarea v-model:value="formData.pbAdvise"  :disabled="disabled"></a-textarea>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="影响分析" v-bind="validateInfos.pbAnalysis">
	          <a-textarea v-model:value="formData.pbAnalysis"  :disabled="disabled"></a-textarea>
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="问题来源" v-bind="validateInfos.pbSource">
	          <a-textarea v-model:value="formData.pbSource"  :disabled="disabled"></a-textarea>
          </a-form-item>
        </a-col>
<!--
        <a-col :span="24">
          <a-form-item label="标签" v-bind="validateInfos.labels">
	          <a-textarea v-model:value="formData.labels"  :disabled="disabled"></a-textarea>
          </a-form-item>
        </a-col>

        <a-col :span="24">
          <a-form-item label="控制项" v-bind="validateInfos.actIds">
	          <a-textarea v-model:value="formData.actIds"  :disabled="disabled"></a-textarea>
          </a-form-item>
        </a-col>
        -->


        
      </a-row>
    </a-form>
  </a-spin>
  
</template>


<script lang="ts" setup>
  import { ref, reactive, defineExpose, nextTick, defineProps, computed, onMounted } from 'vue';
  import { defHttp } from '/@/utils/http/axios';
  import { useMessage } from '/@/hooks/web/useMessage';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import { getValueType } from '/@/utils';
  import { Form } from 'ant-design-vue';
  import { useTabs } from '/@/hooks/web/useTabs';
  import {useModal} from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useUserStoreWithOut } from '/@/store/modules/user';
  import { useRouter } from 'vue-router';
  import { getAuthCache, setAuthCache, removeAuthCache } from '/@/utils/auth';
  import { TOKEN_KEY} from '/@/enums/cacheEnum';
  import { useUserStore } from '/@/store/modules/user';

  const router = useRouter();
  const user = useUserStoreWithOut();
  const { closeCurrent, refreshPage, setTitle } = useTabs();
  
  const props = defineProps({
    formDisabled: { type: Boolean, default: false },
    formData: { type: Object, default: ()=>{} },
    formBpm: { type: Boolean, default: true }
  });
  const formRef = ref();
  const useForm = Form.useForm;
  const emit = defineEmits(['register', 'ok']);
  const formData = reactive<Record<string, any>>({
    id: '',
    pbItem: undefined,
    pbExample: '',   
    pbAdvise: '',   
    pbAnalysis: '',   
    pbSource: '',   
    labels: '',   
    actIds: '',   
    
  });
  const { createMessage } = useMessage();
  const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
  const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
  const confirmLoading = ref<boolean>(false);
  const loading = ref(false);
  //表单验证
  const validatorRules = {
  };
  const { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: true });

  const disabled = ref<boolean>(true);
  const listAll = '/audit/queryActRelates';

  // 从URL获取参数
const getUrlParams = () => {
  const winurl = window.location.href;
  const params = new URLSearchParams(winurl.split('?')[1]);
  return {
    cctoken: params.get('Token') || '',
    WorkID: params.get('WorkID') || '',
  };
};


  const iniData = async () => {
try {
   loading.value = true;
    const { cctoken, WorkID } = getUrlParams();
    console.log('Token:', cctoken, 'WorkID:', WorkID);
  
    const timestamp = new Date().getTime();
    const gettokeyUrl = '/api/jflow/getCCWorkTokenAndTid';
    const {tid,token} = await defHttp.get({
      url: gettokeyUrl,
      params: {
        "targetKey":"targetKey",
        "flowToken":cctoken,
        "WorkID":WorkID,
        "_t": timestamp},
    });

    setAuthCache(TOKEN_KEY, token);
    //params: { id: tid, token: token,  "_t": timestamp },

     defHttp.get({ url: listAll, params: {token: token,tp:4,id:tid} }).then((res) => {
    
    console.log("res ",res[0]);
    
     formData.pbItem=res[0].pbItem;
     formData.pbExample=res[0].pbExample;
     formData.pbAdvise=res[0].pbAdvise;
     formData.pbAnalysis=res[0].pbAnalysis;
     formData.pbSource=res[0].pbSource;
     formData.labels=res[0].labels;
     formData.actIds=res[0].actIds;
    });

    } catch (error) {
    console.error('初始化表单数据失败:', error);
    createMessage.error('初始化表单数据失败');
  } finally {
    loading.value = false;
  }
}


onMounted(async () => {  
    iniData();  
});  
  


  defineExpose({
   
  });
</script>

<style lang="less" scoped>
  .antd-modal-form {
    min-height: 500px !important;
    overflow-y: auto;
    padding: 24px 24px 24px 24px;
  }
</style>

