<template>
  <div
    ref="dashboardWrap"
    id="dashboardWrap"
    style="
      background: #fff !important;
      height: 85vh;
      margin: -12px 0 0 0;
      padding-top: 1px;
    "
  >
    <div style="width: 1470px; margin: 0 auto">
      <el-row
        style="
          margin-top: 10px;
          width: 100%;
          height: 45%;
          margin-left: 10px;
          border: 1px solid #e7e7e7;
        "
      >
        <div class="bumf entrance">
          <span class="iconfont iconkuaijierukou">快捷入口</span>
        </div>
        <div class="bumfCon" style="margin: 10px 0 10px 50px">
          <el-col :span="3" v-for="(item, index) in entranceList" :key="index">
            <a
              class="imgWrap"
              @click="jumpView(item.name)"
              target="_blank"
              @mouseout="changeImg(item.imgPreName, item.imgName)"
            >
              <img
                :src="item.imgSrc"
                :ref="item.imgPreName"
                @mouseover="changeImg(item.imgPreName, item.imgPreName)"
              />
              <div class="imgName">{{ item.name }}</div>
            </a>
          </el-col>
        </div>
      </el-row>
      <el-row
        style="margin-top: 20px; width: 100%; height: 45%; margin-left: 10px"
      >
        <el-col
          style="
            border: 1px solid #e7e7e7;
            width: 49%;
            height: 100%;
            float: left;
          "
        >
          <div class="bumf">
            <span class="iconfont iconyewudaiban">业务待办</span>
            <span @click="jumpView('通用功能')" class="more">更多 ></span>
          </div>
          <div class="bumfCon">
            <!--            <el-row>-->
            <!--              <ul style="background-color:#fff;" v-loading="tzLoading">-->
            <!--                <li class="bumfCon-li" v-for="(item, index) in tzData" :key="index">-->
            <!--                  <span-->
            <!--                    @click="detailtz(item)"-->
            <!--                    style="float:left;width:300px;overflow:hidden;margin-left:5px;-->
            <!--    text-overflow:ellipsis;-->
            <!--    white-space:nowrap"-->
            <!--                  >{{ item.businessName }}</span>-->
            <!--                  <span style="float:right;width:120px;">{{ item.assignTime }}</span>-->
            <!--                </li>-->
            <!--              </ul>-->
            <!--            </el-row>-->
            <el-table
              :data="tzData"
              stripe
              border
              @row-click="jumpDetails"
              style="width: 100%"
            >
              <el-table-column
                prop="itemName"
                label="标题"
                align="center"
              ></el-table-column>
              <el-table-column
                prop="submitter"
                label="发起人"
                align="center"
              ></el-table-column>
              <el-table-column
                prop="reportDate"
                align="center"
                label="发起时间"
              ></el-table-column>
            </el-table>
          </div>
        </el-col>
        <el-col
          style="
            border: 1px solid #efeded;
            width: 49%;
            height: 100%;
            float: right;
          "
        >
          <div class="bumf">
            <span class="iconfont iconyewudaiban">公文待办</span>
            <!-- <span class="more">更多 ></span> -->
          </div>
          <div class="bumfCon"></div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import qs from "qs";
import axios from "axios";
import {
  getDaiBanPagesNew,
  findNoticeList,
  findNoticeId,
  findOAList,
  signTask,
  todoList,
} from "@/api/taskReport/index";

export default {
  name: "dashboard",
  data() {
    return {
      needArray: [],
      tzData: [],
      dialogTableVisible: false,
      tzDetailDialog: false,
      oaDialog: false,
      form: {
        procName: "",
        starter: "",
        userId: "",
      },
      limit: {
        page: 1,
        size: 6,
        total: 0,
      },
      userId: "",
      resultList: [],
      resultList1: [],
      toInven: [],
      toInvens: [],
      numOfPeoEmp: [],
      numOfPeoEmps: [],
      numOfUni: [],
      numOfUnis: [],
      warUni: [],
      warUnis: [],
      laEnCa: [],
      laEnCas: [],
      newFoodEnt: [],
      newFoodEnts: [],
      tableLoading: false,
      tableLoading1: false,
      tzLoading: false,
      detailtzList: {},
      menuUrl: "",
      entranceList: [
        {
          name: "业务检查",
          imgName: "ywjc",
          imgPreName: "ywjc-pre",
          imgSrc: require("./img/ywjc.png"),
        },
        {
          name: "质量管理",
          imgName: "zlgls",
          imgPreName: "zlgls-pre",
          imgSrc: require("./img/zlgls.png"),
        },
        {
          name: "储备粮管理",
          imgName: "cblgl",
          imgPreName: "cblgl-pre",
          imgSrc: require("./img/cblgl.png"),
        },
        {
          name: "粮油交易",
          imgName: "lyjy",
          imgPreName: "lyjy-pre",
          imgSrc: require("./img/lyjy.png"),
        },
        {
          name: "区长责任制",
          imgName: "qzzrz",
          imgPreName: "qzzrz-pre",
          imgSrc: require("./img/qzzrz.png"),
        },
      ],
      systeamList: [
        {
          value: "cbl",
          name: "储备粮管理",
        },
        {
          value: "ywjc",
          name: "业务检查",
        },
        {
          value: "zj",
          name: "质量管理",
        },
        {
          value: "qzzrz",
          name: "区长责任制",
        },
        {
          value: "jy",
          name: "粮油交易",
        },
        {
          value: "pm",
          name: "项目管理",
        },
        {
          value: "xxsh",
          name: "信息审核备案",
        },
      ],
    };
  },
  methods: {
    jumpView(name) {
      getLeftMenuList(name);
      this.getFirstMenu(JSON.parse(sessionStorage.getItem("leftMenuList")));
      // this.$router.push({path: this.menuUrl});
      //   window.location.href = "/web/portal/#" + this.menuUrl;
      window.location.href =
        location.host == "localhost:9000"
          ? "/#" + this.menuUrl
          : "/web/portal/#" + this.menuUrl;
      // switch (name) {
      //     case "业务检查":
      //         this.$router.push({path: this.menuUrl});
      //         break;
      //     case "质量管理":
      //         this.$router.push({path: this.menuUrl});
      //         break;
      //     case "储备粮管理":
      //         this.$router.push({path: "/grainReserves/grainCoManage/coInfo/index"});
      //         break;
      //     case "粮油交易":
      //         this.$router.push({path: "/transaction/tradeEntrust/outInDepotEntrust/index"});
      //         break;
      //     case "区长责任制":
      //         this.$router.push({path: "/accountability/scoringWeight"});
      //         break;
      //     case "通用功能":
      //         this.$router.push({path: "/publicfunction/toDoThings"});
      //         break;
      // }
    },
    getFirstMenu(arr) {
      if (arr[0].children.length) {
        this.getFirstMenu(arr[0].children);
      } else {
        this.menuUrl = arr[0].resourceUrl;
      }
    },
    getSysteamName(code) {
      let name = "";
      this.systeamList.forEach((item) => {
        if (item.value == code) {
          name = item.name;
        }
      });
      return name;
    },
    jumpDetails(row) {
      // let itemQuery = JSON.stringify(row.itemQuery)
      // let itemQuery = "{dialogVisible:true,type:'stamp'}"

      // itemQuery.idKey = 'lhxybm'
      if (row.sysCode == "jy" && row.itemId.indexOf("-") != -1) {
        row.itemId = row.itemId.substring(0, row.itemId.indexOf("-"));
      }
      if (row.sysCode == "cbl" && row.itemId.indexOf("-") != -1) {
        row.itemId = row.itemId.substring(0, row.itemId.indexOf("-"));
      }

      if (row.itemQuery) {
        if (row.itemId.indexOf(",") != -1) {
          row.itemId.split(",");
          row.itemQuery.idKey.split(",");
          row.itemQuery.idKey.map((item, index) => {
            row.itemQuery[row.itemQuery.idKey[index]] = row.itemId[index];
          });
        } else {
          row.itemQuery[row.itemQuery.idKey] = row.itemId;
        }

        getLeftMenuList(this.getSysteamName(row.sysCode));
        sessionStorage.setItem("searchData", null);
        let query = "";
        for (let key in row.itemQuery) {
          query += key + "=" + row.itemQuery[key] + "&";
        }
        window.location.href =
          location.host == "localhost:9000"
            ? "/#" + row.itemUrl + "?" + query
            : "/web/portal/#" + row.itemUrl + "?" + query;
      } else {
        getLeftMenuList(this.getSysteamName(row.sysCode));
        sessionStorage.setItem("searchData", null);
        window.location.href =
          location.host == "localhost:9000"
            ? "/#" + row.itemUrl
            : "/web/portal/#" + row.itemUrl;
      }

      // switch (row.businessType) {
      //     case "CHECK-5000150":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/reserveCompony"});
      //         break;
      //     case "DEAL-5000150":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/reserveCompony"});
      //         break;
      //     case "CHECK-5000110":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/dailyCheckResult"});
      //         break;
      //     case "DEAL-5000110":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/dailyCheckResult"});
      //         break;
      //     case "CHECK-5000120":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/floodPreventionCheck"});
      //         break;
      //     case "DEAL-5000120":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/floodPreventionCheck"});
      //         break;
      //     case "CHECK-5000140":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/reserveCompony"});
      //         break;
      //     case "DEAL-5000140":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/reserveCompony"});
      //         break;
      //     case "CHECK-5000160":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/specialPreventionCheckReserves"});
      //         break;
      //     case "DEAL-5000160":
      //         getLeftMenuList("业务检查");
      //         this.$router.push({path: "/inspection/specialPreventionCheckReserves"});
      //         break;
      //     case "DDCKYS":
      //         getLeftMenuList("储备粮管理");
      //         this.$router.push({path: "/grainReserves/inAccExamine/detail"});
      //         window.location.href = window.location.href.split("#")[0] + "#/grainReserves/inAccExamine/detail?yslx=3&detail=1&ysid=" + row.businessId

      //         break;
      //     case "DDRKYS":
      //         getLeftMenuList("储备粮管理");
      //         window.location.href = window.location.href.split("#")[0] + "#/grainReserves/inAccExamine/detail?yslx=2&detail=1&ysid=" + row.businessId

      //         break;
      //     case "BKRKYS":
      //         getLeftMenuList("储备粮管理");
      //         this.$router.push({path: "/grainReserves/inAccExamine/index"});
      //         break;
      //     case "dcsq_sh":
      //         getLeftMenuList("储备粮管理");
      //         // this.$router.push({path: "/grainReserves/warehouseApproval/index"});
      //         window.location.href = window.location.href.split("#")[0] + "#/grainReserves/warehouseApproval/detail?state=review&zt=90300000&id=" + row.businessId
      //         break;
      //     case "dcsq_ys":
      //         getLeftMenuList("储备粮管理");
      //         // this.$router.push({path: "/grainReserves/warehouseAcceptance/index"});
      //         window.location.href = window.location.href.split("#")[0] + "#/grainReserves/warehouseAcceptance/detail?state=review&zt=90400900&id=" + row.businessId

      //         break;
      //     case "kcys_sh":
      //         getLeftMenuList("信息审核备案");
      //         this.$router.push({path: "/grainReserves/warehouseAudit/index"});
      //         break;
      //     case "kgys_sh":
      //         getLeftMenuList("信息审核备案");
      //         this.$router.push({path: "/grainReserves/emptyTanksAudit/index"});
      //         break;
      //     case "YKSQPF":
      //         getLeftMenuList("储备粮管理");
      //         window.location.href = window.location.href.split("#")[0] + "#/grainReserves/transferAudit/detail?state=review&zt=90300000&id=" + row.businessId

      //         break;
      //     case "YKYSSQSH":
      //         getLeftMenuList("储备粮管理");
      //         window.location.href = window.location.href.split("#")[0] + "#/grainReserves/transferNotice/detail?state=review&zt=90400900&id=" + row.businessId
      //         break;
      // }
    },
    getList() {
      this.listLoading = true;
      let data = {
        pageSize: "10",
        pageNum: "1",
        receiver: sessionStorage.getItem("userCode"),
        orgCode: sessionStorage.getItem("orgCode"),
      };
      todoList(data).then((res) => {
        let wrapHeight = parseInt(this.$refs.dashboardWrap.style.height);
        let windowHeight = window.innerHeight;
        let height = (wrapHeight / 100) * windowHeight;
        if (height > 600) {
          this.tzData = res.items;
        } else {
          this.tzData = res.items.slice(0, 4);
        }
      });
      if (window.sessionStorage.getItem("TOKENL")) {
      } else {
        this.resultList1 = [{}];
      }
    },
    DBList() {
      findNoticeList().then((res) => {
        this.tzLoading = false;
        this.tzData = res.data.splice(10);
      });
    },
    detailtz(item) {
      this.tzDetailDialog = true;
      findNoticeId(item.id).then((res) => {
        this.detailtzList = res.data;
      });
    },
    OAList() {
      // alert(111)
      findOAList().then((res) => {
        // console.log(res)
        if (res.infoCode == "200") {
          this.tableLoading = false;
          this.resultList = res.data.list;
        }
      });
    },
    changeImg(refName, imgName) {
      this.$refs[refName][0].src = require("./img/" + imgName + ".png");
    },
    oaRowClick(row) {
      // console.log()
      window.open(row.linkUrl);
    },

    tableRowClick(row) {
      console.log(row);
      if (row.businessType == 20) {
        window.open(
          `http://218.241.206.66:8097/web/business/#/task/companySh?iframeUrl=${row.procInstId}&from=reportForm2`
        );
      } else if (row.businessType == 30) {
        window.open(
          `http://218.241.206.66:8097/web/business/#/task/companyBg?iframeUrl=${row.procInstId}&from=reportForm2`
        );
      } else {
        let data = {
          code: "20",
          procInstIid: row.procInstId,
          actId: row.actId,
          taskId: row.taskId,
        };
        // signTask(data).then(res => {
        //   if (res.infoCode === 200) {
        //     const iframeUrl = res.data
        //     console.log(iframeUrl)
        //     window.open(
        //       `http://218.241.206.66:8097/web/business/#/task/biDetail?iframeUrl=${iframeUrl}&from=reportForm2`
        //     )
        //   }
        // })
      }
    },
    ywMore() {
      window.open("http://218.241.206.66:8097/web/business/#/task/reportForm2");
    },
    oAPass() {
      axios
        .post(
          "http://218.241.206.66:8097/irpt/esmain/js/login.do?action=login&id=xiaolb&pw={25f9e794323b453885f5181f1b624d0b}&pwdstrength=1&pwdlength=9"
        )
        .then(function (res) {
          res = res.data;
          if (res.code == "000") {
          } else {
          }
        });
      // const timerOA = setInterval(function () {
      //   const LoginCode = JSON.parse(sessionStorage.getItem('LoginCode'))
      //   if (LoginCode.loginCode === '1') {
      //     clearInterval(timerOA)
      //     console.log('我是定时器')
      //     document.getElementById('loginid').value = LoginCode.username
      //     document.getElementById('userpassword').value = "123456789"
      //     console.log( document.getElementById('loginid').value,document.getElementById('userpassword').value)
      //     document.LoginformsOA.submit()
      //   }
      // }, 10)
    },
    //递归函数【遍历权限下的行政管理和综合业务】
    // getResourceUrl() {
    //   // for (let i = 0; i < childrenArray.length; i++) {
    //   //   if (childrenArray[i].children.length === 0 && childrenArray[i].resourceUrl.indexOf('/ssoa/') > -1 && this.numOa === 0) {
    //   this.oAPass() //OA免登
    //   // this.numOa += 1;
    //   //     } else if (childrenArray[i].children.length === 0 && childrenArray[i].resourceUrl.indexOf('/sso/') > -1 && this.numI === 0) {
    //   //       console.log('I免登', childrenArray[i].resourceUrl.split('url=')[1] + '?token=' + sessionStorage.getItem('TOKENL'))
    //   //       this.srcI = childrenArray[i].resourceUrl.split('url=')[1] + '?token=' + sessionStorage.getItem('TOKENL')
    //   //       this.numI += 1;
    //   //     } else {
    //   //       this.getResourceUrl(childrenArray[i].children)
    //   //     }
    //   //   }
    // }
  },
  mounted() {
    window.onresize = () => {
      return (() => {
        this.windowHeight = window.innerHeight;
      })();
    };
    setTimeout(() => {
      this.getList();
    }, 200);

    let num = 1;
    let _this = this;
    setInterval(function () {
      if (num === 1) {
        num += 1;
      }
    }, 500);
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  background: #f6f7f9 !important;
}

/*.dashboard-container {*/
/*    !*width: 1200px;*!*/
/*    margin: 0 auto;*/
/*    border: none;*/
/*    background: #ffffff;*/
/*    padding: 0;*/
/*}*/

// ------局内公文 数据统计 ----/-----
.bumf {
  height: 42px;
  line-height: 42px;
  color: #fff;
  font-size: 14px;
  padding-left: 15px;
  background-repeat: no-repeat;
  // background-color: #eff7ff;
  // background-image: url("./img/tjtitle.png");
  overflow: hidden;
  position: relative;
}
.bumf span {
  font-size: 16px !important;
}

.bumf .more {
  float: right;
  color: #999999;
  font-weight: normal;
  padding-right: 15px;
  position: absolute;
  cursor: pointer;
  right: 15px;
}

.bumf .bumfCon {
  // height: 280px;
  overflow: hidden;
}

.bumfCon {
  overflow: hidden;
}

.button {
  background-color: #006bd5;
}

.imgWrap {
  width: 90px;
  height: 105px;
  display: inline-block;
  text-align: center;
  position: relative;
  /*background: url("./img/ywjc.png") no-repeat;*/
}

.imgName {
  color: #000000;
  position: absolute;
  bottom: 0;
  width: 100%;
}

a {
  color: #000000;
}

.el-table .el-table__body-wrapper .el-table__row {
  cursor: pointer;
}
</style>
