<template>
  <div>
    <!-- 表单查询项 -->
    <div class="headerbox">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="200">
        <el-row>
          <el-col :span="5">
            <el-form-item label="项目名称" style="width: 100%;">
              <el-input v-model="queryParams.xmmc" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="项目建设起止时间">
              <el-date-picker type="daterange" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{ width: '100%' }"
                start-placeholder="开始日期" end-placeholder="结束日期" range-separator="至" clearable
                v-model="queryParams.xmqzsj"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="现状分类">
              <el-select v-model="queryParams.xzfl" placeholder="现状分类" clearable>
                <el-option v-for="dict in dict.type.xzfl" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="评价等级">
              <el-select v-model="queryParams.pjdj" placeholder="请选择评价等级" clearable>
                <el-option v-for="dict in dict.type.pjdj" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <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-col>
        </el-row>
      </el-form>
    </div>
    <!-- 表格内容区 -->
    <div class="tablebox">
      <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" align="center" prop="id" />
        <el-table-column label="项目名称" align="center" prop="xmmc" />
        <el-table-column label="现状分类" align="center">
          <template slot-scope="scope">
            {{ xzflMap[scope.row.xzfl] || scope.row.xzfl }}
          </template>
        </el-table-column>
        <el-table-column label="项目法人单位" align="center" prop="xmfrdw" />
        <el-table-column label="项目建设起止时间" align="center" prop="xmqzsj" />
        <el-table-column label="项目评价" align="center" width="130" prop="xmpj" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-view" @click="handleInfo(scope.row)"
              v-hasPermi="['system:post:detail']">详情</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['system:post:edit']">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.current" :limit.sync="queryParams.size"
        @pagination="getList" />
    </div>

    <!-- 详情对话框 -->
    <el-dialog title="项目详情" :visible.sync="infoDialogVisible" width="50%">
      <el-form :model="infoForm" label-width="120px" :disabled="true">
        <el-form-item label="项目名称">
          <el-input v-model="infoForm.xmmc" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目建设起止时间">
          <el-date-picker type="daterange" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{ width: '100%' }"
            start-placeholder="开始日期" end-placeholder="结束日期" range-separator="至" clearable
            v-model="infoForm.xmqzsj"></el-date-picker>
        </el-form-item>
        <el-form-item label="现状分类">
          <el-select v-model="infoForm.xzfl" placeholder="现状分类" clearable>
            <el-option v-for="dict in dict.type.xzfl" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="评价等级">
          <el-select v-model="infoForm.pjdj" placeholder="请选择评价等级" clearable>
            <el-option label="区域一" value="1"></el-option>
            <el-option label="区域二" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目法人单位">
          <el-input v-model="infoForm.xmfrdw" placeholder="请输入项目法人单位" />
        </el-form-item>
        <el-form-item label="项目评价">
          <el-input v-model="infoForm.xmpj" placeholder="请输入项目评价" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="infoDialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>


    <!-- 修改对话框 -->
    <el-dialog title="修改项目" :visible.sync="dialogVisible" width="50%">
      <el-form :model="editForm" label-width="120px">
        <el-form-item label="项目名称">
          <el-input v-model="editForm.xmmc" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目建设起止时间">
          <el-date-picker type="daterange" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{ width: '100%' }"
            start-placeholder="开始日期" end-placeholder="结束日期" range-separator="至" clearable
            v-model="editForm.xmqzsj"></el-date-picker>
        </el-form-item>
        <el-form-item label="现状分类">
          <el-select v-model="editForm.xzfl" placeholder="现状分类" clearable>
            <el-option v-for="dict in dict.type.xzfl" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="项目法人单位">
          <el-input v-model="editForm.xmfrdw" placeholder="请输入项目法人单位" />
        </el-form-item>
        <el-form-item label="项目评价">
          <el-input v-model="editForm.xmpj" placeholder="请输入项目评价" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateProject">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getProjectEvaluationList, updateProjectEvaluationList } from '@/api/ManageApi/index.js';

export default {
  dicts: [
    'xzfl', 'pjdj'
  ],
  data() {
    return {
      //映射
      xzflMap: {
        '1': '已建',
        '2': '再建',
        '3': '拟建'
      },
      postList: [],
      loading: false,
      total: 0,
      queryParams: {
        current: 1,
        size: 10,
        xmmc: '',
        xmqzsj: '',
        xzfl: '',
        pjdj: ''
      },
      showSearch: true,
      dialogVisible: false,
      editForm: {
        id: '',
        xmmc: '',
        xmqzsj: '',
        xzfl: '',
        pjdj: '',
        xmfrdw: '',
        xmpj: ''
      },
      infoDialogVisible: false,
      infoForm: {
        id: '',
        xmmc: '',
        xmqzsj: '',
        xzfl: '',
        pjdj: '',
        xmfrdw: '',
        xmpj: ''
      }
    };
  },
  methods: {
    handleQuery() {
      this.getList();
    },
    resetQuery() {
      this.queryParams = {
        current: 1,
        size: 10,
        xmmc: '',
        xmqzsj: '',
        xzfl: '',
        pjdj: ''
      };
      this.handleQuery();
    },
    getList() {
      this.loading = true;
      getProjectEvaluationList(this.queryParams)
        .then(response => {
          this.postList = response.data.records;
          this.total = response.data.total;
        })
        .catch(error => {
          console.error('获取项目评价清单失败:', error);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    handleSelectionChange(selection) {
      // 处理选择项变化
    },
    handleInfo(row) {
      this.infoForm = { ...row };
      this.infoDialogVisible = true;
    },
    handleUpdate(row) {
      this.editForm = { ...row };
      this.dialogVisible = true;
    },
    updateProject() {
      updateProjectEvaluationList(this.editForm)
        .then(response => {
          this.$message.success('修改成功');
          this.dialogVisible = false;
          this.getList();
        })
        .catch(error => {
          console.error('修改项目失败:', error);
          this.$message.error('修改失败');
        });
    },
    handleDelete(row) {
      // 处理删除
    }
  },
  mounted() {
    this.getList();
  }
};
</script>

<style scoped>
.headerbox {
  background-color: #fff;
  border-radius: .5rem;
  padding: 1rem;
  margin: .5rem;
  border: 1px solid #eee;
}

.tablebox {
  background-color: #fff;
  border-radius: .5rem;
  padding: 1rem;
  margin: .5rem;
  border: 1px solid #eee;
}

.tablehead {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.headbtn {
  display: flex;
}

.tablebtntwo {
  margin-top: 1rem;
  margin-bottom: 1rem;
}
</style>