zhangzengfei
2021-02-04 0175cda6150656bc74b34c6f6c71edd1e1fc653c
src/pages/shuohuangMonitorAnalyze/components/memberManage.vue
@@ -7,20 +7,22 @@
        </el-input>
      </div>
      <el-tree
        ref="leftTreeNodes"
        :data="treeData"
        node-key="id"
        default-expand-all
        @node-click="checkNode"
        :expand-on-click-node="false"
        :check-on-click-node="true"
        :highlight-current="true"
        @node-click="checkNode"
        @node-contextmenu="nodeContextMenu"
      ></el-tree>
      <div class="menuList" v-show="showMenu" :style="{top:menuTop+'px',left:menuLeft+'px'}">
        <ul>
          <li>创建同级节点</li>
          <li>删除节点</li>
          <li>重命名节点</li>
          <li>关闭</li>
          <li @click="showMenu = false">关闭</li>
        </ul>
      </div>
    </div>
@@ -31,11 +33,12 @@
          <el-option
            v-for="item in genders"
            :key="item.id"
            :value="item.id"
            :value="item.name=='全部'?'':item.name"
            :label="item.name"
          >{{item.name}}</el-option>
        </el-select>
        <el-button type="primary" size="small" @click="dataSearch">查询</el-button>
        <el-button type="primary" size="small" @click="renderMemberTable">查询</el-button>
        <el-button type="primary" size="small" @click="resetFilter">重置</el-button>
      </div>
      <div class="table-area">
        <div class="actions">
@@ -65,7 +68,7 @@
          <el-table-column label="照片" prop="Surface">
            <template slot-scope="scope">
              <div class="table-cell-pic">
                <img :src="`${CLIP}${scope.row.Surface}`" alt />
                <img :src="`/httpImage/${scope.row.Surface}`" alt />
              </div>
            </template>
          </el-table-column>
@@ -96,17 +99,31 @@
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleTableSizeChange"
          @current-change="renderMemberTable"
          :current-page.sync="PageIndex"
          :page-size="PageSize"
          :page-sizes="pageSizes"
          layout="total,sizes, prev, pager, next"
          :total="tableTotal"
        ></el-pagination>
      </div>
    </div>
    <el-dialog
      :visible="memberEditDialogVisible"
      class="member-edit-dialog"
      :append-to-body="false"
      title="添加/编辑人员"
      @close="memberEditDialogVisible=false"
    >
      <div slot="title">
        <div class="title">
          <div class="main-title">{{memberEditForm.ID?'编辑人员':'添加人员'}}</div>
          <div class="subtitle">组织结构:{{curLeftTreeNode.label}}</div>
        </div>
      </div>
      <div class="text-center">
        <el-form :model="memberEditForm">
        <el-form :model="memberEditForm" :rules="memberEditFormRule" ref="memberForm">
          <el-form-item>
            <el-upload
              class="avatar-uploader"
@@ -125,23 +142,23 @@
          <el-form-item label="工号:" prop="WorkID">
            <el-input v-model="memberEditForm.WorkID" size="mini"></el-input>
          </el-form-item>
          <el-form-item label="照片标识:">
          <!-- <el-form-item label="照片标识:">
            <el-input v-model="memberEditForm.SurfaceName" size="mini"></el-input>
          </el-form-item>
          <el-form-item label="姓名:">
          </el-form-item>-->
          <el-form-item label="姓名:" prop="Name">
            <el-input v-model="memberEditForm.Name" size="mini"></el-input>
          </el-form-item>
          <el-form-item label="用户名:">
          <el-form-item label="用户名:" prop="UserName">
            <el-input v-model="memberEditForm.UserName" size="mini"></el-input>
          </el-form-item>
          <el-form-item label="性别:">
          <el-form-item label="性别:" prop="Sex">
            <el-radio v-model="memberEditForm.Sex" label="女">女</el-radio>
            <el-radio v-model="memberEditForm.Sex" label="男">男</el-radio>
          </el-form-item>
          <el-form-item label="身份证号:">
            <el-input v-model="memberEditForm.OwnerID" size="mini"></el-input>
          </el-form-item>
          <el-form-item label="手机号:">
          <el-form-item label="手机号:" prop="Tel">
            <el-input v-model="memberEditForm.Tel" size="mini"></el-input>
          </el-form-item>
          <div class="btns">
@@ -185,26 +202,22 @@
      title="批量导入"
      @close="batchImportDialogVisible=false"
    >
      <div class="text-left">
      <div>
        <p class="tip">
          *请提前根据文件模板中的要求收集人员信息,在一个文件夹中存放人员照片和EXCEL文件
          (
          <a
            href="javascript:;"
            @mouseover="showDemo=true"
            @mouseout="showDemo=false"
          >示例</a>),点击
          <a href="javascript:;">下载模板.excel</a>
          <img class="tip-demo" v-if="showDemo" :src="`${publicPath}images/shuohuang/tip.jpg`" alt />
        </p>
        <div class="flex-box">
          <label>上传文件:</label>
          <el-upload
            class="upload-demo batch-upload"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-remove="handleRemove"
            multiple
            :limit="3"
            :http-request="batchImportFiles"
            :on-exceed="handleExceed"
            :file-list="fileList"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip"></div>
          </el-upload>
          <p>
            *请按照此模板填写信息,点击下载模板
            <a href="javascript:;">.excel</a>
          </p>
          <label>上传文件夹:</label>
          <el-button size="mini" type="primary" @click="uploadDirectoryTrigger">点击上传</el-button>
          <input ref="directoryInput" @change="importDirectory" hidden type="file" webkitdirectory />
        </div>
        <el-table class="thbg" :data="batchImportTableData" fit>
          <el-table-column type="index" label="序号"></el-table-column>
@@ -212,15 +225,6 @@
          <el-table-column prop="time" label="上传时间"></el-table-column>
          <el-table-column prop="state" label="状态"></el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleTableSizeChange"
          @current-change="renderMemberTable"
          :current-page.sync="PageIndex"
          :page-size="PageSize"
          :page-sizes="pageSizes"
          layout="total,sizes, prev, pager, next"
          :total="tableTotal"
        ></el-pagination>
      </div>
    </el-dialog>
  </div>
@@ -228,21 +232,22 @@
<script>
import { getShuohuangDepartTree, getOrganizeTree, getMemberList, updateMemberInfo, addMember, updateUnit, uploadMemberPic } from '@/api/shuohuang'
import { getShuohuangDepartTree, getOrganizeTree, getMemberList, updateMemberInfo, addMember, updateUnit, uploadMemberPic, uploadDirectory, uploadFile } from '@/api/shuohuang'
export default {
  data () {
    return {
      publicPath: process.env.BASE_URL,
      CLIP: 'http://192.168.20.113/',
      treeWord: '',
      treeData: [],
      curLeftTreeNode: {},
      showMenu: false,
      deptId: '',
      menuTop: 0,
      menuLeft: 0,
      keyword: '',
      gender: '',
      genders: [{ name: '男', id: 'g0' }, { name: '女', id: 'g1' }],
      genders: [{id:'g3',name:'全部'},{ name: '男', id: 'g0' }, { name: '女', id: 'g1' }],
      tableData: [],
      multipleTableSelection: [],
      PageIndex: 1,
@@ -257,16 +262,43 @@
      batchImportDialogVisible: false,
      fileList: [],
      memberEditForm: {},
      memberEditFormRule: {
        Name: [{ required: true, message: '请输入姓名', trigger: 'change' }],
        UserName: [{ required: true, message: '请输入姓名', trigger: 'change' }],
        Sex: [{ required: true, message: '请选择性别', trigger: 'change' }],
        Tel: [{ validator: this.isPhone, trigger: 'change' }],
      },
      memberPicUrl: '',
      showDemo: false,
      batchImportTableData: [],
    }
  },
  mounted () {
    this.searchLeftTreeData();
    this.getOrganizeTreeData();
    this.renderMemberTable();
    //this.renderMemberTable();
  },
  methods: {
    resetFilter(){
      this.keyword = '';
      this.gender = '';
      this.renderMemberTable();
    },
    isPhone (rule, value, callback) {
      if (value.trim()) {
        var pattern = /^1[345789]\d{9}$/
        if (pattern.test(value)) {
          return callback()
        }
        return callback(new Error('输入的手机号错误'))
      }
    },
    nodeContextMenu (e, data, node, comp) {
      this.showMenu = true;
      this.menuTop = e.pageY;
      this.menuLeft = e.pageX;
    },
    checkOrgNode (a, b, c) {
      this.checkedOrg = a.id
    },
@@ -294,36 +326,44 @@
      this.multipleTableSelection = val;
    },
    memberSave () {
      if (this.memberEditForm.ID) {
        updateMemberInfo(this.memberEditForm).then(res => {
          if (res.success) {
            this.$notify({
              type: 'success',
              message: res.msg
            });
            this.memberEditDialogVisible = false;
            this.renderMemberTable();
          }
        })
      }else{
        addMember(this.memberEditForm).then(res=>{
          if(res.success){
            this.$notify({
              type:'success',
              message: res.msg
      this.$refs['memberForm'].validate((valid) => {
        if (valid) {
          let params = Object.assign({ DeptID: this.curLeftTreeNode.id }, this.memberEditForm);
          if (this.memberEditForm.ID) {
            updateMemberInfo(params).then(res => {
              if (res.success) {
                this.$notify({
                  type: 'success',
                  message: res.msg
                });
                this.memberEditDialogVisible = false;
                this.renderMemberTable();
                this.searchLeftTreeData();
              }
            })
            this.renderMemberTable();
          } else {
            addMember(params).then(res => {
              if (res.success) {
                this.$notify({
                  type: 'success',
                  message: res.msg
                })
                this.renderMemberTable();
                this.memberEditDialogVisible = false;
                this.searchLeftTreeData();
              }
            })
          }
        })
      }
        } else {
          return false;
        }
      })
    },
    delMember (member) {
      member.IsDel = true;
      member.IsDel = '1';
      this.memberUpdate(member);
    },
    editMember (member) {
      debugger
      this.memberEditDialogVisible = true;
      this.memberEditForm = member;
    },
@@ -335,11 +375,13 @@
            message: res.msg
          });
          this.renderMemberTable();
          this.searchLeftTreeData();
        }
      })
    },
    checkNode (a, b, c) {
      if (a.children) {
      if (a.hasOwnProperty('children')) {
        this.curLeftTreeNode = a;
        this.deptId = a.id;
        this.renderMemberTable();
      }
@@ -352,22 +394,36 @@
      let _this = this;
      let params = {
        DeptID: this.deptId,
        keyword: this.keyword,
        Keyword: this.keyword,
        Sex: this.gender,
        PageIndex: this.PageIndex,
        PageSize: this.PageSize
      }
      getMemberList(params).then(res => {
        _this.tableData = res.data;
        _this.tableTotal = res.total;
      })
    },
    uploadPic () {
    },
    batchImportFiles () {
    uploadDirectoryTrigger () {
      this.$refs['directoryInput'].click();
    },
    importDirectory () {
      //this.$refs['directoryInput'].files //文件夹map
      let formData = new FormData;
      for (var file in this.$refs['directoryInput'].files) {
        formData.append('files', this.$refs['directoryInput'].files[file])
      }
      //formData.append('files', this.$refs['directoryInput'].files)
      uploadDirectory(formData).then(res => {
        debugger
      })
    },
    handleRemove () {
    },
@@ -384,20 +440,15 @@
      let param = new FormData();
      param.append('file', params.file)
      uploadMemberPic(param).then(res => {
        this.$set(this.memberEditForm,'Surface',res.data)
        this.$set(this.memberEditForm, 'Surface', res.data)
      })
    },
    openMenuList (t, l, frame) {
      this.showMenu = true;
      this.menuTop = t;
      this.menuLeft = l;
    },
    closeMenuList () {
      this.showMenu = false;
    },
    deepNodeChildren (node) {
      var arr1 = [];
      var arr2 = [];
      if (node.ChildDept && node.ChildDept.length > 0) {
        return node.ChildDept.map(child => {
        arr1 = node.ChildDept.map(child => {
          let childObj = {};
          childObj.id = child.ID;
          childObj.label = child.Name;
@@ -410,8 +461,9 @@
          }
          return childObj;
        });
      } else if (node.UserLst && node.UserLst.length > 0) {
        return node.UserLst.map(child => {
      }
      if (node.UserLst && node.UserLst.length > 0) {
        arr2 = node.UserLst.map(child => {
          let childObj = {};
          childObj.id = child.ID;
          childObj.label = child.Name;
@@ -419,6 +471,7 @@
          return childObj;
        });
      }
      return arr1.concat(arr2)
    },
    getOrganizeTreeData () {
      let _this = this;
@@ -443,15 +496,24 @@
          obj.Status = item.Status;
          obj.children = _this.deepNodeChildren(item);
          return obj
        });
        this.$nextTick(() => {
          if (!Object.keys(_this.curLeftTreeNode).length) {
            _this.curLeftTreeNode = _this.treeData[0];
            _this.$refs['leftTreeNodes'].setCurrentNode(_this.treeData[0]);
          } else {
            _this.$refs['leftTreeNodes'].setCurrentNode(_this.curLeftTreeNode);
          }
          _this.checkNode(_this.curLeftTreeNode);
        })
      })
    },
    addMember () {
      this.memberEditDialogVisible = true;
      this.memberEditForm = {};
    },
    dataSearch () {
    }
  }
}
</script>
@@ -491,9 +553,27 @@
    .el-dialog {
      width: 500px;
      padding: 0 30px;
      .el-dialog__header {
        .title {
          display: flex;
          align-items: flex-end;
          justify-content: center;
          .main-title {
            font-size: 16px;
            padding-right: 10px;
          }
          .subtitle {
            font-size: 14px;
            color: #666;
          }
        }
      }
      .el-form-item {
        .el-form-item__label {
          width: 100px;
        }
        .el-form-item__error {
          left: 120px;
        }
      }
    }
@@ -513,13 +593,31 @@
      }
    }
  }
  .batch-import-dialog {
    .el-dialog__body {
      padding: 14px 20px;
    }
    .tip {
      text-align: left;
      margin-bottom: 10px;
      position: relative;
      .tip-demo {
        position: absolute;
        width: 530px;
        z-index: 1000;
        top: -10px;
        left: 20px;
      }
    }
  }
  .menuList {
    background: #fff;
    position: absolute;
    z-index: 100;
    width: 180px;
    text-align: left;
    border: 1px solid #ccc;
    border: 1px solid #ddd;
    box-shadow: 4px 4px 3px 0px rgba(0, 0, 0, 0.1);
  }
  .menuList li {
    line-height: 28px;
@@ -528,7 +626,7 @@
    background: #fff;
  }
  .menuList li:hover {
    background: rgba(152, 170, 190, 0.7);
    background: #ecf0fc;
  }
  .right {
    padding-left: 20px;