<template>
  <!-- 测试上传组件 -->
  <div v-loading="loading" id="MakerActivityWord">
    <div class="pAHeader">
      <div class="pAHeader1">个人创客申请</div>
    </div>
    <hr>
       <!-- 创客专项资金及项目申请表（创客活动） -->
      <NomMarkerWord :wordData="wordData" :total="total"/>
      <el-button type="primary" @click="test">提交项目</el-button>
      <el-dialog
        title="提示"
        :visible.sync="submitHint"
        width="600px"
        class="pageSubmitData">
        <div class="addDialogLogo">LOGO</div>
        <div class="deleteContent">确定提交“{{wordData['activityName']}}”个人创客？</div>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="applyActivity" class="AllDialogBtn">确认提交</el-button>
          <el-button @click="submitHint=false" class="AllDialogBtn">取消</el-button>
        </span>
      </el-dialog>
  </div>
</template>

<script>
import NomMarkerWord from './components/NomMarkerWord.vue';
import {getNowDate} from '@/components/tool/Date.js'
import getProjectNo from '@/components/tool/getProjectNo';
export default {
  components: {
    NomMarkerWord
  },
  data() {
    return {
      loading:false,
      submitHint:false,
      wordData:{
        applicationDate:getNowDate(1),//申请日期
        // associatedProjects:"",//关联项目
        activityName:'',//项目名称
        pro_leader:"",//活动负责人
        college: '',//所在学院
        tel:'',//联系电话
        activityTime:"",//活动时间
        student:0,//参与学生人数
        member:[
          {name:"",collage:"",work:""},
          {name:"",collage:"",work:""},
          {name:"",collage:"",work:""},
          {name:"",collage:"",work:""},
          {name:"",collage:"",work:""},
        ],
        activityPlan:"",//活动计划
        expectations:"",//预期目标
        eventAudience:"",//活动受众面
        fundingPlan:"",//经费支出计划
        expenditureMothPlan:['','','','','','','','','','','',''],
        fund:{
          device:"",
          Material:"",
          processing:"",
          Collaboration:"",
          APPRAISAL:"",
          entery:"",
          activities:"",
          Transaction:"",
        },//预算经费
      }
    };
  },
  computed:{
    total() {
          let num = 0;
          for(let i in this.wordData['fund'])num += Number(this.wordData['fund'][i]);
          return num;
          // return (this.wordData.fund.facility*1 + this.wordData.fund.materials*1+this.wordData.fund.process*1+ this.input*1+this.wordData.fund.authenticate*1+ this.wordData.fund.match*1+this.wordData.fund.activity*1+this.wordData.fund.affair*1)/10000
        }
  },
  methods: {
    test(){
        const cEmpty = /^\s*$/g;
        const checkPhone = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/; //获取正则表达式 存放到verify变量中
        for(let i in this.wordData){
          switch(i){
            case "activityName":
              if(cEmpty.test(this.wordData[i])){
                this.$message.error("请输入活动名称")
                document.querySelector('#two').scrollIntoView({ behavior: "smooth" });
                return false;
              }
              break;
            case "pro_leader":
              if(cEmpty.test(this.wordData[i])){
                this.$message.error("请输入活动负责人")
                document.querySelector('#three').scrollIntoView({ behavior: "smooth" });
                return false;
              }
              break;
            case "college":
              if(cEmpty.test(this.wordData[i])){
                this.$message.error("请选择所在学院")
                document.querySelector('#three').scrollIntoView({ behavior: "smooth" });
                return false;;
              }
              break;
            case "tel":
              if(cEmpty.test(this.wordData[i])){
                this.$message.error("请输入联系电话")
                document.querySelector('#three').scrollIntoView({ behavior: "smooth" });
                return false;
              }else if(!checkPhone.test(this.wordData[i])){
                this.$message.error("请输入正确的手机号");
                document.querySelector('#three').scrollIntoView({ behavior: "smooth" });
                return false;
              }
              break;
            case "activityTime":
              if(cEmpty.test(this.wordData[i][0])){
                this.$message.error("请选择活动时间")
                document.querySelector('#four').scrollIntoView({ behavior: "smooth" });
                return false;;
              }
              break;
            case "member":
                let num = 0;
                this.wordData[i].forEach(item=>{
                  for(let j in item){
                    if(cEmpty.test(item[j])){
                      num++;
                    }
                  }
                
                })
                if(num>0){
                  this.$message.error("请填完指导老师信息");
                  document.querySelector('#five').scrollIntoView({ behavior: "smooth" });
                  return false;
                }
              break;
            case "activityPlan":
              if(cEmpty.test(this.wordData[i][0])){
                this.$message.error("请输入活动计划");
                document.querySelector('#six').scrollIntoView({ behavior: "smooth" });
                return false;
              }
              break;
            case "expectations":
              if(cEmpty.test(this.wordData[i][0])){
                this.$message.error("预期目标");
                document.querySelector('#seven').scrollIntoView({ behavior: "smooth" });
                return false;
              }
              break;
            case "eventAudience":
              if(cEmpty.test(this.wordData[i][0])){
                this.$message.error("活动受众面")
                document.querySelector('#nine').scrollIntoView({ behavior: "smooth" });
                return false;
              }
              break;
            case "fundingPlan":
              if(cEmpty.test(this.wordData[i][0])){
                this.$message.error("经费支出计划")
                document.querySelector('#ten').scrollIntoView({ behavior: "smooth" });
                return false;
              }
              break;
          }
        }
        this.submitHint = true;
    },
    applyActivity(){
      getProjectNo("HD").then(result=>{
        let pram = {
          uid:this.$store.state.userInfo.userid,//用户ID
          aNo:result,//活动编号
          tit:this.wordData['activityName'],//活动名称
          courseId:'',//关联项目ID
          pLeader:this.wordData['pro_leader'],//活动负责人
          mon:this.total,//预算经费
          st:this.wordData['student'],//参与学生人数
          ct:JSON.stringify(this.wordData['member']),//活动指导老师
          chp:JSON.stringify({
            activityPlan:this.wordData['activityName'],//活动计划
            expectations:this.wordData['expectations'],//预期目标
            eventAudience:this.wordData['eventAudience'],//活动受众面
            fundingPlan:this.wordData['fundingPlan'],//经费支出计划
          }),//活动信息
          cid:this.wordData['college'],//学院ID,
          ph:this.wordData['tel'],//联系电话
          beg:JSON.stringify(this.wordData['activityTime']),//活动时间
          f:JSON.stringify(this.wordData['fund']),//预算经费明细
          appltTime:this.wordData['applicationDate'],//申请日期
          mp:JSON.stringify(this.wordData['expenditureMothPlan']),
          t:1,//活动分类 1 个人创客
        }
        this.ajax.post(this.$store.state.api+'/ActivityApply',pram).then(result=>{
          if(result['data']==1){
            this.$message.success("活动提交成功");
            this.$router.push('/makerActvity');
          }else{
            this.$message.error("活动提交失败")
          }
        }).catch(err=>{
          console.log(err)
        })
      })
    },
  },
};
</script>

<style lang="less" scoped>
#MakerActivityWord{
width:100%;
display: flex;
flex-direction: column;
align-items: center;
}
</style>