<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="画像标签和知识库字段表id" prop="termCode">
          <el-input
            v-model="queryParams.termCode"
            placeholder="请输入画像标签和知识库字段表id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
      <el-form-item label="内容名称" prop="termName">
        <el-input v-model="queryParams.termName" placeholder="请输入内容名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="父编码" prop="parentTermCode">
          <el-input
            v-model="queryParams.parentTermCode"
            placeholder="请输入父编码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="层级，从1开始，1,2,3……" prop="termLevel">
          <el-input
            v-model="queryParams.termLevel"
            placeholder="请输入层级，从1开始，1,2,3……"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
      <!-- <el-form-item label="内容排序" prop="termSort">
          <el-input
            v-model="queryParams.termSort"
            placeholder="请输入内容排序"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </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="['system:bank: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="['system:bank: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="['system:bank:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:bank:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="bankList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键id" align="center" prop="id" /> -->
      <!-- <el-table-column
              label="画像标签和知识库字段表id"
              align="center"
              prop="termCode"
            /> -->
      <!-- <el-table-column label="内容名称" align="center" prop="termName" /> -->
      <el-table-column label="字段名称" align="center" prop="termContent" />
      <!-- <el-table-column label="父编码" align="center" prop="parentTermCode" /> -->
      <el-table-column label="层级" align="center" prop="termLevel" />
      <el-table-column label="内容排序" align="center" prop="termSort" />
      <el-table-column label="内容备注信息" align="center" prop="termRemark" />
      <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="['system:bank:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:bank:edit']"></el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:bank: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" />
    <!-- 添加或修改常用术语(知识库)对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" :inline="true">
        <!-- <el-form-item label="画像标签和知识库字段表id" prop="termCode">
            <el-input
              v-model="form.termCode"
              placeholder="请输入画像标签和知识库字段表id"
            />
          </el-form-item> -->
        <!-- <el-form-item label="内容名称" prop="termName">
            <el-input v-model="form.termName" placeholder="请输入内容名称" />
          </el-form-item> -->
        <el-form-item label="字段名称" prop="termContent">
          <el-input v-model="form.termContent" placeholder="请输入字段名称" />
          <!-- <editor v-model="form.termContent" :min-height="192" /> -->
        </el-form-item>
        <el-form-item label="父级编码" prop="parentTermCode">
          <el-input v-model="form.parentTermCode" placeholder="请输入父级编码" disabled />

        </el-form-item>
        <el-form-item label="内容排序" prop="termSort">
          <el-input v-model="form.termSort" placeholder="请输入内容排序" />
        </el-form-item>
        <el-form-item label="内容备注信息" prop="termRemark">
          <el-input v-model="form.termRemark" placeholder="请输入内容备注信息" />
        </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 {
  listBank,
  getBank,
  delBank,
  addBank,
  updateBank,
  selectTermBankList,
} from "@/api/system/bank";
export default {
  name: "Bank",
  data() {
    return {
      itemname: "",
      titles: "",
      treeOptions: [],

      count: "", //全部
      DepartmentoList: [], //左侧数组
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 常用术语(知识库)表格数据
      bankList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        termCode: null,
        termName: null,
        termContent: null,
        parentTermCode: null,
        termLevel: null,
        termSort: null,
        termRemark: null,
      },
      name: "",
      querydepartmen: {
        termName: "",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        termCode: [
          {
            required: true,
            message: "画像标签和知识库字段表id不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },

  created() {
    // console.log(this.$route.query, "parentTermCode");
    this.queryParams.parentTermCode = this.$route.query.parentTermCode;


    this.getList();
    //   this.mentlist();
  },
  methods: {

    // change(e) {
    //   console.log(e, "78");
    //   // console.log(this.$refs.cascader)
    //   // this.form.parentId = e;
    //   if (e) {
    //     this.form.parentId = e[e.length - 1];
    //   }
    // },

    /** 查询常用术语(知识库)列表 */
    getList() {
      this.loading = true;
      listBank(this.queryParams).then((response) => {
        if (response.rows.length > 0) {
          response.rows.forEach((e) => {
            // if(e.termLevel==1){
            //   this.DepartmentoList.push(e);

            // }
            // else
            // this.bankList=[]
            if (e.termLevel == 3) {
              this.bankList.push(e);
              console.log(this.bankList)
              this.total = this.bankList.length;

            }
          });
        } else {
          this.bankList = [];
          // this.DepartmentoList=[]
        }
        // this.bankList = response.rows;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        termCode: null,
        termName: null,
        termContent: null,
        parentTermCode: null,
        termLevel: null,
        termSort: null,
        termRemark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.bankList = []

      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.form.name = this.$route.query.termContent;

      this.form.termLevel = this.$route.query.termLevel;
      this.form.parentTermCode = this.$route.query.parentTermCode;

      // console.log(this.form.name, " this.form.name");
      this.open = true;
      this.title = "添加常用术语(知识库)";
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBank(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改常用术语(知识库)";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBank(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.bankList = []
              this.getList();
            });
          } else {
            addBank(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.bankList = []
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除常用术语(知识库)编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBank(ids);
        })
        .then(() => {
          this.bankList = []

          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/bank/export",
        {
          ...this.queryParams,
        },
        `bank_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss">
.left {
  height: 530px;
  overflow: scroll;

  .name {
    font-weight: 700;
    margin-bottom: 10px;
  }

  .listitem {
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #dcdfe6;

    .count {
      display: inline-block;
      position: relative;
      // right: -172px;
      left: 216px;
      color: #a4a6aa;
      top: -35px;
      font-size: 13px;
    }

    .all {
      height: 50px;
      line-height: 50px;
      padding-left: 13px;
    }

    .allactive {
      background: #e8f4ff;
      height: 50px;
      line-height: 50px;
      padding-left: 13px;
      border-left: 3px solid #4d9de7;
    }
  }
}
</style>