<template>
  <div class="position-re ">
    <my-breadcrumb class="my-breadcrumb" :breadcrumb-arr="breadArr"></my-breadcrumb>
    <div class="back" @click="beforeBack"><span class="fa fa-reply cur-po " >返回</span></div>

    <div class="my-detail-main">
      <div class="block">
        <div class="my-b-title ">基础信息</div>
        <diy-el-form :span="4" v-model:model-form="forms" :forms="filterForm"/>
      </div>
      <div class="block">
        <div class="my-b-title ">单位</div>
        <div class="my-search-div btn" v-if="operationType!=='detail'"><el-button :icon="Plus" @click="openAddUnitDialog('add')"></el-button></div>
        <my-table
          operation-width="300px"
          border
          :page-size="8"
          :has-operation="true"
          :is-height-equal-max-height="true"
          :headers="processStateTableDetailTableHeader"
          :table-data="tableData"
        >
          <template #DATASOURCE_UNIT_CODE="{data}">
            {{useRootStore().allSelectUnit.find(i => i.value === data.DATASOURCE_UNIT_CODE)?.label}}
          </template>
         <template #DATASOURCE_UNIT_STATUS="{data}">
           <span :class="{error:+data.DATASOURCE_UNIT_STATUS === 2}">
                     {{getStatus(data.DATASOURCE_UNIT_STATUS)}}
           </span>

         </template>
         <template #DATASOURCE_UNIT_TYPE="{data}">
           {{gettDType(data.DATASOURCE_UNIT_TYPE)}}
         </template>
          <template #operation="{data,index}">

            <el-button type="info" v-if="operationType !== 'detail'" @click="connectLink(data)">连接测试</el-button>
            <el-button type="info" :disabled="operationType === 'detail'" @click="openAddUnitDialog('edit',data)">修改</el-button>
            <el-button type="info" :disabled="operationType === 'detail'" @click="delData(index)">删除</el-button>
          </template>
        </my-table>
        <ele-pagination  ref="refEl"

                         @sizeOrPageChange="handleSizeChange"
                         class="page"
                         :default-page-size="pageSize"


                         :total-count="totalCount">

          <template #default>
            <div class="m-s">
              显示第 {{pageSize * (pageIndex -1) + 1 }} 到第 {{pageSize * pageIndex}} 条记录，总共 {{totalCount}} 条记录 共显示

            </div>
          </template>
        </ele-pagination>
      </div>
      <div class="detail-operation-btn" v-if="operationType!=='detail'">
        <el-button  @click="beforeBack">关闭</el-button>
        <el-button type="info" @click="saveS">提交</el-button>
      </div>
    </div>
    <template v-if="isAddUnitDialogIsShow">
      <add-unit-dialog @editTableInfo="editTableInfo" :current-dialog-obj="currentDialogObj" :dialog-operation-type="dialogOperationType"  v-model:dialog-visible="isAddUnitDialogIsShow"/>
    </template>
  </div>
</template>

<script>


import MyBreadcrumb from "@/components/common/MyBreadcrumb.vue";
import DiyElForm from "@/components/common/DiyElForm.vue";
import {onBeforeMount, ref, watch} from "vue";
import {processStateTableDetailFilterForm} from "@/data/all-forms";
import {Plus} from "@element-plus/icons-vue";
import MyTable from "@/components/common/MyTable.vue";
import {processStateTableDetailTableHeader} from "@/data/all-table-header";
import AddUnitDialog from "@/view/other/c-views/data-watch/data-gather-watch/process-table/AddUnitDialog.vue";
import {useRootStore} from "../../../../../../stores/useStore";
import {
  getDetailConfigLinkData,
  getProcessTableDetailTableData,
  updateOrAddProcessDetailD
} from "@/service/data-gather-watch/process-table";
import ElePagination from "@/components/common/ElePagination.vue";
import {useDetailOrEdit, usePagination} from "@/unit/use-method/usePagination";
import {elAlert, handleMes, showConfirm, showMessage} from "@/unit/element-ui/tip";
import {set_random_id} from "@/unit/random";
import {getAllServiceSelect, linkDataBaseData, updateLinkState} from "@/service/data-gather-watch/process-charts";
import {getAppArrangeWatchDetailInfo} from "@/service/data-process-watch/app-arrange-watch";

export default {
  name: "ProcessTableDetail",
  methods: {useRootStore},
  computed: {
    Plus() {
      return Plus
    }
  },
  props:{
    currentOpObj:{

    },
    operationType:{

    }
  },
  components: {ElePagination, AddUnitDialog, MyTable, DiyElForm, MyBreadcrumb},
  setup(props,{emit}) {
    function beforeBack(){
      let isHasNotSave = tableData.value.find(i => i.isAdd)
      if (isHasNotSave){
        showConfirm(()=>{
          emit('changeOperation','',{})
        },'数据尚未保存,确定要离开吗?','系统提示',{
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
      }else {
        emit('changeOperation','',{})
      }


    }
    const filterForm= ref({...processStateTableDetailFilterForm})
    const {currentOpObj:currentDialogObj,operationType:dialogOperationType,changeOperation:changeDialogOperation} = useDetailOrEdit()

    const configData2 = ref([])
    function saveS() {
      let findI = filterForm.value.formItemsArr.find(i => i.modelValue === 'SERVER_DEPLOYMENT_ID')
      updateOrAddProcessDetailD({
        id:props.currentOpObj.DATASOURCE_ID ||'',
        ip:props.currentOpObj.DATASOURCE_IP || forms.value.INTRANET_ADDRESS||'',
        name:forms.value.DATASOURCE_NAME||'',
        comment:forms.value.REMARKS,
        type:forms.value.DATASOURCE_TYPE,
        service_id:forms.value.SERVER_DEPLOYMENT_ID,
        detailList:tableData.value.map(i=> {
          delete i.isAdd
          return {
            ...i
          }
        })
      }).then(res => {
        handleMes(res,() => {
          emit('changeOperation','')
        })
      })
    }
    function editTableInfo(form) {
      let tempSource = {
        DATASOURCE_UNIT_CODE:form.DATASOURCE_UNIT_CODE,
        DATASOURCE_UNIT_TYPE:form.DATASOURCE_UNIT_TYPE,
        DATASOURCE_UNIT_PORT:form.DATASOURCE_UNIT_PORT ||'',
        DATASOURCE_UNIT_ACCESS:form.DATASOURCE_UNIT_ACCESS ||'',
        DATASOURCE_UNIT_IP:form.DATASOURCE_UNIT_IP ||'',
        DATASOURCE_UNIT_INSTANCE:form.DATASOURCE_UNIT_INSTANCE ||'',
        DATASOURCE_UNIT_SPACE:form.DATASOURCE_UNIT_SPACE ||'',
        DATASOURCE_UNIT_USER:form.DATASOURCE_UNIT_USER ||'',
        DATASOURCE_UNIT_PASSWORD:form.DATASOURCE_UNIT_PASSWORD ||'',
        DATASOURCE_UNIT_URL:form.DATASOURCE_UNIT_URL ||'',
        DATASOURCE_UNIT_PARAMS:form.DATASOURCE_UNIT_PARAMS ||'',
        DATASOURCE_UNIT_STATUS:form.DATASOURCE_UNIT_STATUS ||'',
        DATASOURCE_UNIT_ID:currentDialogObj.value.DATASOURCE_UNIT_ID ||set_random_id(),


      };

      for (let i = 0; i < tableData.value.length; i++) {
        if (+tableData.value[i].DATASOURCE_UNIT_ID === +tempSource.DATASOURCE_UNIT_ID) {
          tableData.value.splice(i, 1);
        }
      }
      tableData.value.push(Object.assign(tempSource,{isAdd:true}))
      isAddUnitDialogIsShow.value = false
    }
    function delData(index) {

        tableData.value.splice(index,1)
    }
    function connectLink(data){
     let options=[
        {value:'',label:'请选择',forms:[
            {
              type:'input',
              label: '连接IP',
              modelValue:'DATASOURCE_UNIT_IP',
              itemOtherAttrs:{
                required:true,
                rules:[
                  {message:'请输入IP地址',required:true,trigger:'blur'}

                ]
              }

            },
            {
              type:'input',
              label: '连接方式',
              modelValue:'DATASOURCE_UNIT_ACCESS',
              itemOtherAttrs:{
                rules:[
                  {required:true,rules:[
                      {message:'请输入连接方式',required:true,trigger:'blur'}
                    ]},

                ]
              }

            },
            {
              type:'input',
              label: '端口号',
              modelValue:'DATASOURCE_UNIT_PORT',
              elInputEleAttrs:{
                'placeholder':'请输入2到5位数字'
              },
              itemOtherAttrs:{
                rules:[
                  {required:true,rules:[
                      {message:'请输入端口号',required:true,trigger:'blur',validator:(rule, value, callback,oldValue) => {

                          let reg2 = new RegExp('[0-9]{2,5}');
                          if(!reg2.test(value)){

                            callback(new Error('请输入2到5位数字'))
                          }
                          else {
                            callback()
                          }
                        }}
                    ]},

                ]
              }

            },
            {
              type:'input',
              label: '实例名',
              modelValue:'DATASOURCE_UNIT_INSTANCE',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入实例名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '用户名',
              modelValue:'DATASOURCE_UNIT_USER',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入用户名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '密码',
              modelValue:'DATASOURCE_UNIT_PASSWORD',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入密码',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
          ]},
        {value:'0',label:'ORACLE',
          forms:[
            {
              type:'input',
              label: '连接IP',
              modelValue:'DATASOURCE_UNIT_IP',
              itemOtherAttrs: {
                required:true,
                rules:[
                  {message:'请输入IP地址',required:true,trigger:'blur'},

                ]
              }
            },
            {
              type:'input',
              label: '连接方式',
              modelValue:'DATASOURCE_UNIT_ACCESS',
              itemOtherAttrs:{
                rules:[
                  {required:true,rules:[
                      {message:'请输入连接方式',required:true,trigger:'blur'}
                    ]},

                ]
              }

            },
            {
              type:'input',
              label: '端口号',
              modelValue:'DATASOURCE_UNIT_PORT',
              elInputEleAttrs:{
                'placeholder':'请输入2到5位数字'
              },
              itemOtherAttrs:{
                rules:[
                  {required:true,rules:[
                      {message:'请输入端口号',required:true,trigger:'blur',validator:(rule, value, callback,oldValue) => {

                          let reg2 = new RegExp('[0-9]{2,5}');
                          if(!reg2.test(value)){

                            callback(new Error('请输入2到5位数字'))
                          }
                          else {
                            callback()
                          }
                        }}
                    ]},

                ]
              }

            },
            {
              type:'input',
              label: '实例名',
              modelValue:'DATASOURCE_UNIT_INSTANCE',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入实例名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '表空间',
              modelValue:'DATASOURCE_UNIT_SPACE',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入表空间',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '用户名',
              modelValue:'DATASOURCE_UNIT_USER',

              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入用户名',required:true,trigger:'blur'}
                    ]},

                ],
              }
            },
            {
              type:'input',
              label: '密码',
              modelValue:'DATASOURCE_UNIT_PASSWORD',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入密码',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
          ]
        },
        {value:'1',label:'SQLSERVER',
          forms:[
            {
              type:'input',
              label: '连接IP',
              modelValue:'DATASOURCE_UNIT_IP',
              required:true,
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入IP地址',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '连接方式',
              modelValue:'DATASOURCE_UNIT_ACCESS',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入连接方式',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '端口号',
              modelValue:'DATASOURCE_UNIT_PORT',
              elInputEleAttrs:{
                'placeholder':'请输入2到5位数字'
              },
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入端口号',required:true,trigger:'blur',validator:(rule, value, callback,oldValue) => {

                          let reg2 = new RegExp('[0-9]{2,5}');
                          if(!reg2.test(value)){

                            callback(new Error('请输入2到5位数字'))
                          }
                          else {
                            callback()
                          }
                        }}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '实例名',
              modelValue:'DATASOURCE_UNIT_INSTANCE',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入实例名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },

            {
              type:'input',
              label: '用户名',
              modelValue:'DATASOURCE_UNIT_USER',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入用户名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '密码',
              modelValue:'DATASOURCE_UNIT_PASSWORD',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入密码',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
          ]
        },
        {value:'2',label:'MYSQL', forms:[
            {
              type:'input',
              label: '连接IP',
              modelValue:'DATASOURCE_UNIT_IP',

              itemOtherAttrs: {
                required:true,
                rules:[
                  {required:true,rules:[
                      {message:'请输入IP地址',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '连接方式',
              modelValue:'DATASOURCE_UNIT_ACCESS',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入连接方式',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '端口号',
              modelValue:'DATASOURCE_UNIT_PORT',
              elInputEleAttrs:{
                'placeholder':'请输入2到5位数字'
              },
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入端口号',required:true,trigger:'blur',validator:(rule, value, callback,oldValue) => {

                          let reg2 = new RegExp('[0-9]{2,5}');
                          if(!reg2.test(value)){

                            callback(new Error('请输入2到5位数字'))
                          }
                          else {
                            callback()
                          }
                        }}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '实例名',
              modelValue:'DATASOURCE_UNIT_INSTANCE',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入实例名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },

            {
              type:'input',
              label: '用户名',
              modelValue:'DATASOURCE_UNIT_USER',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入用户名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '密码',
              modelValue:'DATASOURCE_UNIT_PASSWORD',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入密码',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
          ]},
        {value:'3',label:'接口',forms: [
            {
              type:'input',
              label: '连接IP',
              modelValue:'DATASOURCE_UNIT_IP',
              itemOtherAttrs: {
                required:true,
                rules:[
                  {required:true,rules:[
                      {message:'请输入IP地址',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '接口地址',
              modelValue:'DATASOURCE_UNIT_URL',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入接口地址',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '接口参数',
              modelValue:'DATASOURCE_UNIT_PARAMS',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入接口参数',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
          ]},
        {value:'4',label:'FTP',   forms:[
            {
              type:'input',
              label: '连接IP',
              modelValue:'DATASOURCE_UNIT_IP',
              itemOtherAttrs: {
                required:true,
                rules:[

                  {required:true,rules:[
                      {message:'请输入IP地址',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '连接方式',
              modelValue:'DATASOURCE_UNIT_ACCESS',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入连接方式',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '端口号',
              modelValue:'DATASOURCE_UNIT_PORT',
              elInputEleAttrs:{
                'placeholder':'请输入2到5位数字'
              },
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入端口号',required:true,trigger:'blur',validator:(rule, value, callback,oldValue) => {

                          let reg2 = new RegExp('[0-9]{2,5}');
                          if(!reg2.test(value)){

                            callback(new Error('请输入2到5位数字'))
                          }
                          else {
                            callback()
                          }
                        }}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '实例名',
              modelValue:'DATASOURCE_UNIT_INSTANCE',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入实例名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },

            {
              type:'input',
              label: '用户名',
              modelValue:'DATASOURCE_UNIT_USER',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入用户名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '密码',
              modelValue:'DATASOURCE_UNIT_PASSWORD',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入密码',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
          ]},
        {value:'5',label:'DM',forms:[
            {
              type:'input',
              label: '连接IP',
              modelValue:'DATASOURCE_UNIT_IP',
              itemOtherAttrs: {
                required:true,
                rules:[

                  {required:true,rules:[
                      {message:'请输入IP地址',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '连接方式',
              modelValue:'DATASOURCE_UNIT_ACCESS',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入连接方式',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '端口号',
              modelValue:'DATASOURCE_UNIT_PORT',
              elInputEleAttrs:{
                'placeholder':'请输入2到5位数字'
              },
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入端口号',required:true,trigger:'blur',validator:(rule, value, callback,oldValue) => {

                          let reg2 = new RegExp('[0-9]{2,5}');
                          if(!reg2.test(value)){

                            callback(new Error('请输入2到5位数字'))
                          }
                          else {
                            callback()
                          }
                        }}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '实例名',
              modelValue:'DATASOURCE_UNIT_INSTANCE',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入实例名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },

            {
              type:'input',
              label: '用户名',
              modelValue:'DATASOURCE_UNIT_USER',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入用户名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '密码',
              modelValue:'DATASOURCE_UNIT_PASSWORD',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入密码',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
          ]},
        {value:'6',label:'KINGBASE',forms:[
            {
              type:'input',
              label: '连接IP',
              modelValue:'DATASOURCE_UNIT_IP',
              itemOtherAttrs: {
                required:true,
                rules:[
                  {required:true,rules:[
                      {message:'请输入IP地址',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '连接方式',
              modelValue:'DATASOURCE_UNIT_ACCESS',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入连接方式',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '端口号',
              modelValue:'DATASOURCE_UNIT_PORT',
              elInputEleAttrs:{
                'placeholder':'请输入2到5位数字'
              },
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入端口号',required:true,trigger:'blur',validator:(rule, value, callback,oldValue) => {

                          let reg2 = new RegExp('[0-9]{2,5}');
                          if(!reg2.test(value)){

                            callback(new Error('请输入2到5位数字'))
                          }
                          else {
                            callback()
                          }
                        }}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '实例名',
              modelValue:'DATASOURCE_UNIT_INSTANCE',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入实例名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },

            {
              type:'input',
              label: '用户名',
              modelValue:'DATASOURCE_UNIT_USER',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入用户名',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
            {
              type:'input',
              label: '密码',
              modelValue:'DATASOURCE_UNIT_PASSWORD',
              itemOtherAttrs: {
                rules:[
                  {required:true,rules:[
                      {message:'请输入密码',required:true,trigger:'blur'}
                    ]},

                ]
              }
            },
          ]},
      ]

      let params = {
        NAME:useRootStore().allSelectUnit.find(i => i.value === data.DATASOURCE_UNIT_CODE)?.label,
        SERVER:forms.value.INTRANET_ADDRESS,
        TYPE:options.find(i => i.value && i.value === data.DATASOURCE_UNIT_TYPE)?.label.toUpperCase(),
        DATABASE_ACCESS:data.DATASOURCE_UNIT_ACCESS,
        DATABASE:data.DATASOURCE_UNIT_INSTANCE,
        PORT:data.DATASOURCE_UNIT_PORT,
        USERNAME:data.DATASOURCE_UNIT_USER,
        PASSWORD:data.DATASOURCE_UNIT_PASSWORD,
      }
      linkDataBaseData(params).then(res =>{
          let isSuccess = false
        let errorMsg
        let DATASOURCE_UNIT_STATUS = ''
        try {
          if (+res.state === 1){
            isSuccess = true
            errorMsg = '连接成功'
            DATASOURCE_UNIT_STATUS = 1
          }else {
            DATASOURCE_UNIT_STATUS = 2
            isSuccess = false
            errorMsg = '连接失败'
          }

        }catch {
          DATASOURCE_UNIT_STATUS = 2
          isSuccess = false
          errorMsg = '连接失败'
        }
        console.log(errorMsg,'errormsg')
        if (isSuccess){
          showMessage({
            type:isSuccess?'success':'error',
            message:errorMsg
          })

        }
        else {
          showMessage({
            type:isSuccess?'success':'error',
            message:errorMsg
          })

        }
        data.DATASOURCE_UNIT_STATUS =DATASOURCE_UNIT_STATUS
        if (!data.isAdd){
          updateLinkState(data.DATASOURCE_UNIT_ID,data.DATASOURCE_UNIT_STATUS).then(res => {
          })
        }else {
          data.DATASOURCE_UNIT_STATUS =DATASOURCE_UNIT_STATUS
        }
      })
      // let  configData = [...configData2.value]
      // let testData = {};
      // let configStatus = "2"
      // let index;
      // testData.DATASOURCE_IP = forms.value.DATASOURCE_IP;
      //   for (let i = 0; i < tableData.value.length; i++) {
      //     if (tableData.value[i].DATASOURCE_UNIT_ID == id) {
      //       testData.DATASOURCE_UNIT_IP = tableData.value[i].DATASOURCE_UNIT_IP;
      //       testData.DATASOURCE_UNIT_PORT = tableData.value[i].DATASOURCE_UNIT_PORT;
      //       testData.DATASOURCE_UNIT_ACCESS = tableData.value[i].DATASOURCE_UNIT_ACCESS;
      //       testData.DATASOURCE_UNIT_TYPE = tableData.value[i].DATASOURCE_UNIT_TYPE;
      //       testData.DATASOURCE_UNIT_INSTANCE = tableData.value[i].DATASOURCE_UNIT_INSTANCE;
      //       testData.DATASOURCE_UNIT_USER = tableData.value[i].DATASOURCE_UNIT_USER;
      //       testData.DATASOURCE_UNIT_PASSWORD = tableData.value[i].DATASOURCE_UNIT_PASSWORD;
      //       testData.DATASOURCE_UNIT_URL = tableData.value[i].DATASOURCE_UNIT_URL;
      //       testData.DATASOURCE_UNIT_PARAMS = tableData.value[i].DATASOURCE_UNIT_PARAMS;
      //       index = i;
      //     }
      //   }
      // for (let i = 0; i < configData.length; i++) {
      //   let sum = 0;
      //   point: for (let key in testData) {
      //     if (testData[key] == configData[i][key]) {
      //       sum++;
      //       if (sum < 10) {
      //         continue;
      //       } else {
      //         configStatus = "1"
      //         break;
      //       }
      //     } else {
      //       break point;
      //     }
      //
      //   }
      // }
      //
      //
      // if (configStatus == "1") {
      //   showMessage({
      //     type:'success',
      //     message:'测试连接成功!'
      //   })
      //
      // } else {
      //   showMessage({
      //     type:'error',
      //     message:'测试连接失败!'
      //   })
      //
      // }
      // tableData.value[index].DATASOURCE_UNIT_STATUS = configStatus;
    }
    const {pageIndex,pageSize,tableData,totalCount,initSearch,handleSizeChange,refEl}  = usePagination(getTableData)
    function getStatus(field) {
      if (field == "1") {
        return "正常";
      } else if (field == "2") {
        return "异常";
      } else {
        return "未启用";
      }
    }
    function gettDType(field) {
      if (field == "0") {
        return "ORACLE";
      } else if (field == "1") {
        return "SQLSERVER";
      } else if (field == "2") {
        return "MYSQL";
      } else if (field == "3") {
        return "接口";
      } else if (field == "4") {
        return "FTP";
      } else if (field == "5") {
        return "DM";
      }else if (field == "6") {
        return "KINGBASE";
      }
    }
    function getTableData() {
      if (props.currentOpObj.DATASOURCE_ID){
        getProcessTableDetailTableData({
          pageIndex:pageIndex.value,
          pageSize:pageSize.value,
          DataSource_Id:props.currentOpObj.DATASOURCE_ID,
        }).then(res => {
          tableData.value = res.msg[0].Rows||[]
          totalCount.value = res.msg[0].TotalRowCount
        })
      }

    }
    function openAddUnitDialog(operationType,item){
      isAddUnitDialogIsShow.value = true
      changeDialogOperation(operationType,item)
    }
    let breadArr = [{name:'数据采集监控 '},{name:'各通道运行状态表'}]
    const isAddUnitDialogIsShow = ref(false)

    const forms= ref({})
    onBeforeMount(() => {
      watch(() => forms.value.SERVER_DEPLOYMENT_ID,(val) => {
        getAppArrangeWatchDetailInfo(val).then(res => {
          try {
            forms.value = {
              ...forms.value,
              ...res.msg[0].Rows[0]
            }
          }catch {

          }

        })
      })
      if (props.currentOpObj) {
        forms.value = {
          ...forms.value,
          SERVER_DEPLOYMENT_ID:props.currentOpObj.SERVER_DEPLOYMENT_ID,
          DATASOURCE_TYPE:props.currentOpObj.DATASOURCE_TYPE,
          DATASOURCE_NAME:props.currentOpObj.DATASOURCE_NAME,
        }
      }
      getAllServiceSelect().then(res => {
       let options = res.msg[0].Rows.map(i => {
         return {
           value:i.UUID,
           label:i.HOST_NAME
         }
       })
        let findI = filterForm.value.formItemsArr.find(i => i.modelValue === 'SERVER_DEPLOYMENT_ID')
        findI.options = [{value:'',label:'全部'}].concat(options)
      })
      getDetailConfigLinkData().then(res => {
        let date = res.msg;//将返回的Json格式字符串转换成json对象
        let tempConfigData = date[0].Rows;
        if (tempConfigData.length > 0) {
          configData2.value = tempConfigData;

        } else {
          configData2.value = [];
        }
      })
    })
    return {
      breadArr,
      forms,
      processStateTableDetailFilterForm,
      processStateTableDetailTableHeader ,

      isAddUnitDialogIsShow,
      openAddUnitDialog,
      getStatus,
      gettDType,
      getTableData,
    pageIndex,pageSize,tableData,totalCount,initSearch,handleSizeChange,refEl,
      connectLink,
      delData,
      editTableInfo,
      currentDialogObj,dialogOperationType,
      updateOrAddProcessDetailD,
      saveS,filterForm,
      beforeBack

    }
  }


}
</script>

<style scoped lang="scss">
.my-search-div{
  width: max-content;
}
.error{
  color: #f00;
}
</style>
