index.vue 8.48 KB
<template>
  <div style="padding: 10px;background-color:#F2F3F5">
    <div class="custom_page">
      <div style="height:58px;line-height:58px;">
        <div style="color:#0006"> <span>评论管理</span>   <span style="padding:0 5px;">></span>  <span style="color:#000000e6">关键词管理</span></div>
      </div>
      <div class="content">
        <!-- 顶部搜索 -->
        <div class="toolbar">
          <!-- 顶部搜索 -->
          <el-form :inline="true" :model="formInline">
            <el-form-item label="关键词">
              <el-input v-model="formInline.search" maxlength="20" placeholder="请输入关键词" size="mini" />
            </el-form-item>
            <el-form-item>
              <el-button   @click="search" style="background-color: #3F9B6A;color: #fff">查询</el-button>
              <el-button  @click="clear" class="buttonHover"
            style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;" >重置</el-button>
              <el-button  @click="add" style="background-color: #3F9B6A;color: #fff">新增关键词</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="stateLabel">
          <span class="formItem">状态:</span>
          <el-switch
            v-model="value"
            active-color="#3F9B6A"
            inactive-color="#dcdfe6"
            active-value="1"
            inactive-value="0"
            @change="changeState"
          />
        </div>
        <!--  表格 -->
        <div class="content_table">
          <div class="table">
            <el-table
              :data="tableData"
              :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}"
            >
              <el-table-column type="index" label="序号" width="50" />
              <el-table-column prop="keyWord" label="关键词" />
              <el-table-column prop="createTime" label="创建时间" />
              <el-table-column label="操作" show-overflow-tooltip>
                <template slot-scope="scope">
                  <div class="btnList">
                    <div @click="edit(scope.row)"  class="tableBtn greens">修改</div>
                    <div @click="del(scope.row)" class="tableBtn greens">删除</div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="fenye">
              <el-pagination
                :current-page="currentPage"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="10"
                background
                small
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </div>
        </div>
      </div>
      <!-- 关键词 -->
      <el-dialog
        :visible.sync="isVisible.show"
        :title="isVisible.title"
        width="30%"
        center
        :close-on-click-modal="false"
      >
        <div>
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="关键词">
              <el-input v-model="form.keyWord" maxlength="20" placeholder="请输入关键词" />
            </el-form-item>
          </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button style="background-color: #3F9B6A;color: #fff" @click="agreeEn">确定</el-button>
          <el-button @click="isVisible.show = false" class="buttonHover"
            style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;">取 消</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  wordStart,
  wordGetAll,
  wordAdd,
  wordGetById,
  wordUpdate,
  wordDelete
} from '@/api/business'
export default {
  data() {
    return {
      value: 0,
      formInline: {
        search: '',
        state: '',
        page: 1,
        pageSize: 10
      },
      form: {
        keyWord: '',
        state: '是否启用 1-是 0-否'
      },
      isVisible: {},
      humenList: [],
      total: 1,
      tableData: [],
      currentPage: 1,
      InviteList: []
    }
  },
  created() {
    this.getAll(this.formInline)
  },
  methods: {
    handleSizeChange(val) {
      this.formInline.pageSize = val
      this.getAll(this.formInline)
    },
    handleCurrentChange(val) {
      this.formInline.page = val
      this.getAll(this.formInline)
    },
    // 改变状态
    async changeState(index) {
      const res = await wordStart({ state: this.value })
      if (res.code === '') {
        // this.$message.success("成功");
      }
      console.log(index)
    },
    // 查询
    search() {
      this.total = 1
      this.formInline.page = 1
      this.getAll(this.formInline)
    },
    // 添加关键词
    add() {
      this.form.keyWord = ''
      this.isVisible = {
        show: true,
        title: '添加关键词',
        index: 1
      }
    },
    // 编辑
    async edit(row) {
      const res = await wordGetById({
        wordId: row.wordId
      })
      if (res.code === '') {
        this.form = res.data
        this.isVisible = {
          show: true,
          title: '编辑关键词',
          index: 2
        }
      }
    },
    async agreeEn() {
      if (this.isVisible.index === 1) {
        if (this.form.keyWord === '') {
          this.$message.error('请输入关键词')
          return
        }
        this.form.state = this.value
        const res = await wordAdd(this.form)
        if (res.code === '') {
          this.$message.success('新增成功')
          this.getAll(this.formInline)
          this.isVisible.show = false
        }
      } else if (this.isVisible.index === 2) {
        this.form.state = this.value
        const res = await wordUpdate(this.form)
        if (res.code === '') {
          this.$message.success('编辑成功')
          this.getAll(this.formInline)
          this.isVisible.show = false
        }
      }
    },
    // 删除
    del(row) {
      this.$confirm('确定要删除该条关键词?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          wordDelete({ wordId: row.wordId }).then(res => {
            if (res.code === '') {
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
            }
            this.getAll(this.formInline)
          })
        })
        .catch(() => {})
    },
    // 清除
    clear() {
      this.formInline = {
        orderFormid: '',
        distributorName: '',
        distributorPhone: '',
        dates: [],
        page: 1,
        pageSize: 10
      }
      this.getAll(this.formInline)
    },
    // 初始化查询所有数据
    async getAll(formInline) {
      const res = await wordGetAll(formInline)
      this.tableData = res.data.list
      this.total = res.data.total
    }
  }
}
</script>

<style lang='scss' scoped>
@import url("../../../styles/elDialog.scss");
.custom_page {
padding: 0  20px 20px 20px;
  min-height: calc(100vh - 50px - 20px);
  background-color: #Fff;
}
.checkBoxStyle {
  margin-bottom: 20px;
}
.dialog_content {
  width: 275px;
  height: 46px;
  margin: auto;
  font-size: 16px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #333333;
  line-height: 30px;
  margin-top: 25px;
}
.stateLabel {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 20px;
  .formItem {
    float: left;
    font-size: 14px;
    color: #606266;
    padding: 0 12px 0 0;
    font-weight: 700;
  }
}
 ::v-deep .el-form-item__label{
        font-weight: normal;
         font-size: 14px;

       }

          ::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
           background-color: #3F9B6A;
         }
         ::v-deep .el-input__inner:focus {
              border: #3F9B6A 1px solid;
           }
           .tableBtn {
               display: inline-block;
               margin-right: 10px;
             }

           .greens {
               color: #3F9B6A ;
             }
             ::v-deep .buttonHover:hover{
               color:#3f9b6a !important;
               border-color: #c5e1d2 !important;
               background-color: #ecf5f0 !important;
               outline: none;
             }
             ::v-deep .el-pagination__total {
                 position: absolute;
                 left: 10px;
               }
</style>