<template>
  <div class="app-container">
    <div style="background-color: #fff;padding: 20px;border-radius: 10px;">
      <p style="margin: 0; font-weight: 800;font-size: 16px;color: #343434;display: flex;align-items: center;margin-bottom: 20px;">
        <img src="../../../assets/images/icon_htgl_btzs.png" alt="" style="width: 16px;height: 20px;">
       <span style="margin-left: 10px;">员工管理</span>
      </p>
      <div style="background: #F3F3F3;padding: 20px 15px; padding-bottom: 0;margin-bottom: 20px;">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
          <el-row>
            <el-col :span="24">
              <el-col :span="8">
                <el-form-item label="员工姓名" prop="staffName">
                        <el-input
                          v-model="queryParams.staffName"
                          placeholder="请输入员工姓名"
                          clearable
                          @keyup.enter.native="handleQuery"
                        />
                      </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="员工类别" prop="staffCategory">
                        <el-select v-model="queryParams.staffCategory" placeholder="请选择员工类别" clearable>
                          <el-option
                            v-for="dict in dict.type.yaungong"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                          />
                        </el-select>
                      </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="维修分类" prop="maintenanceCategory">
                        <el-select v-model="queryParams.maintenanceCategory" placeholder="请选择维修分类" clearable>
                          <el-option
                            v-for="dict in dict.type.weixiutype"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                          />
                        </el-select>
                      </el-form-item>
              </el-col>
            </el-col>
            <el-col :span="24">
              <el-col :span="8">
                 <el-form-item label="手机号码" prop="phoneNumber">
                        <el-input
                          v-model="queryParams.phoneNumber"
                          placeholder="请输入手机号码"
                          clearable
                          @keyup.enter.native="handleQuery"
                        />
                      </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item class="butt bnjle">
                  <el-button size="mini" type="primary"   @click="handleQuery">搜索</el-button>
                  <el-button size="mini"   @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-col>
            </el-col>
          </el-row>

        </el-form>
      </div>


      <div class="casr "  >
              <el-row :gutter="10" class="mb8" >
                <!-- <el-col :span="1.5">
                  <div style="font-weight: bold;font-size: 14px;color: #343434; display: flex;align-items: center;">
                    当夜全选
                  </div>
                </el-col> -->
                <el-col :span="1.5">
                  <el-button
                    type="primary"
                    plain
                    size="mini"
                    @click="handleAdd"
                    v-hasPermi="['wuYe:staffManage:add']"
                  >添加</el-button>
                </el-col>
                <!-- <el-col :span="1.5">
                  <el-button
                    type="success"
                    plain
                    size="mini"
                    :disabled="single"
                    @click="handleUpdate"
                    v-hasPermi="['system:post:edit']"
                  >修改</el-button>
                </el-col>
                <el-col :span="1.5">
                  <el-button
                    type="danger"
                    plain
                    size="mini"
                    :disabled="multiple"
                    @click="handleDelete"
                    v-hasPermi="['system:post:remove']"
                  >删除</el-button>
                </el-col> -->
                <el-col :span="1.5">
                  <el-button
                    type="warning"
                    plain
                    size="mini"
                    @click="handleExport"
                    v-hasPermi="['wuYe:staffManage:export']"
                  >导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
              </el-row>
              <div class="infinite-list" :style="dynamicStyle">
                <el-row :gutter="10" v-if="staffManageList.length !=0" style="width: 100%;margin-left: 0;">
                  <el-col :span="6" v-for="(item,index) in staffManageList" :key="index" >
                    <div v-if="isshoe"  :class=" item.isnum ==true ? 'ingwe' :'' " style="position: relative; background-color: #fff;box-shadow: 0px 0px 10px 0px #CDCDCD;border-radius: 4px;margin-bottom: 10px;">
                      <!-- @click="isac(item)" -->
                      <div style="display: flex; align-items: center;padding: 15px 20px;">
                        <img src="../../../assets/images/icon_htgl_rygl_tx_nv.png" alt="" style="width: 50px;height: 50px;border-radius: 50%;" v-if="item.avatarPhoto ==  null">
                         <image-preview :src="item.avatarPhoto" :width="50" :height="50" v-if="item.avatarPhoto !=  null" style="border-radius: 50%;"/>
                        <span style="font-weight: bold;font-size: 16px;color: #161616;margin-left: 15px;">{{item.staffName == null? '暂无数据' : item.staffName}}</span>
                        <img src="../../../assets/images/pic_htgl_wxrygl_yhlx_kx.png" alt="" style="width: 73px;height: 24px;position: absolute;right: 0;top: 15px;" v-if="item.status == 1">
                        <!-- <img src="../../../assets/images/pic_htgl_wxrygl_yhlx_zp.png" alt="" style="width: 73px;height: 24px;position: absolute;right: 0;top: 15px;"> -->
                      </div>
                      <div class="goe renyuangs" style="padding: 0 20px;">
                        <div style="margin-bottom: 10px;">
                          人员类别：<dict-tag :options="dict.type.yaungong" :value="item.staffCategory"/>
                        </div>
                        <div>维修类别：<dict-tag :options="dict.type.weixiutype" :value="item.maintenanceCategory"/></div>
                        <p>
                          手机号码：{{item.phoneNumber == null? '暂无数据' : item.phoneNumber}}
                        </p>
                        <p>
                          身份证号：{{item.idCard == null? '暂无数据' : item.idCard}}
                        </p>
                      </div>
                      <div class="bortt tongty" style="justify-content: space-between;cursor: pointer;">
                        <p ><span  v-hasPermi="['wuYe:staffManage:edit']" @click="handleUpdate(item)">修改</span>  </p>
                        <!-- <span @click="handleUpdatef(item)">查看</span> -->
                        <p v-hasPermi="['wuYe:staffManage:remove']" style="border-left: 1px solid #DADADA;color:red" @click="handleDelete(item)">删除</p>
                      </div>
                      <img v-if="item.isnum == true" src="../../../assets/images/icon_htgl_kp_gx.png" alt="" style="width: 35px;height: 35px;position: absolute;bottom: 0;right: 0;">
                    </div>
                  </el-col>
                </el-row>
                <div style="margin-top: 20px;display: flex;justify-content: center;align-items: center;" v-if="staffManageList.length ==0">
                   <img   src="../../../assets/images/zwshjbig.png" alt="" style="">
                </div>
              </div>
      </div>


      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <!-- 添加或修改岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="640px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="24" class="ngeshimg" >
            <el-form-item label="身份证号" prop="idCard" style="position: relative;">
                  <el-input v-model="form.idCard" placeholder="请输入身份证号码" />
                  <!-- <image-upload :limit="1" v-model="form.idCardBack"/> -->
                  <image-uploadshib @uploadedSuccessfully="uploadedSuccessfully" :typeg = "1" :limit="1" v-model="form.idCardBack"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工性别" prop="gender">
                      <el-select v-model="form.gender" placeholder="请选择员工性别">
                        <el-option
                          v-for="dict in dict.type.gender"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工类别" prop="staffCategory">
                      <el-select v-model="form.staffCategory" placeholder="请选择员工类别">
                        <el-option
                          v-for="dict in dict.type.yaungong"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维修分类" prop="maintenanceCategory">
                      <el-select clearable v-model="form.maintenanceCategory" placeholder="请选择维修分类">
                        <el-option
                          v-for="dict in dict.type.weixiutype"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="phoneNumber">
                <el-input v-model="form.phoneNumber" placeholder="请输入手机号码" />
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item label="员工姓名" prop="staffName">
                      <el-input v-model="form.staffName" placeholder="请输入员工姓名" />
            </el-form-item>
          </el-col>

          <el-col :span="12" class="shefnze" >
              <el-form-item label="头像" prop="avatarPhoto">
            <image-upload :limit="1" v-model="form.avatarPhoto"/>
          </el-form-item>
            </el-col>
          <el-col :span="12" class="shefnze">
             <el-form-item label="身份证国徽面" prop="idCardFront">
               <image-upload :limit="1" v-model="form.idCardFront"/>
             </el-form-item>
          </el-col>

          <el-col :span="24" >
              <el-form-item label="相关证件" prop="certificate">
                        <file-upload v-model="form.certificate"/>
             </el-form-item>
          </el-col>
        </el-row>



      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStaffManage, getStaffManage, delStaffManage, addStaffManage, updateStaffManage } from "@/api/wuguan/staffManage";
import 'videojs-flash'
export default {
   name: "StaffManage",
    dicts: ['yaungong', 'gender', 'technician_selection','weixiutype'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工管理表格数据
      staffManageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
               pageSize: 10,
               staffName: null,
               gender: null,
               staffCategory: null,
               maintenanceCategory: null,
               phoneNumber: null,
               avatarPhoto: null,
               idCard: null,
               idCardFront: null,
               idCardBack: null,
               certificate: null,
               status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        staffName: [
                  { required: true, message: "员工姓名不能为空", trigger: "blur" }
                ],
                staffCategory: [
                  { required: true, message: "员工类别，1：保安 2:维修人员 3：物业管理不能为空", trigger: "change" }
                ],

                phoneNumber: [
                  { required: true, message: "手机号码不能为空", trigger: "blur" }
                ],
      },
      activeName:'first',
      videoState: false, // 视频播放状态
      poster:true,
      controls:true,
      videoData:{},
       player: null,
       isshoe:true,
       tableMaxHeight:'200',
    };
  },

  computed: {
    dynamicStyle() {
      return {
        overflow:'auto',
        height: this.tableMaxHeight+ 'px',
        paddingTop:'10px'
      }
    }
    },

  created() {
    this.getList();
  window.onresize = () => {
  	      this.changeTableMaxHeight()
  	    }
  	    this.changeTableMaxHeight()
  },
  mounted() {
  	window.onresize = () => {
  	          this.changeTableMaxHeight()
  	        }
  	        this.changeTableMaxHeight()
  },
  beforeDestroy() {
      if (this.player) {
        this.player.dispose()
      }
    },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;

      listStaffManage(this.queryParams).then(response => {
        this.staffManageList  = response.rows;
        this.staffManageList .filter(rou=>{
          rou.isnum = false
        })
        // this.getge(this.postList)
        this.total = response.total;
        this.loading = false;
      });
    },
    getInfo(idCard) {
            let sex = null;
            let birth = null;
            let myDate = new Date();
            let month = myDate.getMonth() + 1;
            let day = myDate.getDate();
            let age = 0;

            if (idCard.length === 18) {
              age = myDate.getFullYear() - idCard.substring(6, 10) - 1;
              sex = idCard.substring(16, 17);
              birth = idCard.substring(6, 10) + "-" + idCard.substring(10, 12) + "-" + idCard.substring(12, 14);
              if (idCard.substring(10, 12) < month || idCard.substring(10, 12) === month && idCard.substring(12, 14) <= day)
                age++;

            }
            if (idCard.length === 15) {
              age = myDate.getFullYear() - idCard.substring(6, 8) - 1901;
              sex = idCard.substring(13, 14);
              birth = "19" + idCard.substring(6, 8) + "-" + idCard.substring(8, 10) + "-" + idCard.substring(10, 12);
              if (idCard.substring(8, 10) < month || idCard.substring(8, 10) === month && idCard.substring(10, 12) <= day)
                age++;
            }

            if (sex % 2 === 0)
              sex = 2; // 性别代码 1代表男，0代表女，暂时不涉及其他类型性别
            else
              sex = 1;
            return {
              age,
              sex,
              birth
            }
          },
     getBirthday(idCard) {
             let birthday = "";
             if (idCard != null && idCard !== "") {
               if (idCard.length === 15) {
                 birthday = "19" + idCard.substr(6, 6);
               } else if (idCard.length === 18) {
                 birthday = idCard.substr(6, 8);
               }
               birthday = birthday.replace(/(.{4})(.{2})/, "$1-$2-");
             }
             return birthday;
           },
    uploadedSuccessfully(row){
      // console.log('上传重构员工',row)
      if(row.length !=0){
        row.filter(ru=>{
          this.form.staffName = ru.realName
          this.form.idCard = ru.idCard
          let sge = this.getInfo( this.form.idCard)
          // this.form.yearsOld = sge.age
          this.form.gender = sge.sex + ''
          // this.form.residentBirthday = sge.birth
        })

      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
              staffId: null,
              staffName: null,
              gender: null,
              staffCategory: null,
              maintenanceCategory: null,
              phoneNumber: null,
              avatarPhoto: null,
              idCard: null,
              idCardFront: null,
              idCardBack: null,
              certificate: null,
              status: null,
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              remark: null
            };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.staffId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加员工管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
     this.reset();
           const staffId = row.staffId || this.ids
           getStaffManage(staffId).then(response => {
             this.form = response.data;
             this.open = true;
             this.title = "修改员工管理";
           });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
       if (valid) {
                 if (this.form.staffId != null) {
                   updateStaffManage(this.form).then(response => {
                     this.$modal.msgSuccess("修改成功");
                     this.open = false;
                     this.getList();
                   });
                 } else {
                   addStaffManage(this.form).then(response => {
                     this.$modal.msgSuccess("新增成功");
                     this.open = false;
                     this.getList();
                   });
                 }
        }
      });
    },
    /** 删除按钮操作 */
        handleDelete(row) {
          const staffIds = row.staffId || this.ids;
          this.$modal.confirm('是否确认删除员工管理编号为"' + staffIds + '"的数据项？').then(function() {
            return delStaffManage(staffIds);
          }).then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          }).catch(() => {});
        },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wuYe/staffManage/export', {
        ...this.queryParams
      }, `staffManage_${new Date().getTime()}.xlsx`)
    },

      handleClick(){

      },
    isac(val){
      console.log(5,val)
      val.isnum = !val.isnum
      this.isshoe = false
      this.isshoe = true
    },
    // 获取屏幕高度
    showFilterForm () {
          this.filterActive = !this.filterActive
          this.changeTableMaxHeight()
        },

        changeTableMaxHeight () {
          let height = document.body.offsetHeight // 网页可视区域高度
          // if (this.filterActive) {
          //   this.tableMaxHeight = height - 320
          // } else {
            this.tableMaxHeight = height - 150
          // }
          console.log(height)
        }

  }
};
</script>
<style  lang="scss">
  .shefnze{
    .el-upload--picture-card{
      width: 80px;
      height: 80px;
      line-height: 80px;
    }
    .el-upload-list--picture-card .el-upload-list__item{
      width: 80px;
      height: 80px;
    }
    .el-upload__tip{
      overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
  }
  .ngeshimg{
    .el-upload--picture-card{
      width: 36px;
      height: 36px;
      line-height: 36px;
      position: absolute;
      top:0;
      right: 0;
    }
    .component-upload-image{
      position: absolute;
      top:0;
      right: 0;
    }
    .el-upload--picture-card i{
      font-size: 20px;
    }
    .el-upload-list--picture-card .el-upload-list__item{
      width: 58px;
      height: 36px;
      position: absolute;
      top:0;
      right: -10px;
    }
  }
  .unimg{
    .el-upload--picture-card{
      width:102px;
      height: 102px;
      line-height: 102px;
    }
    .el-upload-list--picture-card .el-upload-list__item{
      width:102px;
      height: 102px;
      line-height: 102px;
    }
  }

  .bnjle{
    margin-left: 20px;
  }
  .butt{
    .el-button--small{
      padding: 9px 23px !important;
      font-size: 14px;
    }
  }
  .casr{
    .el-tabs__item.is-active{
      color: #196CFF;
    }
    .el-tabs--card > .el-tabs__header .el-tabs__item{
      padding: 0  30px !important;
    }
  }
  .el-table .el-table__header-wrapper th{
    background-color:#F5F6F8;
    color:#343434;
  }
  .el-table{
    color:#343434;
  }
</style>
<style scoped lang="scss">
  .goe{
    p{
      margin: 0;
      font-weight: 800;
      font-size: 16px;
      color: #161616;
      margin-top: 10px;
      margin-bottom: 3px;
      padding: 0 10px;
      overflow: hidden;
      text-overflow: ellipsis;
      display:-webkit-box; //作为弹性伸缩盒子模型显示。
      -webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
      -webkit-line-clamp:1; //显示的行
    }
    p:nth-child(2){

    }
  }
  .ingwe{
    border: 2px solid #196CFF;
  }
  .renyuangs{
    p{
      font-weight: 500;
      font-size: 14px;
      color: #161616;
      padding: 0;
    }
    div{
      font-weight: 500;
      font-size: 14px;
      color: #161616;
      height: 28px;
      // margin-bottom: 20px;
      display: flex;
    }
  }
  .tongty{
    display: flex;
    align-items: center;
  }
  .bortt{
    border-top: 1px solid #DADADA;
    margin-top: 15px;

    p{
      margin: 0;
      font-weight: bold;
      font-size: 14px;
      color: #5F8BF4;
      width:50%;
      padding: 10px;
      text-align: center;
    }
  }
  </style>


