<template>
  <PageWrapper>
    <a-spin :spinning="spinning">
      <a-row :gutter="24">
          <a-col :span="10">
              <a-card>
                  <div style="height: 75vh;overflow-y: auto;">
                    <a-input-search v-show="false"
                        v-model:value="searchVal"
                        placeholder="请输入"
                        enter-button
                        @search="onSearch"
                      />
                      评估要素
                      <BasicTree
                          ref="treeRef"
                          :style="{ minWidth: '20px' }"
                          selectable
                          defaultExpandAll="true"
                          @select="onSelect"
                          :treeData="treeData"
                          :selectedKeys="selectedDepIds"
                          :expandedKeys="expandedKeys"
                          :clickRowToExpand="true"
                      >
                      </BasicTree>
                  </div>
              </a-card>
          </a-col>
          <a-col :span="14">
              <a-card>
                  <div style="height: 75vh;overflow-y: auto;">
                  请选择符合当前实际情况的选项
                    <a-empty v-if="!showFlag">
                      <template #description>
                          <span>
                            请选择左侧具体的条目
                          </span>
                        </template>
                      </a-empty>
                      <a-empty v-if="hasOptFlag">
                        <template #description>
                            <span>
                              请选择叶子节点
                            </span>
                        </template>
                      </a-empty>
                      <a-empty v-if="!hasOptFlag && rateOptions.length==0">
                        <template #description>
                        <!--
                            <span>
                              无评分选项数据，请检查监管评级规则
                            </span>
                            -->
                        </template>
                      </a-empty>
                      <div v-if="showFlag && !hasOptFlag && rateOptions.length >0">
                        <a-form
                          ref="formRef"
                          :model="formData"
                          @finish="onFinish"
                        >
                        <a-form-item name="rateName" style="margin-bottom: 0px;font-weight: bold;">
                          {{ formData.rateName }}
                        </a-form-item>
                          <a-form-item name="rateCheck">
                           <a-checkbox-group v-model:value="formData.rateCheck"  :disabled="isDetail">
                              <a-checkbox :style="radioStyle" style="margin-left:10px" v-for="(item,i) in rateOptions" :value="item.value" :disabled="isDetail" :key="i">
                                {{ item.label }}
                              </a-checkbox>
                          </a-checkbox-group>
                          </a-form-item>
                          <a-form-item style="margin-bottom: 0px;font-weight: bold;">
                            现状描述：
                          </a-form-item>
                          <a-form-item :wrapper-col="{span:23}">
                            <a-textarea
                                v-model:value="formData.des"
                                placeholder="请输入"
                                :auto-size="{ minRows: 2, maxRows: 5 }"
                                 :disabled="isDetail"
                              />
                          </a-form-item>
                          <a-form-item style="margin-bottom: 0px;font-weight: bold;">
                            相关附件：
                          </a-form-item>
                          <a-form-item>
                          <div  v-if="rateKeyItemFileList.length==1">
                          <a-form-item>
                          <a-space :span="5" >
                            {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                           </a-space>
                           </a-form-item>
                            </div>
                           <div  v-if="rateKeyItemFileList.length==2">
                          <a-form-item>
                          <a-space :span="5" >
                            {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                           </a-space>
                           </a-form-item>
                           <a-form-item>
                           <a-space :span="5" >
                            {{ rateKeyItemFileList[1].label }} <JUpload v-model:value="formData.fileUploadPath2" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                           </a-space>
                           </a-form-item>
                            </div> 
                          <div  v-if="rateKeyItemFileList.length==3">
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[1].label }} <JUpload v-model:value="formData.fileUploadPath2" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                              </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[2].label }} <JUpload v-model:value="formData.fileUploadPath3" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                          </div>
                        <div  v-if="rateKeyItemFileList.length==4">
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[1].label }} <JUpload v-model:value="formData.fileUploadPath2" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                              </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[2].label }} <JUpload v-model:value="formData.fileUploadPath3" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[3].label }} <JUpload v-model:value="formData.fileUploadPath34" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                          </div>

                           <div  v-if="rateKeyItemFileList.length==5">
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[1].label }} <JUpload v-model:value="formData.fileUploadPath2" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                              </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[2].label }} <JUpload v-model:value="formData.fileUploadPath3" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[3].label }} <JUpload v-model:value="formData.fileUploadPath4" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[4].label }} <JUpload v-model:value="formData.fileUploadPath5" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                          </div>

                          <div  v-if="rateKeyItemFileList.length==6">
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[1].label }} <JUpload v-model:value="formData.fileUploadPath2" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                              </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[2].label }} <JUpload v-model:value="formData.fileUploadPath3" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[3].label }} <JUpload v-model:value="formData.fileUploadPath4" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[4].label }} <JUpload v-model:value="formData.fileUploadPath5" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[5].label }} <JUpload v-model:value="formData.fileUploadPath6" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                          </div>

                          <div  v-if="rateKeyItemFileList.length==7">
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[1].label }} <JUpload v-model:value="formData.fileUploadPath2" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                              </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[2].label }} <JUpload v-model:value="formData.fileUploadPath3" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[3].label }} <JUpload v-model:value="formData.fileUploadPath4" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[4].label }} <JUpload v-model:value="formData.fileUploadPath5" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[6].label }} <JUpload v-model:value="formData.fileUploadPath7" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                          </div>

                           <div  v-if="rateKeyItemFileList.length==8">
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[1].label }} <JUpload v-model:value="formData.fileUploadPath2" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                              </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[2].label }} <JUpload v-model:value="formData.fileUploadPath3" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[3].label }} <JUpload v-model:value="formData.fileUploadPath4" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[4].label }} <JUpload v-model:value="formData.fileUploadPath5" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[6].label }} <JUpload v-model:value="formData.fileUploadPath7" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>

                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[7].label }} <JUpload v-model:value="formData.fileUploadPath8" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>

                          </div>

                          <div  v-if="rateKeyItemFileList.length==9">
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[1].label }} <JUpload v-model:value="formData.fileUploadPath2" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                              </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[2].label }} <JUpload v-model:value="formData.fileUploadPath3" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[3].label }} <JUpload v-model:value="formData.fileUploadPath4" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[4].label }} <JUpload v-model:value="formData.fileUploadPath5" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[6].label }} <JUpload v-model:value="formData.fileUploadPath7" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>

                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[7].label }} <JUpload v-model:value="formData.fileUploadPath8" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[8].label }} <JUpload v-model:value="formData.fileUploadPath9" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>

                          </div>

                          <div  v-if="rateKeyItemFileList.length==10">
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[0].label }} <JUpload v-model:value="formData.fileUploadPath1" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[1].label }} <JUpload v-model:value="formData.fileUploadPath2" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                              </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[2].label }} <JUpload v-model:value="formData.fileUploadPath3" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[3].label }} <JUpload v-model:value="formData.fileUploadPath4" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[4].label }} <JUpload v-model:value="formData.fileUploadPath5" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[6].label }} <JUpload v-model:value="formData.fileUploadPath7" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>

                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[7].label }} <JUpload v-model:value="formData.fileUploadPath8" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>
                            <a-form-item>
                              <a-space :span="5" >
                              {{ rateKeyItemFileList[9].label }} <JUpload v-model:value="formData.fileUploadPath10" :disabled="isDetail" :buttonVisible="!isDetail" desText="支持扩展名: .rar .zip .doc .docx .pdf .jpg..." />
                              </a-space>
                            </a-form-item>

                          </div>




                          </a-form-item>

                          <a-form-item style="margin-bottom: 0px;font-weight: bold;">
                            审核结果：
                          </a-form-item>
                          <a-form-item>
                          <a-radio-group v-model:value="formData.approvestatus"  :options="[{ label: '通过', value: '8' },{ label: '驳回', value: '9' }]" />
          
                          </a-form-item>

                          <a-form-item style="margin-bottom: 0px;font-weight: bold;">
                            审核意见：
                          </a-form-item>
                          <a-form-item :wrapper-col="{span:23}">
                            <a-textarea
                                v-model:value="formData.approveremark"
                                placeholder="请输入"
                                :auto-size="{ minRows: 2, maxRows: 5 }"
                                
                              />
                          </a-form-item>


                          
                          




                         
                          <a-form-item>
                            <a-space :span="5">
                            <a-button type="primary" v-if="treeNextIndex>0" @click="onUpperStep">上一步</a-button>
                            <a-button type="primary" v-if="treeNextIndex<(treeNextKeys.length-1)" @click="onNextStep">下一步</a-button>
                            <a-button type="primary" v-if="treeNextIndex==(treeNextKeys.length-1)" @click="onSure">完成</a-button>
                          </a-space>
                          </a-form-item>
                        </a-form>
                      </div>
                  </div>
              </a-card>
          </a-col>
      </a-row>
      </a-spin>
  </PageWrapper>
</template>
<script setup>
import { message } from 'ant-design-vue';
import { onMounted, reactive, ref,toRaw,inject  } from 'vue';
import { getRateStdOptionList, saveaddAppRate,successAppRate ,getApproverateKeyItemTreeList,getRateKeyItemFileList} from './RateWri.api';
import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
import { PageWrapper } from '/@/components/Page';
import { BasicTree } from '/@/components/Tree/index';
import { useRoute } from 'vue-router';
import { useTabs } from '/@/hooks/web/useTabs';
const { closeCurrent, refreshPage, setTitle } = useTabs();
const route = useRoute();
const spinning = ref(true)
const searchVal = ref('')
const showFlag =ref(false)
const isDetail = ref(false)
const fistData = ref({})
const hasOptFlag = ref(false)
//const closeCurrent = inject('closeCurrent')
const radioStyle = reactive({
      display: 'flex',
      width:'100%',
      
      lineHeight: '30px',
    });
const formData = ref({
  id:'',
  rateId:'',
  rateName:'',
  rateCheck: '',
  des:'',
  approvestatus:'',
  approveremark:'',
  taskdetailid:'',
  fileUploadPath1:'',
  fileUploadPath2:'',
  fileUploadPath3:'',
  fileUploadPath4:'',
  fileUploadPath5:'',
  fileUploadPath6:'',
  fileUploadPath7:'',
  fileUploadPath8:'',
  fileUploadPath9:'',
  fileUploadPath10:'',
  fileUploadPath:[]
})
const rateKeyItemFileList= ref([])
const rateOptions = ref([])
const treeData = ref([
]);
// 进行数据记录
const record = ref([])
const treeNextKeys = ref([])
const treeNextIndex = ref(0)
const selectedDepIds = ref([]);
const expandedKeys = ref([]);
let id = ref('');
// 设置treeIndex
function settingTreeeIndex(key){
  let size = treeNextKeys.value.length
  for(var i=0;i<size;i++){
    if(treeNextKeys.value[i]==key){
      treeNextIndex.value = i;
      break;
    }
  }
}
function onSelect(selectedKeys, info){
  if(selectedKeys.length==0){
    message.warning("请选择子节点！")
    rateOptions.value = []
    hasOptFlag.value = true
    return
  }

  hasOptFlag.value = false
  if(info.selectedNodes[0].leaf){
    let tempkey=info.selectedNodes[0].key.replace('index', '');
    
    initRateOptions(tempkey)
    formData.value.rateId = info.selectedNodes[0].key
    formData.value.rateName = info.selectedNodes[0].des || info.selectedNodes[0].title_bak
    settingTreeeIndex(info.selectedNodes[0].key)

    //formData.value.rateCheck=record.value[treeNextIndex.value].rateCheck;
    formData.value = Object.assign(formData.value,record.value[treeNextIndex.value])
    
  }else{
    message.warning("请选择子节点！")
    rateOptions.value = []
    hasOptFlag.value = true
  }
}
function initRateOptions(key){
  getRateStdOptionList({key:key}).then(rep=>{
    rateOptions.value = rep
  })

getRateKeyItemFileList({key:key}).then(rep=>{
    rateKeyItemFileList.value = rep
  })

}
function autoFirst(){
  initRateOptions(fistData.value.key)
  selectedDepIds.value = [fistData.value.key]
  formData.value = Object.assign(formData.value,record.value[0])
  showFlag.value = 
  formData.value.approvestatus='8'

  //console.log('autoFirst -------------formData.value: ', formData.value);


}
function handlerExpandedKeys(){
  var len = treeData.value.length
  if(len==0){
    return
  }
  var keys = []
  for(var i=0;i<len;i++){
    if(i==0){
      fistData.value = treeData.value[i].children[0].children[0]
    }
    //keys.push(treeData.value[i].key)
  }
  //expandedKeys.value = keys
}
onMounted(() => {
   id = toRaw(route.query).id
  formData.value.id = id
  getApproverateKeyItemTreeList({id:id}).then(rep=>{
    treeData.value = rep.treeList
    treeNextKeys.value = rep.keys
    record.value = rep.record
    expandedKeys.value = rep.expandedKeys
    
    if(!!treeData.value){
      handlerExpandedKeys()
      autoFirst()
    }
    spinning.value = false
  })


 

})
function onNextStep(){
  let index = treeNextIndex.value
  index ++
  // 索引相等标识到最后一项
  if(index >= treeNextKeys.value.length){
    return
  }
  if(!formData.value.id){
    message.error("项目关联信息丢失，请关闭后重新点击填报")
    return
  }

  if(!formData.value.approvestatus){
    message.error("请选择审核结果")
    return
  }

 
  if(!formData.value.rateCheck){
    message.error("请选择评分项")
    return
  }
    
    let val=formData.value.rateCheck;
    if (val instanceof Array) {
            val = val.join(',');
          }

  formData.value.rateCheck=val;
  
  //console.log('-------------formData.value: ', formData.value);
 
  
  saveaddAppRate(formData.value).then(rep=>{
   
  })

  formData.value = Object.assign(formData.value,record.value[index])
   formData.value.approvestatus='8'
  treeNextIndex.value = index
  let key = treeNextKeys.value[index]
  selectedDepIds.value = [key]
  initRateOptions(key)

  getApproverateKeyItemTreeList({id:id}).then(rep=>{
    treeData.value = rep.treeList
    treeNextKeys.value = rep.keys
    record.value = rep.record
    expandedKeys.value = rep.expandedKeys
    
    //spinning.value = false
  })


}
function onUpperStep(){
  let index = treeNextIndex.value
  index --
  if(index <0){
    return;
  }
  formData.value = Object.assign(formData.value,record.value[index])
  treeNextIndex.value = index
  let key = treeNextKeys.value[index]
  selectedDepIds.value = [key]
  initRateOptions(key)
}
function onSure(){
  // 保存或者更新form表单
  if(!formData.value.id){
    message.error("项目关联信息丢失，请关闭后重新点击填报")
    return
  }
  if(!formData.value.rateCheck){
    message.error("请选择评分项")
    return
  }
  let val=formData.value.rateCheck;
    if (val instanceof Array) {
            val = val.join(',');
          }
  
  formData.value.rateCheck=val;

  formData.value.taskdetailid = id;

  let value = Object.assign({},formData.value)
  value.tbIds = treeNextKeys.value.join(",")
   console.log('------------treeNextKeys.value: ', treeNextKeys.value);
    console.log('-----------value.tbIds: ', value.tbIds);
  successAppRate(value).then(rep=>{
    closeCurrent();
  })

  getApproverateKeyItemTreeList({id:id}).then(rep=>{
    treeData.value = rep.treeList
    treeNextKeys.value = rep.keys
    record.value = rep.record
    expandedKeys.value = rep.expandedKeys
    
    //spinning.value = false

    closeCurrent();

  })
  
}
</script>