<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="施工现场因扬尘、渣土管控不力，每发生一起，扣3分。">
        <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="施工现场因文明施工、安全施工、内部管控等组织不力，被区内其他单位或政府通报或上黑榜，每发生一起，视情况扣1-10分。★">
        <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="施工现场因文明施工、安全施工、内部管控等管控有力，被区内其他单位或政府表扬或上红榜，每发生一起，视情况加分。">
        <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="因文明施工、安全施工、内部管控等组织不力，引发12345工单，每发生一起，视情况扣1-2分。若处理不善导致工单频发，视情况追加扣2-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="因文明施工、安全施工、内部管控等组织不力，引发95598意见工单，每发生一起情况不属实扣1分。每发生一起情况属实扣3分。若处理不善导致工单频发，视情况追加扣2-3分。">
        <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="因文明施工、安全施工、内部管控等组织不力，引发95598投诉工单，每发生一起情况不属实扣5分。每发生一起情况属实扣10分。若处理不善导致工单频发，视情况追加扣5-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="因文明施工、安全施工、内部管控等组织不力，引发论坛、微博、来信等投诉、举报，每发生一起，视情况扣1-10分。若处理不善导致投诉、举报，追加扣1-5分。★">
        <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="外协单位内部人员通过12345、95598、论坛、微博、来信等渠道进行投诉，视情况扣5-10分。★">
        <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="reasonNin"
        show-overflow-tooltip
        sortable="custom"
        label="施工现场不服从管理，对工程质量、工程进度造成较大影响，每发生一起，扣5-10分。★">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'9')">{{scope.row.reasonNin}}</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/qualityCivilizedList',
          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 = '06d7938f26454e15a9acae90096ae22e'
            break
          case '2':
            this.subClass = 'fc2a636927124952a2f1d08e0b15a0ee'
            break
          case '3':
            this.subClass = 'd14955b9c9b744d9ad10b1379c1815d9'
            break
          case '4':
            this.subClass = 'af5800c001514d21be011b1826029d99'
            break
          case '5':
            this.subClass = 'daabb42eb3174605996db0bede6def63'
            break
          case '6':
            this.subClass = '922e9d5cf8e1465ba929836749b8b309'
            break
          case '7':
            this.subClass = '578c1507c2984143abb78377b248a672'
            break
          case '8':
            this.subClass = '8cadcc3844dc4ef485964b2bc43abcfb'
            break
          case '9':
            this.subClass = '70ed4b0c8a0443d586f9f9c97a044c41'
            break
        }
        this.$router.push({path: './DeductionShowDetailsList', query: {unitId: id, subClass: this.subClass, classId: 'bc91443b714c4993a3b136e000eb8bc2'}})
      },
      sub (id) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        this.$refs.deductionDetailsForm.init('edit', id, 'bc91443b714c4993a3b136e000eb8bc2')
      },
      // 查看
      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>
