zhanghua
2023-02-09 bf9a412b20afe9f22e99448eb002ff9e92fd30cb
src/views/operate/message/mycontrol/index.vue
@@ -1,470 +1,507 @@
<template>
    <div class="userList">
        <main>
            <div class="mainContent">
                <div class="main-nav">
                    <span>数据列表</span>
                    <el-button class="button-addition" type="primary" icon="el-icon-plus" @click="dialogCreate = true">添加</el-button>
                </div>
                <!-- 数据展示 -->
                <el-table
                    border
                    stripe
                    ref="multipleTable"
                    :header-cell-style="{ 'background':'#F5F5F5','font-weight':'650','line-height':'45px'}"
                    :data="tableData" style="width: 100%" :row-class-name="tableRowClassName"
                    @selection-change="tableChange">
                    <el-table-column type="selection" min-width="5">
                    </el-table-column>
                    <el-table-column prop="columnName" label="栏目名称" min-width="10">
                    </el-table-column>
                    <el-table-column prop="updateTime" label="修改时间" min-width="10">
                        <template slot-scope="scope">
                            <span>{{changeTime(scope.row)}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="noticeAmount" label="公告数量" min-width="10">
                    </el-table-column>
                    <el-table-column prop="isShow" label="显示" min-width="5">
                        <template slot-scope="scope">
                            <el-switch class="switchStyle" v-model="scope.row.isShow" active-text="开" inactive-text="关"
                                active-color="#3fef9a" inactive-color="#000212" @change="handleChangeStatus(scope.row)">
                            </el-switch>
                        </template>
                    </el-table-column>
                    <el-table-column prop="operation" label="操作" min-width="15">
                        <template slot-scope="scope">
                            <div class="operation">
                                <el-link icon="el-icon-edit" :underline="false" @click="handleEdit(scope.row)">编辑</el-link>
                                <el-link class="leftPx" icon="el-icon-delete-solid" :underline="false"
                                    @click="handleDelete([scope.row.id])">删除</el-link>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 创建页面 -->
                <el-dialog title="添加栏目" :visible.sync="dialogCreate" v-if="dialogCreate" width="45%"
                    :before-close="handleClose">
                    <MyCreate @closeDialog="closeDialog"></MyCreate>
                </el-dialog>
                <!-- 编辑页面 -->
                <el-dialog title="修改栏目" :visible.sync="dialogEdit" v-if="dialogEdit" width="45%"
                    :before-close="handleClose">
                    <MyEdit  @closeDialog="closeDialog" :info="info"></MyEdit>
                </el-dialog>
            </div>
        </main>
    </div>
  <div class="userList">
    <main>
      <div class="mainContent">
        <div class="main-nav">
          <span>数据列表</span>
          <el-button
            class="button-addition"
            type="primary"
            icon="el-icon-plus"
            @click="dialogCreate = true"
            >添加</el-button
          >
        </div>
        <!-- 数据展示 -->
        <el-table
          border
          stripe
          ref="multipleTable"
          :header-cell-style="{
            background: '#F5F5F5',
            'font-weight': '650',
            'line-height': '45px',
          }"
          :data="tableData"
          style="width: 100%"
          :row-class-name="tableRowClassName"
          @selection-change="tableChange"
        >
          <el-table-column type="selection" min-width="5"> </el-table-column>
          <el-table-column prop="columnName" label="栏目名称" min-width="10">
          </el-table-column>
          <el-table-column prop="updateTime" label="修改时间" min-width="10">
            <template slot-scope="scope">
              <span>{{ changeTime(scope.row) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="noticeAmount" label="公告数量" min-width="10">
          </el-table-column>
          <el-table-column prop="isShow" label="显示" min-width="5">
            <template slot-scope="scope">
              <el-switch
                class="switchStyle"
                v-model="scope.row.isShow"
                active-text="开"
                inactive-text="关"
                active-color="#3fef9a"
                inactive-color="#000212"
                @change="handleChangeStatus(scope.row)"
              >
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="operation" label="操作" min-width="15">
            <template slot-scope="scope">
              <div class="operation">
                <el-link
                  icon="el-icon-edit"
                  :underline="false"
                  @click="handleEdit(scope.row)"
                  >编辑</el-link
                >
                <el-link
                  class="leftPx"
                  icon="el-icon-delete-solid"
                  :underline="false"
                  @click="handleDelete([scope.row.id])"
                  >删除</el-link
                >
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 创建页面 -->
        <el-dialog
          title="添加栏目"
          :visible.sync="dialogCreate"
          v-if="dialogCreate"
          width="45%"
          :before-close="handleClose"
        >
          <MyCreate @closeDialog="closeDialog"></MyCreate>
        </el-dialog>
        <!-- 编辑页面 -->
        <el-dialog
          title="修改栏目"
          :visible.sync="dialogEdit"
          v-if="dialogEdit"
          width="45%"
          :before-close="handleClose"
        >
          <MyEdit @closeDialog="closeDialog" :info="info"></MyEdit>
        </el-dialog>
      </div>
    </main>
  </div>
</template>
<script>
// 引入创建栏目组件
import MyCreate from './createUser'
import MyCreate from "./createUser";
// 引入编辑组件
import MyEdit from './update'
import MyEdit from "./update";
// 引入日期js
import helper from '@/utils/mydate'
import helper from "@/utils/mydate";
export default {
    components: {
        MyCreate,MyEdit
  components: {
    MyCreate,
    MyEdit,
  },
  data() {
    return {
      tableData: [],
      dialogCreate: false,
      dialogEdit: false,
      pageSize: 10,
      currentPage: 1,
      all: false,
      unsame: false,
      myIdx: 0,
      preMyIdx: 0,
      info: "",
      options: [
        {
          value: 0,
          label: "批量操作",
          disabled: true,
        },
        {
          value: 1,
          label: "批量启用",
        },
        {
          value: 2,
          label: "批量禁用",
        },
        {
          value: 3,
          label: "批量删除",
        },
      ],
      tempList: [],
    };
  },
  created() {
    this.setTableData();
  },
  methods: {
    // 编辑
    handleEdit(data) {
      this.info = data;
      this.dialogEdit = true;
    },
    data() {
        return {
            tableData: [],
            dialogCreate: false,
            dialogEdit:false,
            pageSize: 10,
            currentPage: 1,
            all: false,
            unsame: false,
            myIdx: 0,
            preMyIdx: 0,
            info:'',
            options: [
                {
                    value: 0,
                    label: '批量操作',
                    disabled: true,
                },
                {
                    value: 1,
                    label: '批量启用',
                },
                {
                    value: 2,
                    label: '批量禁用',
                },
                {
                    value: 3,
                    label: '批量删除',
                }
            ],
            tempList: []
    // 删除数据
    handleDelete(idArr) {
      this.$confirm("是否确定确定删除栏目?")
        .then((_) => {
          this.$axios({
            method: "post",
            url: "sccg/message_column/delete" + "?ids=" + idArr,
          }).then((res) => {
            if (res.code === 200) {
              this.$message({
                type: "success",
                message: "删除成功",
              });
              this.setTableData();
            }
          });
        })
        .catch((err) => {});
    },
    // 修改栏目状态
    handleChangeStatus({ id, isShow }) {
      this.$axios({
        method: "post",
        url: `sccg/message_column/update/${id}`,
        data: {
          isShow: Number(isShow),
        },
      }).then((res) => {
        if (res.code === 200) {
          this.setTableData();
        }
      });
    },
    created() {
    // 获取全部栏目
    async getColumnList() {
      let arr = [];
      await this.$axios({
        method: "get",
        url: "sccg/message_column/getAllColumn",
      }).then((res) => {
        res.data.forEach((item) => {
          item.isShow === 1 ? (item.isShow = true) : (item.isShow = false);
        });
        arr = res.data;
      });
      return arr;
    },
    // 设置表格数据
    async setTableData() {
      this.tableData = await this.getColumnList();
    },
    // 下拉框监听
    async selectChange(list) {
      if (this.tempList.length !== 0) {
        this.preMyIdx = list;
        if (list === 3) {
          await this.handleDelete(this.tempList);
        } else if (list === 2) {
          await this.mulUpdateStatus(this.tempList, 0);
        } else {
          await this.mulUpdateStatus(this.tempList, 1);
        }
        this.myIdx = 0;
      } else {
        this.myIdx = this.preMyIdx;
        this.$message({
          type: "warning",
          message: "您还没选中任何数据",
        });
      }
    },
    // 批量操作
    mulUpdateStatus(idArr, flag) {
      this.$confirm(
        flag === 1
          ? "您确定要进行批量启用角色吗?"
          : "您确定要进行批量禁用角色吗?"
      )
        .then((_) => {
          this.$axios({
            method: "post",
            url: "sccg/role/updateStatusBatch?ids=" + idArr + "&status=" + flag,
          }).then((res) => {
            if (res.code === 200) {
              this.$message({
                type: "success",
                message: "更改用户状态成功",
              });
              this.getUserList();
            } else {
              this.$message({
                type: "error",
                message: res.message,
              });
            }
          });
        })
        .catch((err) => {});
    },
    // 表格状态监听
    tableChange(list) {
      this.tempList = [];
      list.forEach((item) => {
        this.tempList.push(item.id);
      });
      if (list.length === this.tableData.length) {
        this.all = true;
      } else {
        this.all = false;
      }
    },
    // 改变日期格式
    changeTime({ updateTime }) {
      return helper(updateTime);
    },
    // 全选
    selectAll() {
      this.$refs.multipleTable.toggleAllSelection();
    },
    // 反选
    disSame(list) {
      list.forEach((row) => {
        this.$refs.multipleTable.toggleRowSelection(row);
      });
    },
    // 设置表格斑马纹
    tableRowClassName({ row, rowIndex }) {
      if ((rowIndex + 1) % 2 == 0) {
        return "warning-row";
      } else {
        return "success-row";
      }
      return "";
    },
    // 当前页改变触发事件
    changeCurrentPage(page) {
      this.currentPage = page;
      this.search();
    },
    // 上一页点击事件
    handlePrev(page) {
      this.currentPage = page;
      this.search();
    },
    // 下一页点击事件
    handleNext(page) {
      this.currentPage = page;
      this.search();
    },
    // 关闭弹窗
    handleClose(done) {
      this.$confirm("确定关闭?")
        .then((_) => {
          done();
        })
        .catch((err) => {});
    },
    // 自定义关闭弹窗
    closeDialog({ flag, index }) {
      this.dialogCreate = flag;
      this.dialogEdit = flag;
      if (index === 1) {
        this.setTableData();
      }
    },
    methods: {
        // 编辑
        handleEdit(data){
            this.info = data;
            this.dialogEdit = true;
        },
        // 删除数据
        handleDelete(idArr) {
            this.$confirm('是否确定确定删除栏目?')
                .then(_ => {
                    this.$axios({
                        method: 'post',
                        url: 'sccg/message_column/delete' + '?ids=' + idArr,
                    })
                        .then(res => {
                            if (res.code === 200) {
                                this.$message({
                                    type: 'success',
                                    message: '删除成功',
                                });
                                this.setTableData();
                            }
                        })
                })
                .catch(err=>{
                })
        },
        // 修改栏目状态
        handleChangeStatus({ id, isShow }) {
            this.$axios({
                method: 'post',
                url: `sccg/message_column/update/${id}`,
                data: {
                    isShow: Number(isShow),
                }
            })
                .then(res => {
                    if (res.code === 200) {
                        this.setTableData();
                    }
                })
        },
        // 获取全部栏目
        async getColumnList() {
            let arr = [];
            await this.$axios({
                method: 'get',
                url: 'sccg/message_column/getAllColumn',
            })
                .then(res => {
                    res.data.forEach(item => {
                        item.isShow === 1 ? item.isShow = true : item.isShow = false;
                    })
                    arr = res.data
                })
            return arr;
        },
        // 设置表格数据
        async setTableData() {
            this.tableData = await this.getColumnList();
        },
        // 下拉框监听
        async selectChange(list) {
            if (this.tempList.length !== 0) {
                this.preMyIdx = list;
                if (list === 3) {
                    await this.handleDelete(this.tempList);
                } else if (list === 2) {
                    await this.mulUpdateStatus(this.tempList, 0);
                } else {
                    await this.mulUpdateStatus(this.tempList, 1);
                }
                this.myIdx = 0;
            } else {
                this.myIdx = this.preMyIdx;
                this.$message({
                    type: 'warning',
                    message: '您还没选中任何数据',
                })
            }
        },
        // 批量操作
        mulUpdateStatus(idArr, flag) {
            this.$confirm(flag === 1 ? "您确定要进行批量启用角色吗?" : '您确定要进行批量禁用角色吗?')
                .then(_ => {
                    this.$axios({
                        method: 'post',
                        url: 'sccg/role/updateStatusBatch?ids=' + idArr + '&status=' + flag,
                    })
                        .then(res => {
                            if (res.code === 200) {
                                this.$message({
                                    type: 'success',
                                    message: '更改用户状态成功',
                                })
                                this.getUserList();
                            } else {
                                this.$message({
                                    type: 'error',
                                    message: res.message
                                })
                            }
                        })
                })
                .catch(err => {  })
        },
        // 表格状态监听
        tableChange(list) {
            this.tempList = [];
            list.forEach(item => {
                this.tempList.push(item.id);
            })
            if (list.length === this.tableData.length) {
                this.all = true;
            } else {
                this.all = false
            }
        },
        // 改变日期格式
        changeTime({ updateTime }) {
            return helper(updateTime);
        },
        // 全选
        selectAll() {
            this.$refs.multipleTable.toggleAllSelection();
        },
        // 反选
        disSame(list) {
            list.forEach(row => {
                this.$refs.multipleTable.toggleRowSelection(row)
            })
        },
        // 设置表格斑马纹
        tableRowClassName({ row, rowIndex }) {
            if ((rowIndex + 1) % 2 == 0) {
                return 'warning-row';
            } else {
                return 'success-row';
            }
            return '';
        },
        // 当前页改变触发事件
        changeCurrentPage(page) {
            this.currentPage = page;
            this.search();
        },
        // 上一页点击事件
        handlePrev(page) {
            this.currentPage = page;
            this.search();
        },
        // 下一页点击事件
        handleNext(page) {
            this.currentPage = page;
            this.search();
        },
        // 关闭弹窗
        handleClose(done) {
            this.$confirm('确定关闭?')
                .then(_ => {
                    done();
                })
                .catch(err => {
                })
        },
        // 自定义关闭弹窗
        closeDialog({ flag, index }) {
            this.dialogCreate = flag;
            this.dialogEdit = flag;
            if (index === 1) {
                this.setTableData();
            }
        }
    }
}
  },
};
</script>
<style lang="scss" scoped>
.userList {
    text-align: left;
    padding: 10px 20px;
    color: #606266;
  text-align: left;
  padding: 10px 20px;
  color: #606266;
  border: 1px solid #ccc;
    main {
        background-color: white;
        margin-top: 20px;
        padding-bottom: 50px;
        border: 1px solid #fff;
  main {
    background-color: white;
    margin-top: 20px;
    padding-bottom: 50px;
    border: 1px solid #fff;
        .mainTitle {
            line-height: 60px;
        }
        .main-nav {
            line-height: 40px;
            display: flex;
            padding: 10px;
            justify-content: space-between;
        }
        .tools {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
            .funs {
                display: flex;
                .funsItem {
                    line-height: 28px;
                    display: flex;
                    align-items: center;
                    border: 1px solid #17324c;
                    border-radius: 4px;
                    font-size: 12px;
                    margin-left: 10px;
                    .el-checkbox {
                        width: 80px;
                        padding: 0 10px;
                    }
                    .el-select {
                        width: 120px;
                    }
                    &::v-deep .el-input__inner {
                        border: none;
                        //background-color: #09152f;
                    }
                    &:hover {
                        border: 1px solid #4b9bb7;
                    }
                    &:hover .el-checkbox {
                        color: #4b9bb7;
                    }
                }
            }
            .pagination {
                margin-top: 50px;
                display: flex;
                line-height: 50px;
                justify-content: center;
                //.el-pagination {
                //
                //    &::v-deep li,
                //    &::v-deep .btn-prev,
                //    &::v-deep .btn-next {
                //        background-color: #071f39;
                //        color: #4b9bb7;
                //    }
                //
                //    &::v-deep .active {
                //        background-color: #409eff;
                //        color: #fff;
                //    }
                //}
            }
        }
        .el-table {
            // color: #606266;
            // font-size: 10px;
            &::v-deep .el-table__empty-block {
                //background-color: #09152f;
            }
            &::v-deep .el-table__empty-block {
                color: #4b9bb7;
            }
            .operation {
                display: flex;
                .el-link {
                    color: #4b9bb7;
                }
                .leftPx {
                    margin-left: 10px;
                }
                .line {
                    padding: 0 5px;
                }
                span:hover {
                    cursor: pointer;
                }
            }
        }
        //.el-table::v-deep .warning-row {
        //    background: #06122c;
        //}
        //
        //.el-table::v-deep .success-row {
        //    background: #071f39;
        //}
        &::v-deep .switchStyle .el-switch__label {
            position: absolute;
            display: none;
            color: #fff;
        }
        &::v-deep .el-switch__core {
            background-color: rgba(166, 166, 166, 1);
        }
        &::v-deep .switchStyle .el-switch__label--left {
            z-index: 9;
            left: 20px;
        }
        &::v-deep .switchStyle .el-switch__label--right {
            z-index: 9;
            left: 4px;
        }
        &::v-deep .switchStyle .el-switch__label.is-active {
            display: block;
        }
        &::v-deep .switchStyle.el-switch .el-switch__core,
        &::v-deep .el-switch .el-switch__label {
            width: 50px !important;
        }
    .mainTitle {
      line-height: 60px;
    }
    //&::v-deep .el-dialog__header,
    //&::v-deep .el-dialog__body {
    //    background-color: #06122c;
    .main-nav {
      line-height: 40px;
      display: flex;
      padding: 10px;
      justify-content: space-between;
    }
    .tools {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 20px;
      .funs {
        display: flex;
        .funsItem {
          line-height: 28px;
          display: flex;
          align-items: center;
          border: 1px solid #17324c;
          border-radius: 4px;
          font-size: 12px;
          margin-left: 10px;
          .el-checkbox {
            width: 80px;
            padding: 0 10px;
          }
          .el-select {
            width: 120px;
          }
          &::v-deep .el-input__inner {
            border: none;
            //background-color: #09152f;
          }
          &:hover {
            border: 1px solid #4b9bb7;
          }
          &:hover .el-checkbox {
            color: #4b9bb7;
          }
        }
      }
      .pagination {
        margin-top: 50px;
        display: flex;
        line-height: 50px;
        justify-content: center;
        //.el-pagination {
        //
        //    &::v-deep li,
        //    &::v-deep .btn-prev,
        //    &::v-deep .btn-next {
        //        background-color: #071f39;
        //        color: #4b9bb7;
        //    }
        //
        //    &::v-deep .active {
        //        background-color: #409eff;
        //        color: #fff;
        //    }
        //}
      }
    }
    .el-table {
      // color: #606266;
      // font-size: 10px;
      &::v-deep .el-table__empty-block {
        //background-color: #09152f;
      }
      &::v-deep .el-table__empty-block {
        color: #4b9bb7;
      }
      .operation {
        display: flex;
        .el-link {
          color: #4b9bb7;
        }
        color: var(--operation-color);
        .leftPx {
          margin-left: 10px;
        }
        .line {
          padding: 0 5px;
        }
        span:hover {
          cursor: pointer;
        }
      }
    }
    //.el-table::v-deep .warning-row {
    //    background: #06122c;
    //}
    //
    //.el-table::v-deep .success-row {
    //    background: #071f39;
    //}
    &::v-deep .el-dialog__header {
        display: flex;
        align-items: center;
        background-color: #fff;
        padding: 20px;
        line-height: 60px;
    &::v-deep .switchStyle .el-switch__label {
      position: absolute;
      display: none;
      color: #fff;
    }
    &::v-deep .el-dialog__title {
        color: #606266;
    &::v-deep .el-switch__core {
      background-color: rgba(166, 166, 166, 1);
    }
    &::v-deep .el-dialog__close {
        width: 20px;
        height: 20px;
        // color: #fff;
    &::v-deep .switchStyle .el-switch__label--left {
      z-index: 9;
      left: 20px;
    }
    &::v-deep .el-dialog__body {
        padding: 0;
    &::v-deep .switchStyle .el-switch__label--right {
      z-index: 9;
      left: 4px;
    }
    &::v-deep .switchStyle .el-switch__label.is-active {
      display: block;
    }
    &::v-deep .switchStyle.el-switch .el-switch__core,
    &::v-deep .el-switch .el-switch__label {
      width: 50px !important;
    }
  }
  //&::v-deep .el-dialog__header,
  //&::v-deep .el-dialog__body {
  //    background-color: #06122c;
  //}
  &::v-deep .el-dialog__header {
    display: flex;
    align-items: center;
    background-color: #fff;
    padding: 20px;
    line-height: 60px;
  }
  &::v-deep .el-dialog__title {
    color: #606266;
  }
  &::v-deep .el-dialog__close {
    width: 20px;
    height: 20px;
    // color: #fff;
  }
  &::v-deep .el-dialog__body {
    padding: 0;
  }
}
</style>