<template>
  <div class="template-open-wrap">
      <bread-crumb :curmbFirst="curmbFirst" :curmbSecond="curmbSecond" :curmbThird="curmbThird"></bread-crumb>
    
      <div class="add-content screenSet" id="screenSet">
        <div class="top-lin"></div>
        <el-row class="step-content">
          <el-col :span="14">
            <el-steps :active="active" simple class>
              <span class="step-num" v-bind:class="{ 'on-step': active==0 }">1</span>
              <el-step title="选择项目模板">1</el-step>
              <span class="step-num" v-bind:class="{ 'on-step': active==1 }">2</span>
              <el-step title="填写项目信息">2</el-step>
              <span class="step-num" v-bind:class="{ 'on-step': active==2 }">3</span>
              <el-step title="选择学员范围">3</el-step>
            </el-steps>
          </el-col>
          <el-col :span="5" :offset="5">
            <el-button v-if="!canNext" size="small" type="info" plain>下一步</el-button>
            <el-button v-if="active!==2 && canNext" size="small" type="primary" @click="nextStep">下一步</el-button>
            <el-button v-if="active==2" size="small" type="primary" @click="complete">完成</el-button>
          </el-col>
        </el-row>
        <div v-if="active == 0" class="tpl-main">
           <template-list @checkFn="checkFn"></template-list>
        </div>
        <!-- 模板列表 -->
       

        <!-- 填写项目信息-->
        <base-message
         ref="baseMessage"
          v-if="active == 1 && formData"
          :formData="formData"
          :projectManger="projectManger"
        />
      
         <!-- 选择学员 -->
        <div class="three-step" v-else-if="active === 2">
          <el-tabs v-model="activeName" @tab-click="handleClickTabs">
            <el-tab-pane label="设定行政范围" name="first">
              <select-region @setRegion="setRegion"></select-region>
            </el-tab-pane>
            <el-tab-pane label="设定机构" name="second">
              <set-Organization ></set-Organization>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
  </div>
</template>

<script>
import BreadCrumb from "../../components/breadcrumb.vue";
import baseMessage from "../../components/education/template/baseMessage";
import selectTemplate from "../../components/education/template/selectTemplate";
import selectRegion from "../../components/education/template/selectRegion";
import setOrganization from "../../components/education/template/setOrganization";
import templateList from "../../components/education/template/templateList";
import { openLoading, closeLoading } from "../../utils/utils";
import * as commonUtil from "../../utils/utils";
let vm = null;
export default {
  data() {
    return {
      curmbFirst: "教培项目",
      curmbSecond: "项目管理",
      curmbThird: '发起项目',
      active: 0,
      fished: false,
      projectManger: true,
      formData: {
        projectName: "",
        projectBegintime: "",
        projectEndtime: "",
        projectIntro: "",
        type: 1,
        useTime: "",
        xueke: "",
        attachmentUrl1: "",
        attachmentUrl2: "",
        attachmentUrl3: "",
        attachmentMore1: {},
        attachmentMore2: {},
        scopeType: 0,
        organizationName: "",
        organizationNameList: [''],
        sendOption: 1,
        receiveOption: 1,
        visibleFlag: 1,
        learnableFlag: 2,
        authorityType: 1,
        allowLearn: 2,
        richContent: ''
      },
      formTemplate: {
        component: [],
        configure: 2,
        certificate: ""
      },
      activeName: "first",
      canNext: false,
      openTemplateId: '',
      r: []//设定行政范围和设定机构相互影响的行政范围
    }
  },
  components: {
    BreadCrumb,
    baseMessage,
    selectTemplate,
    selectRegion,
    setOrganization,
    templateList
  },
  created() {
    vm = this;
  },
  mounted() {
    commonUtil.resizeHeight();
  },
  methods: {
    // 下一步
    nextStep() {
      // let flag = this.$refs.baseMessage.nextStep();
      // if (!flag) {
      //   return;
      // }
      this.active++;
      if (this.active == 1) {
        this.fished = true;
      }
    },
    complete() {
      console.log('完成');
    },
     //切换tabs
    handleClickTabs(tab, event) {
      // this.activeName = tab.name;
    },
    // 模板列表选中
    checkFn(id) {
      this.canNext = true;
      this.openTemplateId = id;
    },
    //选中模板后点击下一步时检测(机构和进行中的项目)
    checkSelectTemplate() {
      openLoading(vm);
      vm.GET(`portal/openTemplateProject/checkAfterSelectOneOpenTemplate/${vm.openTemplateId}`)
        .then(res => {
          closeLoading(vm);
          if (res.code == "000000") {
            console.log()
          } else {
            vm.$message.info(res.message);
          }
        })
        .catch((err) => {
          closeLoading(vm);
          vm.$message.warning('请稍后重试');
        });
    },
    // 设定行政范围和设定机构范围相互影响
    setRegion(r) {
      this.r = r;
      console.log('====================================');
      console.log(r);
      console.log('====================================');
    }
  }
}
</script>

<style lang="scss">
.template-open-wrap {
  .el-step.is-simple:not(:last-of-type) .el-step__title {
    max-width: 100%;
  }
  .top-lin {
    position: fixed;
    height: 30px;
    background: #F0F2F5;
    right: 30px;
    left: 285px;
    z-index: 1001;
    top: 125px;
  }
  .step-content {
    background: #fff;
    z-index: 1001;
    background: #fff;
    position: fixed;
    right: 30px;
    left: 285px;
    overflow: hidden;
    height: 60px;
    // margin-top: 66px;
    padding: 15px 0 50px 0;
    border-bottom: 1px solid #efefef;
    background: #fff;
    .is-text {
      display: none;
    }
    .el-steps--simple {
      background: #fff;
    }
    .button-green {
      color: #ffffff;
      background: #449284;
      border-color: #bfdad5;
      border-radius: 2px;
    }
    .button-white {
      color: #606266;
      background: #ffffff;
      border-color: #ecedf1;
      border-radius: 2px;
    }
    .step-num {
      display: block;
      // margin-top: 1.5px;
      font-size: 12px;
      border: 1px solid #999 !important;
      border-radius: 50%;
      width: 25px;
      height: 18px;
      line-height: 16px;
      text-align: center;
      color: #999;
    }
    .el-step__title.is-wait {
      color: #999;
    }
    .el-step__title.is-process {
      color: #449284;
    }
    .is-finish {
      color: #999 !important;
    }
    .on-step {
      color: #449284;
      border: 1px solid #449284 !important;
    }
  }
  .add-content {
    background: #fff;
  }
  .three-step {
    padding-top: 64px;
    margin: 10px 0 0 20px;
    .area-p {
      margin-bottom: 15px;
      font-size: 14px;
    }
    .span_ecology {
      line-height: 45px;
      margin-left: 8px;
    }
    .dialog-p {
      text-align: center;
      span {
        color: #449284;
      }
    }
    //隐藏树展开
    .table-empty {
      img {
        width: 100px;
      }
      p {
        margin-top: -50px;
      }
    }
    .el-tree-node__expand-icon {
      display: none;
    }
    .department {
      margin-top: 20px;
      border: 1px solid #dddddd;
    }
    .el-tabs__nav-wrap::after {
      display: none;
    }
    .el-tabs__active-bar {
      display: none;
    }
    #tab-first,
    #tab-second,
    #tab-third {
      padding-right: 0px;
    }
    #tab-first::after {
      color: #c7cbd2;
      margin-left: 20px;
      content: "•";
    }
    .el-tabs__item.is-active {
      color: #fff;
    }
    .el-tag {
      margin: 0 10px 10px 0;
      border: 1.3px solid #48a8fe;
      color: #1e92fe;
      background-color: #e7f6fe;
      .el-icon-close {
        width: 13px;
        height: 13px;
        line-height: 13px;
        font-size: 12px;
        background-color: #0486fe;
        border-radius: 50%;
        color: #d4edfe;
      }
    }
    .down-button {
      margin-left: 10px;
    }
    .down-button-close {
      margin-left: 100px;
      float: left;
    }
    .dialog-success {
      p {
        text-align: center;
        .upload-text{
          color: #449284;
        }
      }
    }
    .dialog-fail {
      .fail-type {
        p {
          margin-top: 10px;
        }
        .fail-num {
          color: #db3f52;
        }
        .fail-notice {
          color: #e3e3e3;
          font-size: 13px;
        }
        .fail-link {
          text-align: center;
          color: #449284;
          cursor: pointer;
        }
      }
    }
    
  }
  .tpl-main {
    padding-top: 60px;
  }
}
</style>
