<template>
  <div class="workbench-box-pro" v-if="userType == '02'">
    <header class="pro_header"> 
      <div class="workbench-serch">
        <div class="workbench-title">
          <div class="title-item" :class="checked == index ? 'checked-item' : ''" v-for="(item,index) in tabs" :key="index" @click="changeTab(index)">
            {{ item.value }}
          </div>
        </div>
        <div class="workbench-btn">
          <!-- :placeholder="checked == 0 ? '请输入企业名称' : checked == 1 ? '请输入项目名称' : checked == 2 ? '请输入荣誉名称' : ''"  -->
          <el-autocomplete 
            placeholder="请输入企业名称" 
            ref="autocomplete"
            v-model="search" 
            :fetch-suggestions="querySearch" 
            :trigger-on-focus="false" 
            @select="handleSelect"
            class="input-with-select"
          >
            <el-button slot="append" class="work-btn" @click="searchBtn">搜索</el-button>
          </el-autocomplete>
        </div>
      </div>
    </header>
    <main class="home-main">
      <el-row class="main-row">
        <el-col :span="16" class="work-main-left service-left">
          <div class="home-mainPro-top">
            <div class="pro-left-box" style="margin-right: 10px;">
              <div class="box-header" id="zhongdian-header-id">
                <span class="garden"></span>
                <span class="box-header-title">服务业发展总览</span>
              </div>
              <div class="AFuwufazhanzonglan-box home-mainPro-top-box">
                <AFuwufazhanzonglan :typeValue="typeValue" :yearsChange="yearsChange"></AFuwufazhanzonglan>
              </div>
            </div>
            <div class="pro-right-box">
              <div class="box-header" id="zhongdian-header-id">
                <span class="garden"></span>
                <span class="box-header-title">近三年资金拨付情况</span>
              </div>
              <div class="BJinsannianzijin-box home-mainPro-top-box">
                <BJinsannianzijin :typeValue="typeValue" :yearsChange="yearsChange"></BJinsannianzijin>
              </div>
            </div>
          </div>
          <div class="home-mainPro-middle">
            <div class="pro-left-box" style="margin-right: 10px;">
              <div class="box-header" id="zhongdian-header-id">
                <span class="garden"></span>
                <span class="box-header-title">企业获得资金拨付排名TOP5</span>
                <div class="left-box-select">
                  <el-select v-model="yearsChange" placeholder="请选择">
                    <el-option
                      label="当年"
                      :value="1">
                    </el-option>
                    <el-option
                      label="近三年"
                      :value="2">
                    </el-option>
                  </el-select>
                  <el-select v-model="typeValue" placeholder="请选择">
                    <el-option
                      label="总部专项"
                      :value="1">
                    </el-option>
                    <el-option
                      label="服务业专项"
                      :value="2">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="capitalConditionTOP5-box">
                <table-three :typeValue="typeValue" :yearsChange="yearsChange"></table-three>
              </div>
            </div>
            <div class="pro-right-box">
              <div class="box-header" id="zhongdian-header-id">
                <span class="garden"></span>
                <span class="box-header-title">当年已申报完成的项目</span>
              </div>
            </div>
          </div>
          <div class="home-mainPro-bottom">
            <div class="pro-left-box" style="margin-right: 10px;">
              <div class="box-header" id="zhongdian-header-id">
                <span class="garden"></span>
                <span class="box-header-title">项目追踪情况</span>
              </div>
            </div>
            <div class="pro-right-box">
              <div class="box-header" id="zhongdian-header-id">
                <span class="garden"></span>
                <span class="box-header-title">备忘录更新情况</span>
              </div>
            </div>
          </div>
        </el-col>
        
        <el-col :span="8">
          <el-row type="flex" class="main-two-row">
            <el-col :span="24" class="work-main-left" style="height: 49%;">
              <div class="main-left">
                <div class="left-header">
                  <div class="left-header-titleS">
                    <span class="dataCloudMap-birght"></span>
                    <div class="left-header-title">智能提醒</div>
                  </div>
                  <el-button @click="zhinengtixingBtn" type="text" v-if="remindList.length > 0">>> 更多记录</el-button>
                </div>
                <div class="left-main" v-if="remindList.length > 0">
                  <el-card shadow="never" v-for="(item,index) in remindList" :key="index" :class="item.isRead == 1 ? 'el-card-border' : ''">
                    <div class="warn-main">
                      <div class="warn-main-left" v-if="item.alertManner == 2">
                        <div class="warn-main-img"><img src="@/assets/images/warn-green.png" alt=""></div>
                        <div class="warn-main-content">
                          <div class="content-title">【{{ item.declarationName }}】【预计{{ item.daysAdvance }}天后建设完成】</div>
                          <div class="content-middle">{{ item.alertContent }}</div>
                          <!-- <div class="content-middle">已发送短信、已发送邮件</div> -->
                          <!-- <div class="content-time">{{ item.alertTime }}</div> -->
                          <div class="tixing-duanxin">
                            <div class="content-time">{{ item.alertTime }}</div>
                            <div class="content-time content-time-two">已发送短信</div>
                          </div>
                        </div>
                      </div>
                      <div class="warn-main-left" v-else-if="item.alertManner == 1 && item.qymc && item.alertRecipients == 2">
                        <div class="warn-main-img"><img src="@/assets/images/warn-orange.png" alt=""></div>
                        <div class="warn-main-content">
                          <div class="content-title" style="display: flex;">【{{ item.qymc }}】</div>
                          <div class="content-title-type"><dict-tag :options="dict.type.project_small_type" :value="item.declarationName"/></div>
                          <div class="content-middle">{{ item.alertContent }}</div>
                          <!-- <div class="content-middle">已发送短信、已发送邮件</div> -->
                          <!-- <div class="content-time">{{ item.alertTime }}</div> -->
                          <div class="tixing-duanxin">
                            <div class="content-time">{{ item.alertTime }}</div>
                            <div class="content-time content-time-two">已发送短信</div>
                          </div>
                        </div>
                      </div>
                      <div class="warn-main-left" v-else-if="item.alertManner == 1 && item.projectId">
                        <div class="warn-main-img"><img src="@/assets/images/warn-orange.png" alt=""></div>
                        <div class="warn-main-content">
                          <div class="content-title">【{{ item.declarationName }}】</div>
                          <div class="content-middle">{{ item.alertContent }}</div>
                          <div class="tixing-duanxin">
                            <div class="content-time">{{ item.alertTime }}</div>
                            <div class="content-time content-time-two">已发送短信</div>
                          </div>
                        </div>
                      </div>
                      <div class="warn-main-left different-left" v-else-if="item.alertManner == 1 && !item.projectId">
                        <div class="warn-main-img"><img src="@/assets/images/warn-blue.png" alt=""></div>
                        <div class="warn-main-content">
                          <div class="content-title">{{ item.alertContent }}</div>
                          <!-- <div class="content-middle">已发送短信、已发送邮件</div> -->
                          <!-- <div class="content-time">{{ item.alertTime }}</div> -->
                          <div class="tixing-duanxin">
                            <div class="content-time">{{ item.alertTime }}</div>
                            <div class="content-time content-time-two">已发送短信</div>
                          </div>
                        </div>
                      </div>
                      <div class="warn-main-right">
                        <div class="warn-main-right-chakan" @click="putMemo(item)">
                          查看
                        </div>
                        <div class="warn-main-right-status" :class="item.isRead == 1 ? 'status-unread' : ''">
                          {{ item.isRead == 1 ? '未读' : '已读' }}
                        </div>
                      </div>
                    </div>
                  </el-card>
                </div>
                <el-empty class="left-main" :image-size="160" v-else></el-empty>
              </div>
            </el-col>
            <el-col :span="24" style="height: 49%;">
              <div class="work-main-right">
                <div class="main-right">
                  <div class="right-header">
                    <div class="right-header-box">
                      <span class="dataCloudMap-birght"></span>
                      <div class="right-header-title">待办任务</div>
                    </div>
                    <el-button @click="MoreRecords('all')" type="text" v-if="backlogArray.length > 0">>> 更多记录</el-button>
                  </div>
                  <div class="right-main" v-if="backlogArray.length > 0" v-loading="loading">
                    <div class="main-items" v-for="(item,index) in backlogArray" :key="index" :class="index % 2 == 0 ? '':'main-item'">
                      <div>【{{ item.enterpriseDirectory }}】 </div>
                      <div>{{ (item.status == 1 ? "待初审" : item.status == 2 ? "待复审" : item.status == 3 ? "待终审" : "") }}</div>
                      <!-- <div>审批【知识产权】材料</div> -->
                      <div @click="MoreRecords('id',item.status)" class="last_child_item">去审批</div>
                    </div>
                  </div>
                  <el-empty class="right-main" :image-size="160" v-else></el-empty>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </main>
    <el-dialog title="详情" :visible.sync="open" width="400px" append-to-body :close-on-click-modal="false">
      <div class="team-main">
        <div>提醒时间:</div>
        <div>{{ info.alertTime }}</div>
      </div>
      <div class="team-main">
        <div>提醒内容:</div>
        <div>{{ info.alertContent  }}</div>
      </div>
    </el-dialog>
    <!-- 智能提醒弹框 -->
    <zhinengtixing ref="zhinengtixing" @changeIsRead="govRemind()" />
    <!-- 待办任务弹框 -->
    <daibanrenwu ref="daibanrenwu" />
  </div>
  <hometwoIndex v-else-if="userType == '01'" />
</template>
<script>
import { approvalList, uploadFile } from "@/api/onlineDeclartion/pendingReview"
import { selectAll, workSearch } from "@/api/jin_ji_hu/home"
import { chiefAll, changeIsRead } from "@/api/jin_ji_hu/intelligentReminder"
import hometwoIndex from "@/views/homeTwo/index.vue"
import { zhinengtixing, daibanrenwu } from "@/views/workbench/components"
import TableThree from "./components/capitalConditionTOP5"
import AFuwufazhanzonglan from "./components/AFuwufazhanzonglan"
import BJinsannianzijin from "./components/BJinsannianzijin"
export default {
  dicts: ["project_small_type"],
  components:{
    hometwoIndex,
    zhinengtixing,
    daibanrenwu,
    TableThree,
    AFuwufazhanzonglan,
    BJinsannianzijin
  },
  data() {
    return {
      // 判断登陆用户是何身份⌈ 01 ： 企业  02 ： 政务 ⌋
      userType: this.$store.state.user.userType,
      search:"",
      backlogArray:[],
      pagination: {
        current:1,
        size:10,
        approvalStatusStr: 0,
      },
      // 是否显示弹出层
      open: false,
      tabs: [
        {
          value:"查企业"
        },{
          value:"查项目"
        },{
          value:"查荣誉"
        },
      ],
      checked: 0,
      loading:false,
      remindList: [],
      info:{},
      time:"",
      yearsChange: 1,
      typeValue: 1
    }
  },
  mounted(){
    if(this.userType == '02') {
      this.getList();
      this.govRemind();
      this.time = this.getNowFormatDate();
    }
  },
  methods:{
    // 获取最新年月日
    getNowFormatDate() {
      let date = new Date(),
      year = date.getFullYear(), //获取完整的年份(4位)
      month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
      strDate = date.getDate() // 获取当前日(1-31)
      if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
      if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数，在前面补0
      return `${year}-${month}-${strDate}`
    },
    // 行业纵深情况查看详情按钮
    industryBtn(){
      this.$refs.collectDialog.open();
    },
    // 智能提醒
    zhinengtixingBtn(){
      this.$refs.zhinengtixing.open();
    },
    // 待审批
    getList(){
      this.loading = true;
      approvalList(this.pagination).then(res=>{
        // console.log(res);
        this.backlogArray = res.rows
        this.loading = false;
      })
    },
    // 政务端智能提醒
    govRemind(){
      chiefAll({current:1,size:20}).then(res=>{
        this.remindList = res.data.records;
      })
    },
    // 智能提醒去查看并修改状态
    putMemo(item){
      if(item.isRead == 1) {
        changeIsRead({id:item.id}).then(res=>{
          this.govRemind();
        })
      }
      if(item.projectId) {
        this.$router.push({
          name: 'projectInfo',
          query: { userId: Number(item.projectId) }
        })
      } else if(item.alertManner == 1) {
        this.open = true;
        this.info = item;
      }
    },
    // 更多记录
    MoreRecords(type,status){
      if(type == 'all') {
        // this.$router.push({
        //   name: 'PendingReview',
        //   params: { approvalStatusStr: "" }
        // })
        this.$refs.daibanrenwu.open();
      } else {
        this.$router.push({
          name: 'PendingReview',
          params: { approvalStatusStr: "0" }
        })
      }
    },
    // 切换查询tab
    changeTab(index){
      this.checked = index;
      this.search = "";
      // 切换搜索类型时清空上次搜索的推荐内容避免跳转问题
      this.$refs.autocomplete.suggestions = [];
      this.$refs.autocomplete.highlightedIndex = -1;
    },
    querySearch(queryString, cb) {
      let results = []
      if(this.checked == 0) {
        workSearch({enterpriseInfo: queryString}).then(res => {
          res.data.forEach(item => {
            results.push({
              value: item.qymc,
              id: item.id,
              tyshxydm: item.tyshxydm
            })
          })
        })
      } else if(this.checked == 1) {
        selectAll({ name: queryString }).then(res => {
          res.data.forEach(item => {
            results.push({
              value: item.declareUnit,
              id: item.id
            })
          })
        })
      } else if(this.checked == 2) {
        selectAll({ name: queryString, status: 5}).then(res => {
          res.data.forEach(item => {
            results.push({
              value: item.declareUnit,
              id: item.id
            })
          })
        })
      }
      // queryString 拿到搜索到的数据
      /**
       * 通过queryString 调用接口参数搜索到的数据【数据处理成所需的列表⌈ 对象带value ⌋】使用callback返回列表数据
       */
      // var restaurants = this.restaurants;
      // var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    // 点击搜索到的数据
    handleSelect(item) {
      if(this.checked == 0) {
        this.$router.push({
          name: 'enterpriselibraryInfo',
          query: { userId: item.id, creditCode: item.tyshxydm }
        })
      } else if(this.checked == 1) {
        this.$router.push({
          name: 'projectInfo',
          query: { userId: Number(item.id) }
        })
      } else if(this.checked == 2) {
        this.$router.push({
          name: 'projectInfo',
          query: { userId: Number(item.id) }
        })
      }
    },
    searchBtn(){
      // console.log(this.search);
      if(this.checked == 0) {
        this.$router.push({
          name: 'Enterpriselibrary',
          params: { enterpriseName: this.search }
        })
      } else if(this.checked == 1) {
        // this.$router.push({
        //   name: 'Project',
        //   params: { projectName: this.search }
        // })
        this.$router.push({
          name: 'Project',
          params: { declareUnit: this.search }
        })
      } else if(this.checked == 2) {
        this.$router.push({
          name: 'Project',
          params: { declareUnit: this.search, status: '5' }
        })
      }
    },
  },
}
</script>
<style lang="scss" scoped>

</style>
