<template>
  <div class="agencyinfo" v-loading="loading">
    <el-form ref="formData" :model="formData" :rules="rules" label-width="140px">
      
      <h3 style="z-index: 999;position: relative;">
        <el-button type="primary" @click="submit" class="float-r" v-if="isShowSubmit">提交</el-button>
        <el-button v-if="formData.id" @click="testConnectivity" type="primary" class="float-r" style="margin-right:20px;">
          测试连通性</el-button>
        <!-- <el-button type="primary" @click="showMsg" class="float-r mr-15" v-if="currentRow.id">依赖检测</el-button> -->
      </h3>
      <!-- 信息tab页 -->
      <el-tabs v-model="activeName" type="card">
        
        <el-tab-pane label="一般信息" name="first">
          <div class="formGroup">
            <el-row :gutter="20">
              <el-col :span="20">
                <el-form-item label="名称：" prop="name" required>
                  <el-input v-model="formData.name" @input="changeVal('name')"></el-input>
                </el-form-item>
                <el-form-item label="说明：">
                  <el-input type="textarea" v-model="formData.description"></el-input>
                </el-form-item>
                <el-form-item label="Connector类型：" prop="connectorType" required>
                  <el-select
                  @change="test"
                    v-model="formData.connectorType"
                    @input="changeVal('connectorType')"
                    clearable
                    placeholder="请选择">
                    <el-option v-for="item in typeList" :key="item.type" :label="item.type" :value="item.type">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="唯一标识：" prop="mark" required>
                  <el-input v-model="formData.mark"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>
        <el-tab-pane label="适配器配置" v-if="formData.connectorType !== 'Sap'" name="thirds">
          <!-- <div class="rivise">修改适配器配置需修改适配器名称才能生效</div> -->
          <el-row :gutter="20" v-if="formData.connectorType === 'Soap'">
            <el-col :span="20">
              <el-form-item label="wsdl：">
                <el-input v-model="formData.wsdl"></el-input>
              </el-form-item>
              <el-form-item label="支持压缩：">
                <el-checkbox v-model="formData.compress"></el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" v-if="formData.connectorType === 'DB'">
            <el-col :span="20">
              <el-form-item label="数据库类型：" prop="dbType">
                <el-select
                  v-model="formData.dbType"
                  clearable
                  placeholder="请选择">
                  <el-option v-for="item in dbTypeList" :key="item.dbType" :label="item.dbType" :value="item.dbType">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="地址：" prop="url">
                <el-input v-model="formData.url"></el-input>
              </el-form-item>
              <el-form-item label="用户名：" prop="username">
                <el-input v-model="formData.username" autocomplete="new-password"></el-input>
              </el-form-item>
              <el-form-item label="密码：" prop="password">
                <el-input v-model="formData.password" type="password" autocomplete='new-password'>
                </el-input>
              </el-form-item>
              <el-form-item label="连接参数：">
                <el-input v-model="formData.urlParams" type="textarea"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" v-if="formData.connectorType === 'Ftp'">
            <el-col :span="20">
              <!-- <div style="text-align: right;margin-bottom: 15px;">
                <el-button type="primary">测试</el-button>
              </div> -->
              <el-form-item label="地址：" prop="host">
                <el-input v-model="formData.host"></el-input>
              </el-form-item>
              <el-form-item label="端口：">
                <el-input v-model="formData.port"></el-input>
              </el-form-item>
              <el-form-item label="账号：" prop="username">
                <el-input v-model="formData.username" autocomplete="new-password"></el-input>
              </el-form-item>
              <el-form-item label="密码：" prop="password">
                <el-input v-model="formData.password" type="password" autocomplete='new-password'>
                </el-input>
              </el-form-item>
              <el-form-item label="超时时间：">
                <el-input v-model.number="formData.connectTimeout" type="number"></el-input>
              </el-form-item>
              <el-form-item label="重试次数：">
                <el-input v-model.number="formData.maximumReconnectAttempts" type="number"></el-input>
              </el-form-item>
              <el-form-item label="重试间隔：">
                <el-input v-model.number="formData.reconnectDelay" type="number"></el-input>
              </el-form-item>
              <el-form-item label="被动模式：">
                <el-checkbox v-model="formData.passiveMode"></el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" v-if="formData.connectorType === 'Mail'">
            <el-col :span="20">
              <el-form-item label="地址：" prop="host">
                <el-input v-model="formData.host"></el-input>
              </el-form-item>
              <el-form-item label="端口：">
                <el-input v-model="formData.port"></el-input>
              </el-form-item>
              <el-form-item label="SSL：">
                <!-- <el-checkbox v-model="1" label="SSL"></el-checkbox> -->
                <el-checkbox  ></el-checkbox>
              </el-form-item>
              <el-form-item label="账号：" prop="username">
                <el-input v-model="formData.username" autocomplete="new-password"></el-input>
              </el-form-item>
              <el-form-item label="密码：" prop="password">
                <el-input v-model="formData.password" type="password" autocomplete='new-password'>
                </el-input>
              </el-form-item>
              <!-- <el-form-item label="类型：" prop="type">
                <el-select v-model="formData.type"  clearable placeholder="请选择">
                  <el-option v-for="item in connectTypeList" :key = "item.name" :label="item.name" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item> -->
              <el-form-item label="连接超时：">
                <el-input v-model.number="formData.connectionTimeout" type="number"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" v-if="formData.connectorType === 'Kafka'">
            <el-col :span="20">
              <el-form-item label="brokers：" prop="brokers">
                <el-input v-model="formData.brokers"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- JMS -->
          <div class="formGroup" v-if="formData.connectorType === 'Jms' ">
            <el-row :gutter="20">
              <el-col :span="20">
                <el-form-item label="地址：" prop="host">
                  <el-input v-model="formData.host"></el-input>
                </el-form-item>
                <el-form-item label="端口：" prop="port" required>
                  <el-input type="number" v-model="formData.port"></el-input>
                </el-form-item>
                <el-form-item label="账号：" prop="username">
                  <el-input v-model="formData.username"></el-input>
                </el-form-item>
                <el-form-item label="密码：" prop="password">
                  <el-input v-model="formData.password" type="password">
                  </el-input>
                </el-form-item>
                <el-form-item label="类型：" prop="type">
                  <el-select v-model="formData.type"  clearable placeholder="请选择">
                    <el-option v-for="item in connectTypeList" :key = "item.name" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>
        <el-tab-pane label="高级配置" v-if="formData.connectorType === 'DB' && formData.connectorType !== 'Sap'" name="second">
            <el-row :gutter="20">
              <el-col :span="20">
                <el-form-item label="初始化连接池大小：">
                  <el-input v-model.number="formData.initialSize" type="number"></el-input>
                </el-form-item>
                <el-form-item label="最小连接池大小：">
                  <el-input v-model.number="formData.minIdle" type="number"></el-input>
                </el-form-item>
                <el-form-item label="最大活动数量：">
                  <el-input v-model.number="formData.maxActive" type="number"></el-input>
                </el-form-item>
                <el-form-item label="连接最大等待时间：">
                  <el-input v-model.number="formData.maxWait" type="number"></el-input>
                </el-form-item>
                <el-form-item label="连接检测的空闲时间：">
                  <el-input v-model.number="formData.minEvictableIdleTimeMillis" type="number"></el-input>
                </el-form-item>
                <el-form-item label="连接保持空闲而不被驱逐的最长时间：">
                  <el-input v-model.number="formData.maxPoolPreparedStatementPerConnectionSize" type="number">
                  </el-input>
                </el-form-item>
                <el-form-item label="测试语句：">
                  <el-input v-model.number="formData.validationQuery"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
        </el-tab-pane>
        <el-tab-pane v-if="currentRow.id && formData.connectorType !== 'Sap'" label="依赖检测" name="third">
          <depend-onthe-test type="connect" :formData="formData"  :titleName="titleName" :dialogVisible="dialogVisible"/>
        </el-tab-pane>
        
        <el-tab-pane name="userInfo" label="用户信息" v-if="formData.connectorType === 'Sap'">
          <div class="formGroup">
            <el-row :gutter="20">
              <el-col :span="20">
                <el-form-item label="用户登录参数：">
                </el-form-item>
                <el-form-item label="用户名：" prop="username" required>
                  <el-input v-model="formData.username"></el-input>
                </el-form-item>
                <el-form-item label="密码：" prop="password" required>
                  <el-input v-model="formData.password"></el-input>
                </el-form-item>
                <el-form-item label="客户号：" prop="client" required>
                  <el-input v-model="formData.client"></el-input>
                </el-form-item>
                <el-form-item label="语言：" prop="language" required>
                  <el-input v-model="formData.language"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>
        <el-tab-pane name="linkInfo" label="连接信息" v-if="formData.connectorType === 'Sap'">
          <div class="formGroup">
            <el-row :gutter="20">
              <el-col :span="20">
                <el-form-item label="SAP连接参数：">
                </el-form-item>
                <el-form-item label="连接类型：" prop="connectType" required>
                  <el-radio-group v-model="formData.connectType">
                    <el-radio label="直接连接"></el-radio>
                    <el-radio label="负载连接"></el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="应用服务器：" prop="gatewayHost" required>
                  <el-input v-model="formData.gatewayHost"></el-input>
                </el-form-item>
                <el-form-item label="系统编号：" prop="systemNumber" required>
                  <el-input v-model="formData.systemNumber"></el-input>
                </el-form-item>
                <el-form-item label="消息主机：" prop="messageHost" required>
                  <el-input v-model="formData.messageHost"></el-input>
                </el-form-item>
                <el-form-item label="消息服务：" prop="messageService" required>
                  <el-input v-model="formData.messageService"></el-input>
                </el-form-item>
                <el-form-item label="R/3 Name：" prop="r3Name" required>
                  <el-input v-model="formData.r3Name"></el-input>
                </el-form-item>
                <el-form-item label="服务器群组：" prop="serverGroup" required>
                  <el-input v-model="formData.serverGroup"></el-input>
                </el-form-item>
                <el-form-item label="SAP路由：" prop="routingString" required>
                  <el-input v-model="formData.routingString"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>
        <el-tab-pane name="server" label="服务器信息" v-if="formData.connectorType === 'Sap'">
          <div class="formGroup">
            <el-row :gutter="20">
              <el-col :span="20">
                <el-form-item label="服务器参数：">
                  (只有在接受SAP输入时才需要)
                </el-form-item>
                <el-form-item label="网关主机：" prop="applicationServer">
                  <el-input v-model="formData.applicationServer"></el-input>
                </el-form-item>
                <el-form-item label="网关服务：" prop="gatewayService">
                  <el-input v-model="formData.gatewayService"></el-input>
                </el-form-item>
                <el-form-item label="程序ID：" prop="programId">
                  <el-input v-model="formData.programId"></el-input>
                </el-form-item>
                <el-form-item label="连接数：" prop="connectionCount">
                  <el-input v-model="formData.connectionCount"></el-input>
                </el-form-item>
                <el-form-item label="接收服务器：" prop="repoDestination">
                  <el-input v-model="formData.repoDestination"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>
        <el-tab-pane name="aq" label="安全配置" v-if="formData.connectorType === 'Sap'">
          <div class="formGroup">
            <el-row :gutter="20">
              <el-col :span="20">
                <el-form-item label="安全参数：">
                  (可选)
                </el-form-item>
                <el-form-item label="SNC方式：" prop="sncMode" required>
                  <el-checkbox v-model="formData.sncMode"></el-checkbox>
                </el-form-item>
                <el-form-item label="SNC级别：" prop="sncLevel">
                  <el-select v-model="formData.sncLevel">
                    <el-option
                      v-for="item in SNCLevelOption"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="SNC名称：" prop="sncName">
                  <el-input v-model="formData.sncName"></el-input>
                </el-form-item>
                <el-form-item label="SNC Partner：" prop="sncPartner">
                  <el-input v-model="formData.sncPartner"></el-input>
                </el-form-item>
                <el-form-item label="SNC Liberary：" prop="sncLiberary">
                  <el-input v-model="formData.sncLiberary"></el-input>
                </el-form-item>
                <el-form-item label="服务器安全参数：">
                  (可选)
                </el-form-item>
                <el-form-item label="SNC级别：" prop="sncLevel2">
                  <el-select v-model="formData.sncLevel2">
                    <el-option
                      v-for="item in SNCLevelOption"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="SNC名称：" prop="sncName2">
                  <el-input v-model="formData.sncName2"></el-input>
                </el-form-item>
                <el-form-item label="SNC Liberary：" prop="sncLiberary2">
                  <el-input v-model="formData.sncLiberary2"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>
        <el-tab-pane name="link" label="连接管理" v-if="formData.connectorType === 'Sap'">
          <div class="formGroup">
            <el-row :gutter="20">
              <el-col :span="20">
                <el-form-item label="连接管理参数：">
                  (可选)
                </el-form-item>
                <el-form-item label="连接池数量：" prop="sapLinksNun">
                  <el-input v-model="formData.sapLinksNun"></el-input>
                </el-form-item>
                <el-form-item label="最大连接数量：" prop="poolCapacity">
                  <el-input v-model="formData.poolCapacity"></el-input>
                </el-form-item>
                <el-form-item label="最大等待时长(ms)：" prop="sapMaxWait">
                  <el-input v-model="formData.sapMaxWait"></el-input>
                </el-form-item>
                <el-form-item label="读取超时(ms)：" prop="sapOvertime">
                  <el-input v-model="formData.sapOvertime"></el-input>
                </el-form-item>
                <el-form-item label="有效连接时长(ms)：" prop="sapValid">
                  <el-input v-model="formData.sapValid"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>
        <el-tab-pane name="extra" label="额外属性" v-if="formData.connectorType === 'Sap'">
          <div class="formGroup">
            <el-row :gutter="20">
              <el-col :span="20">
                <el-form-item label="其他参数：">
                  (可选)
                </el-form-item>
                <el-form-item>
                  <el-table
                    border
                    highlight-current-row
                    @current-change="handleCurrentRow"
                    :data="formData.additionParameters"
                    style="width: 100%">
                    <el-table-column
                      prop="key"
                      label="名称"
                      width="auto">
                    </el-table-column>
                    <el-table-column
                      prop="value"
                      label="值"
                      width="auto">
                    </el-table-column>
                  </el-table>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="addExtraItem" class="float-l">添加</el-button>
                  <el-button type="primary" @click="delExtraItem(sapCurrentRow)" class="float-l">移除</el-button>
                </el-form-item>
                <el-dialog
                 :close-on-click-modal="false"
                  append-to-body
                  title="添加"
                  :visible.sync="extraDialog"
                  width="50%"
                  :before-close="handleextraDialog">
                  <el-form-item label="请输入名称：">
                    <el-input v-model="extraKey" size="small" placeholder="请输入名称"></el-input>
                  </el-form-item>
                  <el-form-item label="请输入值：">
                    <el-input v-model="extraValue" size="small" placeholder="请输入值"></el-input>
                  </el-form-item>
                  <span slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="extraDialogSub">添加</el-button>
                  </span>
                </el-dialog>
              </el-col>
            </el-row>
          </div>
        </el-tab-pane>
      </el-tabs>

    </el-form>
    <!--    <el-row class="formFooter align-center mt-20" v-if="isShowSubmit">-->
    <!--      <el-button type="primary" @click="submit">提交</el-button>-->
    <!--    </el-row>-->
    <!-- <depend-onthe-test v-model="connectVisible" type="connect" :formData="formData" :titleName="titleName">
    </depend-onthe-test> -->
  </div>
</template>

<script>
import DependOntheTest from '@/components/Dependonthetest/Dependonthetest'
import { saveConnector, getConnectorDetail, findAvailableConnectType, testConnector, deployConnector } from '@/api/esb_service'
import { checkFormData } from '@/utils/common'
import { createNamespacedHelpers } from 'vuex'
// const { mapMutations, mapGetters } = createNamespacedHelpers('app')
const { mapGetters } = createNamespacedHelpers('app')
export default {
  data() {
    var checkPort = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('端口不能为空'))
      }
      if (!Number(value)) {
        callback(new Error('端口必须为整数值'))
      } else {
        if (value < 0 || value > 65536) {
          callback(new Error('请输入0~65536整数字值'))
        } else {
          callback()
        }
      }
    }
    return {
      extraKey: '',
      extraValue: '',
      extraDialog: false,
      sapCurrentRow: null,
      SNCLevelOption: [
        {
          value: 1,
          label: 1
        },
        {
          value: 2,
          label: 2
        },
        {
          value: 3,
          label: 3
        },
        {
          value: 8,
          label: 8
        },
        {
          value: 9,
          label: 9
        }
      ],
      loading: false,
      formData: {},
      activeName: 'first',
      dialogVisible: false,
      typeList: [],
      dbTypeList: [],
      rules: {
        sncMode: [
          { required: true, message: 'SNC方式不能为空', trigger: ['change', 'blur'] }
        ],
        connectType: [
          { required: true, message: '连接类型不能为空', trigger: ['change', 'blur'] }
        ],
        gatewayHost: [
          { required: true, message: '应用服务器不能为空', trigger: ['change', 'blur'] }
        ],
        systemNumber: [
          { required: true, message: '系统编号不能为空', trigger: ['change', 'blur'] }
        ],
        messageHost: [
          { required: true, message: '消息主机不能为空', trigger: ['change', 'blur'] }
        ],
        messageService: [
          { required: true, message: '消息服务不能为空', trigger: ['change', 'blur'] }
        ],
        r3Name: [
          { required: true, message: 'R/3 Name不能为空', trigger: ['change', 'blur'] }
        ],
        serverGroup: [
          { required: true, message: '服务器群组不能为空', trigger: ['change', 'blur'] }
        ],
        routingString: [
          { required: true, message: 'SAP路由不能为空', trigger: ['change', 'blur'] }
        ],
        username: [
          { required: true, message: '用户名不能为空', trigger: ['change', 'blur'] }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: ['change', 'blur'] }
        ],
        client: [
          { required: true, message: '客户号不能为空', trigger: ['change', 'blur'] }
        ],
        language: [
          { required: true, message: '语言不能为空', trigger: ['change', 'blur'] }
        ],
        name: [
          { required: true, message: '名称不能为空', trigger: ['change', 'blur'] }
        ],
        mark: [
          { required: true, message: '唯一标识不能为空', trigger: ['change', 'blur'] }
        ],
        connectorType: [
          { required: true, message: 'Connector类型不能为空', trigger: ['change', 'blur'] }
        ],
        dbType: [
          { required: true, message: '数据库类型不能为空', trigger: ['change', 'blur'] }
        ],
        url: [
          { required: true, message: '地址不能为空', trigger: ['change', 'blur'] }
        ],
        // name: [
        //   { required: true, message: '名称不能为空', trigger: ['change', 'blur'] }
        // ],
        // username: [
        //   { required: true, message: '用户名不能为空', trigger: ['change', 'blur'] }
        // ],
        // password: [
        //   { required: true, message: '密码不能为空', trigger: ['change', 'blur'] }
        // ],
        urlParams: [
          { required: true, message: '连接参数不能为空', trigger: ['change', 'blur'] }
        ],
        host: [
          { required: true, message: '地址不能为空', trigger: ['change', 'blur'] }
        ],
        // port: [
        //   { required: true, message: '端口号不能为空', trigger: ['change', 'blur'] }
        // ],
        connectTimeout: [
          { required: true, message: '超时时间不能为空', trigger: ['change', 'blur'] }
        ],
        maximumReconnectAttempts: [
          { required: true, message: '重试次数不能为空', trigger: ['change', 'blur'] }
        ],
        reconnectDelay: [
          { required: true, message: '重试时间不能为空', trigger: ['change', 'blur'] }
        ],
        port: [
          { validator: checkPort, trigger: ['change', 'blur'] }
        ],
        type: [
          { required: true, message: '类型不能为空', trigger: ['change', 'blur'] }
        ]
      },
      connectVisible: false,
      titleName: '适配器',
      connectTypeList: [
        { name: 'activeMQ', value: 'activemq' }
      ]
    }
  },
  props: {
    isShowSubmit: {
      type: Boolean,
      default: true
    },
    value: {
      type: Boolean,
      default: false
    },
    currentRow: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    value: {
      immediate: true,
      handler: function(val) {
        this.dialogVisible = val
        this.$nextTick(() => {
          this.$refs.formData.clearValidate()
        })
        this.formData = {
          additionParameters: [],
          sncMode: false,
          sncLevel: 1,
          sncLevel2: 1,
          initialSize: 10,
          maxActive: 50,
          maxPoolPreparedStatementPerConnectionSize: 10,
          maxWait: -1,
          minEvictableIdleTimeMillis: 1800000,
          maxEvictableIdleTimeMillis: 25200000,
          minIdle: 0,
          maxIdle: 50,
          poolPreparedStatements: false,
          timeBetweenEvictionRunsMillis: 60000,
          passiveMode: false
        }
        this.$set(this.currentRow, 'changetime', Date.parse(new Date()))
      },
      deep: true
    },
    dialogVisible(val) {
      this.$emit('input', val)
    },
    currentRow: {
      immediate: true,
      handler: function(val) {
        if (val && val.id ) {
          console.log('打印深度监视数据',val,val.id)
          this.getConnectorDetail(val.id)
        }
      },
      // deep: true
    }
  },
  mounted() {
    this.findAvailableConnectType()
  },
  computed: {
    ...mapGetters(['projectID'])
  },
  methods: {
    extraDialogSub() {
      // 额外 添加 添加
      if (this.extraKey && this.extraValue) {
        const i = this.formData.additionParameters.findIndex(it => it.key === this.extraKey)
        if (i >= 0) {
          this.formData.additionParameters[i].value = this.extraValue
        } else {
          this.formData.additionParameters.push({
            key: this.extraKey,
            value: this.extraValue
          })
        }
        this.handleextraDialog()
      } else {
        this.$message({
          message: '请输入名称或者值',
          type: 'warning'
        })
      }
    },
    handleextraDialog() {
      // 额外 添加 关闭
      this.extraKey = ''
      this.extraValue = ''
      this.extraDialog = false
    },
    addExtraItem() {
      this.extraDialog = true
    },
    delExtraItem(data) {
      if (data) {
        this.formData.additionParameters = this.formData.additionParameters.filter(it => it.key !== data.key)
      } else {
        this.$message({
          message: '请先选择',
          type: 'warning'
        })
      }
      this.sapCurrentRow = null
    },
    handleCurrentRow(data) {
      this.sapCurrentRow = data
    },
    test() {
      console.log(this.formData)
    },
    changeVal(name) {
      this.$set(this.formData, 'mark', `conn/${this.formData.connectorType || ''}/${this.formData.name || ''}`)
    },
    testConnectivity() {
      this.loading = true
      testConnector(this.formData.id).then(rt => {
        this.loading = false
        if (rt.data && rt.data[0].success) {
          this.$message.success('测试成功')
        } else {
          this.$message.error(rt.data[0].message)
        }
      }).catch(er => {
        this.loading = false
      })
    },
    findAvailableConnectType() {
      findAvailableConnectType(false).then((rt) => {
        if (rt.status === '200') {
          this.typeList = rt.data
          // console.log(999999, rt.data)
          this.jmsormData = rt.data
          const _this = this
          this.typeList.forEach(function(item) {
            if (item.type === 'DB') {
              _this.dbTypeList = item.driverList
            }
          })
        }
      }).catch(() => {
      })
    },
    getConnectorDetail(id) {
      getConnectorDetail(id).then((rt) => {
        if (rt.status === '200') {
          this.formData = rt.data
        }
      }).catch(() => {
      })
    },
    async submit() {
      this.$refs['formData'].validate((valid) => {
        if (valid) {
          let forms = {}
          if (this.formData.connectorType === 'Jms') {
            forms = {
              'description': this.formData.description,
              'name': this.formData.name,
              'host': this.formData.host,
              'port': this.formData.port,
              'username': this.formData.username,
              'password': this.formData.password,
              'type': this.formData.type,
              'connectorType': this.formData.connectorType,
              'mark': this.formData.mark,
              'id': this.formData.id
            }
          }

          let ftpForm = {}
          if (this.formData.connectorType === 'Ftp') {
            ftpForm = {
              'description': this.formData.description,
              'connectTimeout': this.formData.connectTimeout,
              'connectorType': this.formData.connectorType,
              // 'description': this.formData.description,
              'host': this.formData.host,
              'id': this.formData.id,
              'mark': this.formData.mark,
              'maximumReconnectAttempts': this.formData.maximumReconnectAttempts,
              'name': this.formData.name,
              'passiveMode': this.formData.passiveMode,
              'password': this.formData.password,
              'port': this.formData.port,
              'reconnectDelay': this.formData.reconnectDelay,
              'resourceSubType': this.formData.resourceSubType,
              'resourceType': this.formData.resourceType,
              'username': this.formData.username
            }
          }

          forms.projectId = this.projectID
          ftpForm.projectId = this.projectID
          this.formData.projectId = this.projectID

          if (this.formData.connectorType === 'Ftp') {
            // console.log('Ftp', ftpForm)
            saveConnector(ftpForm).then((rt) => {
              if (rt.status === '200') {
                this.$message({
                  message: '提交成功',
                  type: 'success'
                })
                // this.deploy(rt)
                this.$emit('confirm')
              }
            }).catch(err => {
              const data = err.data || []
              const hint = [
                { fieName: '名称', field: 'name' },
                { fieName: '说明', field: 'description' },
                { fieName: 'Connector类型', field: 'connectorType' },
                { fieName: 'wsdl', field: 'wsdl' }
              ]
              checkFormData(data, hint)
            })
          } else if (this.formData.connectorType === 'Jms') {
            // console.log('Jms', forms)
            saveConnector(forms).then((rt) => {
              if (rt.status === '200') {
                this.$message({
                  message: '提交成功',
                  type: 'success'
                })
                this.deploy(rt)
                // this.$emit('confirm')
              }
            }).catch(err => {
              const data = err.data || []
              const hint = [
                { fieName: '名称', field: 'name' },
                { fieName: '说明', field: 'description' },
                { fieName: 'Connector类型', field: 'connectorType' },
                { fieName: 'wsdl', field: 'wsdl' }
              ]
              checkFormData(data, hint)
            })
          } else {
            if (this.$route.fullPath.indexOf('/system_manage/global_configuration/connector') !== -1 && !this.formData.projectId) {
              delete this.formData.projectId
            }
            saveConnector(this.formData).then((rt) => {
              if (rt.status === '200') {
                this.$message({
                  message: '提交成功',
                  type: 'success'
                })
                this.deploy(rt)
                // this.$emit('confirm')
              }
            }).catch(err => {
              const data = err.data || []
              const hint = [
                { fieName: '名称', field: 'name' },
                { fieName: '说明', field: 'description' },
                { fieName: 'Connector类型', field: 'connectorType' },
                { fieName: 'wsdl', field: 'wsdl' }
              ]
              checkFormData(data, hint)
            })
          }
        }
      })
    },
    deploy(info) {
      deployConnector(info.data.id).then((rt) => {
        this.$emit('confirm')
      })
    },
    showMsg() {
      this.connectVisible = true
    }
  },
  components: {
    DependOntheTest
  }
}
</script>

<style type="text/scss" lang="scss" scoped>
.el-select {
  width: 100%;
}
.rivise{
  margin-left: 45px;
  font-size: 12px;
  color: red;
}
</style>
