<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-button-group class="pull-right">
        <el-button
          type="default"
          size="small"
          icon="el-icon-search"
          @click="isSearchCollapse = !isSearchCollapse, isImportCollapse=false">
        </el-button>
        <el-button
          type="default"
          size="small"
          icon="el-icon-refresh"
          @click="refreshList">
        </el-button>
      </el-button-group>
    </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="工程竣工结束30天内，未按要求上报竣工资料至结算中心，每发生一起，扣5分。">
        <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-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="工作量弄虚作假，上报工作量与实际存在10%以上的偏差，每发生一起，扣5分。★">
        <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="接到分包中标通知书后，15天内未至安能杰签订分包合同，每发生一起，扣3分。经催办后7天内仍未至安能杰签订合同，追加扣分5分。">
        <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="接到安能杰公司开票通知后，7天内未将发票送至安能杰公司，扣1-10分。">
        <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="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/costCompletionList',
          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 = 'f3cfc08e5ea24d3780bfe89c0d6c8c80'
            break
          case '2':
            this.subClass = '92c068926a8041369b73708c7ff1eda8'
            break
          case '3':
            this.subClass = 'b5010972a5a44e9a8a8e1e04f5361808'
            break
          case '4':
            this.subClass = 'e30f4db933ef477ca66415d0bb426dac'
            break
          case '5':
            this.subClass = '5aabe8b2882c4de396626e7de6a712f7'
            break
        }
        this.$router.push({path: './DeductionShowDetailsList', query: {unitId: id, subClass: this.subClass}})
      },
      sub (id) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        this.$refs.deductionDetailsForm.init('edit', id)
      },
      // 查看
      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>
