<template>
  <ed-dialog ref="BasicDialog" :fullscreen="true" :showOkBtn="false" :visible="visible"
          title="接口调用管理"
          @close="closeDialog">
    <easy-data-list ref="EasyDataList" :data-source-name="dataSourceName"
                  :action-props="{showExportBtn:false,showAddBtn:false}">
      <template v-slot:tableSlot="{row, $index}">
        <el-button size="mini" type="text" @click="$refs.EasyDataList.handlerEdit(row, $index)">编辑</el-button>
        <el-divider direction="vertical"></el-divider>
        <el-button size="mini" type="text" @click="handleCall(row)">调用</el-button>
        <el-divider direction="vertical"></el-divider>
        <el-button size="mini" type="text" @click="longLogShow">日志</el-button>
        <el-divider direction="vertical"></el-divider>
        <el-popconfirm
          :title="`确定删除该日志吗？`"
          @confirm="$refs.EasyDataList.handlerDelete(row.id)"
        >
          <el-button slot="reference" size="small" style="color: red" type="text">删除</el-button>
        </el-popconfirm>
      </template>
    </easy-data-list>
    <ed-dialog ref="BasicDialog" :fullscreen="false" :showOkBtn="false" :visible="logVisible" title="接口调用管理"
            width="80%"
            @close="closeLogDialog">
      <easy-data-list ref="jobLogList" :action-props="{showAddBtn:false,showExportBtn:false}" data-source-name="job_log"></easy-data-list>
    </ed-dialog>
  </ed-dialog>
</template>

<script>
import {jobCall} from "../../../../api/interface";
import {convertToViewModel} from "../../../../utils/utils";

export default {
  name: "InterfaceVariable",
  data() {
    return {visible: false, logVisible: false, dataSourceName: 'interface_call'}
  },
  methods: {
    show() {
      this.visible = true;
    },
    closeDialog() {
      this.visible = false;
    },
    longLogShow() {
      this.logVisible = true;
    },
    closeLogDialog() {
      this.logVisible = false;
    },
    handleCall(record) {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
      });
      jobCall(convertToViewModel(record)).then((res) => {
        if (res.success) {
          this.$message.success(res.msg)
        } else {
          this.$message.error(res.msg)
        }
      }).finally(() => {
        loading.close();
      })
    },
  }
}
</script>

<style scoped>
</style>
