<template>
  <div class="main-content m20">
    <!--头部-查询-->
    <div class="content-header">
      <div class="body search-body">
        <el-row class="mb10" style="margin-bottom:10px">
          <el-col :span="12">
            <label class="label-name" style="width: 220px">统一社会信用代码/注册号：</label>
            <div class="search-input-box" style="width: calc(100% - 220px)">
              <el-input v-model="searchForm.searchCode" clearable size="mini" type="text" class="search-input" placeholder="请输入统一社会信用代码/注册号" @keyup.enter.native="search" />
            </div>
          </el-col>
          <el-col :span="12">
            <label class="label-name">主体名称（模糊）：</label>
            <div class="search-input-box">
              <el-input v-model="searchForm.searchName" clearable size="mini" type="text" class="search-input" placeholder="请输入名称（模糊）" @keyup.enter.native="search" />
            </div>
          </el-col>

        </el-row>
        <el-row class="mb10">
          <el-col :span="12">
            <label class="label-name">处罚决定书文号：</label>
            <div class="search-input-box">
              <el-input v-model="searchForm.writsno" clearable size="mini" type="text" class="search-input" placeholder="处罚决定书文号" @keyup.enter.native="search" />
            </div>
          </el-col>
          <el-col :span="12">
            <label class="label-name" style="width: 220px">案件编号：</label>
            <div class="search-input-box" style="width: calc(100% - 220px)">
              <el-input v-model="searchForm.caseno" clearable size="mini" type="text" class="search-input" placeholder="请输入案件编号" @keyup.enter.native="search" />
            </div>
          </el-col>
          <!-- <el-col :span="6">
            <label class="label-name">未报年报年度：</label>
            <el-select v-model="searchForm.reportYear" style="width: calc(100% - 150px)" filterable clearable size="mini" @blur="selectBlur">
              <el-option
                v-for="item in reportYearList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-col> -->
        </el-row>
        <el-row>
          <el-col :span="12" :offset="1">
            <div class="btn-box">
              <!-- <span v-if="!showMore" style="margin-right:20px;color:#409EFF;cursor:pointer;font-size: 16px;" @click="showMoreCriteria">
                展开<i class="el-icon-d-arrow-right" />
              </span>
              <span v-if="showMore" style="margin-right:20px;color:#409EFF;cursor:pointer;font-size: 16px;" @click="showMoreCriteria">
                <i class="el-icon-d-arrow-left" />隐藏
              </span> -->
              <el-button type="primary" size="mini" @click="search">查询</el-button>
              <el-button size="mini" @click="searchForm.writsno = '';searchForm.searchCode = '';searchForm.searchName='';searchForm.reportYear='';searchForm.caseno='';handleType='';">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <!--body-查询结果-->
    <div class="content-body">
      <div class="body">
        <el-row>
          <el-col :span="12" :offset="2">
            <label class="label-name">处理方式：</label>
            <el-radio v-model="handleType" label="1">撤销</el-radio>
            <el-radio v-model="handleType" label="2">复议</el-radio>
            <el-radio v-model="handleType" label="3">诉讼</el-radio>
          </el-col>
        </el-row>
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="tableData"
          tooltip-effect="dark"
          class="table-style"
          :fit="true"
          :row-class-name="tableRowClassName"
          :header-cell-style="{background:'#8cc3fb',color:'#fff'}"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column class="no" type="selection" min-width="30" align="center" /> -->
          <el-table-column prop="index" label="序号" min-width="40" align="center" />
          <el-table-column prop="uscc" label="统一社会信用代码/注册号" min-width="150" align="left" />
          <el-table-column prop="entname" :show-overflow-tooltip="true" label="主体名称" min-width="120" align="left" />
          <el-table-column prop="writsno" :show-overflow-tooltip="true" label="处罚决定书文号" min-width="150" align="left" />
          <el-table-column prop="caseno" :show-overflow-tooltip="true" label="案件编号" min-width="100" align="left" />
          <el-table-column prop="intosponsorname" :show-overflow-tooltip="true" label="经办人" min-width="80" align="left" />
          <el-table-column prop="revokedate" label="吊销时间" min-width="100" align="left" />
          <el-table-column label="操作" min-width="60" align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="startTask(scope.row.revlistid)">办理</el-button>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="regulatoryName" :show-overflow-tooltip="true" label="管辖机关" min-width="100" align="left" /> -->
        </el-table>
        <div class="page-box">
          <el-row>
            <!-- <el-col :xs="24" :sm="24" :md="24" :lg="8" :xl="8"> -->
            <!-- <el-button size="mini" @click="selectAll">全选</el-button> -->
            <!-- <el-button size="mini" @click="$util.toggleSelect($refs.multipleTable)">反选</el-button> -->
            <!--              <el-button size="mini" type="primary" @click="startTask">办理</el-button>-->
            <!-- <el-button size="mini" type="primary" @click="templateDialog1 = true">办理</el-button> -->
            <!-- <el-button size="mini" type="primary" @click="templateDialog = true">导入</el-button> -->
            <!-- </el-col> -->
            <el-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16" :offset="8">
              <el-pagination
                :disabled="loading"
                :page-size="pageParam.pageSize"
                :total="pageParam.total"
                :page-sizes="[10, 20, 30, 40,50,100,200]"
                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>
        <!--分页多选组件-->
        <pageSelector :selection="selection" :columns="selectionColumn" @removeCallback="removeCallback" />
      </div>
    </div>
  </div>
  <!-- <div>
    <el-card>
      <el-form size="mini" :model="searchInfo">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="当事人名称" label-width="100px">
              <el-input v-model="searchInfo.name" placeholder="请输入当事人名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="统一社会信用代码/注册号" label-width="200px">
              <el-input v-model="searchInfo.name" placeholder="请输入统一社会信用代码/注册号" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="处理方式" label-width="100px">
              <el-input v-model="searchInfo.name" placeholder="请输入处理方式" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button type="primary" size="mini">查找</el-button>
            <el-button size="mini">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

    <el-card>
      <el-table
        ref="multipleTable"
        :data="tableData"
        size="mini"
        tooltip-effect="dark"
        style="width: 100%"
        :fit="true"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          min-width="5%"
        />
        <el-table-column
          label="序号"
          min-width="5%"
          type="index"
        />
        <el-table-column
          prop="name"
          label="处罚决定书文号"
          min-width="10%"
          show-overflow-tooltip
        />
        <el-table-column
          prop="address"
          label="当事人"
          min-width="10%"
          show-overflow-tooltip
        />
        <el-table-column
          prop="address"
          label="案件编号"
          min-width="10%"
          show-overflow-tooltip
        />
        <el-table-column
          prop="address"
          label="经办人"
          min-width="10%"
          show-overflow-tooltip
        />
        <el-table-column
          prop="address"
          label="吊销时间"
          min-width="10%"
          show-overflow-tooltip
        />
        <el-table-column
          fixed="right"
          label="操作"
          min-width="10"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="edit">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align:right">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[100, 200, 300, 400]"
          :page-size="size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>
  </div> -->
</template>

<script>
import pageSelector from '@/components/PageSelector'
import { revokeListPage, startBizRevCancel } from '@/api/revoke'
import { saveAbnormalAccept, getRegulatory } from '@/api/abnormal'
export default {
  components: {
    pageSelector: pageSelector
  },
  data() {
    return {
      handleType: '',
      bustypeOptions: [],
      templateDialog1: false,
      showMore: false,
      templateDialog: false,
      uploadPath: `${process.env.VUE_APP_BASE_API}/bizSpeList/upload`,
      selection: [],
      selectionColumn: [{ label: '序号', type: 'index', minWidth: '30px' }, { label: '统一社会信用代码/注册号', prop: 'uscc', minWidth: '100px' }, { label: '主体名称', prop: 'entname', minWidth: '100px' }],
      searchForm: {
        searchCode: '',
        searchName: ''
        // reportYear: '',
        // regulatory: ''
      },
      loading: false,
      showFixed: false,
      tableData: [],
      pageParam: {
        customParamMap: {},
        curPage: 1,
        total: 0,
        pageSize: 10
      }
    }
  },
  computed: {
    fixedHeader() {
      return this.$store.state.settings.fixedHeader
    }
  },
  mounted() {
    // this.getbustypeOptions()
    // this.loadPage()
    window.addEventListener('scroll', this.handleScroll, true)
  },
  methods: {
    showMoreCriteria() {
      this.showMore = !this.showMore
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      }
    },
    getbustypeOptions() {
      getRegulatory().then(res => {
        if (res.code === 0) {
          this.bustypeOptions = res.data
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    uploadCallback(res, file) {
      if (res.code === 0) {
        this.$router.push({ path: '/abnormal/company/inclusion/accept', query: { tasklistid: res.data.tasklistid, bizseq: res.data.bizseq, workflowId: res.data.workflowId }})
      } else {
        this.$message.error(res.msg)
      }
    },
    // 模板下载
    downLoadTemp() {
      const name = 'company_list.xls'
      window.open(process.env.NODE_ENV === '"development"' ? `/${name}` : `/aiccs/${name}`)
    },
    handleScroll() {
      var scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop
      if (scrollTop > 80) {
        this.showFixed = true
      } else {
        this.showFixed = false
      }
    },
    selectBlur(e) {
      this.searchForm.reportYear = e.target.value
      // this.$set(this.searchForm, 'reportYear', e.target.value)
    },
    test(row) {
      this.$router.push({ path: '/revoke/revokeDetail', query: { currentNode: 'revCancelEnter', revlistid: row.revlistid, handleType: this.handleType }})
    },
    // 启动待办
    startTask(revlistid) {
      if (this.$util.isEmpty(this.handleType)) {
        return this.$message.warning('请先选择处理方式')
      }
      var handleTypeName = ''
      switch (this.handleType) {
        case '1': handleTypeName = '撤销'; break
        case '2': handleTypeName = '复议'; break
        case '3': handleTypeName = '诉讼'; break
      }
      this.$confirm('是否确认启动' + handleTypeName + '待办', '提示').then(() => {
        startBizRevCancel(revlistid, this.handleType).then(res => {
          if (res.code === 0) {
            this.$router.push({ path: '/revoke/revokeDetail', query: { handleType: this.handleType, currentNode: 'revCancelEnter', workflowId: res.data.workflowid, 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()
    },
    // 分页多选插件回调
    removeCallback(index, row) {
      this.$refs.multipleTable.toggleRowSelection(row, false)
    },
    // 全选按钮事件
    selectAll() {
      const table = this.$refs.multipleTable
      for (const i in table.data) {
        const each = table.data[i]
        table.toggleRowSelection(each, true)
      }
    },
    // 选项变更事件
    handleSelectionChange(selectData) {
      const cancel = []
      if (selectData.length !== this.tableData.length) {
        // 找出没有选中的内容
        this.tableData.forEach(each => {
          for (const i in selectData) {
            const atom = selectData[i]
            if (atom.pripid === each.pripid) {
              return
            }
          }
          cancel.push(each)
        })
      }
      // 取消选中的内容
      for (const i in cancel) {
        const each = cancel[i]
        let index
        for (const j in this.selection) {
          const select = this.selection[j]
          if (select.pripid === each.pripid) {
            index = parseInt(j)
            break
          }
        }
        if (index !== undefined) {
          this.selection.splice(index, 1)
        }
      }
      // 增加选中内容
      for (const i in selectData) {
        const each = selectData[i]
        let exist = false
        for (const j in this.selection) {
          const select = this.selection[j]
          if (select.pripid === each.pripid) {
            exist = true
            break
          }
        }
        if (!exist) {
          this.selection.push(each)
        }
      }
    },
    // 当前分页改变
    pageIndexChange(curPage) {
      this.pageParam.curPage = curPage
      this.loadPage()
    },
    // 分页大小改变
    pageSizeChange(pageSize) {
      this.pageParam.pageSize = pageSize
      this.loadPage()
    },
    // 加载分页
    loadPage() {
      if (this.loading) return
      this.loading = true
      revokeListPage(this.pageParam).then(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.regno
          list.push(each)
        })
        this.tableData = list
        this.pageParam.total = res.data.total
        const selection = JSON.parse(JSON.stringify(this.selection))
        this.$nextTick(() => {
          for (const i in list) {
            const each = list[i]
            for (const j in selection) {
              if (each.pripid === selection[j].pripid) {
                this.$refs.multipleTable.toggleRowSelection(each, true)
              }
            }
          }
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.main-content{
  background: #fff;
  margin-bottom: 50px;
  padding: 10px;
  .content-header{
    background: white;
    .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);
    }
    .search-input{
      cursor: pointer;
    }
    .body{
      padding: 20px 0 ;
      border-top:none;
      margin-bottom: 40PX;
    }
  }
  .content-body{
    background:white;
    margin-bottom: 100px;
  }
  .header{
    .title{
      font-weight: 600;
      font-size: 1.2rem;
    }
  }
  .page-box{
    margin:10PX;
    .el-pagination{
      text-align: right;
    }
  }
  .prompt{
    color: #F53633;
  }
.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);
}
}
.mb10{
  margin-bottom: 10px;
}
.content-body{
  background: #fff;
  /deep/.el-table .warning-row {
    background: #eaf4fe!important;
  }
}
</style>
