<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实现类" prop="providerClassName">
        <el-select
          v-model="queryParams.providerClassName"
          placeholder="请选择实现类"
          clearable
          size="small"
          style="width: 100%"
        >
          <el-option label="全部" value="" />
          <el-option label="DeepSeekChat" value="DeepSeekChat" />
          <el-option label="Coze" value="Coze" />
          <el-option label="MaxKB" value="MaxKB" />
          <el-option label="Dify" value="Dify" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['company:aiSipCall:llmAgentAccount:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['company:aiSipCall:llmAgentAccount:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['company:aiSipCall:llmAgentAccount:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          :loading="exportLoading"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['company:aiSipCall:llmAgentAccount:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="aiSipCallList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="实现类" align="center" prop="providerClassName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['company:aiSipCall:llmAgentAccount:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['company:aiSipCall:llmAgentAccount:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改aiSIP外呼大模型对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="实现类" prop="providerClassName">
          <el-select v-model="form.providerClassName" placeholder="请选择实现类" size="small" style="width: 100%">
            <el-option label="DeepSeekChat" value="DeepSeekChat" />
            <el-option label="Coze" value="Coze" />
            <el-option label="MaxKB" value="MaxKB" />
            <el-option label="Dify" value="Dify" />
          </el-select>
        </el-form-item>
        <el-form-item label="模型并发数" prop="concurrentNum">
          <el-input v-model="form.concurrentNum" placeholder="请输入模型并发数" />
        </el-form-item>
        <el-form-item label="打断开关" prop="interruptFlag">
          <el-select v-model="form.interruptFlag" placeholder="请选择打断方式" size="small" style="width: 100%">
            <el-option label="不打断" value="0" />
            <el-option label="关键词打断" value="1" />
            <el-option label="有声音就打断" value="2" />
          </el-select>
        </el-form-item>




<!--        <el-form-item label="大模型类型，枚举值：LlmAccount, CozeAccount" prop="accountEntity">-->
<!--          <el-input v-model="form.accountEntity" placeholder="请输入大模型类型，枚举值：LlmAccount, CozeAccount" />-->
<!--        </el-form-item>-->

<!--        <el-form-item label="打断关键词列表" prop="interruptKeywords">-->
<!--          <el-input v-model="form.interruptKeywords" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="打断忽略关键字列表" prop="interruptIgnoreKeywords">-->
<!--          <el-input v-model="form.interruptIgnoreKeywords" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="客户意向提示词" prop="intentionTips">-->
<!--          <el-input v-model="form.intentionTips" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="一个用于启动向人工座席转移的单位数字代码。" prop="transferManualDigit">-->
<!--          <el-input v-model="form.transferManualDigit" placeholder="请输入一个用于启动向人工座席转移的单位数字代码。" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="知识库分类ID" prop="kbCatId">-->
<!--          <el-input v-model="form.kbCatId" placeholder="请输入知识库分类ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="远程大模型ID" prop="remoteLlmAgentAccountId">-->
<!--          <el-input v-model="form.remoteLlmAgentAccountId" placeholder="请输入远程大模型ID" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAiSipCallLlmAgentAccount, getAiSipCallLlmAgentAccount, delAiSipCallLlmAgentAccount, addAiSipCallLlmAgentAccount, updateAiSipCallLlmAgentAccount, exportAiSipCallLlmAgentAccount } from "@/api/aiSipCall/aiSipCallLlmAgentAccount";

export default {
  name: "aiSipCallLlmAgentAccount",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // aiSIP外呼大模型表格数据
      aiSipCallList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        accountJson: null,
        providerClassName: null,
        name: null,
        accountEntity: null,
        interruptFlag: null,
        interruptKeywords: null,
        interruptIgnoreKeywords: null,
        intentionTips: null,
        concurrentNum: null,
        transferManualDigit: null,
        kbCatId: null,
        remoteLlmAgentAccountId: null
      },
      // 表单参数
      form: {
        interruptFlag: "0"
      },
      // 表单校验
      rules: {
        providerClassName: [
          { required: true, message: "实现类，枚举值：DeepSeekChat, Coze, MaxKB, Dify不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "别名不能为空", trigger: "blur" }
        ],
        accountEntity: [
          { required: true, message: "大模型类型，枚举值：LlmAccount, CozeAccount不能为空", trigger: "blur" }
        ],
        transferManualDigit: [
          { required: true, message: "一个用于启动向人工座席转移的单位数字代码。不能为空", trigger: "blur" }
        ],
        kbCatId: [
          { required: true, message: "知识库分类ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询aiSIP外呼大模型列表 */
    getList() {
      this.loading = true;
      listAiSipCallLlmAgentAccount(this.queryParams).then(response => {
        this.aiSipCallList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        accountJson: null,
        providerClassName: null,
        name: null,
        accountEntity: null,
        interruptFlag: null,
        interruptKeywords: null,
        interruptIgnoreKeywords: null,
        intentionTips: null,
        concurrentNum: null,
        transferManualDigit: null,
        kbCatId: null,
        remoteLlmAgentAccountId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加aiSIP外呼大模型";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAiSipCallLlmAgentAccount(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改aiSIP外呼大模型";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAiSipCallLlmAgentAccount(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAiSipCallLlmAgentAccount(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除aiSIP外呼大模型编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delAiSipCallLlmAgentAccount(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有aiSIP外呼大模型数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportAiSipCallLlmAgentAccount(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
