<template>
  <div class="main-content m20">
    <!--头部-查询-->
    <div class="content-header">
      <searchHeader title="查询" />
      <div class="body search-body">
        <el-row>
          <el-col :span="12">
            <el-row class="mb10">
              <label class="label-name_1">统一社会信用代码/注册号：</label>
              <div class="search-input-box_1">
                <el-input v-model="searchForm.searchUscc" size="mini" clearable type="text" class="search-input" placeholder="请输入统一社会信用代码/注册号" @keyup.enter.native="search" />
              </div>
            </el-row>
          </el-col>

          <el-col :span="12">
            <el-row>
              <label class="label-name_2">列异原因：</label> <!-- clearable 可以清空选项  -->
              <el-select v-model="searchForm.specause" clearable size="mini" placeholder="请选择列入原因" class="custom">
                <el-option
                  v-for="item in reasonList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" class="mb10">
            <label class="label-name">主体名称(模糊)：</label>
            <div class="search-input-box">
              <el-input v-model="searchForm.searchName" size="mini" clearable type="text" class="search-input" placeholder="请输入主体名称（模糊）" @keyup.enter.native="search" />
            </div>
          </el-col>
          <el-col :span="12">
            <el-row class="mb10">
              <label class="label-name">列异日期：</label> <!-- value-format="yyyy-MM-dd" 指定日期发送格式  -->
              <el-date-picker
                v-model="searchForm.searchDate"
                size="mini"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" :offset="1">
            <div class="btn-box">
              <el-button size="mini" type="primary" @click="search">查询</el-button>
              <el-button size="mini" @click="searchForm.searchUscc = '';searchForm.searchName='';searchForm.reportYear='';searchForm.searchDate='';searchForm.specause=''">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <!--body-查询结果-->
    <div class="content-body">
      <div class="body">
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 95%;margin:0 auto"
          :fit="true"
          :row-class-name="tableRowClassName"
          :header-cell-style="{background:'#8cc3fb',color:'#fff'}"
        >
          <el-table-column prop="index" label="序号" min-width="30" align="center" />
          <el-table-column prop="uscc" label="统一社会信用代码/注册号" min-width="120" align="left" />
          <el-table-column prop="entname" :show-overflow-tooltip="true" label="主体名称" min-width="130" align="left" />
          <el-table-column prop="enttypeName" :show-overflow-tooltip="true" label="主体类型" min-width="120" align="left" />
          <el-table-column prop="abntime" label="列异日期" min-width="70" align="left" />
          <el-table-column prop="specause" :show-overflow-tooltip="true" label="列异原因" min-width="150" align="left" :formatter="reasonFormat" />
          <el-table-column label="操作" min-width="60" align="center">
            <template slot-scope="scope">
              <el-button type="primary" :loading="scope.row.loading" size="mini" @click="startTask(scope.row)">办理</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="page-box">
          <el-row class="bl0">
            <el-col :span="24">
              <el-pagination
                :disabled="loading"
                :page-size="pageParam.pageSize"
                :current-page.sync="pageParam.curPage"
                :page-sizes="[10, 20, 30, 40,50,100,200]"
                layout="slot,total, sizes, prev, pager, next, jumper"
                @size-change="pageSizeChange"
                @current-change="pageIndexChange"
              >
                <span>
                  第 {{ pageParam.curPage }} 页 /
                  共 {{ (pageParam.total !== 0 ? parseInt((pageParam.total + pageParam.pageSize - 1)/pageParam.pageSize) : 1) }} 页
                </span>
              </el-pagination>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import searchHeader from '@/components/searchHeader'
import { commonPage, dissentList } from '@/api/abnormal'
import { startbizDissent, validateBizDissent } from '@/api/abnormal'
import { getConstant } from '@/api/system'
export default {
  components: {
    searchHeader
  },
  data() {
    return {
      isOnlyRem: this.$route.meta.isOnlyRem,
      searchForm: {
        entertype: '',
        searchtype: 'yy',
        isOnlyRem: this.$route.meta.isOnlyRem
      },
      reasonList: [], // 几种列入原因
      reason: '',
      showFixed: false,
      showMore: false,
      loading: false,
      tableData: [],
      pageParam: {
        customParamMap: {},
        curPage: 1,
        total: 0,
        pageSize: 10
      }
    }
  },
  mounted() {
    // 加载企业列入原因
    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
      }
    })
    // this.loadPage()
    window.addEventListener('scroll', this.handleScroll, true)
  },
  methods: {
    showMoreCriteria() {
      this.showMore = !this.showMore
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      }
    },
    handleScroll() {
      const scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      if (scrollTop > 80) {
        this.showFixed = true
      } else {
        this.showFixed = false
      }
    },
    // 列入原因
    reasonFormat(row) {
      let name = ''
      this.reasonList.forEach(each => {
        if (each.value === row.specause) {
          name = each.label
        }
      })
      return name
    },
    // 启动待办
    startTask(row) {
      this.$set(row, 'loading', true)
      validateBizDissent(row.abnlistid).then(res => {
        this.loading = false
        if (res.code === 0) {
          this.$confirm('是否确认启动待办', '提示').then(() => {
            startbizDissent(row.abnlistid, 'company', this.isOnlyRem).then(res => {
              if (res.code === 0) {
                this.$router.push({ path: '/abnormal/company/dissent/ApplyAccept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq }})
              }
            })
          })
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 搜索
    search() {
      this.pageParam.customParamMap = this.searchForm
      this.pageParam.curPage = 1
      this.loadPage()
    },
    // 当前分页改变
    pageIndexChange(curPage) {
      this.pageParam.curPage = curPage
      this.loadPage()
    },
    // 分页大小改变
    pageSizeChange(pageSize) {
      this.pageParam.pageSize = pageSize
      this.loadPage()
    },
    // 加载分页
    loadPage() {
      if (this.loading) return
      this.loading = true
      if (this.isOnlyRem === '1') { // 移出异议接口
        dissentList(this.pageParam).then(res => {
          this.handleSearchData(res)
        })
      } else { // 经营异常异议接口
        commonPage(this.pageParam).then(res => {
          this.handleSearchData(res)
        })
      }
    },
    // 处理查询数据
    handleSearchData(res) {
      this.loading = false
      const list = []
      let i = 1
      const pageStart = (this.pageParam.curPage - 1) * this.pageParam.pageSize
      res.data.records.forEach(each => {
        each.index = pageStart + i++
        each.uscc = each.uniscid ? each.uniscid : each.regno
        list.push(each)
      })
      this.tableData = list
      this.pageParam.total = res.data.total
    }
  }
}
</script>

<style lang="scss" scoped>
.main-content{
  background: #fff;
  .content-header{
    background: white;
    .search-body{
      .el-date-editor {
        width: calc(100% - 229px);
      }
      /deep/ .el-date-editor *{
        font-size: 16px!important;
      }
      /deep/ .el-date-editor .el-range-separator{
        width: 8%!important;
      }
    }
    .label-name_1{
      text-align: right;
      display: inline-block;//转成行内快，才可定义宽度
      width: 220px;
      font-size: $table-content-font-size;
    }
    .search-input-box_1{
      display: inline-block;
      width: calc(100% - 220px);
    }
    .label-name_2{
      text-align: right;
      display: inline-block;//转成行内快，才可定义宽度
      width: 220px;
      font-size: $table-content-font-size;
    }
    .search-input-box_2{
      display: inline-block;
      width: calc(100% - 220px);
    }
    .label-name {
      text-align: right;
      display: inline-block;//转成行内快，才可定义宽度
      width: 220px;
      font-size: $table-content-font-size;
    }

    .search-input-box{
      display: inline-block;
      width: calc(100% - 220px);
      // width: 300px;
    }
    .custom{
      width: calc(100% - 230px);
    }
    // .search-select-box{
    //   width: calc(100% - 100px);
    // }
    .search-input{
      cursor: pointer;

    }
    .body{
      padding: 20px 0;
      border-top:none;
      margin-bottom: 10PX;
    }
  }
  .content-body{
    background:white;
    margin-bottom: 100px;
  }
  .header{
    /* height: 50PX;
    padding: 15px 10PX; */
    .title{
      font-weight: 600;
      font-size: 1.2rem;
    }
  }
  .page-box{
    margin:10PX;
    .el-pagination{
      text-align: right;
    }
  }
  .mb10{
    margin-bottom: 10px;
  }
}
.content-body{
  background: #fff;
  /deep/.el-table .warning-row {
    background: #eaf4fe!important;
  }
}
.content-body .el-table-column--selection .cell{
  padding-right: 0px;
}
.fixed-bottom {
  position: fixed;
  width: 100%;
  bottom: -10px;
  right: 0;
  z-index: 99;
  padding: 10px;
  /* background: #8bbef6; */
  border-radius: 5px 5px 0 0;
  background: linear-gradient(to bottom, #fff 0%,#8bbef6 100%);
  box-shadow:  1px -4px 4px rgba(0, 21, 41, 0.08);
  .el-pagination {
    text-align: right!important;
  }
}
</style>
