<template>
  <!-- 全流程管理组件 -->
  <div class="StepsMyBox">
    <div style="padding: 10px">
      <el-button type="primary" icon="el-icon-arrow-left" @click="backEvent()">返回上级</el-button>
    </div>
    <!-- 全流程管理主题 -->
    <div class="StepsMyBox_main">
      <!-- 左侧项目明细 -->
      <div class="StepsMyBox_main_left">
        <div class="StepsMyBox_main_left_main">
          <div class="StepsMyBox_main_left_main_title">{{ clickData.c_project_name ? clickData.c_project_name : "--" }}</div>
          <div class="StepsMyBox_main_left_main_info">基本信息</div>
          <div class="StepsMyBox_main_left_main_info">
            <div>创建日期:</div>
            <div>{{ clickData.c_create_date ? $dayjs(clickData.c_create_date).format("YYYY-MM-DD") : "--" }}</div>
          </div>
          <div class="StepsMyBox_main_left_main_info">
            <div>项目类型:</div>
            <div>{{ clickData.c_task_type_str ? clickData.c_task_type_str : "" }}</div>
          </div>
          <div class="StepsMyBox_main_left_main_info">
            <div>涉及街镇:</div>
            <div>{{ clickData.c_owning_street_town_str ? clickData.c_owning_street_town_str : "" }}</div>
          </div>
          <div class="StepsMyBox_main_left_main_info">
            <div>参与人员:</div>
            <div>{{ countUser }}个</div>
          </div>
          <div class="StepsMyBox_main_left_main_info">
            <div>追踪问题:</div>
            <div>5个</div>
          </div>
        </div>
      </div>
      <!-- 右侧流程明细 -->
      <div class="StepsMyBox_main_right">
        <div>
          <el-steps :active="stepsIndex" style="margin: 40px 40px 40px 80px">
            <el-step v-for="(item, index) in stepsList" :key="index">
              <template slot="title">
                <div
                  class="stepsTitle"
                  :style="{ background: stepsIndex == index + 1 ? '#00aaff' : '' }"
                  @click="changeStepsIndex(index + 1)"
                >
                  {{ item.title }}
                </div>
              </template>
            </el-step>
          </el-steps>
        </div>
        <div class="stepsInfoBox">
          <!-- 流程明细文字描述 -->
          <div>{{ stepsList[stepsIndex - 1].info.text }}</div>
          <!-- 流程明细文件预览（通知和报告会用到文件预览） -->
          <FilePreView ref="filePreview" v-show="fileView" />
          <!-- 流程明细-实施列表 -->
          <div v-if="stepsList[stepsIndex - 1].info.infos">
            <div v-for="item in stepsList[stepsIndex - 1].info.infos" :key="item.id" style="padding-bottom: 1rem">
              <span>{{ item.title }}</span
              ><el-button size="mini" type="primary" class="infoBut" style="margin-left: 2rem" @click="getInfoById(item.id)"
                >查看详情</el-button
              >
            </div>
          </div>
          <!-- 流程明细-整改表格 -->
          <div v-if="stepsList[stepsIndex - 1].info.tableData">
            <div class="flexBox">
              <div v-for="(value, key) in stepsList[stepsIndex - 1].info.props" :key="key">
                <div class="tableTitle">{{ value }}</div>
              </div>
            </div>
            <div
              v-for="(item, index) in stepsList[stepsIndex - 1].info.tableData"
              :key="item.id"
              class="flexBox"
              style="padding: 0.5rem 0"
            >
              <div v-for="(value, key) in stepsList[stepsIndex - 1].info.props" :key="key">
                <span v-if="key != 'opt'">{{ stepsList[stepsIndex - 1].info.tableData[index][key] }}</span>
                <el-button
                  v-else
                  size="mini"
                  type="primary"
                  class="infoBut"
                  @click="getInfoById(stepsList[stepsIndex - 1].info.tableData[index].id)"
                >
                  查看详情
                </el-button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/**
 * 头部菜单（全流程管理）组件
 * @author: LiuMengxiang
 * @Date: 2022年11月21-25日
 */
import FilePreView from "./FilePreView.vue";
export default {
  name: "StepsMyBox",
  components: { FilePreView },
  data() {
    return {
      // 当前或默认选中的步骤条下标加一
      stepsIndex: 1,
      // 是否显示在线文档预览
      fileView: false,
      // 该项目关联任务列表
      tableData: [],
      // 参与人员
      countUser: 0,
      // 步骤条列表
      stepsList: [
        { title: "立项", info: { text: "--" } },
        {
          title: "通知",
          info: { text: "2018年张江基本农田审计项目审计通知书.pdf", filePath: "./static/word/test.pdf" }
        },
        {
          title: "实施",
          info: {
            infos: [
              { title: "用户A 完成张江镇xxx片区的审计", id: "1" },
              { title: "用户B 完成张江镇xxx片区的审计", id: "2" },
              { title: "用户C 完成张江镇xxx片区的审计", id: "3" }
            ]
          }
        },
        {
          title: "报告",
          // info: { text: "2018年张江基本农田审计项目审计通知书.pdf", filePath: "/upload/20221128/20221128230553I6Nf00TN.docx" }
          info: { text: "2018年张江基本农田审计项目审计通知书.docx", filePath: "./static/word/test.docx" }
        },
        {
          title: "整改",
          info: {
            tableData: [
              {
                id: "1",
                desc: "xxxxx问题",
                status: "已完成",
                endTime: "2023-01-12"
              },
              {
                id: "2",
                desc: "xxxxx问题",
                status: "未开始",
                endTime: "2023-01-12"
              },
              {
                id: "3",
                desc: "xxxxx问题",
                status: "已完成",
                endTime: "2023-01-12"
              }
            ],
            props: { desc: "问题描述", status: "当前状态", endTime: "整改期限", opt: "操作" }
          }
        }
      ]
    };
  },
  props: ["clickData"],
  mounted() {},
  watch: {
    clickData: {
      handler(newValue, oldValue) {
        if (newValue != oldValue) {
          this.$nextTick(() => {
            // 获取项目基本信息
            this.stepsList[0].info.text =
              this.$dayjs(this.clickData.check_time).format("YYYY-MM-DD") +
              ": " +
              this.clickData.c_project_name +
              "（通过立项！）";
            // 获取项目关联任务信息
            this.getAllTasks();
            // 获取项目流程数据
            // console.log("全流程管理详情", newValue, oldValue);
          });
        }
      },
      deep: true,
      immediate: false
    }
  },
  methods: {
    // 流程管理【实施】节点，根据id查看详情
    getInfoById(id) {
      console.log("流程管理【实施】节点，根据id查看详情id:", id);
    },
    // 返回上级
    backEvent() {
      this.$emit("hideStepsMyBoxState");
    },
    // 切换步骤条
    changeStepsIndex(index) {
      this.stepsIndex = index;
      if (this.fileView) {
        this.$refs.filePreview.cancel();
        this.fileView = false;
      }
      // 判断流程明细是否存在文件，存在的话自动请求文件并渲染
      if (this.stepsList[this.stepsIndex - 1].info.filePath) {
        this.fileView = true;
        this.$refs.filePreview.showView(this.stepsList[this.stepsIndex - 1].info.filePath);
      }
    },

    // 查询事件
    getAllTasks() {
      let params = new FormData();
      this.countUser = 0;
      params.append("columnId", "61");
      params.append("states", "2,3");
      params.append("pageSize", 999);
      params.append("page", 0);
      let searchParam = [];
      if (this.clickData.id) {
        let param1 = {
          field: "c_associated_item_ids",
          searchType: "2",
          content: {
            value: this.clickData.id
          }
        };
        searchParam.push(param1);
      }
      params.append("search", JSON.stringify(searchParam));
      this.$Post(this.urlsCollection.selectContentList, params).then(
        res => {
          if (res.code === 200 && res.content.data.length > 0) {
            this.tableData = res.content.data;
            if (this.tableData.length > 0) {
              let usersList = [];
              this.tableData.forEach(item => {
                if (usersList.indexOf(item.author_id) < 0) {
                  usersList.push(item.author_id);
                  this.countUser++;
                }
              });
            }
          } else {
            this.tableData = [];
            this.countUser = 0;
          }
        },
        error => {
          this.tableData = [];
          this.countUser = 0;
        }
      );
    }
  }
};
</script>
<style lang="less" scoped>
.StepsMyBox {
  padding: 0;
  position: absolute;
  display: flex;
  background: #001220 !important;
  z-index: 999;
  width: 100%;
  height: 100%;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -khtml-user-select: none;
  user-select: none;
  overflow: hidden;
  flex-direction: column;
  &_main {
    padding: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    display: flex;
    justify-content: space-between;
    &_left {
      width: calc(25% - 5px);
      height: 100%;
      background: #00274d !important;
      &_main {
        margin: 20px 30px;
        display: flex;
        flex-direction: column;
        &_title {
          font-size: 20px;
          font-family: pingfangSC;
          font-weight: 400;
          color: #4dc3ff;
          line-height: 58px;
        }
        &_info {
          display: flex;
          padding: 10px 0;
          font-size: 18px;
          font-family: pingfangSC;
          font-weight: bold;
          color: #ffffff;
          line-height: 60px;
          div {
            font-size: 16px;
            font-family: pingfangSC;
            font-weight: 400;
            color: #ffffff;
            line-height: 50px;
            width: 50%;
          }
        }
      }
    }
    &_right {
      width: calc(75% - 5px);
      height: 100%;
      background: #00274d !important;
      .stepsTitle {
        margin-top: 10px;
        transform: translate(-30%, 0%);
        width: 2rem;
        cursor: pointer;
        padding: 0px 20px;
        border: 1px solid #00aaff;
        border-radius: 3px;
        color: #ffffff;
        font-weight: bold;
      }
      .stepsInfoBox {
        width: calc(100% - 80px);
        height: calc(100% - 200px);
        margin: 40px;
        margin-top: 0px;
        font-size: 18px;
        font-weight: bold;
        font-family: pingfangSC;
        line-height: 30px;
        color: #ffffff;
        .flexBox {
          display: flex;
          width: 100%;
          justify-content: space-evenly;
          align-items: center;
          align-content: space-around;
          flex-wrap: nowrap;
          flex-direction: row;
          .tableTitle {
            font-size: 20px;
            font-family: pingfangSC;
            font-weight: 400;
            color: #4dc3ff;
            padding-bottom: 0.5rem;
          }
          & > div {
            width: 100%;
          }
        }
      }
    }
  }
}
</style>
