<template>
  <d2-container class="page">
    <el-tabs value="first">
      <el-tab-pane label="转入省内" name="first">
        <div style="margin-bottom: 8px; border-left: 3px solid; color: rgb(230, 162, 60);">
          <div role="alert" class="el-alert el-alert--warning" v-if="timeLimit">
            <div class="el-alert__content">
              <span class="el-alert__title">外省转至省内办理时间：{{timeLimit.start_time}} 到 {{timeLimit.end_time}}</span>
             
            </div>
          </div>

           <div role="alert" class="el-alert el-alert--warning" v-if="auditTimeLimit">
            <div class="el-alert__content">
              <span class="el-alert__title">外省转至省内市级审核时间：{{auditTimeLimit.start_time}} 到 {{auditTimeLimit.end_time}}</span>
             
            </div>
          </div>

          <div role="alert" class="el-alert el-alert--warning" v-if="confirmTimeLimit">
            <div class="el-alert__content">
              <span class="el-alert__title">外省转至省内网上确认时间：{{confirmTimeLimit.start_time}} 到 {{confirmTimeLimit.end_time}}</span>
             
            </div>
          </div>

           <div role="alert" style="padding-top: 0px;padding-bottom: 0px;margin-top: 0px;margin-bottom: 0px;" class="el-alert el-alert--warning" v-if="ByTurnInApplyControl">
            <div class="el-alert__content" style="padding-top: 0px;padding-bottom: 0px;margin-top: 0px;margin-bottom: 0px;">
              <span class="el-alert__title" style="padding-top: 0px;padding-bottom: 0px;margin-top: 0px;margin-bottom: 0px;">{{ByTurnInApplyControl}}</span>
            </div>
          </div>
<!--
           <div role="alert" class="el-alert el-alert--warning" >
            <div class="el-alert__content">
              <a class="el-alert__title" style="color:red;font-size:16px;font-weight:600;cursor:pointer" @click="shouPlaces()">点击查看材料接受地点 </a>
             
            </div>
          </div>
-->
        </div>
        <!-- v-if="timeLimit && timeLimit.in_time" -->
        <div v-if="timeLimit && timeLimit.in_time">
          <!-- <el-button type="primary" @click="goApply()">申请转入</el-button> -->
        </div>
        <el-table
          v-loading="loading"
          :data="applyList"
          style="width: 100%">
          <el-table-column
            type="index"
             label="序号"
            width="50">
          </el-table-column>
            <el-table-column
            prop="year_time"
            label="批次"
            width="100">
          </el-table-column>
          <el-table-column
            prop="zk_in_zkz"
            label="本省准考证"
            width="120">
          </el-table-column>
          <el-table-column
            prop="zk_in_zy_dm"
            label="本省专业代码"
            width="110">
          </el-table-column>
          <el-table-column
            prop="zk_in_zy_mc"
            label="本省专业名称"
            width="140"
            >
          </el-table-column>
          
          <el-table-column
            prop="ks_zkz"
            label="外省准考证"
            width="120">
          </el-table-column>
          <el-table-column
            prop="zy_dm"
            label="外省专业代码 "
            width="120">
          </el-table-column>
          <el-table-column
            prop="zy_mc"
            label="外省专业名称"
            width="140">
          </el-table-column>
          <el-table-column
            prop="score"
            label="转入成绩"
            width="80">
            <template slot-scope="scope">
              <template>
                <a @click="showScore(scope.row)" style="color:blue;cursor:pointer;">成绩</a>
              </template>
            </template>
          </el-table-column>
        
          <el-table-column
            prop="status_text"
            label="状态"
            width="120">
          </el-table-column>
          <el-table-column
            prop="overtime"
            label="是否超时"
            width="90">
          </el-table-column>
           <el-table-column
            label="操作"
            fixed="right"
            width="120">
              <template slot-scope="scope">
               
                <div v-if="scope.row.status == 8 && scope.row.overtime != '已过期'"> 
                  <el-button @click="showTableDialog(scope.row)">网上确认</el-button>
                </div>
              </template>
          </el-table-column>
        </el-table>

<!--
        <div class="el-alert__content " style="padding-top:10px">
          <span class="el-alert__title">申请步骤：</span>
          <p class="el-alert__description">
            1 广西自考系统定时从国家平台接收转入申请单。
          </p>
          <p class="el-alert__description">
            2 考生在此页面查看转入申请单，存在申请单才能在广西区内办理转入业务。
          </p>
          <p class="el-alert__description">
            3 社会考生携带相关证明材料到就近市考办，具体办理时间请先打电话咨询各市考办，助学考生携带相关证明材料到主考学校，现场填写申请表。
          </p>
          <p class="el-alert__description">
            4 市考办或主考学校现场审核，上报考试院。
          </p>
          <p class="el-alert__description">
            5 考试院审核通过后，完成转入申请。
          </p>
        </div>
-->
        <el-dialog title="申请外省转入" width="1000px" :visible.sync="applyDialogVisible">
            <el-form ref="itemForm" :model="item" :rules="itemRules" label-width="160px">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="考生姓名" prop="ks_xm">
                    <div style="width:200px">
                      <el-input size="medium" v-model="item.ks_xm" readonly></el-input>
                    </div>
                  </el-form-item>
                  <el-form-item label="学生身份证" prop="ks_sfz">
                    <div style="width:200px">
                      <el-input size="medium" v-model="item.ks_sfz" readonly></el-input>
                    </div>
                  </el-form-item>
                  <el-form-item label="本省准考证" prop="zk_in_zkz">
                    <el-select size="medium" v-model="item.zk_in_zkz" filterable clearable placeholder="本省准考证" >
                      <el-option v-for="item in ticketList" :key="item.major_id" :label="item.ticket_no" :value="item.ticket_no"></el-option>
                   </el-select>
                  </el-form-item>
                  <el-form-item label="外省准考证" prop="ks_zkz">
                    <div style="width:200px">
                      <el-input size="medium" v-model="item.ks_zkz" placeholder="请输入内容"></el-input>
                    </div>
                  </el-form-item>
                </el-col>
              </el-row>
            
            </el-form>
          
            <center>
              <br>
              <!-- <el-button type="primary" @click="submit()">提交</el-button> -->
            </center>

        </el-dialog>

        <el-dialog title="成绩列表" width="1000px" :visible.sync="scoreListDialogVisible">
          <el-table
                :data="scoreList"
                style="width: 100%">
                <el-table-column
                  prop="pt_bh"
                  label="转考编号"
                  width="170">
                </el-table-column>
                <el-table-column
                  prop="ks_zkz"
                  label="准考证号"
                  width="120">
                </el-table-column>
                <el-table-column
                  prop="et_dm"
                  label="考次号"
                  width="70">
                </el-table-column>
                <el-table-column
                  prop="kc_dm"
                  label="课程代码"
                  width="80">
                </el-table-column>
                <el-table-column
                  prop="kc_mc"
                  label="课程名称"
                  width="200">
                </el-table-column>
                <el-table-column
                  prop="kc_xf"
                  label="课程学分"
                  width="80">
                </el-table-column>
                <el-table-column
                  prop="bk_cj"
                  label="成绩"
                  width="60">
                </el-table-column>
                <el-table-column
                  prop="hg_yydm"
                  label="合格原因"
                  width="80">
                </el-table-column>
                <el-table-column
                  prop="hg_sj"
                  label="合格时间"
                  width="100">
                </el-table-column>
          </el-table>
        </el-dialog>

        <el-dialog title="材料接受地点列表" width="1100px" :visible.sync="showPlacesWin">
          <el-table
          v-loading="loading"
          :data="places">
            <el-table-column
              type="index"
              label="序号"
              width="50">
            </el-table-column>
             <el-table-column
              prop="org_name"
              label="地区"
              width="100">
            </el-table-column>
            <el-table-column
              prop="start_time"
              label="开始时间"
              width="100">
            </el-table-column>
            <el-table-column
              prop="end_time"
              label="结束时间"
              width="100">
            </el-table-column>
            <el-table-column
              prop="phone"
              label="电话"
              width="120">
            </el-table-column>
             <el-table-column
              prop="qq"
              label="qq"
              width="100">
            </el-table-column>
             <el-table-column
              prop="website"
              label="网址"
              width="180">
              <template slot-scope="scope">
                        <span v-if="scope.row.website ">
                          
                          <a v-bind:href ="scope.row.website" target="new">{{scope.row.website}}</a>
                        </span>
              </template>
            </el-table-column>
            <el-table-column
              prop="address"
              label="地址"
              width="300">
            </el-table-column>
           
          </el-table>
        </el-dialog>

        <el-dialog title="网上确认" width="800px" :visible.sync="tableDialogVisible">
          <div>
            
          
            <center>
              <el-button type="primary" @click="downByApplyRegisterPdf">下载转考（转入）登记表</el-button>

            </center>
            <br>
             <br>
              <br>
             <center v-if="item && item.status=='8'">

              <el-button type="primary" @click="confirmByApply(item)">确认外省转至省内信息无误</el-button>

            </center>
             
          </div>

          
          

        </el-dialog>

      </el-tab-pane>
    </el-tabs>
  </d2-container>
</template>

<script>
import { mapState, mapActions } from "vuex";
import { json } from "body-parser";

export default {
  computed: {
    ...mapState({
      stdReg: state => state.enrol.StdReg
    })
  },

  data() {
    return {
      scoreListDialogVisible:false,
      loading: false,
      courseLoading: false,
      applyDialogVisible: false,
      tableDialogVisible: false,
      timeLimit: null,
      auditTimeLimit: null,
      confirmTimeLimit: null,
      applyList: null,
      ticketList: null,
      std: null,
      scoreList: null,
      showPlacesWin:false,
      places:[],
      ByTurnInApplyControl:null,
      item: {
        ks_xm: "",
        ks_sfz: "",
        zk_in_zkz: "",
        ks_zkz: "",
      },
      itemRules: {
        ks_xm: [{ required: true, message: "请输入考生姓名", trigger: "blur" }],
        ks_sfz: [{ required: true, message: "请输入考生身份证", trigger: "blur" }],
        zk_in_zkz: [{ required: true, message: "请输入本省准考证", trigger: "blur" }],
        ks_zkz: [{ required: true, message: "请输入外省准考证", trigger: "blur" }]
      },
    };
  },

  async mounted() {
    this.loading = true;
    this.init();
    this.loading = false;
  },
  methods: {
    //初始化列表查询
    async init() {
      let res = await this.$http.post(
        "/by/byTurnInApply/list.htm",
        {},
        this.$http.headers.FORM
      );
      this.timeLimit = res.data.map.timeLimit;
      this.auditTimeLimit = res.data.map.auditTimeLimit;
      this.confirmTimeLimit = res.data.map.confirmTimeLimit;
      
      this.applyList = res.data.map.applyList;
      this.places =  res.data.map.placeList;
      this.ByTurnInApplyControl = res.data.map.ByTurnInApplyControl;
    },

    async showScore(item){
      let { data } = await this.$http.post(
        "/by/byTurnInScore/list.htm",
        this.Qs.stringify({
          out_ticket_no: item.ks_zkz,
          time_config_id: item.time_config_id
        }),
        this.$http.headers.FORM
      );
        if (data.success) {
          this.scoreListDialogVisible = true;
          this.loading = false;
          this.$nextTick(() => {
            this.scoreList = data.array;
          });
        }
    },

    showTableDialog(item){
      this.item = item;
      
      this.tableDialogVisible = true;
    },
      
    //跳转申请页面
    async goApply() {
      for (const key in this.item) {
        if (this.item.hasOwnProperty(key)) {
          this.item[key] = "";
        }
      }

      this.fileList = [];
      
      this.loading = true;
      let { data } = await this.$http.post(
        "/by/byTurnInApply/toApply.htm",
        {},
        this.$http.headers.FORM
      );
      this.ticketList = data.map.ticketList;
      this.std = data.map.std;

      this.item.ks_xm = this.std.std_name;
      this.item.ks_sfz = this.std.cert_no;

      //默认选择第一个
      if (this.ticketList.length > 0) {
        this.item.zk_in_zkz = this.ticketList[0].ticket_no;
      }
      this.loading = false;
      this.applyDialogVisible = true;
    },
 
    async submit() {
     
       this.$refs["itemForm"].validate(valid => {
        if (valid) {
          this.saveData();
          return true;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    //保存
    async saveData() {
      let { data } = await this.$http.post(
        "by/byTurnInApply/apply.htm",
        this.Qs.stringify(this.item),
        this.$http.headers.FORM
      );
      if (data.success) {
        this.alert("提交成功");
        this.init();
        this.$nextTick(() => {
          this.applyDialogVisible = false;
        });
      }else{
        this.alert(data.errorMsg);
      }
    },

     shouPlaces(){
      this.showPlacesWin = true;
    },

    
    async downByApplyRegisterPdf(){
      let res = await this.$http({
        method: "post",
        url: `/by/byTurnInApply/downApplyPdf.htm?id=`+this.item.id,
        responseType: "blob"
      });
      let fileName = null;
      
      if(this.stdReg.ticket_no){
        fileName = `高等教育自学考试转考（转入）登记表(${this.stdReg.ticket_no}).pdf`;
      }else{
        fileName = `高等教育自学考试转考（转入）登记表.pdf`;
      }
      if (window.navigator.msSaveBlob) {
        try {
          var blobObject = new Blob([res.data]);
          window.navigator.msSaveBlob(blobObject, fileName);
        } catch (e) {
          console.log(e);
        }
      } else {
        let loading = this.showLoading();
        let url = window.URL.createObjectURL(new Blob([res.data]));
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", fileName);

        document.body.appendChild(link);
        link.click();
        this.hideLoading(loading);
      }
    },

     async confirmByApply(item){
    
    this.$confirm("确认外省转至省内信息无误吗？", "信息提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning"
          })
            .then(async () => {

              this.doConfirmByApply(item);
              
            })
            .catch(() => {});
  },

  async doConfirmByApply(item){
    let loading = this.showLoading();
          let { data } = await this.$http.post(
              "by/byTurnInApply/confirmByApply.htm",
              this.Qs.stringify({
                id: item.id
              }),
              this.$http.headers.FORM
            );
            this.hideLoading(loading);
            
            if (data.success) {
              this.alert("网上确认成功");
              this.init();
              this.$nextTick(() => {
                this.tableDialogVisible = false;
              });
            } else {
             
              this.hideLoading(loading);
              this.alert(data.errorMsg);
              return false;
            }
  },
  
  }
};
</script>

<style lang="scss" scoped>
@import "~@/assets/style/public.scss";
</style>
