odc.xiaohui
2023-05-22 0782140a00e554ec7a1c724ecc1eb36726d994f8
src/views/manager/User.vue
@@ -3,8 +3,8 @@
    <el-card style="height: 100%">
      <template slot="header">
        <el-form :inline="true" :model="queryInfo" class="demo-form-inline">
          <el-form-item label="用户名:">
            <el-input placeholder="请输入" v-model="queryInfo.nickName"></el-input>
          <el-form-item label="手机号:">
            <el-input placeholder="请输入" v-model="queryInfo.userMobile"></el-input>
          </el-form-item>
          <el-form-item label="用户姓名:">
            <el-input placeholder="请输入" v-model="queryInfo.realName"></el-input>
@@ -14,6 +14,7 @@
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="addPublicityVisibel = true">添加</el-button>
            <el-button type="primary" @click="exportList">导出</el-button>
          </el-form-item>
        </el-form>
      </template>
@@ -21,29 +22,43 @@
        <el-table :data="publicityList" style="width: 100%">
          <el-table-column prop="nickName" label="用户名" width="180" align="center">
          </el-table-column>
          <el-table-column prop="realName" label="用户姓名" width="180" header-align="center" align="center">
          </el-table-column>
          <el-table-column prop="userMobile" label="手机号码" width="180" header-align="center" align="center">
          </el-table-column>
          <el-table-column prop="ctime" label="创建时间" width="180" header-align="center" align="center">
          </el-table-column>
          <el-table-column prop="userMemo" label="备注" width="180" align="center">
          </el-table-column>
          <el-table-column label="操作" align="conter">
            <template slot-scope="scope">
              <el-button type="text" size="medium" @click="details(scope.row)">编辑</el-button>
              <el-button type="text" size="medium" @click="reset(scope.row.id)">重置密码</el-button>
              <el-button type="text" size="medium" @click="remove(scope.row.id)" style="color:#ff0000">删除
              <!--              <el-button type="text" size="medium" @click="reset(scope.row.id)">重置密码</el-button>-->
              <el-button type="text" size="medium" @click="handleToManager(scope.row)">设为警员</el-button>
              <el-button type="text" size="medium" @click="updateStatus(scope.row.id,scope.row.status)">
                {{ scope.row.status == 1 ? "禁用" : "启用" }}
              </el-button>
              <el-popconfirm
                  title="确定删除吗?"
                  @confirm="removeuser(scope.row.id)"
              >
                <el-button type="text" style="margin-left: 5px;color: red" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <el-pagination @current-change="handleCurrentChange" :current-page="queryInfo.current" :page-size="queryInfo.size"
        layout="prev, pager, next" :total="total"></el-pagination>
                     layout="prev, pager, next" :total="total"></el-pagination>
    </el-card>
    <!--添加用户弹窗-->
    <el-dialog title="用户添加" :visible.sync="addPublicityVisibel" width="50%" :before-close="addPublicityClose"
      :append-to-body="true">
               :append-to-body="true">
      <el-row :gutter="15">
        <el-form ref="addPublicityForm" :model="addPublicityForm" :rules="rules" size="medium" label-width="100px">
@@ -64,7 +79,7 @@
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证" prop="userIdcard">
              <el-input v-model="addPublicityForm.userIdcard" clearable placeholder="请输入身份证"> </el-input>
              <el-input v-model="addPublicityForm.userIdcard" clearable placeholder="请输入身份证"></el-input>
            </el-form-item>
          </el-col>
        </el-form>
@@ -75,46 +90,50 @@
      </span>
    </el-dialog>
     <el-dialog title="编辑" :visible.sync="detailsVisible" width="50%" :append-to-body="true"
          :before-close="detailsVisibleclose">
          <el-row :gutter="15">
            <el-form ref="detailsRow" :model="detailsRow" size="medium"
              label-width="100px">
              <el-col :span="12">
                <el-form-item label="用户名" prop="nickName">
                  <el-input v-model="detailsRow.nickName" placeholder="请输入用户名" clearable
                    :style="{ width: '100%' }">
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="用户姓名" prop="realName">
                  <el-input v-model="detailsRow.realName" placeholder="请输入用户姓名" clearable
                    :style="{ width: '100%' }">
                  </el-input>
                </el-form-item>
              </el-col>
               <el-col :span="12">
                <el-form-item label="手机号码" prop="userMobile">
                  <el-input v-model="detailsRow.userMobile" placeholder="请输入手机号码" clearable
                    :style="{ width: '100%' }">
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="身份证号" prop="userIdcard">
                  <el-input v-model="detailsRow.userIdcard" placeholder="请输入身份证号" clearable
                    :style="{ width: '100%' }">
                  </el-input>
                </el-form-item>
              </el-col>
            </el-form>
          </el-row>
          <span slot="footer" class="dialog-footer">
            <el-button @click="detailsVisible = false">取 消</el-button>
            <el-button type="primary" @click="update">确 定</el-button>
          </span>
        </el-dialog>
    <el-dialog title="编辑" :visible.sync="detailsVisible" width="50%" :append-to-body="true"
               :before-close="detailsVisibleclose">
      <el-row :gutter="15">
        <el-form ref="detailsRow" :model="detailsRow" size="medium" label-width="100px">
          <el-col :span="12">
            <el-form-item label="用户名" prop="nickName">
              <el-input v-model="detailsRow.nickName" placeholder="请输入用户名" clearable :style="{ width: '100%' }">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户姓名" prop="realName">
              <el-input v-model="detailsRow.realName" placeholder="请输入用户姓名" clearable :style="{ width: '100%' }">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="userMobile">
              <el-input v-model="detailsRow.userMobile" placeholder="请输入手机号码" clearable
                        :style="{ width: '100%' }">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证号" prop="userIdcard">
              <el-input v-model="detailsRow.userIdcard" placeholder="请输入身份证号" clearable
                        :style="{ width: '100%' }">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="备注" prop="userMemo">
            <el-input v-model="detailsRow.userMemo" placeholder="请输入备注" clearable
                      :style="{ width: '100%' }">
            </el-input>
          </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="detailsVisible = false">取 消</el-button>
        <el-button type="primary" @click="update">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
@@ -122,7 +141,8 @@
<script>
import {
  getPublicityList,
  addPublicityList
  addPublicityList,
  toManager, deleteUser
} from '@/api/User'
@@ -130,14 +150,14 @@
  name: "User",
  data() {
    return {
 rules: {
      visible:false,
      rules: {
        nickName: [{
          required: true,
          message: '请输入用户名 ',
          trigger: 'blur'
        }],
         realName: [{
        realName: [{
          required: true,
          message: '请输入用户姓名',
          trigger: 'blur'
@@ -147,18 +167,17 @@
          message: '请输入手机号 ',
          trigger: 'blur'
        }],
           userIdcard: [{
        userIdcard: [{
          required: true,
          message: '请输入身份证 ',
          trigger: 'blur'
        }],
        },
      },
      //详细内容弹框
      detailsVisible: false,
      //详细内容
      detailsRow:
        {
        }
      detailsRow:
          {}
      ,
      //表单提交内容
      addPublicityForm: {
@@ -175,7 +194,8 @@
      total: null,
      //查询条件
      queryInfo: {
        nickName: '',
        userMobile: '',
        realName: '',
        current: 1,
        size: 10
      },
@@ -206,120 +226,177 @@
  },
  methods:
  {
    //删除
    remove(val) {
      this.$http.delete('/api/user', { params: { id: val } }).then(res => {
        this.$message({
          message: '删除成功',
          type: 'success'
        })
      {
        exportList(){
          this.$http({
            url:'/api/user/exp',
            responseType: 'blob',
            method: 'post',
          }).then(res=>{
            console.log(res)
            this.$message.success('操作成功');
            let time = new Date()
            let deathdate =time.toLocaleDateString()
            const blob = new Blob([res.data], {
              type: "application/vnd.ms-excel;charset=utf-8",
            });
            if (window.navigator.msSaveBlob) {
              window.navigator.msSaveBlob(blob, deathdate + ".xlsx");
            } else {
              const url = window.URL.createObjectURL(blob);
              const link = document.createElement("a");
              link.style.display = "none";
              link.href = url;
              link.download = deathdate + ".xlsx";
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link);
            }
          })
        },
        handleToManager(data) {
          toManager(data.id).then(res => {
            this.$message({
              message: '设置成功',
              type: 'success'
            })
            this.search();
          })
        },
        //更新用户状态
        updateStatus(id, status) {
          var _this = this;
          this.$confirm('确认修改账户状态吗?').then(() => {
                _this.$http.get('/api/user/status', {params: {id: id, status: status}}).then(res => {
                  _this.$message({
                    message: '修改成功',
                    type: 'success'
                  })
                  this.search();
                })
              }
          )
        this.search();
      })
    },
    // //发布/下架
    // punlish(val, val2) {
    //   if (val2 == 0) {
    //     this.$http.get('/api/commonQuestion/release/' + val).then(res => {
    //       this.$message({
    //         message: '发布成功',
    //         type: 'success'
    //       })
        },
        // //发布/下架
        // punlish(val, val2) {
        //   if (val2 == 0) {
        //     this.$http.get('/api/commonQuestion/release/' + val).then(res => {
        //       this.$message({
        //         message: '发布成功',
        //         type: 'success'
        //       })
    //       this.search();
    //     }
    //     )
    //   }
    //   if (val2 == 1) {
    //     this.$http.get('/api/commonQuestion/offline/' + val).then(res => {
    //       this.$message({
    //         message: '下架成功',
    //         type: 'success'
    //       })
    //       this.search();
    //     }
    //     );
    //   }
    // },
        //       this.search();
        //     }
        //     )
        //   }
        //   if (val2 == 1) {
        //     this.$http.get('/api/commonQuestion/offline/' + val).then(res => {
        //       this.$message({
        //         message: '下架成功',
        //         type: 'success'
        //       })
        //       this.search();
        //     }
        //     );
        //   }
        // },
        removeuser(id){
          console.log(id)
          deleteUser(id).then(res=>{
            console.log(res)
            this.init()
          })
        },
        //编辑
        details(val) {
          this.detailsVisible = true;
          this.detailsRow = Object.assign({}, val);
        },
        update() {
          this.$http.put('/api/user', this.detailsRow).then(res => {
            console.log(res)
            if (res.data.code == 200){
              this.$message({
                    message: '编辑成功',
                    type: 'success'
                  }
              )
              this.search();
            }else {
              this.$message.error(res.data.msg)
              this.search();
            }
    //编辑
    details(val) {
      this.detailsVisible = true;
            this.detailsRow = Object.assign({}, val);
    },
    update(){
          this.$http.put('/api/user',this.detailsRow).then(res => {this.$message({
        message: '编辑成功',
        type: 'success'}
        )
         this.search();}
        );
          this.detailsVisible =false;
    },
              }
          );
          this.detailsVisible = false;
        },
    //重置密码
    reset(val) {
      this.$http.get('/api/user/resetPassword/' + val).then(res => this.$message({
        message: '重置成功',
        type: 'success'
      }));
    },
    //添加
    add() {
        this.$refs.addPublicityForm.validate(async (vaild) => {
        if (!vaild) return this.$message.error('输入有误')
      let param = null;
      param = this.addPublicityForm;
      addPublicityList(param).then(res => {
        this.$message({
          message: '操作成功',
          type: 'success'
        });
        this.addPublicityForm={};
        this.init();
        //重置密码
        reset(val) {
          this.$http.get('/api/user/resetPassword/' + val).then(res => this.$message({
            message: '重置成功',
            type: 'success'
          }));
        },
        //添加
        add() {
          this.$refs.addPublicityForm.validate(async (vaild) => {
            if (!vaild) return this.$message.error('输入有误')
            let param = null;
            param = this.addPublicityForm;
            addPublicityList(param).then(res => {
                  this.$message({
                    message: '操作成功',
                    type: 'success'
                  });
                  this.addPublicityForm = {};
                  this.init();
                }
            )
            this.addPublicityVisibel = false;
          })
        },
        //关闭之前
        addPublicityClose() {
          this.addPublicityVisibel = false;
        },
        detailsVisibleclose() {
          this.detailsVisible = false;
        },
        //分页方法
        handleCurrentChange(val) {
          this.queryInfo.current = val;
          this.search();
        },
        //公共宣传加载
        init() {
          let param = {}
          param.current = this.queryInfo.current
          param.size = this.queryInfo.size
          getPublicityList(param).then(res => {
            this.publicityList = res.records;
            this.total = res.total
          })
        },
        //查询
        search() {
          let param = {}
          param.current = this.queryInfo.current
          param.realName = this.queryInfo.realName
          param.userMobile = this.queryInfo.userMobile
          param.size = this.queryInfo.size
          getPublicityList(param).then(res => {
            this.publicityList = res.records;
            this.total = res.total
            this.current = res.current
          })
        },
      }
      )
      this.addPublicityVisibel = false;
      })
    },
    //关闭之前
    addPublicityClose() {
      this.addPublicityVisibel = false;
    },
    detailsVisibleclose() {
      this.detailsVisible = false;
    },
    //分页方法
    handleCurrentChange(val) {
      this.queryInfo.current = val;
      this.search();
    },
    //公共宣传加载
    init() {
      let param = {}
      param.current = this.queryInfo.current
      param.size = this.queryInfo.size
      getPublicityList(param).then(res => {
        this.publicityList = res.records;
        this.total = res.total
      })
    },
    //查询
    search() {
      let param = {}
      param.realName = this.queryInfo.realName
      param.nickName = this.queryInfo.nickName
      param.size = this.queryInfo.size
      getPublicityList(param).then(res => {
        this.publicityList = res.records;
        this.total = res.total
        this.current = res.current
      })
    },
  }
}
</script>
@@ -327,4 +404,4 @@
::v-deep(.el-table thead) {
  color: #000000;
}
</style>
</style>