<template>
  <div class="workbench-box" v-if="userType == '02'">
    <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="12" class="work-main-left service-left">
          <!-- <div class="main-left">
            <div class="left-header">
              <div class="left-header-title">【服务业数据概览】</div>
            </div>
          </div> -->
          <div class="echart-title">
            <div class="echart-left-title">
              <div class="L-title-left">
                <span class="dataCloudMap-birght"></span>
                <span class="dataCloudMap-title">服务业发展总览</span>
              </div>
              <span class="dataCloudMap-data">【统计数据截至：2024-01】</span>
            </div>
            <div class="rightBigNav">
              <div class="right-nav">
                <div
                  class="tabStyle"
                  v-for="(item, index) in options1"
                  :key="index"
                  @click="active(index + 1)"
                  :class="activeIndex == index + 1 ? 'change-blue' : ''"
                >
                  <div class="change-grey-birght" :class="activeIndex == index + 1 ? 'change-blue-birght' : ''"></div>
                  <span class="change-grey-text" :class="activeIndex == index + 1 ? 'change-blue-text' : ''">{{ item.name }}</span>
                </div>
              </div>
            </div>
          </div>
          <echartData :activeIndex="activeIndex" ref="echartData"/>
        </el-col>
        
        <!-- <el-col :span="10">
          <el-row type="flex" class="main-two-row"> -->
            <el-col :span="6" class="work-main-left">
              <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">已发送短信、已发送邮件</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">已发送短信、已发送邮件</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">已发送短信、已发送邮件</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">已发送短信、已发送邮件</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 class="right-main" v-else>
                  <el-divider content-position="center">暂无</el-divider>
                </div> -->
              </div>
            </el-col>
            <el-col :span="6">
              <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 class="right-main" v-else>
                    <el-divider content-position="center">暂无</el-divider>
                  </div> -->
                </div>
              </div>
            </el-col>
          <!-- </el-row>
        </el-col> -->
      </el-row>
      <el-row class="main-row-two">
        <div class="analyse-header">
          <span class="dataCloudMap-birght"></span>
          <div class="analyse-header-title">招商信息分析</div>
        </div>
        <div class="analyse-main">
          <el-col :span="7" class="analyse-left-box">
            <div class="box-header">
              <span class="garden"></span>
              <span class="box-header-title">新落户企业统计</span>
            </div>
            <div class="statisticsNew-box">
              <echart-data-two></echart-data-two>
            </div>
          </el-col>
          <el-col :span="10" class="analyse-middle-box" id="zhongdian-xiangmu">
            <div class="box-header" id="zhongdian-header-id">
              <span class="garden"></span>
              <span class="box-header-title">重点及特色项目</span>
            </div>
            <div class="emphasisProject-box">
              <table-one></table-one>
            </div>
          </el-col>
          <el-col :span="7" class="analyse-right-box">
            <div class="box-header">
              <span class="garden"></span>
              <span class="box-header-title">引入投资统计分析</span>
            </div>
            <div class="statisticsAnalyse-box">
              <echart-data-three></echart-data-three>
            </div>
          </el-col>
        </div>
      </el-row>
      <el-row class="main-row-three">
        <div class="analyse-header">
          <span class="dataCloudMap-birght"></span>
          <div class="analyse-header-title">产业促进分析</div>
        </div>
        <div class="industry-main">
          <el-row class="main-row-three-topbox">
            <!-- <el-col :span="8" class="industry-top-left-box" id="zhijinyindao-qingkuang">
              <div class="box-header" id="zhijinyindao-header-id">
                <span class="garden"></span>
                <span class="box-header-title">资金引导情况分析</span>
              </div>
              <div class="capitalCondition-box">
                <table-two></table-two>
              </div>
            </el-col> -->
            <el-col :span="8" class="industry-top-middle-box" id="zhijinbofu-qingkaung">
              <div class="box-header" id="zhijinbofu-header-id">
                <span class="garden"></span>
                <span class="box-header-title">拨付资金企业申请情况TOP5</span>
              </div>
              <div class="capitalConditionTOP5-box">
                <table-three></table-three>
              </div>
            </el-col>
            <el-col :span="8" class="bottombox-left-box">
              <div class="box-header">
                <span class="garden"></span>
                <span class="box-header-title">重点及特色项目</span>
              </div>
              <div class="featureProject-box">
                <TableSeven></TableSeven>
              </div>
            </el-col>
            <el-col :span="8" class="industry-top-right-box">
              <div class="box-header">
                <span class="garden"></span>
                <span class="box-header-title">促进产业项目情况</span>
              </div>
              <div class="promoteProject-box">
                <table-four></table-four>
              </div>
            </el-col>
          </el-row>
          <el-row class="main-row-three-minddlebox">
            <el-col :span="12" class="col-left-box">
              <el-row class="change-August-eight-th-style-row">
                <el-col :span="12" class="change-August-eight-th-style">
                  <div class="appropriate-analyse-box">
                    <div class="box-header">
                      <span class="garden"></span>
                      <span class="box-header-title">资金拨付情况分析</span>
                    </div>
                    <div class="capital-appropriate-analyse-box">
                      <echartDataFour></echartDataFour>
                    </div>
                  </div>
                </el-col>
                <el-col :span="12" class="bottombox-right-box">
                  <div class="box-header">
                    <span class="garden"></span>
                    <span class="box-header-title">产业品牌打造宣传</span>
                  </div>
                  <div class="brandPublicity-box">
                    <TableEight></TableEight>
                  </div>
                </el-col>
              </el-row>
              <div class="promote-analyse-box">
                <div class="box-header">
                  <span class="garden"></span>
                  <span class="box-header-title">促进产业载体分析</span>
                </div>
                <div class="promoteTable-box">
                  <TableSix></TableSix>
                </div>
              </div>
            </el-col>
            <el-col :span="12" class="col-right-box">
              <div class="box-header">
                <span class="garden"></span>
                <span class="box-header-title">促进产业企业情况分析</span>
              </div>
              <div class="headline-one-header">
                <span>01.</span> 企业综合经营贡献TOP5
              </div>
              <div class="headline-one-main">
                <echartDataFive></echartDataFive>
              </div>
              <div class="headline-two-header">
                <div class="work-industry-condition">
                  <div class="industry-condition">
                    <span>02.</span> 行业纵深情况
                  </div>
                  <span class="industry-condition-statistics">【统计数据截至：2024-01】</span>
                </div>
                <div class="rightBtn" @click="industryBtn">查看更多数据>></div>
              </div>
              <div class="headline-two-main">
                <TableFive></TableFive>
              </div>
            </el-col>
          </el-row>
          <!-- <el-row class="main-row-three-bottombox">
            <el-col :span="12" class="bottombox-left-box">
              <div class="box-header">
                <span class="garden"></span>
                <span class="box-header-title">重点及特色项目</span>
              </div>
              <div class="featureProject-box">
                <TableSeven></TableSeven>
              </div>
            </el-col>
            <el-col :span="12" class="bottombox-right-box">
              <div class="box-header">
                <span class="garden"></span>
                <span class="box-header-title">产业品牌打造宣传</span>
              </div>
              <div class="brandPublicity-box">
                <TableEight></TableEight>
              </div>
            </el-col>
          </el-row> -->
        </div>
      </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>
    <!-- 行业纵深弹框 -->
    <collectDialog ref="collectDialog" />
    <!-- 智能提醒弹框 -->
    <zhinengtixing ref="zhinengtixing" @changeIsRead="govRemind()" />
    <!-- 待办任务弹框 -->
    <daibanrenwu ref="daibanrenwu" />
  </div>
  <homeIndex 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 homeIndex from "@/views/home/index.vue"
import echartData from '@/views/dataCloudMap/components/echartData.vue'
//  TableTwo,
import { echartDataTwo, echartDataThree, 
  TableOne, TableThree, TableFour, echartDataFour, 
  echartDataFive, TableFive, TableSix, TableSeven, TableEight,
  zhinengtixing, daibanrenwu
} from "./components"
import collectDialog from '@/views/dataCloudMap/components/collectDialog.vue'
export default {
  dicts: ["project_small_type"],
  components:{
    homeIndex,
    echartData,
    echartDataTwo,
    echartDataThree,
    TableOne,
    // TableTwo,
    TableThree,
    TableFour,
    echartDataFour,
    echartDataFive,
    TableFive,
    TableSix,
    TableSeven,
    TableEight,
    collectDialog,
    zhinengtixing,
    daibanrenwu
  },
  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:{},
      activeIndex:1,
      options1: [
        {
          name: "按年",
        },
        {
          name: "按季度",
        },
      ],
      time:"",
    }
  },
  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();
    },
    active(e) {
      this.activeIndex = e;
      this.$refs.echartData.getService(e);
    },
    // 智能提醒
    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>
