<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="对安能杰相关重点工作进行支撑，视情况加分。">
        <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="对安能杰相关重点工作未进行支撑或支撑不足，视情况扣分。">
        <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="出现因施工产生廉政问题线索经调查属实的情况，全年考评分数为0，情形恶劣的，从合格供应商名录中剔除。★">
        <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="承担工程范围内发生设备、人身伤亡事故、交通事故、电网事故等情况，全年考评分数为0，情形恶劣的，从合格供应商名录中剔除。★">
        <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="分包商超越资质承接业务，签订分包合同，全年考评分数为0，情形恶劣的，从合格供应商名录中剔除。★">
        <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="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: '',
        classId: '',
        dataListSelections: [],
        isSearchCollapse: false,
        isImportCollapse: false,
        loading: false
      }
    },
    components: {
      DeductionShowDetailsForm,
      DeductionDetailsForm
    },
    activated () {
      this.refreshList()
    },

    methods: {
      // 获取数据列表
      refreshList () {
        this.loading = true
        this.$http({
          url: '/deductionShowDetails/deductionShowDetails/otherPointsList',
          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 = '324d659b184b40068f9524848729070f'
            this.classId = '2f0e74b9e50b4bbb8d6322feac578076'
            break
          case '2':
            this.subClass = '2da85bc46a474f5fabab19a456b3f09c'
            this.classId = '2f0e74b9e50b4bbb8d6322feac578076'
            break
          case '3':
            this.subClass = '6f3134f09f404a0db5c7f3ccf9830993'
            this.classId = '2f0e74b9e50b4bbb8d6322feac578076'
            break
          case '4':
            this.subClass = '8c72c9a41d5445dc80e43efe90f9eec8'
            this.classId = '6018a3a93b164602aebc08ae44207ba5'
            break
          case '5':
            this.subClass = '0c242a74d37c4005a45655329e8cb178'
            this.classId = '6018a3a93b164602aebc08ae44207ba5'
            break
          case '6':
            this.subClass = 'be115e9ac0c841d5b475743be8499f4c'
            this.classId = '6018a3a93b164602aebc08ae44207ba5'
            break
        }
        this.$router.push({path: './DeductionShowDetailsList', query: {unitId: id, subClass: this.subClass, classId: this.classId}})
      },
      sub (id) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        this.$refs.deductionDetailsForm.init('edit', id, '2f0e74b9e50b4bbb8d6322feac578076')
      },
      // 查看
      view (id) {
        this.$refs.deductionDetailsForm.init('edit', 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>
