<template>
  <div class="custom-dialog-wrap">
    <el-dialog title="员工个人详情页展示字段设置" :visible.sync="customDialog" width="761px" :before-close="handleCardClose">
      <div class="custom-dialog__title">
        <p class="custom-dialog__p">tips：添加后的字段将在员工个人详情页展示出来，个人敏感信息不建议添加</p>
      </div>
      <div class="custom-dialog-body">
        <template v-for="(item,index) in customData">
          <div class="detail-field-cell flex" :key="index">
            <div class="detail-field-left">{{item.name}}</div>
            <div class="detail-field-right flex">
              <el-checkbox-group class="flex flex-wrap" v-model="item.checkList" @change="customChange">
                <el-checkbox v-for="(childItem,childIndex) in item.childList" :label="childItem.id" :key="childItem.id" name="type">{{childItem.name}}</el-checkbox>
              </el-checkbox-group>
            </div>
          </div>
        </template>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="customCancel">取 消</el-button>
        <el-button type="primary" @click="customConfirm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import { getRequest, postRequest, postJsonRequest } from '@/api/api';
  import showMsg from '@/common/js/showmsg';
  import errMsg  from '@/common/js/error';
  import qs from 'qs';
  export default {
    name: 'staff-detail-field',
    props: {
      showCustomDialog: {
        type: Boolean,
        default: false
      }
    },
    data () {
      return {
        repProjectName: 'gic-web', // 项目名
        customDialog: false, // 弹框显示
        // 复选框数据
        customData: [
          {
            id: 1,
            name: "基本信息",
            checkList: [],
            childList: [
              {
                id: 'name',
                name: '姓名'
              },
              {
                id: 'depart',
                name: '部门'
              },
              {
                id: 'phone',
                name: '手机号'
              },
              {
                id: 'email',
                name: '邮箱'
              },
              {
                id: 'profession',
                name: '职业'
              },
              {
                id: 'hiredate',
                name: '入职时间'
              },

            ]
          },
          {
            id: 2,
            name: "工作信息",
            checkList: [],
            childList: [
              {
                id: 'name',
                name: '姓名'
              },
              {
                id: 'depart',
                name: '部门'
              }
            ]
          },
          {
            id: 3,
            name: "个人信息",
            checkList: [],
            childList: [
              {
                id: 'name',
                name: '姓名'
              },
              {
                id: 'depart',
                name: '部门'
              },
            ]
          },
          {
            id: 4,
            name: "学历信息",
            checkList: [],
            childList: [
              {
                id: 'name',
                name: '姓名'
              },
              {
                id: 'depart',
                name: '部门'
              },
            ]
          },

        ],
        checkList: [], //已选数据

        // 获取 location origin
        baseUrl: '',
      }
    },
    beforeMount() {
      const that = this
      var host = window.location.origin;
      console.log("当前host:",host)
      if (host.indexOf('localhost') != '-1') {
        that.baseUrl = 'http://gicdev.demogic.com';
      }else {
        that.baseUrl = host
      }
    },
    methods:{

      /**
       * 关闭
       */
      handleCardClose() {
        const that = this;
        that.customCancel();
      },

      /**
       * 取消
       */
      customCancel() {
        const that = this;
        that.customDialog = false
        that.$emit('customHandleConfirm')
      },

      /**
       * 确定
       */
      customConfirm() {
        const that = this;
        // console.log(that.customData)
        that.$emit('customHandleConfirm')
      },

      /**
       * 复选框选择事件
       */
      customChange(value) {
        const that = this
        console.log(value)
      },

       /**
       * 获取已经勾选
       */
      getCardList() {
        const that = this
        var para = {
          requestProject: that.repProjectName
        }
        that.axios.post(that.baseUrl+'/api-plug/get-coupon-list',qs.stringify(para))
        .then((res) => {
          console.log(res,res.data,res.data.errorCode)
          var resData = res.data
          if (resData.errorCode == 0) {

            return;
          }
          that.$message.error({
            duration: 1000,
            message: resData.message
          })

        })
        .catch(function (error) {
          console.log(error);
          // that.toLogin()
          that.$message.error({
            duration: 1000,
            message: error.message
          })
        });
      },

      formatDate(time,flag) {
        const that = this
        //  (0-9)年月数字的显示
        function formatDig(num) {
          return num > 9 ? '' + num : '0' + num;
        }
        var myDate = new Date(time);
        let y = myDate.getFullYear();
        let m = myDate.getMonth()+1;
        let d = myDate.getDate();
        return y + flag + formatDig(m) + flag + formatDig(d) + flag
      }

    },
    watch: {
      showCustomDialog: function(newData,oldData){
        const that = this;
        console.log("新数据:",newData,oldData)
        that.customDialog = newData
      },
    },

    /* 接收数据 */
    mounted(){
      console.log("传递的参数对象:",this.showCustomDialog)
      const that = this;
      that.customDialog = that.showCustomDialog
    },

  }
</script>

<style lang="scss" scoped>
  .custom-dialog {
    &-body {
      width: 100%;
      height: 410px;
      padding: 5px 0 22px 0;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      overflow-y: auto;
    }
    &-wrap {
      .border-box {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
      }

      /* display */
      .inline-block {
        display: inline-block;
      }

      .block {
        display: block;
      }

      .top {
        vertical-align: top;
      }

      .middle {
        vertical-align: middle;
      }

      /* flex */
      .flex {
        display: -webkit-box;
        display: -webkit-flex;
        display: -ms-flexbox;
        display: flex;
      }

      .flex-1 {
        -webkit-box-flex: 1;
        -webkit-flex: 1;
        -ms-flex: 1;
        flex: 1;
      }

      .flex-column {
        -webkit-flex-direction: column;
        -moz-flex-direction: column;
        -ms-flex-direction: column;
        -o-flex-direction: column;
        flex-direction: column;
      }

      .flex-row {
        -webkit-flex-direction: row;
        -moz-flex-direction: row;
        -ms-flex-direction: row;
        -o-flex-direction: row;
        flex-direction: row;
      }

      .flex-align-center {
        -webkit-box-align: center;
        -webkit-align-items: center;
        -ms-flex-align: center;
        align-items: center;
      }

      .flex-pack-center {
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        -ms-flex-pack: center;
        justify-content: center;
      }

      .flex-between {
        -webkit-justify-content: space-between;
        justify-content: space-between;
      }

      .flex-wrap {
        -webkit-flex-wrap: wrap;
        -moz-flex-wrap: wrap;
        -ms-flex-wrap: wrap;
        -o-flex-wrap: wrap;
        flex-wrap: wrap;
      }

      .detail-field {
        &-cell {
          width: 100%;
          margin-top: 24px;
          .el-checkbox {
            min-width: 25%;
            margin-bottom: 24px;
            &+.el-checkbox {
              margin-left: 0;
            }

            &.is-checked {
              /deep/ .el-checkbox__label{
                color: #1890ff;
              }
            }
          }
        }

        &-left {
          width: 100px;
          padding-top: 4px;
        }
        &-right {
          width: calc(100% - 100px);

          .el-checkbox-group {
            width: 100%;

          }
        }
      }
    }

    &__title {
      width: 100%;
      height:38px;
      padding: 12px 15px;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      background:rgba(235,238,245,1);
    }

    &__p {
      width: 100%;
      font-size: 14px;
      color: #606266;

      span {
        color: #1890ff;
      }
    }

    &__checkbox {
      width: 100%;
      height: 410px;
      padding-top: 10px;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      overflow-y: auto;

      .el-checkbox {
        width: 22%;
        margin-left: 16px;
        line-height: 62px;
      }
    }


  }
</style>
