<template>
  <!-- 工程违章统计 -->
  <div class="app-container">
    <el-form v-show="showSearch" :model="queryParams" ref="queryForm" size="small" inline>
      <el-form-item label="工程名称" prop="proName">
        <el-input
          v-model="queryParams.proName"
          placeholder="请输入工程名称"
          clearable v-no-whitespace
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工程负责人" prop="leaderName">
        <el-input
          v-model="queryParams.leaderName"
          placeholder="请输入工程负责人名称"
          clearable v-no-whitespace
          @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" @click="handleReset">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出数据</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="tableList" fit highlight-current-row style="width: 100%">
      <!-- 多选 -->
      <el-table-column type="selection" width="55" align="center" @selection-change="selectionChange" />
      <el-table-column
        type="index"
        width="55"
        label="序号"
        align="center"
        :index="indexContinuous(queryParams.pageNum, queryParams.pageSize)"
      />
      <el-table-column
        v-for="(column, index) in tableColumns"
        show-overflow-tooltip
        :key="column.prop"
        :label="column.label"
        :prop="column.prop"
        align="center"
      >
        <!-- 插槽 -->
        <!-- <template v-slot="scope" v-if="column.prop == 'checkingInStatus'">
          <span>
            <el-switch v-model="scope.row.checkingInStatus" @change="changeSwitch(scope.row)"></el-switch>
          </span>
        </template> -->
      </el-table-column>
      <!-- 操作 -->
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleView(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { dictTableOption } from '@/api/tool/select'
import {
  exportProViolationStatisticsList,
  exportViolationPunishInfo,
  getProViolationStatistics
} from '@/api/violation/violation'

export default {
  data() {
    return {
      showSearch: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proName: '',
        leaderName: ''
      },
      total: 0, // 总条数
      // 表头
      tableColumns: [
        { label: '工程名称', prop: 'proName' },
        { label: '工程负责人', prop: 'leaderName' },
        { label: '违章总次数', prop: 'totalNum' },
        { label: '已下发处罚单数', prop: 'punishNum' },
        { label: '已完成处罚数', prop: 'finishNum' },
        { label: '未完成处罚数', prop: 'unFinishNum' },
      ],
      // 表格数据
      tableList: [],
      dialogVisible: false,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 查询
    handleQuery() {
      console.log('查询')
      this.getList()
    },
    // 重置
    handleReset() {
      console.log('重置')
      this.$refs.queryForm.resetFields()
      this.getList()
    },
    // 获取列表
    async getList() {
      try {
        getProViolationStatistics(this.queryParams).then(response => {
          console.log('🚀 ~ 获取列表 ~ response:', response)
          this.tableList = response.rows
          this.total = response.total
        })
      } catch (error) {
        console.log('🚀 ~ 获取列表 ~ error:', error)
      }
    },
    // 多选
    selectionChange(val) {
      console.log('selectionChange', val)
    },
    //获取工程类型
    getProType() {
      const params = {
        dictType: 'sys_pro_type',
        dictValue: '',
      }
      dictTableOption(params).then(response => {
        console.log('🚀 ~ dictTableOption ~ response:', response)
        this.proTypeOptions = response.data
      })
    },
    //获取工程类型
    getStatus() {
      const params = {
        dictType: 'sys_pro_status',
        dictValue: '',
      }
      dictTableOption(params).then(response => {
        console.log('🚀 ~ dictTableOption ~ response:', response)
        this.proStatusOptions = response.data
      })
    },
    // 查看详情
    handleView(row) {
      this.$router.push({
        path: '/violationManagenment/violationCount/violationDetails',
        query: {
          ...row,
          type:'工程违章详情'
        },
      })
    },
    // 导出数据
    handleExport() {
      try {
        let fileName = `工程违章统计记录_${new Date().getTime()}.xlsx`
        let url = exportProViolationStatisticsList()
        const params = { ...this.queryParams }
        console.log('🚀 ~ 导出 ~ params:', params)
        this.derive(url, params, fileName)
      } catch (error) {
        console.log('导出数据失败', error)
      }
    },
  },
}
</script>

<style lang="scss" scoped></style>
