<template>
  <div>
    <edit-sql-builder-dialog v-model='editSqlBuilderVisible' :rowData="currentRow" @closeEditDialog="closeEditDialog" @confirmEdit="handleSubmit()"></edit-sql-builder-dialog>
    <el-dialog :title="title" @close="closeEditDialog" :close-on-click-modal="false" :visible.sync="dialogFormVisibleR" :destroy-on-close="true" width="72%">
      <resource-info v-model="dialogFormVisibleR" :currentRow="currentRow" @confirm="handleSubmit()" />
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      title="消息流定义"
      :visible.sync="dialogFormVisibleF"
      @close="closeEditDialog"
      :destroy-on-close="true"
      width="72%">
      <flow-info
        v-model="dialogFormVisibleF"
        :currentRow="currentRow"
        ref="flowInfoBridge"
        @confirm="handleSubmit()" />
    </el-dialog>
    <flow-stage-dialog v-model="dialogVisibleFL" :flowId="currentRow.id" @confirm="handleStage" />
    <el-dialog @close="closeEditDialog" :close-on-click-modal="false" title="业务服务定义" :visible.sync="dialogFormVisibleB" :destroy-on-close="true" width="72%">
      <business-info v-model="dialogFormVisibleB" :currentRow="currentRow" ref="businessInfoBridge" @confirm="handleSubmit()" />
    </el-dialog>
    <el-dialog v-if="type === 'agency'" @close="closeEditDialog" :close-on-click-modal="false" title="代理服务定义" :visible.sync="dialogFormVisibleA" :destroy-on-close="true" width="72%">
      <agency-info v-model="dialogFormVisibleA" :currentRow="currentRow" @confirm="handleSubmit()" />
    </el-dialog>
    <el-dialog @close="closeEditDialog" :close-on-click-modal="false" title="适配器定义" :visible.sync="dialogFormVisibleC" :destroy-on-close="true" width="72%">
        <connector-info v-model="dialogFormVisibleC" :currentRow="currentRow" @confirm="handleSubmit()" />
    </el-dialog>
  </div>
</template>

<script>
// import EsbServiceListMixins from '@/mixins/esb_service_list_mixins'
import AgencyInfo from '@/views/esb_service/agency_service/AgencyInfo'
import BusinessInfo from '@/views/esb_service/business_service/BusinessInfo'
import ConnectorInfo from '@/views/esb_service/connector/ConnectorInfo'
import FlowInfo from '@/views/esb_service/message_flow/FlowInfo'
import ResourceInfo from '@/views/esb_service/resource_file/ResourceInfo'
import FlowStageDialog from '@/views/esb_service/message_flow/flow_stage/FlowStageDialog'
import EditSqlBuilderDialog from '@/views/esb_service/sql_builder/editSqlBuilderDialog'
export default {
//   mixins: [EsbServiceListMixins],
  components: {
    AgencyInfo,
    BusinessInfo,
    ConnectorInfo,
    FlowInfo,
    ResourceInfo,
    FlowStageDialog,
    EditSqlBuilderDialog
  },
  data() {
    return {
      editSqlBuilderVisible: false,
      dialogVisibleFL: false,
      dialogFormVisibleR: false,
      dialogFormVisibleF: false,
      dialogFormVisibleB: false,
      dialogFormVisibleA: false,
      dialogFormVisibleC: false,
      types: ''
    }
  },
  props: {
    type: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: ''
    },
    currentRow: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  watch: {
    type(val) {
      const vm = this
      vm.typeChange(true)
    },
    currentRow(val) {
      console.log(val)
    }
  },
  methods: {
    handleStage() {
      const vm = this
      vm.typeChange(false)
      this.$nextTick(() => {
        vm.$emit('confirm', 'no')
      })
    },
    closeEditDialog(val) {
      console.log(1)
      const vm = this
      vm.typeChange(false)
      this.$nextTick(() => {
        vm.$emit('confirm', 'no')
      })
    },
    typeChange(val) {
      console.log(val)
      const vals = val || false
      const vm = this
      console.log(vm.type)
      switch (vm.type) {
        case 'sql':
          vm.editSqlBuilderVisible = vals
          break
        case 'connector':
          vm.dialogFormVisibleC = vals
          break
        case 'business':
          vm.dialogFormVisibleB = vals
          break
        case 'agency':
          vm.dialogFormVisibleA = vals
          console.log(1, vm.dialogFormVisibleA, vals)
          break
        case 'flow':
          console.log(2)
          vm.dialogFormVisibleF = vals
          break
        case 'flows':
          vm.dialogVisibleFL = vals
          break
        case 'resource':
          vm.dialogFormVisibleR = vals
          break
        default:
          break
      }
    },
    handleSubmit() {
      const vm = this
      vm.typeChange(false)
      this.$nextTick(() => {
        vm.$emit('confirm', 'ok')
      })
    }
  }
}
</script>
