<!--
  1.rows cut from 3600 to 370
  2.tables columns head request from mysql,not write in this file,
    so if change table columns,not need fix this file.

     ---by Paul 2022-11-10
-->
<!--
  1.tables columns head request not from mysql,
    from the file "check.xlsx.full.js" use method "getObjColumnsAndProps"

     ---by Paul 2022-11-17
-->

<template>
    <div class="app-container">
    <el-row :gutter="10">
            <el-col :span="22" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>同步查询</span>
          </div>


          <div style="text-align:center;">
            <el-button-group>
                <el-button  type= "success"  @click="todayBtnClick"  :disabled="todayBtnDisabled" >{{ServerDate+todayUploadStatus}}</el-button>
                <el-button  type= "success"  @click="yestodayBtnClick"  :disabled="yestodayBtnDisabled" >{{ServerLastDate+yestodayUploadStatus}}</el-button>
            </el-button-group>

          </div>


          <div style="text-align:center;">
            <el-button-group>
                <el-button type="primary"  @click="btnb1click" :loading="b1loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B1</el-button>
                <el-button type="primary"  @click="btnb2click" :loading="b2loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B2</el-button>
                <el-button type="primary"  @click="btnb3click" :loading="b3loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B3</el-button>
                <el-button type="primary"  @click="btnb4click" :loading="b4loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B4</el-button>
                <el-button type="primary"  @click="btnb6click" :loading="b6loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B6</el-button>
                <el-button type="primary"  @click="btnb7click" :loading="b7loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B7</el-button>
                <el-button type="primary"  @click="btnb8click" :loading="b8loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B8</el-button>
                <el-button type="primary"  @click="btnb9click" :loading="b9loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B9</el-button>
                <el-button type="primary"  @click="btnb10click" :loading="b10loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B10</el-button>
                <el-button type="primary"  @click="btnb11click" :loading="b11loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B11</el-button>
                <el-button type="primary"  @click="btnb12click" :loading="b12loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B12</el-button>
                <el-button type="primary"  @click="btnb13click" :loading="b13loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B13</el-button>
                <el-button type="primary"  @click="btnb14click" :loading="b14loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B14</el-button>
                <el-button type="primary"  @click="btnb15click" :loading="b15loading" :disabled="BXBtnDisabled">{{BXBtnPrefix}}B15</el-button>
            </el-button-group>

          </div>

          <el-table
                    :data="BX"
                    border
                    v-loading="bxloading"
                    stripe
                    lazy
                    style="width: 100%">
                    <el-table-column
                        v-for="(index,item) in tmpfields"
                        :key="index"
                        :label="item"
                        :prop="index"
                        :show-overflow-tooltip="true">
                    </el-table-column>
          </el-table>

        </el-card>
      </el-col>
    </el-row>
    </div>
</template>

<script>
import { getNowDate,getStatus,getB1,getB2,getB3,getB4,getB6,getB7,getB8,getB9,getB10,getB11,getB12,getB13,getB14,getB15 } from "@/api/daily/daily";
import Cookies from "js-cookie";
//import { getColumns } from "@/api/comprehensive/search";
import {getObjColumnsAndProps} from "@/api/check.xlsx.full.js";


export default {
  name: "dailyselect",
  data() {
    return {
        tmpfields:[],
        tmpcolumns:[],//by Paul 2022-11-10 current file not use
        tmpprops:[],//by Paul 2022-11-10 current file not use
        BX:[],
        Arr:[],
        BXBtnDisabled: true, //by Paul 2022-11-10 use for disabled ,not for enabled
        BXBtnPrefix:"",
        DailydateAt:"",

        todayUploadStatus:"",
        yestodayUploadStatus:"",
        todayBtnDisabled: true, //by Paul 2022-11-10 use for disabled ,not for enabled
        yestodayBtnDisabled: true, //by Paul 2022-11-10 use for disabled ,not for enabled
        personalDailyUserId:"",

        SystemDate : "",//by Paul 2022-11-10 current file not use
        ServerDate : "",
        ServerLastDate : "",

        b1loading:false,
        b2loading:false,
        b3loading:false,
        b4loading:false,
        b6loading:false,
        b7loading:false,
        b8loading:false,
        b9loading:false,
        b10loading:false,
        b11loading:false,
        b12loading:false,
        b13loading:false,
        b14loading:false,
        b15loading:false,
        bxloading:false,

    };
  },
  created(){
      this.getNow();
      this.getStatus();
     // this.getColumnsInfo("b15");
  },
  methods :{
    btnb1click(){
            this.b1loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b1");
            this.tmpfields = getObjColumnsAndProps(0);
            getB1(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b1loading=false;
            this.bxloading=false;
            });
    },
    btnb2click(){
            this.b2loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b2");
            this.tmpfields = getObjColumnsAndProps(1);
            getB2(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b2loading=false;
            this.bxloading=false;
            });
    },
    btnb3click(){
            this.b3loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b3");
            this.tmpfields = getObjColumnsAndProps(2);
            getB3(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b3loading=false;
            this.bxloading=false;
            });
    },
    btnb4click(){
            this.b4loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b4");
            this.tmpfields = getObjColumnsAndProps(3);
            getB4(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b4loading=false;
            this.bxloading=false;
            });
    },
    btnb6click(){
            this.b6loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b6");
            this.tmpfields = getObjColumnsAndProps(4);
            getB6(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b6loading=false;
            this.bxloading=false;
            });
    },
    btnb7click(){
            this.b7loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b7");
            this.tmpfields = getObjColumnsAndProps(5);
            getB7(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b7loading=false;
            this.bxloading=false;
            });
    },
    btnb8click(){
            this.b8loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b8");
            this.tmpfields = getObjColumnsAndProps(6);
            getB8(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b8loading=false;
            this.bxloading=false;
            });
    },
    btnb9click(){
            this.b9loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b9");
            this.tmpfields = getObjColumnsAndProps(7);
            getB9(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b9loading=false;
            this.bxloading=false;
            });
    },
    btnb10click(){
            this.b10loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b10");
            this.tmpfields = getObjColumnsAndProps(8);
            getB10(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b10loading=false;
            this.bxloading=false;
            });
    },
    btnb11click(){
            this.b11loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b11");
            this.tmpfields = getObjColumnsAndProps(9);
            getB11(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b11loading=false;
            this.bxloading=false;
            });
    },
    btnb12click(){
            this.b12loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b12");
            this.tmpfields = getObjColumnsAndProps(10);
            getB12(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b12loading=false;
            this.bxloading=false;
            });
    },
    btnb13click(){
            this.b13loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b13");
            this.tmpfields = getObjColumnsAndProps(11);
            getB13(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b13loading=false;
            this.bxloading=false;
            });
    },
    btnb14click(){
            this.b14loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b14");
            this.tmpfields = getObjColumnsAndProps(12);
            getB14(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b14loading=false;
            this.bxloading=false;
            });
    },
    btnb15click(){
            this.b15loading=true;
            this.bxloading=true;
            //this.getColumnsInfo("b15");
            this.tmpfields = getObjColumnsAndProps(13);
            getB15(this.personalDailyUserId,this.DailydateAt).then(response =>{
            this.Arr = response;
            this.transMeans(this.Arr);
            this.BX=this.Arr;
            this.b15loading=false;
            this.bxloading=false;
            });
    },
    transMeans(arr){
      for(let i = 0; i < arr.length ; i++ ){
              if(arr[i].agreeSign == "2"){
                 arr[i].agreeSign = "已删除";
              }
              if(arr[i].agreeSign == "0"){
                 arr[i].agreeSign = "未同意";
              }
              if(arr[i].agreeSign == "1"){
                 arr[i].agreeSign = "同意";
              }
            }
    },
    todayBtnClick(){
      this.BXBtnDisabled=false;
     //console.log(this.ServerDate.substr(5,2));
     //console.log(this.ServerDate.substr(8,2));
     this.BXBtnPrefix=this.ServerDate.substr(8,2);
     this.DailydateAt=this.ServerDate;
    },
    yestodayBtnClick(){
      this.BXBtnDisabled=false;
     //console.log(this.ServerDate.substr(5,2));
     //console.log(this.ServerDate.substr(8,2));
     this.BXBtnPrefix=this.ServerLastDate.substr(8,2);
     this.DailydateAt=this.ServerLastDate;
    },
    getColumnsInfo(tableName){
      getColumns(tableName).then(res => {
       //console.log(res.data);
      this.tmpfields = res.data;
       // console.log(res.columns);
      this.tmpcolumns = res.columns;
       //console.log(res.props);
      this.tmpprops = res.props;
    });
  },

      getNow() {
          var nowDate = new Date();
          this.SystemDate = this.dateFormat("YYYY-mm-dd",nowDate);
          getNowDate().then(response =>{
            this.ServerDate = response.data;
            this.ServerLastDate = response.data1;
          })
  },
  dateFormat(fmt, date) {
    let ret;
    const opt = {
        "Y+": date.getFullYear().toString(),        // 年
        "m+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "H+": date.getHours().toString(),           // 时
        "M+": date.getMinutes().toString(),         // 分
        "S+": date.getSeconds().toString()          // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
  },
  getStatus(){
     this.personalDailyUserId = Cookies.get("id");
    getStatus(this.personalDailyUserId).then(response =>{
        this.todayUploadStatus = response.data;
        this.yestodayUploadStatus = response.data1;
        if(this.todayUploadStatus !== null && this.todayUploadStatus !== "2"){
          this.todayUploadStatus = "已上传";
          this.todayBtnDisabled = false;

        }else{
          this.todayUploadStatus = "未上传";
        }
        if(this.yestodayUploadStatus !== null && this.yestodayUploadStatus !== "2"){
          this.yestodayUploadStatus = "已上传";
          this.yestodayBtnDisabled = false;

        }else{
          this.yestodayUploadStatus = "未上传";
        }

    })
  },


  }
}
</script>
