<template>
  <div class="agencyinfo">
    <el-form
      ref="formData"
      :model="formData"
      :rules="rules"
      label-width="130px"
    >
      <!-- 信息页 -->
      <el-form name="first">
        <el-form-item label="名称：" prop="name">
          <el-input v-model="formData.name"></el-input>
        </el-form-item>
        <el-form-item label="类型：" prop="name">
          <el-input v-model="formData.name"></el-input>
        </el-form-item>
        <el-form-item label="项目：" prop="projectName">
          <el-input v-model="formData.projectName"></el-input>
        </el-form-item>
        <el-form-item label="修改者：" prop="name">
          <el-input v-model="formData.name"></el-input>
        </el-form-item>
        <el-form-item label="最终修改日期" prop="updateon">
          <el-input v-model="formData.updateon"></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="目标：" prop="targetService.name">
          <el-input
            v-model="formData.targetService.name"
            suffix-icon="el-icon-search"
            @click.native="chooseTarget"
            readonly
          >
          </el-input>
        </el-form-item>
        <el-form-item label="最终服务地址：">
          <p>
            {{ formData.callingAddress ? formData.callingAddress[0] : '' }}
          </p>
        </el-form-item>
      </el-form>
      <choose-connector-dialog
        v-model="connectorVisible"
        :connectorId="formData.connectorId"
        :connectorType="formData.protocol"
        @confirm="handleConnector"
      />
      <choose-target-dialog
        v-model="targetVisible"
        :targetId="formData.targetId"
        :targetType="formData.targetType"
        :targetIncludes="['business', 'flow']"
        @confirm="handleTarget"
      />
      <choose-resourcefile-dialog
        v-model="resourcefileVisible"
        :seletedId="chickId1 || formData.chickId1"
        :defineFileType="defineFileType"
        @confirm="handleResourcefile(arguments)"
      />
      <choose-resourcefile-dialog
        v-model="resourceFileVisible2"
        :seleted-id="chickId2"
        :defineFileType="defineFileType"
        @confirm="handleResourceFile2(arguments)"
      />
      <TestSql
        v-model="testSqlVisible"
        :sqlData="sqlData"
        :sqlFormData="sqlFormData"
        @confirm="getStatus"
      />
      <choose-resource-dialog
        v-model="resourceVisible"
        resourceType="sql"
        @confirm="handleResource"
      />
      <SelectArea
        v-model="areaDialog"
        :connectorId="formData.domainId"
        @confirm="getArea"
      />
    </el-form>
    <div>
      <!-- <depend-onthe-test v-model="dependVisible" type="agency" :formData="formData" :titleName="titleName">
      </depend-onthe-test> -->
    </div>
    <!-- 构建器列表弹框 -->
    <el-dialog
      class="scrollbar-dialog"
      :visible.sync="isClick"
      width="900px"
      top="5vh"
      append-to-body
    >
      <sql-list @getSqlData="getSql" />
    </el-dialog>
    <!-- 构建器列表 -->
    <sql-details
      v-model="editSqlBuilderVisible"
      :buildId="this.formData.connectorSrvParamsMap.id"
      @closeEditDialog="closeEditDialog"
      :porjectId="sqlObj.perjectId"
      @confirmEdit="confirmEdit"
    />
    <user-list-dialog
      v-model="userListVisible"
      :userListOld="userList"
      @getCheckeduserList="getCheckeduserList"
      :id="currentRow.id"
      @closeUserList="closeUserList"
    />
    <editOldVersionVue
      :visibles="editOldVersionDailog"
      :ruleForm="ruleForm"
      :rowData="currentRow"
      @confirm="publishProxyServices"
    />
  </div>
</template>

<script>
import editOldVersionVue from './editOldVersion.vue'
import ChooseConnectorDialog from '@/components/connector/ChooseConnectorDialog'
import ChooseTargetDialog from '@/components/target/ChooseTargetDialog'
import ChooseResourcefileDialog from '@/components/resourcefile/ChooseResourcefileDialog'
import ChooseResourceDialog from '@/components/resource/ChooseResourceDialog'
import SelectArea from '../node_manage/SelectArea'
import userListDialog from './userListDialog'
import sqlList from '../sql_builder/sqlList' // 获取sql列表
import sqlDetails from '../sql_builder/sqldatil'
import { versionSave, versionBackup, versionQuery } from '@/api/system_manage'
import DependOntheTest from '@/components/Dependonthetest/Dependonthetest'

import TestSql from './TestSql'
import {
  saveProxyService,
  getProxyServiceDetail,
  publishProxyService,
  saveSql,
  scriptValidate,
  getRuntimeInfo,
  // getPublish, startService, stopService, suspendService, resumeService, restartService, getResourceFile,
  getPublish,
  startService,
  stopService,
  suspendService,
  resumeService,
  restartService,
  generateSql,
  kongInfoSave,
  kongInfosGet,
  kongInfoGet
} from '@/api/esb_service'
import { checkFormData } from '@/utils/common'
import EsbServiceInfoMixins from '@/mixins/esb_service_info_mixins'
import { createNamespacedHelpers } from 'vuex'

const { mapGetters } = createNamespacedHelpers('app')
export default {
  mixins: [EsbServiceInfoMixins],
  components: {
    editOldVersionVue,
    ChooseConnectorDialog,
    ChooseTargetDialog,
    ChooseResourcefileDialog,
    TestSql,
    ChooseResourceDialog,
    DependOntheTest,
    SelectArea,
    userListDialog,
    sqlList,
    sqlDetails
  },
  data() {
    return {
      editOldVersionDailog: false,
      httpLL: {},
      statusTab: '',
      tabName: '',
      LimiOption: [
        { value: 'second', name: '秒' },
        { value: 'minute', name: '分钟' },
        { value: 'hour', name: '小时' },
        { value: 'day', name: '日' },
        { value: 'month', name: '月' },
        { value: 'year', name: '年' }
      ],
      sizeOption: [
        { value: 'bytes', name: 'bytes' },
        { value: 'kilobytes', name: 'kilobytes' },
        { value: 'megabytes', name: 'megabytes' }
      ],
      STATUS: { 1: '运行中', 2: '异常', 3: '未知', 4: '部分异常' },
      deploymentData: [
        {
          id: '10001',
          name: '测试节点1',
          status: '运行中',
          result: 'OK'
        }
      ],
      verson: [],
      editSqlBuilderVisible: false, // 打开详情页面
      deploymentMultipleSelection: [],
      sqlObj: {}, // 构建器名字
      ruleForm: {},
      isClick: false,
      // jms
      rules: {
        isEnableRequestSizeLimiting: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ],
        isEnableRateLimiting: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ],
        isEnableWhiteList: [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ],
        'connectorSrvParamsMap.destinationType': [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ],
        'connectorSrvParamsMap.destinationName': [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ],
        'connectorSrvParamsMap.cron': [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ],
        'connectorSrvParamsMap.delay': [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ],
        'securityConf.authStrategy': [
          {
            required: true,
            message: '验证策略不能为空',
            trigger: ['change', 'blur']
          }
        ],
        'connectorSrvParamsMap.topic': [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ],
        'connectorSrvParamsMap.groupId': [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ],
        'connectorSrvParamsMap.brokers': [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ]
      },
      areaDialog: false,
      formData: {
        serviceParamsMap: {},
        connector: {},
        targetService: {},
        connectorSrvParamsMap: {
          initialDelay: 1000
        },
        commonConf: {
          enableMonitor: false,
          // "id": "",
          logRequestBody: false,
          logResponseBody: false
          // "serviceId": "",
          // "serviceType": ""
        },
        disable: false,
        securityConf: {
          id: '',
          enableSecurity: false, // 是否启用安全验证
          authStrategy: '' // 验证策略
        },
        authAccountsMap: {},
        projectName: this.projectName
      },
      ispass: '',
      ispass1: '',
      ispass2: '',
      debugVisible: false,
      targetVisible: false,
      testSqlVisible: false,
      resourceVisible: false,
      sqlData: [],
      sqlFormData: {},
      activeType: '',
      analysisData: '',
      dependVisible: false,
      options: [
        { key: 'none', value: 'none' },
        { key: 'markerFile', value: 'markerFile' },
        { key: 'fileLock', value: 'fileLock' },
        { key: 'rename', value: 'rename' }
      ],
      options1: [
        { key: '间隔执行', value: 'delay' },
        { key: '执行计划', value: 'cron' }
      ],
      titleName: '代理服务',
      userListVisible: false,
      userList: {},
      activeName: 'first',
      dialogVisible: false,
      transActive: '1', // ['1','2']
      id_list: []
    }
  },
  created: function () {
    console.log('formdata', this.formData)
    console.log('formdata-name', this.formData.name)
    const _this = this
    this.kafkaParams.forEach(function (item) {
      if (item.isrequired) {
        _this.rules['connectorSrvParamsMap.' + item.name] = [
          { required: true, message: '不能为空', trigger: ['change', 'blur'] }
        ]
      }
    })
  },
  props: {
    value: {
      type: Boolean,
      default: false
    },
    currentRow: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    value: {
      immediate: true,
      handler: function (val) {
        this.dialogVisible = val
        if (val) {
          this.$nextTick(() => {
            this.$refs.formData.clearValidate()
          })
          this.ispass = ''
          this.ispass1 = ''
          this.ispass2 = ''
          this.httpLL = {
            isEnableWhiteList: 'false',
            isEnableRateLimiting: false,
            isEnableRequestSizeLimiting: false,
            sizeUnit: 'megabytes',
            allowedPayloadSize: '128'
          }
          this.formData = {
            id: '',
            messageType: 'REST',
            payloadType: 'json',
            protocol: 'http',
            serviceParamsMap: {},
            connector: {},
            targetService: {},
            connectorSrvParamsMap: {
              sql: '',
              maxMessagesPerPoll: '',
              delay: '',
              cron: '',
              pollType: this.radio1 === '1' ? 'delay' : 'cron',
              initialDelay: 0,
              onConsume: '',
              onConsumeFailed: '',
              greedy: false,
              breakBatchOnConsumeFail: false,
              transacted: false
            },
            commonConf: {
              enableMonitor: false,
              // "id": "",
              logRequestBody: false,
              logResponseBody: false
              // "serviceId": "",
              // "serviceType": ""
            },
            disable: false,
            securityConf: {
              id: '',
              enableSecurity: false, // 是否启用安全验证
              authStrategy: '' // 验证策略
            },
            authAccountsMap: {}
          }
          console.log('你变了', this.formData.connectorSrvParamsMap)
          // this.httpMethod = ['POST']
          // this.formData.connectorSrvParamsMap.httpMethod = ['POST']

          this.analysisData = ''
        }
        this.$set(this.currentRow, 'changetime', Date.parse(new Date()))
      },
      deep: true
    },
    dialogVisible(val) {
      this.$emit('input', val)
    },
    currentRow: {
      immediate: true,
      handler: function (val) {
        console.log('打印watch数据监听', val, val.id)
        if (val && val.id) {
          this.getProxyServiceDetail(val.id)
        }
      },
      deep: true
    }
  },
  computed: {
    ...mapGetters(['projectID'])
  },
  methods: {
    // debug打开
    debugs() {
      this.debugVisible = true
    },
    // 切换表格
    handleClicks(tab) {
      this.fileList1 = []
      this.typeList.map((item) => {
        if (item.type === tab.name) {
          this.fileList1.push(item.content)
        }
      })
    },
    // 切换类型
    // 发布调用的接口
    getPublish(id) {
      getPublish(id).then((res) => {
        this.statusTab = res.status
      })
    },
    // 获取信息部署
    getRuntimeInfo() {
      getRuntimeInfo(this.currentRow.id).then((res) => {
        this.deploymentData = res.data
      })
    },
    confirmEdit(val) {
      this.$set(this.sqlObj, 'name', val)
      this.formData.connectorSrvParamsMap.sql = val.customSql
      this.getResourceFile(this.sqlObj.id, this.sqlObj.perjectId)
      this.editSqlBuilderVisible = false
    },
    closeEditDialog(val) {
      this.editSqlBuilderVisible = val
    },
    getArea(data) {
      // console.log(data, 'domain')
      this.$set(this.formData, 'domainId', data.id)
      this.$set(this.formData, 'domainName', data.name)
    },
    /* 部署信息的多选 */
    deploySelectionChange(rows) {
      // console.log(rows, '选中')
      this.deploymentMultipleSelection = rows
    },
    // 启动获取
    startServices(id1, id) {
      startService({
        id: id1,
        servers: id
      }).then((res) => {
        this.statusTab = res.status === '500' ? '服务异常' : '正常'
        if (res.status === '200') {
          this.$message({
            message: '启动指定服务成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '启动指定服务失败',
            type: 'error'
          })
        }
      })
    },
    // 停止启动服务
    stopService(id1, id) {
      stopService({
        id: id1,
        servers: id
      }).then((res) => {
        this.statusTab = res.status === '500' ? '服务异常' : '正常'
        if (res.status === '200') {
          this.$message({
            message: '停止启动服务成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '停止启动服务失败',
            type: 'error'
          })
        }
      })
    },
    // 部署信息恢复指定服务
    resumeService(id1, id) {
      resumeService({
        id: id1,
        servers: id
      }).then((res) => {
        this.statusTab = res.status === '500' ? '服务异常' : '正常'
        if (res.status === '200') {
          this.$message({
            message: '恢复指定服务成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '恢复指定服务失败',
            type: 'error'
          })
        }
      })
    },
    // 部署信息暂停指定服务
    suspendService(id1, id) {
      suspendService({
        id: id1,
        servers: id
      }).then((res) => {
        this.statusTab = res.status === '500' ? '服务异常' : '正常'
        if (res.status === '200') {
          this.$message({
            message: '暂停指定服务成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '暂停指定服务失败',
            type: 'error'
          })
        }
      })
    },
    // 部署信息重启指定服务
    restartService(id1, id) {
      restartService({
        id: id1,
        servers: id
      }).then((res) => {
        this.statusTab = res.status === '500' ? '服务异常' : '正常'
        if (res.status === '200') {
          this.$message({
            message: '重启指定服务成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '重启指定服务失败',
            type: 'error'
          })
        }
      })
    },
    /* 部署信息的操作 -> 批量操作*/
    deployAction(actionType, singleItem) {
      if (this.deploymentMultipleSelection.length === 0) {
        this.$message.warning('请先选择节点！')
        return false
      }
      // console.log(actionType, singleItem, '1111111111111111111111')
      var str = ''
      this.deploymentMultipleSelection.forEach(function (e) {
        str += e.serverId + ','
      })
      str = str.substring(0, str.length - 1)
      this.id_list = str.split(',')
      switch (actionType) {
        // 启动
        case 'start':
          // this.startServices(this.deploymentMultipleSelection[0].serverId)
          this.startServices(this.formData.id, this.id_list)
          this.id_list = []
          break
        // 暂停
        case 'pause':
          this.suspendService(this.formData.id, this.id_list)
          this.id_list = []
          break
        //  恢复
        case 'restore':
          this.resumeService(this.formData.id, this.id_list)
          this.id_list = []
          break
        //  停止
        case 'stop':
          this.stopService(this.formData.id, this.id_list)
          this.id_list = []
          break
        //  重启
        case 'reboot':
          this.restartService(this.formData.id, this.id_list)
          this.id_list = []
          break
        default:
          break
      }
      // if (singleItem) {
      //   // TODO 这里进行单个操作
      //   switch (actionType) {
      //     // 启动
      //     case 'start':
      //       startService(this.deploymentMultipleSelection.id).then(res => {
      //         console.log(res, '11')
      //       })
      //       break
      //     // 暂停
      //     case 'pause':
      //       break
      //     //  恢复
      //     case 'restore':
      //       break
      //     //  停止
      //     case 'stop':
      //       break
      //     //  重启
      //     case 'reboot':
      //       break
      //     default:
      //       break
      //   }
      // } else {
      //   // TODO 这里进行批量操作
      //   if (this.deploymentMultipleSelection && this.deploymentMultipleSelection.length > 0) {

      //   } else {
      //     this.$message({ message: '请选择需要操作的节点', type: 'error' })
      //   }
      // }
    },
    /* 部署信息的操作 -> 启动*/
    deployActionStart(item) {
      let str = ''
      str = item.serverId
      // console.log(str, 'mmmm')
      str = str.substring(0, str.length)
      this.id_list = str.split()
      // console.log('qqq', this.id_list)
      this.startServices(this.formData.id, this.id_list)
      this.id_list = []
    },
    /* 部署信息的操作 -> 暂停*/
    deployActionPause(item) {
      let str = ''
      str = item.serverId
      str = str.substring(0, str.length)
      this.id_list = str.split()
      this.suspendService(this.formData.id, this.id_list)
      this.id_list = []
    },
    /* 部署信息的操 作 -> 恢复*/
    deployActionRestore(item) {
      let str = ''
      str = item.serverId
      str = str.substring(0, str.length)
      this.id_list = str.split()
      this.resumeService(this.formData.id, this.id_list)
      this.id_list = []
    },
    /* 部署信息的操作 -> 停止*/
    deployActionStop(item) {
      let str = ''
      str = item.serverId
      str = str.substring(0, str.length)
      this.id_list = str.split()
      this.stopService(this.formData.id, this.id_list)
      this.id_list = []
    },
    /* 部署信息的操作 -> 重启*/
    deployActionReboot(item) {
      let str = ''
      str = item.serverId
      str = str.substring(0, str.length)
      this.id_list = str.split()
      this.restartService(this.formData.id, this.id_list)
      this.id_list = []
    },
    handleClick(tab, event) {
      this.tabName = tab.label
      if (tab.label === '部署信息') {
        this.getRuntimeInfo()
      }
    },
    transTabClick(tab, event) {
      this.transActive = '1'
    },
    getSql(data) {
      // console.log(data, '11')
      this.sqlObj = data
      this.isClick = false
      this.generateSql(data.id, data.name)
    },
    // 获取sql
    generateSql(id, name) {
      // console.log('name', name)
      generateSql({
        id: id
      }).then((res) => {
        // console.log(res, '1')
        if (res.status === '200') {
          this.formData.connectorSrvParamsMap.sql = res.data.sql
          this.$set(this.formData.connectorSrvParamsMap, 'name', name)
          this.formData.connectorSrvParamsMap.name = name
          this.formData.connectorSrvParamsMap.id = id
        }
      })
    },
    // 获取默认的配置文件
    // getResourceFile (id, pid) {
    //   getResourceFile(id, pid).then(res => {
    //     if (res.data.length > 0) {

    //     }
    //   })
    // },
    changeSql() {
      this.analysisData = ''
      this.ispass = ''
    },
    getProxyServiceDetail(id) {
      // console.log('kkkkkkkkkkkkk')
      kongInfosGet(id).then((res) => {
        if (res.status === '200') {
          if (res.data.hasOwnProperty('isEnableWhiteList')) {
            this.httpLL = res.data
          }
          if (
            !this.httpLL.hasOwnProperty('isEnableWhiteList') ||
            !this.httpLL.isEnableWhiteList
          ) {
            this.httpLL.isEnableWhiteList = 'false'
            this.httpLL.whiteListType = 'allow'
          }
          if (
            !this.httpLL.hasOwnProperty('isEnableRequestSizeLimiting') ||
            !this.httpLL.isEnableRequestSizeLimiting
          ) {
            this.httpLL.isEnableRequestSizeLimiting = false
          }
          if (
            !this.httpLL.hasOwnProperty('isEnableRateLimiting') ||
            !this.httpLL.isEnableRateLimiting
          ) {
            this.httpLL.isEnableRateLimiting = false
          }
          this.httpLL.isEnableRequestSizeLimiting = JSON.parse(
            this.httpLL.isEnableRequestSizeLimiting
          )
          this.httpLL.isEnableRateLimiting = JSON.parse(
            this.httpLL.isEnableRateLimiting
          )
        }
      })
      // kongInfoGet(id).then(res => {
      //   console.log(res)
      // })
      getProxyServiceDetail(id)
        .then((rt) => {
          if (rt.status === '200' && rt.data) {
            // 注释掉
            // rt.data.connectorSrvParamsMap = rt.data.connectorSrvParams
            this.formData = rt.data
            this.ruleForm = rt.data
            console.log(this.ruleForm, 'nishihuiadasd')
            // console.log(8888888, this.formData)
            // 文件的id
            if (this.formData.gateAwayDtoInfo) {
              this.httpLL = this.formData.gateAwayDtoInfo
            }
            if (!this.formData.chickId1) {
              this.formData.chickId1 = this.formData.defineFileInfo
                ? this.formData.defineFileInfo.id
                : ''
            }
            if (!this.formData.serviceParamsMap) {
              this.$set(this.formData, 'serviceParamsMap', {})
            }
            if (!this.formData.connector) {
              this.$set(this.formData, 'connector', {})
            }
            if (!this.formData.commonConf) {
              this.$set(this.formData, 'commonConf', {
                enableMonitor: false,
                logRequestBody: false,
                logResponseBody: false
              })
            }
            if (!this.formData.securityConf) {
              this.$set(this.formData, 'securityConf', {
                id: this.formData.securityConfId,
                enableSecurity: false,
                authStrategy: ''
              })
            }
            if (!this.formData.authAccountsMap) {
              this.$set(this.formData, 'authAccountsMap', {})
            }
            // 默认不禁用,有默认值，不需要添加
            // this.$set(this.formData, 'disable',false)

            if (!this.formData.targetService) {
              this.$set(this.formData, 'targetService', {})
            }
            // console.log('llllll')
            if (!this.formData.connectorSrvParamsMap) {
              // console.log('jjjjj', this.formData)
              this.$set(this.formData, 'connectorSrvParamsMap', {})
            } else {
              // console.log(11111111)
              this.httpMethod = this.formData.connectorSrvParamsMap.httpMethod
                ? this.formData.connectorSrvParamsMap.httpMethod.split(',')
                : []
            }
            // console.log(2222222)
            this.formData.messageType = rt.data.messageType.toUpperCase()
            if (this.formData.protocol === 'DB') {
              if (
                this.formData.connectorId &&
                this.formData.connectorSrvParamsMap.sql
              ) {
                saveSql({
                  id: this.formData.connectorId,
                  script: this.formData.connectorSrvParamsMap.sql
                })
                  .then((rt) => {
                    if (rt.status === '200') {
                      this.analysisData = rt.data
                      if (this.analysisData) {
                        this.ispass = 'true'
                      }
                    }
                  })
                  .catch(() => {})
              }
            }
          }
        })
        .catch(() => {})
    },
    chooseTarget() {
      this.targetVisible = true
    },
    handleTarget(data) {
      // 先清空
      this.$set(this.formData, 'messageType', '')
      this.$set(this.formData, 'payloadType', '')
      this.$set(this.formData, 'defineFile', '')
      this.$set(this.formData, 'defineFileId', '')
      this.$set(this.formData, 'defineFileType', '')
      this.$set(this.formData, 'secondDefineFileId', '')
      this.$set(this.formData, 'secondDefineFile', '')
      this.$set(this.formData.serviceParamsMap, 'binding', '')
      this.$set(this.formData.connectorSrvParamsMap, 'httpMethod', '')

      this.$set(this.formData, 'commonConf', '')
      this.$set(this.formData, 'disable', false)
      this.$set(this.formData, 'securityConf', '')
      this.$set(this.formData, 'authAccountsMap', {})

      // this.$set(this.formData.connectorSrvParamsMap, 'sql', '')
      // this.$set(this.formData.connectorSrvParamsMap, 'maxMessagesPerPoll', '')
      // this.$set(this.formData.connectorSrvParamsMap, 'delay', '')
      // this.$set(this.formData.connectorSrvParamsMap, 'cron', '')
      // this.$set(this.formData.connectorSrvParamsMap, 'pollType', '')
      // this.$set(this.formData.connectorSrvParamsMap, 'initialDelay', '')
      // this.$set(this.formData.connectorSrvParamsMap, 'maxMessagesPerPoll', '')
      // this.$set(this.formData.connectorSrvParamsMap, 'onConsume', '')
      // this.$set(this.formData.connectorSrvParamsMap, 'onConsumeFailed', '')
      // this.$set(this.formData.connectorSrvParamsMap, 'greedy', false)
      // this.$set(this.formData.connectorSrvParamsMap, 'breakBatchOnConsumeFail', false)
      // this.$set(this.formData.connectorSrvParamsMap, 'transacted', false)
      // this.httpMethod = []
      this.$set(this.formData.targetService, 'name', data.name)
      this.$set(this.formData, 'targetType', data.type)
      this.$set(this.formData, 'targetId', data.id)
      // 再添加
      this.$set(this.formData, 'messageType', data.messageType.toUpperCase())
      this.$set(this.formData, 'payloadType', data.payloadType)
      this.$set(this.formData, 'defineFile', data.defineFile)
      this.$set(this.formData, 'defineFileId', data.defineFileId)
      this.$set(this.formData, 'secondDefineFileId', data.secondDefineFileId)
      this.$set(this.formData, 'defineFileType', data.defineFileType)
      this.$set(this.formData, 'secondDefineFile', data.secondDefineFile)
      if (data.commonConf === undefined) {
        // 新增
        this.$set(this.formData, 'commonConf', {
          enableMonitor: false,
          logRequestBody: false,
          logResponseBody: false
        })
      } else {
        this.$set(this.formData, 'commonConf', data.commonConf)
      }
      if (data.securityConf === undefined) {
        // 新增
        this.$set(this.formData, 'securityConf', {
          id: this.formData.securityConfId,
          enableSecurity: false,
          authStrategy: ''
        })
      } else {
        this.$set(this.formData, 'securityConf', data.securityConf)
      }
      if (data.authAccountsMap === undefined) {
        // 新增
        this.$set(this.formData, 'authAccountsMap', {})
      } else {
        this.$set(this.formData, 'authAccountsMap', data.authAccountsMap)
      }
      this.$set(this.formData, 'disable', data.disable)

      if (data.serviceParamsMap) {
        this.$set(
          this.formData.serviceParamsMap,
          'binding',
          data.serviceParamsMap.binding
        )
        if (data.serviceParamsMap.httpMethod) {
          this.httpMethod = []
        }
        this.$set(
          this.formData.connectorSrvParamsMap,
          'httpMethod',
          data.serviceParamsMap.httpMethod
        )
        this.httpMethod = this.formData.connectorSrvParamsMap.httpMethod
          ? this.formData.connectorSrvParamsMap.httpMethod.split(',')
          : this.httpMethod
      }
    },
    publishProxyService() {
      // this.editOldVersionDailog = true
      publishProxyService(this.currentRow.id)
        .then((rt) => {
          if (rt.status === '200') {
            let ind = true
            let inds = ''
            rt.data.forEach((item) => {
              if (!item.success) {
                ind = false
                inds += item.message
              }
            })
            if (ind) {
              this.$message({
                message: '发布成功',
                type: 'success'
              })
              this.$emit('confirm')
            } else {
              this.$message({
                message: inds,
                type: 'error'
              })
            }
          }
        })
        .catch(() => {})
    },
    versionBackup() {
      console.log(this.currentRow, 'this.verson')
      const filters = [
        {
          key: 'proxy_service_id',
          opt: 'LIKE',
          type: 'S',
          value: 1
        }
      ]
      versionQuery({
        filters: filters,
        orderby: 'updateon',
        pageNum: 1,
        pageSize: 1000,
        sort: 'desc'
      }).then((res) => {
        this.tableData = res.data.list
      })
      versionBackup({
        id: this.currentRow.id,
        versionNo: 'v1'
      }).then((res) => {})
    },

    publishProxyServices(data) {
      this.editOldVersionDailog = false
      if (!data) {
        return
      }
      if (this.tabName === '部署信息') {
        this.getPublish(this.deploymentMultipleSelection.serverId)
        return
      }
      versionSave({
        proxyServiceId: this.currentRow.id,
        versionDesc: data.intro,
        versionNo: data.versionNoOld
      }).then((res) => {
        publishProxyService(this.currentRow.id)
          .then((rt) => {
            if (rt.status === '200') {
              let ind = true
              let inds = ''
              rt.data.forEach((item) => {
                if (!item.success) {
                  ind = false
                  inds += item.message
                }
              })
              if (ind) {
                this.$message({
                  message: '发布成功',
                  type: 'success'
                })
                this.$emit('confirm')
              } else {
                this.$message({
                  message: inds,
                  type: 'error'
                })
              }
            }
          })
          .catch(() => {})
      })
    },
    async submit() {
      // 'securityConf.authStrategy': [
      //     { required: true, message: '验证策略不能为空', trigger: ['change', 'blur'] }
      //   ],
      if (this.formData.isEnableWhiteList === 'true') {
        if (!this.formData.whiteListType && !this.formData.whiteList) {
          this.$message.warning('ip和名单类型不能为空')
          this.activeName = 'fourth'
          return
        }
      }
      if (this.formData.securityConf.enableSecurity) {
        this.rules['securityConf.authStrategy'] = [
          {
            required: true,
            message: '验证策略不能为空',
            trigger: ['change', 'blur']
          }
        ]
      } else {
        this.rules['securityConf.authStrategy'] = [
          {
            required: false,
            message: '验证策略不能为空',
            trigger: ['change', 'blur']
          }
        ]
      }
      this.$refs['formData'].validate((valid, obj) => {
        // console.log('valid', valid)
        // console.log(222, this.formData)
        if (valid) {
          if (this.formData.messageType === 'db') {
            this.$message.warning('消息定义中消息类型不能为db')
            this.activeName = 'fourth'
            return
          }
          if (this.formData.protocol === 'DB') {
            if (!this.formData.connectorSrvParamsMap.sql) {
              this.$message.warning('基础配置中请输入sql语句')
              this.activeName = 'fourth'
              return
            }
            if (
              !this.formData.connectorSrvParamsMap.delay &&
              !this.formData.connectorSrvParamsMap.cron
            ) {
              this.$message.warning('轮询配置中请输入轮询间隔或者使用cron')
              this.activeName = 'fourth'
              return
            }
            // if (!this.analysisData) {
            //   this.$message.warning('基础配置中请测试sql，sql有效方可提交')
            //   return
            // }
          }

          let forms = {}
          forms.serviceParamsMap = {}
          forms.connector = this.formData.connector
          forms.targetService = this.formData.targetService
          forms.connectorSrvParamsMap = {}
          forms.commonConf = this.formData.commonConf
          forms.disable = this.formData.disable
          forms.securityConf = this.formData.securityConf
          forms.authAccountsMap = this.formData.authAccountsMap

          if (this.formData.protocol === 'Jms') {
            forms = {
              id: this.formData.id,
              name: this.formData.name,
              description: this.formData.description,
              messageType: this.formData.messageType,
              payloadType: this.formData.payloadType,
              defineFileType: this.formData.defineFileType,
              defineFile: this.formData.defineFile,
              secondDefineFile: this.formData.secondDefineFile,
              protocol: this.formData.protocol,
              uri: this.formData.uri,
              compress: this.formData.compress,
              type: this.formData.type,
              encoding: this.formData.encoding,
              connectorType: this.formData.connectorType,
              connectorId: this.formData.connectorId,
              defineFileId: this.formData.defineFileId,
              secondDefineFileId: this.formData.secondDefineFileId,
              domainId: this.formData.domainId,
              domainName: this.formData.domainName,
              targetId: this.formData.targetId,
              targetType: this.formData.targetType,
              serviceParamsMap: {
                binding: this.formData.serviceParamsMap.binding
              },
              connector: {
                name: this.formData.connector.name
              },
              targetService: {
                name: this.formData.targetService.name
                // 'defineFile': this.formData.targetService.defineFile,
                // 'defineFileId' :this.formData.targetService.defineFileId
              },
              connectorSrvParamsMap: {
                destinationType:
                  this.formData.connectorSrvParamsMap.destinationType,
                destinationName:
                  this.formData.connectorSrvParamsMap.destinationName,
                transacted: this.formData.connectorSrvParamsMap.transacted,
                transactedInOut:
                  this.formData.connectorSrvParamsMap.transactedInOut,
                transactionTimeout:
                  this.formData.connectorSrvParamsMap.transactionTimeout,
                concurrentConsumers:
                  this.formData.connectorSrvParamsMap.concurrentConsumers,
                maxConcurrentConsumers:
                  this.formData.connectorSrvParamsMap.maxConcurrentConsumers,
                selector: this.formData.connectorSrvParamsMap.selector,
                asyncConsumer: this.formData.connectorSrvParamsMap.asyncConsumer
                // 'httpMethod': this.formData.connectorSrvParamsMap.httpMethod
              },
              commonConf: {
                enableMonitor: this.formData.commonConf.enableMonitor,
                logRequestBody: this.formData.commonConf.logRequestBody,
                logResponseBody: this.formData.commonConf.logResponseBody
              },
              disable: this.formData.disable
            }
          }
          // http
          let httpForm = {}
          httpForm.serviceParamsMap = {}
          httpForm.connector = this.formData.connector
          httpForm.targetService = this.formData.targetService
          httpForm.connectorSrvParamsMap = {}
          httpForm.commonConf = this.formData.commonConf
          httpForm.disable = this.formData.disable
          httpForm.securityConf = this.formData.securityConf
          httpForm.authAccountsMap = this.formData.authAccountsMap

          if (this.formData.protocol === 'http') {
            if (this.httpLL.isEnableWhiteList === 'true') {
              var reg =
                /^(?:(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:1[0-9][0-9]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:2[0-4][0-9])|(?:25[0-5])|(?:1[0-9][0-9])|(?:[1-9][0-9])|(?:[0-9]))$/
              let regI = 0
              if (!this.httpLL.whiteList) {
                this.httpLL.whiteList = ''
              }
              this.httpLL.whiteList.split(',').forEach((item) => {
                if (
                  item.split('.').length !== 4 &&
                  !reg.test(item.split('/')[0])
                ) {
                  regI = 1
                }
              })
              // if (regI === 1) {
              //   this.$message.warning('你的IP不符合规格')
              //   return
              // }
            }
            if (this.httpLL.isEnableWhiteList === 'false') {
              this.httpLL.whiteList = ''
            }
            if (this.formData.id) {
              this.httpLL.serviceId = this.formData.id
            }
            this.httpLL.isEnableRequestSizeLimiting =
              this.httpLL.isEnableRequestSizeLimiting.toString()
            this.httpLL.isEnableRateLimiting =
              this.httpLL.isEnableRateLimiting.toString()

            httpForm = {
              id: this.formData.id,
              name: this.formData.name,
              description: this.formData.description,
              messageType: this.formData.messageType,
              payloadType: this.formData.payloadType,
              defineFileType: this.formData.defineFileType,
              defineFile: this.formData.defineFile,
              secondDefineFile: this.formData.secondDefineFile,
              protocol: this.formData.protocol,
              uri: this.formData.uri,
              compress: this.formData.compress,
              type: this.formData.type,
              encoding: this.formData.encoding,
              connectorType: this.formData.connectorType,
              connectorId: this.formData.connectorId,
              defineFileId: this.formData.defineFileId,
              secondDefineFileId: this.formData.secondDefineFileId,
              domainId: this.formData.domainId,
              domainName: this.formData.domainName,
              targetId: this.formData.targetId,
              targetType: this.formData.targetType,
              // 'whiteList': this.formData.whiteList,
              // 'whiteListType': this.formData.whiteListType,
              // 'isEnableWhiteList': this.formData.isEnableWhiteList,
              // 'isEnableRateLimiting': this.formData.isEnableRateLimiting,
              // 'isEnableRequestSizeLimiting': this.formData.isEnableRequestSizeLimiting,
              // 'sizeUnit': this.formData.sizeUnit,
              // 'rateLimitingType': this.formData.rateLimitingType,
              // 'rateLimitingNumber': this.formData.rateLimitingNumber,
              // 'allowedPayloadSize': this.formData.allowedPayloadSize,
              // 'compress': this.formData.compress,
              gateAwayDtoInfo: JSON.stringify(this.httpLL),
              connectorSrvParamsMap: {
                httpMethod: this.formData.connectorSrvParamsMap.httpMethod
              },
              serviceParamsMap: {
                binding: this.formData.serviceParamsMap.binding,
                httpMethod: this.formData.serviceParamsMap.httpMethod
              },
              commonConf: {
                enableMonitor: this.formData.commonConf.enableMonitor,
                logRequestBody: this.formData.commonConf.logRequestBody,
                logResponseBody: this.formData.commonConf.logResponseBody
              },
              disable: this.formData.disable,
              securityConf: {
                id: this.formData.securityConfId,
                enableSecurity: this.formData.securityConf.enableSecurity,
                authStrategy: this.formData.securityConf.authStrategy
              },
              authAccountsMap: this.formData.authAccountsMap
            }
          }

          // Ftp
          let ftpForm = {}
          ftpForm.serviceParamsMap = this.formData.serviceParamsMap
          ftpForm.connector = this.formData.connector
          ftpForm.targetService = this.formData.targetService
          ftpForm.connectorSrvParamsMap = {}
          ftpForm.commonConf = this.formData.commonConf
          ftpForm.disable = this.formData.disable
          if (this.formData.protocol === 'Ftp') {
            ftpForm = {
              id: this.formData.id,
              name: this.formData.name,
              description: this.formData.description,
              messageType: this.formData.messageType,
              payloadType: this.formData.payloadType,
              defineFileType: this.formData.defineFileType,
              defineFile: this.formData.defineFile,
              secondDefineFile: this.formData.secondDefineFile,
              protocol: this.formData.protocol,
              uri: this.formData.uri,
              compress: this.formData.compress,
              type: this.formData.type,
              encoding: this.formData.encoding,
              connectorType: this.formData.connectorType,
              connectorId: this.formData.connectorId,
              defineFileId: this.formData.defineFileId,
              secondDefineFileId: this.formData.secondDefineFileId,
              domainId: this.formData.domainId,
              domainName: this.formData.domainName,
              targetId: this.formData.targetId,
              targetType: this.formData.targetType,
              // 'compress': this.formData.compress,
              resourceType: this.formData.resourceType,
              publishStatus: this.formData.publishStatus,
              connectorSrvParamsMap: {
                antExclude: this.formData.connectorSrvParamsMap.antExclude,
                antInclude: this.formData.connectorSrvParamsMap.antInclude,
                autoCreate: this.formData.connectorSrvParamsMap.autoCreate,
                charset: this.formData.connectorSrvParamsMap.charset,
                cron: this.formData.connectorSrvParamsMap.cron,
                delay: this.formData.connectorSrvParamsMap.delay,
                greedy: this.formData.connectorSrvParamsMap.greedy,
                // 'httpMethod': this.formData.connectorSrvParamsMap.httpMethod,
                initialDelay: this.formData.connectorSrvParamsMap.initialDelay,
                move: this.formData.connectorSrvParamsMap.move,
                recursive: this.formData.connectorSrvParamsMap.recursive,
                delete: this.formData.connectorSrvParamsMap.delete,
                moveFailed: this.formData.connectorSrvParamsMap.moveFailed,
                path: this.formData.connectorSrvParamsMap.path,
                pollType: this.formData.connectorSrvParamsMap.pollType,
                preMove: this.formData.connectorSrvParamsMap.preMove,
                readLock: this.formData.connectorSrvParamsMap.readLock
              },
              serviceParamsMap: {
                binding: this.formData.serviceParamsMap.binding,
                httpMethod: this.formData.serviceParamsMap.httpMethod
              },
              commonConf: {
                enableMonitor: this.formData.commonConf.enableMonitor,
                logRequestBody: this.formData.commonConf.logRequestBody,
                logResponseBody: this.formData.commonConf.logResponseBody
              },
              disable: this.formData.disable
            }
          }
          // File
          let fileForm = {}
          fileForm.serviceParamsMap = this.formData.serviceParamsMap
          fileForm.connector = this.formData.connector
          fileForm.connectorSrvParamsMap = this.formData.connectorSrvParamsMap
          fileForm.commonConf = this.formData.commonConf
          fileForm.disable = this.formData.disable
          if (this.formData.protocol === 'File') {
            fileForm = {
              id: this.formData.id,
              name: this.formData.name,
              description: this.formData.description,
              messageType: this.formData.messageType,
              payloadType: this.formData.payloadType,
              defineFileType: this.formData.defineFileType,
              defineFile: this.formData.defineFile,
              secondDefineFile: this.formData.secondDefineFile,
              protocol: this.formData.protocol,
              uri: this.formData.uri,
              compress: this.formData.compress,
              type: this.formData.type,
              encoding: this.formData.encoding,
              connectorType: this.formData.connectorType,
              connectorId: this.formData.connectorId,
              defineFileId: this.formData.defineFileId,
              secondDefineFileId: this.formData.secondDefineFileId,
              domainId: this.formData.domainId,
              domainName: this.formData.domainName,
              targetId: this.formData.targetId,
              targetType: this.formData.targetType,
              resourceType: this.formData.resourceType,
              publishStatus: this.formData.publishStatus,
              serviceParamsMap: {
                binding: this.formData.serviceParamsMap.binding,
                httpMethod: this.formData.serviceParamsMap.httpMethod
              },
              commonConf: {
                enableMonitor: this.formData.commonConf.enableMonitor,
                logRequestBody: this.formData.commonConf.logRequestBody,
                logResponseBody: this.formData.commonConf.logResponseBody
              },
              disable: this.formData.disable
            }
          }
          forms.projectId = this.projectID
          httpForm.projectId = this.projectID
          ftpForm.projectId = this.projectID
          fileForm.projectId = this.projectID
          this.formData.projectId = this.projectID
          if (this.formData.protocol === 'File') {
            fileForm.messageType = fileForm.messageType.toLowerCase()
            saveProxyService(fileForm)
              .then((rt) => {
                if (rt.status === '200') {
                  this.$message({
                    message: '提交成功',
                    type: 'success'
                  })
                  this.$emit('confirm')
                }
              })
              .catch((err) => {
                const data = err.data || []
                const hint = [
                  { fieName: '名称', field: 'name' },
                  { fieName: '说明', field: 'description' },
                  { fieName: '目标', field: 'targetService.name' },
                  { fieName: '消息类型', field: 'messageType' },
                  {
                    fieName: 'Http Method',
                    field: 'connectorSrvParamsMap.httpMethod'
                  },
                  { fieName: '报文格式', field: 'payloadType' },
                  { fieName: '定义文件类型', field: 'defineFileType' },
                  { fieName: '请求报文', field: 'defineFile' },
                  { fieName: '响应报文', field: 'secondDefineFile' },
                  { fieName: '端点', field: 'serviceParamsMap.binding' },
                  { fieName: '协议', field: 'protocol' },
                  { fieName: '适配器', field: 'connector.name' },
                  { fieName: '端点uri', field: 'uri' },
                  { fieName: 'sql', field: 'connectorSrvParamsMap.sql' },
                  { fieName: '轮询间隔', field: 'connectorSrvParamsMap.delay' },
                  { fieName: '使用cron', field: 'connectorSrvParamsMap.cron' },
                  {
                    fieName: '轮询类型',
                    field: 'connectorSrvParamsMap.pollType'
                  },
                  {
                    fieName: '延迟启动',
                    field: 'connectorSrvParamsMap.initialDelay'
                  },
                  {
                    fieName: '每次轮询数量',
                    field: 'connectorSrvParamsMap.maxMessagesPerPoll'
                  },
                  {
                    fieName: '成功后处理',
                    field: 'connectorSrvParamsMap.onConsume'
                  },
                  {
                    fieName: '失败后处理',
                    field: 'connectorSrvParamsMap.onConsumeFailed'
                  },
                  {
                    fieName: '贪婪模式',
                    field: 'connectorSrvParamsMap.greedy'
                  },
                  {
                    fieName: '出错时中断',
                    field: 'connectorSrvParamsMap.breakBatchOnConsumeFail'
                  },
                  {
                    fieName: '启用事务',
                    field: 'connectorSrvParamsMap.transacted'
                  }
                ]
                checkFormData(data, hint)
              })
          } else if (this.formData.protocol === 'http') {
            httpForm.messageType = httpForm.messageType.toLowerCase()
            saveProxyService(httpForm)
              .then((rt) => {
                if (rt.status === '200') {
                  // this.httpLL.serviceId = rt.data.id
                  // if (!this.httpLL.id) {
                  //   this.httpLL.id = ''
                  // }
                  // kongInfoSave(this.httpLL).then(res => {
                  //   console.log(res)
                  // })
                  this.$message({
                    message: '提交成功',
                    type: 'success'
                  })
                  this.$emit('confirm')
                } else {
                  this.$message({
                    message: '存在重复的uri',
                    type: 'error'
                  })
                }
              })
              .catch((err) => {
                const data = err.data || []
                this.httpLL.isEnableRequestSizeLimiting = JSON.parse(
                  this.httpLL.isEnableRequestSizeLimiting
                )
                this.httpLL.isEnableRateLimiting = JSON.parse(
                  this.httpLL.isEnableRateLimiting
                )
                const hint = [
                  { fieName: '名称', field: 'name' },
                  { fieName: '说明', field: 'description' },
                  { fieName: '目标', field: 'targetService.name' },
                  { fieName: '消息类型', field: 'messageType' },
                  {
                    fieName: 'Http Method',
                    field: 'connectorSrvParamsMap.httpMethod'
                  },
                  { fieName: '报文格式', field: 'payloadType' },
                  { fieName: '定义文件类型', field: 'defineFileType' },
                  { fieName: '请求报文', field: 'defineFile' },
                  { fieName: '响应报文', field: 'secondDefineFile' },
                  { fieName: '端点', field: 'serviceParamsMap.binding' },
                  { fieName: '协议', field: 'protocol' },
                  { fieName: '适配器', field: 'connector.name' },
                  { fieName: '端点uri', field: 'uri' },
                  { fieName: 'sql', field: 'connectorSrvParamsMap.sql' },
                  { fieName: '轮询间隔', field: 'connectorSrvParamsMap.delay' },
                  { fieName: '使用cron', field: 'connectorSrvParamsMap.cron' },
                  {
                    fieName: '轮询类型',
                    field: 'connectorSrvParamsMap.pollType'
                  },
                  {
                    fieName: '延迟启动',
                    field: 'connectorSrvParamsMap.initialDelay'
                  },
                  {
                    fieName: '每次轮询数量',
                    field: 'connectorSrvParamsMap.maxMessagesPerPoll'
                  },
                  {
                    fieName: '成功后处理',
                    field: 'connectorSrvParamsMap.onConsume'
                  },
                  {
                    fieName: '失败后处理',
                    field: 'connectorSrvParamsMap.onConsumeFailed'
                  },
                  {
                    fieName: '贪婪模式',
                    field: 'connectorSrvParamsMap.greedy'
                  },
                  {
                    fieName: '出错时中断',
                    field: 'connectorSrvParamsMap.breakBatchOnConsumeFail'
                  },
                  {
                    fieName: '启用事务',
                    field: 'connectorSrvParamsMap.transacted'
                  },
                  { fieName: '验证策略', field: 'securityConf.authStrategy' }
                ]
                checkFormData(data, hint)
              })
          } else if (this.formData.protocol === 'Ftp') {
            ftpForm.messageType = ftpForm.messageType.toLowerCase()
            saveProxyService(ftpForm)
              .then((rt) => {
                if (rt.status === '200') {
                  this.$message({
                    message: '提交成功',
                    type: 'success'
                  })
                  this.$emit('confirm')
                }
              })
              .catch((err) => {
                const data = err.data || []
                const hint = [
                  { fieName: '名称', field: 'name' },
                  { fieName: '说明', field: 'description' },
                  { fieName: '目标', field: 'targetService.name' },
                  { fieName: '消息类型', field: 'messageType' },
                  {
                    fieName: 'Http Method',
                    field: 'connectorSrvParamsMap.httpMethod'
                  },
                  { fieName: '报文格式', field: 'payloadType' },
                  { fieName: '定义文件类型', field: 'defineFileType' },
                  { fieName: '请求报文', field: 'defineFile' },
                  { fieName: '响应报文', field: 'secondDefineFile' },
                  { fieName: '端点', field: 'serviceParamsMap.binding' },
                  { fieName: '协议', field: 'protocol' },
                  { fieName: '适配器', field: 'connector.name' },
                  { fieName: '端点uri', field: 'uri' },
                  { fieName: 'sql', field: 'connectorSrvParamsMap.sql' },
                  { fieName: '轮询间隔', field: 'connectorSrvParamsMap.delay' },
                  { fieName: '使用cron', field: 'connectorSrvParamsMap.cron' },
                  {
                    fieName: '轮询类型',
                    field: 'connectorSrvParamsMap.pollType'
                  },
                  {
                    fieName: '延迟启动',
                    field: 'connectorSrvParamsMap.initialDelay'
                  },
                  {
                    fieName: '每次轮询数量',
                    field: 'connectorSrvParamsMap.maxMessagesPerPoll'
                  },
                  {
                    fieName: '成功后处理',
                    field: 'connectorSrvParamsMap.onConsume'
                  },
                  {
                    fieName: '失败后处理',
                    field: 'connectorSrvParamsMap.onConsumeFailed'
                  },
                  {
                    fieName: '贪婪模式',
                    field: 'connectorSrvParamsMap.greedy'
                  },
                  {
                    fieName: '出错时中断',
                    field: 'connectorSrvParamsMap.breakBatchOnConsumeFail'
                  },
                  {
                    fieName: '启用事务',
                    field: 'connectorSrvParamsMap.transacted'
                  }
                ]
                checkFormData(data, hint)
              })
          } else if (this.formData.protocol === 'Jms') {
            forms.messageType = forms.messageType.toLowerCase()
            saveProxyService(forms)
              .then((rt) => {
                if (rt.status === '200') {
                  this.$message({
                    message: '提交成功',
                    type: 'success'
                  })
                  this.$emit('confirm')
                }
              })
              .catch((err) => {
                const data = err.data || []
                const hint = [
                  { fieName: '名称', field: 'name' },
                  { fieName: '说明', field: 'description' },
                  { fieName: '目标', field: 'targetService.name' },
                  { fieName: '消息类型', field: 'messageType' },
                  {
                    fieName: 'Http Method',
                    field: 'connectorSrvParamsMap.httpMethod'
                  },
                  { fieName: '报文格式', field: 'payloadType' },
                  { fieName: '定义文件类型', field: 'defineFileType' },
                  { fieName: '请求报文', field: 'defineFile' },
                  { fieName: '响应报文', field: 'secondDefineFile' },
                  { fieName: '端点', field: 'serviceParamsMap.binding' },
                  { fieName: '协议', field: 'protocol' },
                  { fieName: '适配器', field: 'connector.name' },
                  { fieName: '端点uri', field: 'uri' },
                  { fieName: 'sql', field: 'connectorSrvParamsMap.sql' },
                  { fieName: '轮询间隔', field: 'connectorSrvParamsMap.delay' },
                  { fieName: '使用cron', field: 'connectorSrvParamsMap.cron' },
                  {
                    fieName: '轮询类型',
                    field: 'connectorSrvParamsMap.pollType'
                  },
                  {
                    fieName: '延迟启动',
                    field: 'connectorSrvParamsMap.initialDelay'
                  },
                  {
                    fieName: '每次轮询数量',
                    field: 'connectorSrvParamsMap.maxMessagesPerPoll'
                  },
                  {
                    fieName: '成功后处理',
                    field: 'connectorSrvParamsMap.onConsume'
                  },
                  {
                    fieName: '失败后处理',
                    field: 'connectorSrvParamsMap.onConsumeFailed'
                  },
                  {
                    fieName: '贪婪模式',
                    field: 'connectorSrvParamsMap.greedy'
                  },
                  {
                    fieName: '出错时中断',
                    field: 'connectorSrvParamsMap.breakBatchOnConsumeFail'
                  },
                  {
                    fieName: '启用事务',
                    field: 'connectorSrvParamsMap.transacted'
                  }
                ]
                checkFormData(data, hint)
              })
          } else {
            this.formData.messageType = this.formData.messageType.toLowerCase()
            saveProxyService(this.formData)
              .then((rt) => {
                if (rt.status === '200') {
                  this.$message({
                    message: '提交成功',
                    type: 'success'
                  })
                  this.$emit('confirm')
                }
              })
              .catch((err) => {
                const data = err.data || []
                const hint = [
                  { fieName: '名称', field: 'name' },
                  { fieName: '说明', field: 'description' },
                  { fieName: '目标', field: 'targetService.name' },
                  // { fieName: '消息类型', field: 'messageType' },
                  {
                    fieName: 'Http Method',
                    field: 'connectorSrvParamsMap.httpMethod'
                  },
                  { fieName: '报文格式', field: 'payloadType' },
                  { fieName: '定义文件类型', field: 'defineFileType' },
                  { fieName: '请求报文', field: 'defineFile' },
                  { fieName: '响应报文', field: 'secondDefineFile' },
                  { fieName: '端点', field: 'serviceParamsMap.binding' },
                  { fieName: '协议', field: 'protocol' },
                  { fieName: '适配器', field: 'connector.name' },
                  { fieName: '端点uri', field: 'uri' },
                  { fieName: 'sql', field: 'connectorSrvParamsMap.sql' },
                  { fieName: '轮询间隔', field: 'connectorSrvParamsMap.delay' },
                  { fieName: '使用cron', field: 'connectorSrvParamsMap.cron' },
                  {
                    fieName: '轮询类型',
                    field: 'connectorSrvParamsMap.pollType'
                  },
                  {
                    fieName: '延迟启动',
                    field: 'connectorSrvParamsMap.initialDelay'
                  },
                  {
                    fieName: '每次轮询数量',
                    field: 'connectorSrvParamsMap.maxMessagesPerPoll'
                  },
                  {
                    fieName: '成功后处理',
                    field: 'connectorSrvParamsMap.onConsume'
                  },
                  {
                    fieName: '失败后处理',
                    field: 'connectorSrvParamsMap.onConsumeFailed'
                  },
                  {
                    fieName: '贪婪模式',
                    field: 'connectorSrvParamsMap.greedy'
                  },
                  {
                    fieName: '出错时中断',
                    field: 'connectorSrvParamsMap.breakBatchOnConsumeFail'
                  },
                  {
                    fieName: '启用事务',
                    field: 'connectorSrvParamsMap.transacted'
                  }
                ]
                checkFormData(data, hint)
              })
          }
        } else {
          // console.log('validFaild', obj)
          // console.log('validFaild111', Object.values(obj)[0][0].message)
          this.$message.warning(
            Object.values(obj)[0][0].message || '请将信息填写完整。'
          )
          if (
            Object.values(obj)[0][0].message.indexOf('目标') !== -1 ||
            Object.values(obj)[0][0].message.indexOf('名称') !== -1 ||
            Object.values(obj)[0][0].message.indexOf('分组') !== -1
          ) {
            this.activeName = 'first'
          }
          if (
            Object.values(obj)[0][0].message.indexOf('端点uri') !== -1 ||
            Object.values(obj)[0][0].message.indexOf('请求方法') !== -1 ||
            Object.values(obj)[0][0].message.indexOf('分组') !== -1
          ) {
            this.activeName = 'fourth'
          }
        }
      })
    },
    // sql测试
    testSqlFun(type) {
      this.activeType = type
      if (!this.formData.connectorId) {
        this.$message.warning('请先选择适配器！')
        return
      }
      let sqlstr = ''
      if (type === 1) {
        if (!this.formData.connectorSrvParamsMap.sql) {
          this.$message.warning('请输入sql语句！')
          return
        }
        sqlstr = this.formData.connectorSrvParamsMap.sql
      }
      if (type === 2) {
        if (!this.formData.connectorSrvParamsMap.onConsume) {
          this.$message.warning('成功后处理不能为空！')
          return
        }
        sqlstr = this.formData.connectorSrvParamsMap.onConsume
      }
      if (type === 3) {
        if (!this.formData.connectorSrvParamsMap.onConsumeFailed) {
          this.$message.warning('失败后处理不能为空！')
          return
        }
        sqlstr = this.formData.connectorSrvParamsMap.onConsumeFailed
      }
      this.sqlFormData = {
        id: this.formData.connectorId,
        script: sqlstr
      }
      // console.log(this.sqlFormData, '适配器Sql')
      saveSql({
        id: this.formData.connectorId,
        script: sqlstr
      })
        .then((rt) => {
          if (rt.status === '200') {
            this.sqlData = Object.keys(rt.data)
            if (type === 1) {
              this.analysisData = rt.data
            }
            if (this.sqlData.length > 0) {
              this.testSqlVisible = true
            } else {
              scriptValidate({
                id: this.formData.connectorId,
                script: sqlstr,
                params: {}
              })
                .then((res) => {
                  if (type === 1) {
                    this.ispass = res.status === '200' ? 'true' : 'false'
                  }
                  if (type === 2) {
                    this.ispass1 = res.status === '200' ? 'true' : 'false'
                  }
                  if (type === 3) {
                    this.ispass2 = res.status === '200' ? 'true' : 'false'
                  }
                })
                .catch(() => {})
            }
          }
        })
        .catch(() => {})
    },
    handleResource(data) {
      this.filename = data.name
    },
    getStatus(data) {
      if (this.activeType === 1) {
        this.ispass = data
      }
      if (this.activeType === 2) {
        this.ispass1 = data
      }
      if (this.activeType === 3) {
        this.ispass2 = data
      }
    },
    // tree事件
    handleNodeClick(data) {},

    // 显示
    isshowdepend() {
      this.dependVisible = true
    },

    // 用户列表
    closeUserList(val) {
      this.userListVisible = val
    },
    getCheckeduserList(val, val2) {
      // console.log(val)
      var that = this
      that.userListVisible = false
      this.userList = {
        authUsers: val,
        authRoles: val2
      }
      that.formData.authAccountsMap = {
        authUsers: [],
        authRoles: []
      }
      val.map(function (item) {
        that.formData.authAccountsMap.authUsers.push(item.id)
      })
      val2.map(function (item) {
        that.formData.authAccountsMap.authRoles.push(item.id)
      })
      // console.log(that.formData.authAccountsMap)
    }
  }
}
</script>

<style type="text/scss" lang="scss" scoped>
.radios {
  position: relative;
  width: 100%;

  /deep/ .el-radio__input {
    position: relative;
    top: 22px;
    left: 18px;
  }
}

.el-icon-check {
  color: #67c23a;
  font-size: 20px;
  font-weight: 600;
  margin: 0 10px;
}

.el-icon-close {
  color: #f56c6c;
  font-size: 20px;
  font-weight: 600;
  margin: 0 10px;
}

.changgename {
  cursor: pointer;
}
</style>
