<!-- 成果管理 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="xmmc">
        <el-input v-model="queryParams.xmmc" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="区块" prop="qk">
        <el-input v-model="queryParams.qk" placeholder="请输入区块" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="yscgList" :span-method="spanMethod">
      <el-table-column label="项目名称" align="center" prop="xmmc" min-width="150" show-overflow-tooltip />
      <el-table-column label="区块" align="center" prop="qk" min-width="120" show-overflow-tooltip />
      <el-table-column label="资料类型" align="center" prop="zllxmc" min-width="120" show-overflow-tooltip />
     
      <el-table-column label="上传情况" align="center" min-width="120">
        <template slot-scope="scope">
          <i :class="scope.row.zlsl > 0 ? 'el-icon-check' : 'el-icon-close'" 
             :style="{ color: scope.row.zlsl > 0 ? '#67C23A' : '#F56C6C', fontSize: '18px' }">
          </i>
        </template>
      </el-table-column>
      <el-table-column label="成果" align="center" prop="id" min-width="100" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看成果</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listYscgList } from "@/api/yscgWjscqk/wjscqk"

export default {
  name: "Yscg",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
      total: 0,
      // 成果管理表格数据
      yscgList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        xmmc: null,
        qk: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询成果管理列表 */
    getList() {
      this.loading = true
      listYscgList(this.queryParams).then(response => {
        this.yscgList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    /** 成果按钮操作 */
    handleView(row) {
      // 跳转到成果详情页面，传id
      this.$router.push({
        path: '/yscgWjscqk/wjscqk/index',
        query: {
          xmid: row.id
        }
      })
    },
    /** 表格行合并方法 */
    spanMethod({ row, column, rowIndex, columnIndex }) {
      // 项目名称列（第0列）、区块列（第1列）和成果列（第3列）需要合并
      if (columnIndex === 0 || columnIndex === 1 || columnIndex === 4) {
        let fieldName, currentValue
        
        if (columnIndex === 0) {
          fieldName = 'xmmc'
          currentValue = row[fieldName]
        } else if (columnIndex === 1) {
          fieldName = 'qk'
          currentValue = row[fieldName]
        } else if (columnIndex === 4) {
          fieldName = 'id'
          currentValue = row[fieldName]
        }
        
        // 如果当前值为空，不合并
        if (!currentValue) {
          return [1, 1]
        }
        
        // 如果当前值与上一行相同，则隐藏当前行
        if (rowIndex > 0 && this.yscgList[rowIndex - 1][fieldName] === currentValue) {
          return [0, 0]
        }
        
        // 计算需要合并的行数
        let rowspan = 1
        for (let i = rowIndex + 1; i < this.yscgList.length; i++) {
          if (this.yscgList[i][fieldName] === currentValue) {
            rowspan++
          } else {
            break
          }
        }
        
        return [rowspan, 1]
      }
      
      // 其他列不合并
      return [1, 1]
    }
  }
}
</script>
