<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-form :inline="true" v-show="isImportCollapse"  class="query-form" ref="importForm">
         <el-form-item>
          <el-button type="default" @click="downloadTpl()" size="small">下载模板</el-button>
         </el-form-item>
         <el-form-item prop="loginName">
            <el-upload
              class="upload-demo"
              :action="`${this.$http.BASE_URL}/deductiondetails/deductionDetails/import`"
              :on-success="uploadSuccess"
               :show-file-list="true">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只允许导入“xls”或“xlsx”格式文件！</div>
            </el-upload>
        </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 v-if="hasPermission('deductiondetails:deductionDetails:del')" type="danger"   size="small" icon="el-icon-delete" @click="del()"
                  :disabled="dataListSelections.length <= 0" 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="evaName"
        show-overflow-tooltip
        sortable="custom"
        label="施工单位名称">
      </el-table-column>
	  <el-table-column
        prop="safetyEva"
        show-overflow-tooltip
        sortable="custom"
        label="现场安全管控评价">
      <template slot-scope="scope">
      <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'1')">{{scope.row.safetyEva}}</el-link>
      </template>
    </el-table-column>
	  <el-table-column
        prop="progressEva"
        show-overflow-tooltip
        sortable="custom"
        label="现场施工质量及进度评价">
      <template slot-scope="scope">
      <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'2')">{{scope.row.progressEva}}</el-link>
      </template>
    </el-table-column>
	  <el-table-column
        prop="costEva"
        show-overflow-tooltip
        sortable="custom"
        label="造价及竣工资料评价">
      <template slot-scope="scope">
      <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'3')">{{scope.row.costEva}}</el-link>
      </template>
    </el-table-column>
	  <el-table-column
        prop="qualityEva"
        show-overflow-tooltip
        sortable="custom"
        label="优质服务及文明施工评价">
      <template slot-scope="scope">
      <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'4')">{{scope.row.qualityEva}}</el-link>
      </template>
    </el-table-column>
	  <el-table-column
        prop="pointsEva"
        show-overflow-tooltip
        sortable="custom"
        label="其他加减分评价">
      <template slot-scope="scope">
      <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'5')">{{scope.row.pointsEva}}</el-link>
      </template>
    </el-table-column>
	  <el-table-column
        prop="veto"
        show-overflow-tooltip
        sortable="custom"
        label="是否存在否决事项">
      <template slot-scope="scope">
      <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'6')">{{scope.row.veto}}</el-link>
      </template>
    </el-table-column>
      <el-table-column
        prop="sumScore"
        show-overflow-tooltip
        sortable="custom"
        label="汇总评分">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false"  @click="edit(scope.row.id,'7')">{{scope.row.sumScore}}</el-link>
        </template>
      </el-table-column>
<!--      <el-table-column
        header-align="center"
        align="center"
        fixed="right"
        width="200"
        label="操作">
        <template  slot-scope="scope">
          <el-button v-if="hasPermission('deductiondetails:deductionDetails:view')" type="text" icon="el-icon-view" size="small" @click="view(scope.row.id)">查看</el-button>
          <el-button v-if="hasPermission('deductiondetails:deductionDetails:edit')" type="text" icon="el-icon-edit" size="small" @click="edit(scope.row.id)">修改</el-button>
          <el-button v-if="hasPermission('deductiondetails:deductionDetails:del')" type="text"  icon="el-icon-delete" size="small" @click="del(scope.row.id)">删除</el-button>
        </template>
      </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>
    <DeductionDetailsForm  ref="deductionDetailsForm" @refreshDataList="refreshList"></DeductionDetailsForm>
  </div>
</template>

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

    methods: {
      // 获取数据列表
      refreshList () {
        this.loading = true
        this.$http({
          url: '/deductiondetails/deductionDetails/summaryList',
          method: 'get',
          params: {
            'pageNo': this.pageNo,
            'pageSize': this.pageSize,
            'orderBy': this.orderBy,
            ...this.searchForm
          }
        }).then(({data}) => {
          if (data && data.success) {
            console.log(data.page.list)
            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.deductionDetailsForm.init('add', '')
      },
      // 修改
      edit (id, type) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        console.log(id)
        switch (type) {
          case '1':
            this.classId = '8c9fe0f62745471e8c341e0e7327aa9b'
            break
          case '2':
            this.classId = '7a77a8251b124e858a1bef1bb353372b'
            break
          case '3':
            this.classId = '783ba447e0774b139fa1dc6ad4eeb4f3'
            break
          case '4':
            this.classId = 'bc91443b714c4993a3b136e000eb8bc2'
            break
          case '5':
            this.classId = '2f0e74b9e50b4bbb8d6322feac578076'
            break
          case '6':
            this.classId = '6018a3a93b164602aebc08ae44207ba5'
            break
          case '7':
            this.classId = ''
            break
        }
        this.$router.push({path: '../deductionshowdetails/DeductionShowDetailsList', query: {unitId: id, classId: this.classId}})
      },
      sub (id) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        this.$refs.deductionDetailsForm.init('edit', id, '')
      },
      // 查看
      view (id) {
        this.$refs.deductionDetailsForm.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: '/deductiondetails/deductionDetails/delete',
            method: 'delete',
            params: {'ids': ids}
          }).then(({data}) => {
            if (data && data.success) {
              this.$message.success(data.msg)
              this.DeductionShowDetailsList.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('/deductiondetails/deductionDetails/import/template')
      },
      exportExcel () {
        this.$utils.download('/deductiondetails/deductionDetails/export')
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.refreshList()
      }
    }
  }
</script>
