<template>
  <div class="main-content market search-result content m20">
    <div class="search-box">
      <el-row>
        <el-col :span="10">
          <div class="search-field">
            <p>案件编号：</p>
            <el-input v-model.trim="searchForm.caseNo" placeholder="精准查询" @keyup.enter.native="submitSearch" />
          </div>
        </el-col>
        <el-col :span="10" >
          <div class="search-field">
            <p>案件名称：</p>
            <el-input v-model.trim="searchForm.caseName" style="width:100%" placeholder="精准查询" @keyup.enter.native="submitSearch" />
          </div>
        </el-col>
        <el-col v-if="!showMore" :span="8" style="text-align:center;">
          <span class="arrow" @click="showMore = !showMore"><i class="el-icon-arrow-down" />展开</span>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="submitSearch" :loading="loading">查询</el-button>
          <el-button type="info" icon="el-icon-refresh-left" size="mini" @click="resetForm">重置</el-button>
        </el-col>
      </el-row>
      <template v-if="showMore">
        <el-row>
          <el-col :span="10">
            <div class="search-field">
              <p>统一社会信用代码/注册号：
                <!--                包括下属片区：<el-checkbox v-model="searchForm.checked" />-->
              </p>
              <el-input v-model.trim="searchForm.UNISCIDORREGNO" style="width:100%" placeholder="精准查询" @keyup.enter.native="submitSearch" />
            </div>
          </el-col>
          <el-col :span="10">
            <div class="search-field">
              <p>主体名称：</p>
              <el-input v-model.trim="searchForm.entName" style="width:100%" placeholder="模糊查询" @keyup.enter.native="submitSearch" />
            </div>
          </el-col>
        </el-row>

        <!-- 信用修复查询条件-->
        <el-row>
          <el-col :span="10">
              <div class="search-field">
                <p>办理机关：</p>
                <el-select v-model="searchForm.orgNumber" clearable size="mini" placeholder="请选择" style="width:100%">
                  <el-option
                    v-for="item in orgList"
                    :key="item.orgNumber"
                    :label="item.orgUnitName"
                    :value="item.orgNumber"
                  />
                </el-select>
              </div>
          </el-col>
          <el-col :span="10">
            <div class="search-field">
              <p>立案时间自选：</p>
              <el-date-picker
                v-model="searchForm.setTimeDate"
                size="mini"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:100%"
              />
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <div class="search-field">
              <p>行政处罚时间自选：</p>
              <el-date-picker
                v-model="searchForm.punishTime"
                size="mini"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:100%"
              />
            </div>
          </el-col>
        </el-row>
      </template>
    </div>
    <div v-if="showMore" class="func-box">
      <div class="btn-box">
        <span v-if="showMore" class="arrow" @click="showMore = !showMore"><i class="el-icon-arrow-up" />隐藏</span>
        <span v-if="!showMore" class="arrow" @click="showMore = !showMore"><i class="el-icon-arrow-down" />展开</span>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="submitSearch" :loading="loading">查询</el-button>
        <el-button type="info" icon="el-icon-refresh-left" size="mini" @click="resetForm">重置</el-button>
      </div>
    </div>
    <el-table
      v-loading="loading"
      :data="tableData"
      :header-cell-style="{background:'#8cc3fb',color:'#fff'}"
      @row-click="rowClick"
    >
      <el-table-column label="序号" prop="index" min-width="30" />
      <el-table-column label="案件编号" prop="caseNo" min-width="90" show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="案件名称" prop="caseName" min-width="120" show-overflow-tooltip />
      <el-table-column label="办理机关" prop="handleOrgCn" show-overflow-tooltip />
      <el-table-column label="当前环节" prop="busStatusName" show-overflow-tooltip />
      <el-table-column label="已立案数" prop="isRegisterNum" min-width="50" align="center" show-overflow-tooltip />
      <!-- <el-table-column label="经营期限" prop="opto" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.opto ? scope.row.opto: '长期' }}
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="信用等级" /> -->
      <el-table-column label="已吊销数" prop="isRevokeNum" min-width="50" align="center" show-overflow-tooltip />
      <el-table-column label="撤销吊销数" prop="otherNum" align="center" min-width="80"  />
    </el-table>
    <div class="page-box">
      <el-row>
        <!-- <el-col :span="6">
          <el-button type="primary" @click="$router.back()">返回</el-button>
          <el-button v-if="this.$util.isNotEmpty(searchType) && searchType !== undefined" :disabled="tableData.length == 0" type="primary" @click="revokeEntListExport">导出Excel</el-button>
          <el-button v-else type="primary" @click="openDialog">导出Excel</el-button>
        </el-col> -->
        <el-col :span="18" style="text-align:right">
          <el-pagination
            :disabled="loading"
            :page-size="pageParam.pageSize"
            :total="pageParam.total"
            :page-sizes="[10, 20, 30, 40,50,100,200]"
            :current-page="pageParam.curPage"
            layout="slot,total, sizes, prev, pager, next, jumper"
            @size-change="pageSizeChange"
            @current-change="pageIndexChange"
          >
            <!-- <batchFunction :options="options" style="float:left" /> -->
            <span>
              第 {{ pageParam.curPage }} 页 /
              共 {{ (pageParam.total !== 0 ? parseInt((pageParam.total + pageParam.pageSize - 1)/pageParam.pageSize) : 1) }} 页
            </span>
          </el-pagination>
        </el-col>
      </el-row>
    </div>
    <!-- <el-dialog title="请选择需要导出的字段" :visible.sync="isExport" width="90%">
      <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选</el-checkbox>
      <el-checkbox-group v-model="checkedfields" @change="handleCheckedCitiesChange">
        <el-checkbox v-for="each in fields" :key="each" style="margin: 15px;" :label="each">{{ each }}</el-checkbox>
      </el-checkbox-group>
      <el-button v-loading="exportLoading" type="primary" @click="exportData">确认导出</el-button>
    </el-dialog> -->
  </div>
</template>

<script>
import { businessQuery , queryAllOrg } from '@/api/comprehensive'
import { revBusQuery } from '@/api/revoke'
export default{
  data() {
    return {
      orgList: [],
      showMore: false,
      searchForm: {
        orgNumber:'',
        UNISCIDORREGNO:'',
        caseNo:'',
        caseName:'',
        entName:'',
        setTimeDate:'',
        punishTime:''
      },
      pageParam: {
        curPage: 1,
        pageSize: 10,
        total: 0,
        customParamMap: {}
      },
      loading: false,
      tableData:[],
    }
  },
  mounted() {
    this.searchForm.orgNumber = JSON.parse(sessionStorage.getItem('user')).orgCode
    if(this.searchForm.orgNumber == '440101') this.getCache()
    this.getOrgList()
    //this.submitSearch()
  },
  methods: {
    getOrgList() {
      queryAllOrg().then(res => {
        if (res.code === 0) {
          let orgCode = JSON.parse(sessionStorage.getItem('user')).orgCode
          res.data.forEach(each => {
            if(orgCode == "440101" ){
              this.orgList.push(each)
            }else if(orgCode == each.orgNumber){
              this.orgList.push(each)
            }
          })
        }
      })
    },
    getCache() {
      const pageParam = sessionStorage.getItem('pageParam-rbq')
      const tableData = sessionStorage.getItem('tableData-rbq')
      if (pageParam) {
        this.pageParam = JSON.parse(pageParam)
        this.searchForm = this.pageParam.customParamMap
      }
      if (tableData) {
        this.tableData = JSON.parse(tableData)
      }
    },
    rowClick(row, column, event) {
        const bizStatus = row.currentNodeOrBizStatus
        switch (row.currentNodeOrBizStatus) {
        // active_top: 1 立案审批环节
        case '1': this.$router.push({ path: '/revoke/register/accept', query: { active_top: 1, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '2': this.$router.push({ path: '/revoke/register/review', query: { active_top: 1, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '3': this.$router.push({ path: '/revoke/register/examine', query: { active_top: 1, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
            // active_top: 2 调查与听证环节
        case '4': this.$router.push({ path: '/revoke/investigate/accept', query: { active_top: 2, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        // case '5': this.$router.push({ path: '/revoke/investigate/review', query: { active_top: 2, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: true }})
        //   break
        // case '6': this.$router.push({ path: '/revoke/investigate/examine', query: { active_top: 2, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: true }})
        //   break
        // case '7': this.$router.push({ path: '/revoke/hearing/accept', query: { active_top: 3, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: true }})
        //   break
        case '8': this.$router.push({ path: '/revoke/hearing/review', query: { active_top: 2, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '9': this.$router.push({ path: '/revoke/hearing/examine', query: { active_top: 2, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '24': this.$router.push({ path: '/revoke/hearing/review', query: { active_top: 2, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '25': this.$router.push({ path: '/revoke/hearing/review', query: { active_top: 2, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '26': this.$router.push({ path: '/revoke/hearing/review', query: { active_top: 2, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
            // active_top: 4 决定环节
        case '10': this.$router.push({ path: '/revoke/decision/accept', query: { active_top: 3, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '11': this.$router.push({ path: '/revoke/decision/review', query: { active_top: 3, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '12': this.$router.push({ path: '/revoke/decision/department', query: { active_top: 3, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '27': this.$router.push({ path: '/revoke/decision/department', query: { active_top: 3, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '28': this.$router.push({ path: '/revoke/decision/department', query: { active_top: 3, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '29': this.$router.push({ path: '/revoke/decision/department', query: { active_top: 3, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '13': this.$router.push({ path: '/revoke/decision/examine', query: { active_top: 3, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
            // active_top: 5 送达与结束环节
        case '14': this.$router.push({ path: '/revoke/send/accept', query: { active_top: 5, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '15': this.$router.push({ path: '/revoke/send/review', query: { active_top: 5, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '16': this.$router.push({ path: '/revoke/send/examine', query: { active_top: 5, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '20': this.$router.push({ path: '/revoke/send/accept', query: { active_top: 5, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case '22': this.$router.push({ path: '/revoke/noRegister/', query: { bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        case 'endRevoke':this.$router.push({ path: '/revoke/send/examine', query: { active_top: 6, active: 3, bizStatus: bizStatus, bizseq: row.bizseqid, workflowid: row.workflowid, tasklistid: row.tasklistid, onlyShow: 'true' }})
            break
        }
    },
    // 当前分页改变
    pageIndexChange(curPage) {
      this.pageParam.curPage = curPage
      this.submitSearch()
    },
    // 分页大小改变
    pageSizeChange(pageSize) {
      this.pageParam.pageSize = pageSize
      this.submitSearch()
    },
    // 加载分页
    submitSearch() {
      if (this.loading) return
      this.pageParam.customParamMap = this.searchForm
      // 判断是否填写了条件
      let flag = false
      // obj的遍历
      Object.keys(this.pageParam.customParamMap).forEach(key => {
        if (this.pageParam.customParamMap[key] !== '' && this.pageParam.customParamMap[key] !== null) {
          flag = true
        }
      })
      if (!flag) {
        this.$message({
          message: '请至少填写一个查询条件！',
          type: 'warning'
        })
        return
      }
      this.loading = true
      //this.searchType = this.pageParam.customParamMap.type
      revBusQuery(this.pageParam).then(res => {
        this.loading = false
        if (res.code === 0) {
          const data = res.data
          const list = []
          let index = (this.pageParam.curPage - 1) * this.pageParam.pageSize
          data.records.forEach(each => {
            each.index = ++index
            if(each.currentNodeOrBizStatus === '合计')
              each.busStatusName = '合计'
            else
              each.busStatusName = this.$util.getTaskNodeName(each.currentNodeOrBizStatus)
            list.push(each)
          })
          this.tableData = list
          this.pageParam.total = data.total
          sessionStorage.setItem('pageParam-rbq', JSON.stringify(this.pageParam))
          sessionStorage.setItem('tableData-rbq', JSON.stringify(this.tableData))
        }
      })
    },
    getDifferList() {
      getConstant('CD71').then(res => {
        if (res.code === 0) {
          const list = []
          res.data.forEach(each => {
            list.push({
              value: each.code,
              label: each.name
            })
          })
          this.reasonList = list
        }
      })
    },

    resetForm() {
      for (const key in this.searchForm) {
        this.$set(this.searchForm, key, '')
      }
    }
  }
}

</script>


<style lang="scss" scoped>
.content{
  background: #fff;
  .el-table .warning-row {
    background: #eaf4fe!important;
  }
}
/* 搜索条件 */
  .main-content{
    >div:not(:first-child){
      margin-top:16px;
    }
    .search-box{
      padding:10px 0;
      .search-field{
        display:flex;
        width:100%;
        >p{
          margin:3px 16px 10px 0;
          font-family: Microsoft YaHei, Microsoft YaHei-Bold;
          color: #666;
          font-size:16PX;
          width:200px;
          text-align: right;
        }
      }
      .el-col{
        margin-bottom:15px;
      }
    }
    .btn-box{
      text-align:right;
    }
    .main-body{
      padding:16px 0;
      border-top: 1px dashed #70AEFF;
      .header{
        .header-label{
          font-size: 20PX;
          font-family: Microsoft YaHei, Microsoft YaHei-Bold;
          font-weight: bold;
          color: #243668;
          line-height: 32px;
        }
      }
    }
  }
  /deep/.el-input__inner{
    height: 28px;
  }
  /deep/.el-input__icon{
    line-height: 28px;
  }
  .arrow{
    color: #3296FA;
    cursor: pointer;
    margin-right: 16px;
  }
</style>
<style lang="scss">
  .market.search-result{
    .el-table__row{
      cursor: pointer;
    }
  }
</style>
