<template>
  <div class="tjzbManage" v-loading="loading">
    <div class="flex-row" style="margin: 10px;">
      <div>{{detailForm.jdd_name}}</div>
      <el-button type="success" size="medium" @click="createNew">
        <span class="d-in-block v-mid el-icon-plus font-size-16"></span>
        <span class="d-in-block v-mid font-size-16">新建指标</span>
      </el-button>
    </div>

    <el-table :data="tableData" tooltip-effect="dark" v-loading="loading" style="width: 100%">
      <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
      <el-table-column v-for="(item, index) in columnData" :key="index" :label="item.name" show-overflow-tooltip :prop="item.key" width="auto"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-popover placement="bottom-end" trigger="hover">
            <div>
              <el-button type="text" @click="lookDetail(scope.row)">详情</el-button>
              <el-button type="text" @click="editData(scope.row)">编辑</el-button>
              <el-button type="text" @click="delData(scope.row)">删除</el-button>
            </div>
            <i style="transform: rotate(90deg);" class="el-icon-more" slot="reference"></i>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <!-- <footer class="flex-item-none" style="display: flex; justify-content: flex-end; margin-top: 30px">
      <el-pagination background layout="total,prev, pager, next" :page-size="limit" :total="total" :current-page.sync="cur_page" @current-change="handleCurrentChange"></el-pagination>
    </footer> -->

    <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" width="600px" :close-on-click-modal="false" @close="handleClose">
      <add-and-edit-indicator v-if="dialogType==1" ref="addAndEditIndicator" :parentId="parentId" :currentId="currentId" @close="handleClose"></add-and-edit-indicator>
      <indicator-detail v-if="dialogType==2" :currentId="currentId"></indicator-detail>
      <div slot="footer" v-if="dialogType==1">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="formSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { ddrwDetail, rwzbList, rwzbDelete } from "./api";
import AddAndEditIndicator from "./AddAndEditIndicator.vue";
import IndicatorDetail from "./IndicatorDetail.vue";
export default {
  data() {
    return {
      loading: false,
      parentId: "",
      detailForm: {},
      columnData: [
        {
          name: "指标名称",
          key: "jddr_name"
        },
        {
          name: "指标内容",
          key: "jddr_content"
        },
        {
          name: "指标说明",
          key: "jddr_brief"
        },
        {
          name: "指标分值",
          key: "jddr_score"
        },
        {
          name: "附件数量",
          key: "jddr_fjsl"
        },
        {
          name: "计划开始时间",
          key: "jddr_start_date"
        },
        {
          name: "计划结束时间",
          key: "jddr_end_date"
        },
        {
          name: "责任部门",
          key: "jddr_uo_name"
        }
      ],
      tableData: [],
      limit: 9999,
      total: 0,
      cur_page: 1,
      dialogTitle: "",
      dialogType: "",
      dialogFormVisible: false,
      currentId: "",
    }
  },
  components: { AddAndEditIndicator, IndicatorDetail },
  methods: {
    async initDetailInfo() {
      let res = await ddrwDetail({ jdd_id: this.parentId });
      this.detailForm = res.one_info;
    },
    async getListData() {
      this.loading = true;
      let obj = {
        page: this.cur_page,
        limit: this.limit,
        jdd_id: this.parentId,
      }
      let data = await rwzbList(obj);
      if (data) {
        this.tableData = data.page_data;
        this.cur_page = Number(data.page_now);
        this.total = Number(data.total_rows);
        this.loading = false;
      }
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    createNew() {
      this.dialogFormVisible = true;
      this.dialogTitle = "新建指标";
      this.dialogType = 1;
    },
    editData(data) {
      this.dialogFormVisible = true;
      this.dialogTitle = "编辑指标";
      this.currentId = data.jddr_id;
      this.dialogType = 1;
    },
    delData(data) {
      this.$confirm("是否确定删除当前数据？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          let res = await rwzbDelete({ jddr_id: data.jddr_id });
          if (res) {
            this.$message.success("删除成功！");
            this.getListData();
          }
        })
        .catch(() => { });
    },
    handleClose(type) {
      this.dialogFormVisible = false;
      this.dialogType = "";
      this.$refs.addAndEditIndicator && this.$refs.addAndEditIndicator.resetForm();
      this.currentId = "";
      if (type == 1) {
        this.getListData();
      }
    },
    formSubmit() {
      this.$refs.addAndEditIndicator.commitData();
    },
    lookDetail(data) {
      this.currentId = data.jddr_id;
      this.dialogFormVisible = true;
      this.dialogType = 2;
      this.dialogTitle = "详情";
    },
  },
  created() {
    this.parentId = this.$route.params.id;
    this.initDetailInfo();
    this.getListData();
  }
}
</script>

<style>
</style>