<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">请选择您想在首页展示的快捷操作，最多勾选8，已经勾选了<span>{{checkList.length}}</span>个</p>
      </div>
      <div class="custom-dialog__checkbox">
        <el-checkbox-group v-model="checkList" @change="customChange" :max="8">
          <el-checkbox v-for="item in customData" :label="item.id" :key="item.id" name="type">{{item.name}}</el-checkbox>
        </el-checkbox-group>
      </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: 'custom-dialog',
    props: {
      showCustomDialog: {
        type: Boolean,
        default: false
      }
    },
    data () {
      return {
        repProjectName: 'gic-web', // 项目名
        customDialog: false, // 弹框显示
        // 复选框数据
        customData: [
          {
            id: 1,
            name: "通讯录行政架构",
          },
          {
            id: 2,
            name: "通讯录门店架构",
          },
          {
            id: 3,
            name: "员工档案",
          },
          {
            id: 4,
            name: "共享通讯录",
          },
          {
            id: 5,
            name: "企业应用",
          },
          {
            id: 6,
            name: "我的企业",
          },
          {
            id: 7,
            name: "企业地址",
          },
          {
            id: 8,
            name: "企业认证设置",
          },
          {
            id: 9,
            name: "员工详情设置",
          },
          {
            id: 10,
            name: "门店权限设置",
          },
          {
            id: 11,
            name: "设置子管理员",
          },
          {
            id: 12,
            name: "更换超级管理员",
          },
          {
            id: 13,
            name: "行政架构添加部门",
          },
        ],
        checkList: [], //已选数据

        // 获取 location origin
        baseUrl: '',
      }
    },
    beforeMount() {
      var 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() {
        var that = this;
        that.customCancel();
      },

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

      // 确定
      customConfirm() {
        var that = this
        that.$emit('customHandleConfirm')
      },

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

      // 获取已经勾选
      getCardList() {
        var 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) {
        var 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){
        var that = this;
        console.log("新数据:",newData,oldData)
        that.customDialog = newData
      },
    },

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

  }
</script>

<style lang="scss" scoped>
  .custom-dialog {
    &-wrap {

    }

    &__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: 300px;
      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;
        &.is-checked {
          /deep/ .el-checkbox__label{
            color: #1890ff;
          }
        }
      }
    }
  }
</style>
