<template>
  <div>
    <div class="font-size-14">任务指标</div>
    <div class="font-size-12 text-right" style="color: #ff0000;">*只能看见需要我({{userInfo.uo_name}})自己需要上传的内容</div>

    <el-table :data="tableData" tooltip-effect="dark" 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="操作" width="90">
        <template slot-scope="scope">
          <el-button type="text" v-if="scope.row.is_upload==2" @click="handleUpload(scope.row)">上传</el-button>
          <el-button type="text" v-if="scope.row.is_upload==1" @click="lookDetail(scope.row)">查看</el-button>
          <el-button type="text" v-if="scope.row.is_upload==1" @click="handleEdit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="上传" :visible.sync="dialogFormVisible" width="800px" :close-on-click-modal="false" @close="handleClose">
      <indicator-upload v-if="dialogType==1" ref="indicatorUpload" :parentId="parentId" :xfId="xfId" :currentId="currentId" :detailId="detailId" :dialogFormVisible="dialogFormVisible" @close="handleClose" />
      <indicator-show v-if="dialogType==2" :detailId="detailId" />
      <div slot="footer" v-if="dialogType==1">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="formSubmit" :loading="btnLoading">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { rwzbList } from "../api";
import { useUserStore } from "@/stores/user";
import IndicatorUpload from "./IndicatorUpload.vue";
import IndicatorShow from "./IndicatorShow.vue";
export default {
  data() {
    return {
      userInfo: useUserStore(),
      parentId: "",
      xfId: "",
      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"
        },
        {
          name: "状态",
          key: "statusName"
        }
      ],
      tableData: [],
      limit: 9999,
      total: 0,
      cur_page: 1,
      dialogType: "",
      dialogFormVisible: false,
      currentId: "",
      detailId: "",
      shObj: {
        "1": "已审核",
        "2": "未提交",
        "3": "待审核"
      },
      btnLoading: false,
    }
  },
  components: { IndicatorUpload, IndicatorShow },
  methods: {
    async getListData() {
      let obj = {
        page: this.cur_page,
        limit: this.limit,
        jdd_id: this.parentId,
        jddx_uo_id: this.userInfo.uo_id,
        ptype: "2",
        page_type: "myupload"
      }
      let data = await rwzbList(obj);
      if (data) {
        this.tableData = data.page_data;
        this.tableData.map(item => {
          item.statusName = item.is_upload == 2 ? "未上传" : "已上传";
          if (item.jdbg_dddx_ddrw_tjjl && item.jdbg_dddx_ddrw_tjjl.jddt_id) {
            for (let key in this.shObj) {
              if (item.jdbg_dddx_ddrw_tjjl.jddr_sh_status == key) {
                item.statusName = this.shObj[key];
              }
            }
          }
        })
      }
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    handleUpload(data) {
      this.dialogType = 1;
      this.dialogFormVisible = true;
      this.currentId = data.jddr_id;
    },
    handleEdit(data) {
      this.dialogType = 1;
      this.dialogFormVisible = true;
      this.currentId = data.jddr_id;
      this.detailId = data.jdbg_dddx_ddrw_tjjl.jddt_id;
    },
    lookDetail(data) {
      this.dialogType = 2;
      this.dialogFormVisible = true;
      this.currentId = data.jddr_id;
      this.detailId = data.jdbg_dddx_ddrw_tjjl.jddt_id;
    },
    handleClose(type) {
      this.dialogFormVisible = false;
      this.$refs.indicatorUpload && this.$refs.indicatorUpload.resetForm();
      this.currentId = "";
      this.detailId = "";
      this.dialogType = "";
      this.btnLoading = false;
      if (type == 1) {
        this.getListData();
      }
    },
    formSubmit() {
      this.btnLoading = true;
      this.$refs.indicatorUpload.commitData();
    },
  },
  created() {
    this.parentId = this.$route.params.id;
    this.xfId = this.$route.params.xfId;
    this.getListData();
  }
}
</script>