<template>
  <div class="workbench-box">
    <main class="home-main">
      <el-row class="main-row">
        <el-col :span="8" class="work-main-left">
          <div class="main-left">
            <div class="left-header">
              <div class="left-header-title">【服务业数据概览】</div>
            </div>
          </div>
        </el-col>
        <el-col :span="8" class="work-main-left">
          <div class="main-left">
            <div class="left-header">
              <div class="left-header-title">【智能提醒】</div>
            </div>
            <div class="left-main">
              <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 }}天后{{ item.alertRecipients == 1 ? "填报结束" : item.alertRecipients == 2 ? "建设完成" : "" }}】</div>
                      <div class="content-middle">{{ item.alertContent }}</div>
                      <div class="content-time">{{ item.alertTime }}</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 }}】<dict-tag :options="dict.type.project_small_type" :value="item.declarationName"/></div>
                      <div class="content-middle">{{ item.alertContent }}</div>
                      <div class="content-time">{{ item.alertTime }}</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="content-time">{{ item.alertTime }}</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-time">{{ item.alertTime }}</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>
          </div>
        </el-col>
        <el-col :span="8" class="work-main-right">
          <div class="main-right">
            <div class="right-header">
              <div class="right-header-title">【待办提醒】</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.enterpriseName }}</div> -->
                <div>{{ (item.status == 0 ? "待填报" : item.status == 8 ? "初审不通过" : item.status == 10 ? "初审退回修改" : item.status == 7 ? "复审不通过" : item.status == 9 ? "终审不通过" : item.status == 5 ? "终审通过" : "") }}</div>
                <!-- <div>审批【知识产权】材料</div> -->
                <div @click="MoreRecords('id',item.status)" class="last_child_item" :class="item.status == 0 ? 'tab-red' : item.status == 10 ? 'tab-red' : 'last_child_item'">{{ item.status == 0 ? "去填报" : item.status == 10 ? "去修改" : "去查看"}}</div>
              </div>
            </div>
            <div class="right-main" v-else>
              <el-divider content-position="center">暂无</el-divider>
            </div>
          </div>
        </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>
  </div>
</template>
<script>
import { approvalList, approvalEdit, uploadFile } from "@/api/onlineDeclartion/pendingReview"
import { listRecords } from "@/api/onlineDeclartion/records"
import { selectAll, workSearch } from "@/api/jin_ji_hu/home"
import { chiefAll, enterpriseAll, changeIsRead } from "@/api/jin_ji_hu/intelligentReminder"
export default {
  dicts: ["project_small_type"],
  data() {
    return {
      // 判断登陆用户是何身份⌈ 01 ： 企业  02 ： 政务 ⌋
      userType: this.$store.state.user.userType,
      search:"",
      backlogArray:[],
      pagination: {
        pageNum:1,
        pageSize:10,
        approvalStatusStr: 0,
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        creditCode: this.$store.state.user.name,
        statusStr: [0, 5, 7, 8, 9, 10],
      },
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {
        approvalOpinions: ''
      },
      // 表单校验
      rules: {
        approvalStatus: [
          { required: true, message: "请选择审批状态", trigger: "blur" }
        ],
        approvalOpinions: [
          { required: true, message: "名录维护方式不能为空", trigger: "blur" }
        ],
      },
      fileList: [],
      uploadList: [],
      tabs: [
        {
          value:"查企业"
        },{
          value:"查项目"
        },{
          value:"查荣誉"
        },
      ],
      checked: 0,
      loading:false,
      remindList: [],
      info:{},
    }
  },
  mounted(){
    if(this.userType == "02") {
      this.getList();
      this.govRemind();
    } else if(this.userType == "01") {
      this.getListTwo();
      this.entRemind();
    }
    
  },
  methods:{
    // 待审批
    getList(){
      this.loading = true;
      approvalList(this.pagination).then(res=>{
        // console.log(res);
        this.backlogArray = res.rows
        this.loading = false;
      })
    },
    // 待填报
    getListTwo(){
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        this.backlogArray = response.rows
        this.loading = false;
      });
    },
    // 企业端智能提醒
    entRemind(){
      enterpriseAll().then(res=>{
        this.remindList = res.data;
      })
    },
    // 政务端智能提醒
    govRemind(){
      chiefAll().then(res=>{
        this.remindList = res.data;
      })
    },
    // 智能提醒去查看并修改状态
    putMemo(item){
      if(item.isRead == 1) {
        changeIsRead({id:item.id}).then(res=>{
          if(this.userType == "02") {
            this.govRemind();
          } else if(this.userType == "01") {
            this.entRemind();
          }
        })
      }
      if(item.projectId) {
        this.$router.push({
          name: 'projectInfo',
          query: { userId: Number(item.projectId) }
        })
      } else if(item.alertRecipients == 1 && item.alertManner == 2) {
        this.$router.push({
          name: 'Records',
          params: { statusChange: "0" }
        })
      } else if(item.alertManner == 1) {
        this.open = true;
        this.info = item;
      }
    },
    // 更多记录
    MoreRecords(type,status){
      if(type == 'all') {
        this.$router.push({
          name: 'Records',
          params: { statusChange: "" }
        })
      } else {
        if(status == 0 || status == 10) {
          this.$router.push({
            name: 'Records',
            params: { statusChange: "0" }
          })
        } else {
          this.$router.push({
            name: 'Records',
            params: { statusChange: "1" }
          })
        }
      }
    },
    // 切换查询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) {

      }
    },
  },
}
</script>
<style lang="scss" scoped>

</style>
