<template>
  <div>
      <el-form :inline="true" v-show="isSearchCollapse" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
            <!-- 搜索框-->
        <el-col :span="8">
          <el-form-item label="评价年份" prop="yearOfEvaluation">
            <el-date-picker
              v-model="searchForm.yearOfEvaluation"
              type="year"
              size="small"
              value-format="yyyy"
              placeholder="选择年份">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="单位名称" prop="unitName">
            <el-input size="small" v-model="searchForm.unitName" placeholder="单位名称" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-form-item>
            <el-button type="primary" @click="refreshList()" size="small">查询</el-button>
            <el-button @click="resetSearch()" size="small">重置</el-button>
          </el-form-item>
      </el-form>
    <el-row>
      <!--        <el-button v-if="hasPermission('deductiondetails:deductionDetails:add')" type="primary" size="small" icon="el-icon-plus" @click="add()">扣分</el-button>-->
      <el-button v-if="hasPermission('deductiondetails:deductionDetails:edit')" type="warning" size="small" icon="el-icon-edit-outline" @click="sub()"
                 :disabled="dataListSelections.length != 1" plain>扣分</el-button>
    </el-row>
    <el-table
      :data="dataList"
      border
      size="medium"
      @selection-change="selectionChangeHandle"
      @sort-change="sortChangeHandle"
      v-loading="loading"
      class="table">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="yearOfEvaluation"
        show-overflow-tooltip
        sortable="custom"
        label="施工单位年份">
      </el-table-column>
      <el-table-column
        prop="unitName"
        show-overflow-tooltip
        sortable="custom"
        label="施工单位名称">
      </el-table-column>
      <el-table-column
        prop="basicScore"
        show-overflow-tooltip
        sortable="custom"
        label="基础分数">
      </el-table-column>
      <el-table-column
        prop="reasonOne"
        show-overflow-tooltip
        sortable="custom"
        label="现场工作被发现存在违章行为并被处以黄牌，每发生一起，扣1分。">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'1')">{{scope.row.reasonOne}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="reasonTwo"
        show-overflow-tooltip
        sortable="custom"
        label="现场工作被发现存在违章行为并被处以橙牌，每发生一起，扣2分。">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'2')">{{scope.row.reasonTwo}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="reasonThree"
        show-overflow-tooltip
        sortable="custom"
        label="现场工作被发现存在违章行为并被处以红牌，每发生一起，扣3分。">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'3')">{{scope.row.reasonThree}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="reasonFour"
        show-overflow-tooltip
        sortable="custom"
        label="现场工作被市公司发现存在违章行为并被亮牌，按1.1、1.2、1.3中扣分值2倍扣减；现场工作被省公司发现存在违章行为并被亮牌，按1.1、1.2、1.3中扣分值3倍扣减；">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'4')">{{scope.row.reasonFour}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="reasonFive"
        show-overflow-tooltip
        sortable="custom"
        label="违章行为被发现后，未按要求反馈整改报告、或未按要求缴纳罚款，每发生一起，扣5分。">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'5')">{{scope.row.reasonFive}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="reasonSix"
        show-overflow-tooltip
        sortable="custom"
        label="违章行为被发现后，拒不整改或整改态度较差，每发生一起，视情况扣3-10分。★">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'6')">{{scope.row.reasonSix}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="reasonSen"
        show-overflow-tooltip
        sortable="custom"
        label="施工现场因安全管控不力，被勒令停工，每发生一起，视情况扣5-20分。">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'7')">{{scope.row.reasonSen}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="reasonEig"
        show-overflow-tooltip
        sortable="custom"
        label="未按要求上报工作计划，每发生一起，扣6分。">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'8')">{{scope.row.reasonEig}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        prop="sumScore"
        show-overflow-tooltip
        sortable="custom"
        label="汇总评分">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageNo"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="total"
      background
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
        <!-- 弹窗, 新增 / 修改 -->
    <DeductionShowDetailsForm  ref="deductionShowDetailsForm" @refreshDataList="refreshList"></DeductionShowDetailsForm>
    <DeductionDetailsForm  ref="deductionDetailsForm" @refreshDataList="refreshList"></DeductionDetailsForm>
  </div>
</template>

<script>
  import DeductionShowDetailsForm from './DeductionShowDetailsForm'
  import DeductionDetailsForm from '../deductiondetails/DeductionDetailsForm'
  export default {
    data () {
      return {
        searchForm: {
          yearOfEvaluation: new Date().getFullYear().toString(),
          id: '',
          unitId: '',
          classId: ''
        },
        columns: [],
        dataList: [],
        pageNo: 1,
        pageSize: 10,
        total: 0,
        orderBy: '',
        subClass: '',
        dataListSelections: [],
        isSearchCollapse: false,
        isImportCollapse: false,
        loading: false
      }
    },
    components: {
      DeductionShowDetailsForm,
      DeductionDetailsForm
    },
    activated () {
      this.refreshList()
    },

    methods: {
      // 获取数据列表
      refreshList () {
        this.loading = true
        this.$http({
          url: '/deductionShowDetails/deductionShowDetails/siteQualityList',
          method: 'get',
          params: {
            'pageNo': this.pageNo,
            'pageSize': this.pageSize,
            'orderBy': this.orderBy,
            ...this.searchForm
          }
        }).then(({data}) => {
          if (data && data.success) {
            console.log(data)
            this.dataList = data.page.list
            this.total = data.page.count
            this.loading = false
          }
        })
      },

      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageNo = 1
        this.refreshList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageNo = val
        this.refreshList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },

    // 排序
      sortChangeHandle (obj) {
        if (obj.order === 'ascending') {
          this.orderBy = obj.prop + ' asc'
        } else if (obj.order === 'descending') {
          this.orderBy = obj.prop + ' desc'
        } else {
          this.orderBy = ''
        }
        this.refreshList()
      },
      // 新增
      add () {
        this.$refs.deductionShowDetailsForm.init('add', '')
      },
      edit (id, type) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        console.log(id)
        switch (type) {
          case '1':
            this.subClass = '40d3781b833d4aa1b71e554540a2f343'
            break
          case '2':
            this.subClass = '272732b61c3e4433a7ea995c3c380d3f'
            break
          case '3':
            this.subClass = '508908a274c14a70a16897ae54aca5d7'
            break
          case '4':
            this.subClass = 'b268162d96be428d9426f17559143658'
            break
          case '5':
            this.subClass = 'bee7ec8b8eaa4303bd08b22b040906fe'
            break
          case '6':
            this.subClass = 'aba0d89ce70c4dbdb1ab027d5b20182d'
            break
          case '7':
            this.subClass = 'aadfb12bb0b549c6bee44c5695c11e2f'
            break
          case '8':
            this.subClass = '7e9cdf43a4ba4db490ae03a23844b2f3'
            break
        }
        this.$router.push({path: './DeductionShowDetailsList', query: {unitId: id, subClass: this.subClass, classId: '8c9fe0f62745471e8c341e0e7327aa9b'}})
      },
      sub (id) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        this.$refs.deductionDetailsForm.init('edit', id, '8c9fe0f62745471e8c341e0e7327aa9b')
      },
      // 查看
      view (id) {
        this.$refs.deductionShowDetailsForm.init('view', id)
      },
      // 删除
      del (id) {
        let ids = id || this.dataListSelections.map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.$http({
            url: '/deductionshowdetails/deductionShowDetails/delete',
            method: 'delete',
            params: {'ids': ids}
          }).then(({data}) => {
            if (data && data.success) {
              this.$message.success(data.msg)
              this.refreshList()
            }
            this.loading = false
          })
        })
      },
      // 导入成功
      uploadSuccess (res, file) {
        if (res.success) {
          this.$message.success({dangerouslyUseHTMLString: true,
            message: res.msg})
        } else {
          this.$message.error(res.msg)
        }
      },
      // 下载模板
      downloadTpl () {
        this.$utils.download('/deductionshowdetails/deductionShowDetails/import/template')
      },
      exportExcel () {
        this.$utils.download('/deductionshowdetails/deductionShowDetails/export')
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.refreshList()
      }
    }
  }
</script>
