<style lang="scss">
.preview {
  .el-form-item {
    margin-bottom: 15px;
  }
  label,
  p {
    line-height: 25px !important;
  }
}
</style>
<template>
  <section>
    <p><span>系统管理></span>敏感词管理</p>
    <div class="content">
      <div class="filter">
        <el-form
          size="small"
          label-width="70px"
          :inline="true"
          label-position="left"
        >
          <el-form-item label="">
            <el-input
              clearable
              placeholder="请输入热词"
              v-model="form.name"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="search">搜索</el-button>
          </el-form-item>
          <el-form-item style="float: right">
            <el-button
              @click="(dialogVisible = true), (dialogTitle = '新增敏感词')"
              type="primary"
              >新增敏感词</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <el-table
        class="table"
        :data="list"
        height="50vh"
        border
        v-loading="loading"
        default-expand-all
        row-key="id"
        style="width: 100%"
      >
        <el-table-column prop="name" width="300" label="关键字">
        </el-table-column>
        <el-table-column prop="cname" label="编辑人"> </el-table-column>
        <el-table-column prop="ctime" label="编辑时间"> </el-table-column>
        <el-table-column prop="zip" width="150" label="操作">
          <template slot-scope="scope">
            <el-button class="del" @click="del(scope.row.id)" type="text"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <Page
        ref="pageButton"
        :current="form.page"
        :page_size="form.page_size"
        :total="total"
        @pageChange="gopage"
      />
    </div>

    <el-dialog
      :title="dialogTitle"
      :close-on-click-modal="false"
      :visible.sync="dialogVisible"
    >
      <el-form size="small" class="preview" :inline="false" label-width="80px">
        <el-form-item label="敏感词">
          <el-input v-model="form1.name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="save">确 定</el-button>
      </span>
    </el-dialog>
  </section>
</template>
<script>
import Page from "../../components/Page";
export default {
  components: {
    Page,
  },
  data() {
    return {
      form: { name: "", page: 1, page_size: 20 },
      form1: {},
      total: 1,
      list: [],
      loading: false,
      input: "",
      dialogVisible: false,
      dialogTitle: "",
      defaultProps: {},
      data: [],
      selected: [],
    };
  },
  methods: {
    search() {
      let parm = this.form;
      this.getData();
    },
    getData() {
      var parm = this.form;
      this.loading = true;
      this.$api.getSenWordList(parm).then((res) => {
        this.loading = false;
        if(res.data.code != 0){
          return
        }
        let list = res.data.data.list;
        this.list = list;
        this.total = res.data.data.total;
        
      });
    },
    gopage(size) {
      if (size) {
        this.form.page_size = size;
      }
      this.form.page = this.$refs.pageButton.page;
      this.getData();
    },
    del(id) {
      this.$confirm("确定删除吗", "提示", {
        type: "warning",
      }).then(() => {
        this.$api.delSenWord({ id: id }).then((res) => {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.getData();
        });
      });
    },
    save() {
      let parm = this.form1;
      if (parm.id) {
        this.$api.updateSenWord(parm).then((res) => {
          if (res.data.code == 0) {
            this.$message({
              type: "success",
              message: "保存成功!",
            });
            this.getData();
          } else {
            this.$message.error("失败!");
          }
        });
      } else {
        this.$api.addSenWord(parm).then((res) => {
          if (res.data.code == 0) {
            this.$message({
              type: "success",
              message: "保存成功!",
            });
            this.getData();
          } else {
            this.$message.error("失败!");
          }
        });
      }
      this.dialogVisible = false;
    },
  },
  created() {
    this.getData();
  },
};
</script>
