<template>
  <div class="">
    <div class="g-page" v-show="pageType == 'info'">
      <div class="g-left">
        <el-card style="overflow: auto">
          <h3>项目详情</h3>

          <div class="m-info">
            <div class="info-prop">
              <span class="info-title-2">项目标题：</span>
              <span>{{ projectInfo.projectTitle }}</span>
            </div>
            <div class="info-prop">
              <span class="info-title-2">项目背景：</span>
              <span>{{ projectInfo.backGround || "--" }}</span>
            </div>
            <div class="info-prop">
              <span class="info-title-2">项目方案：</span>
              <span>{{ projectInfo.publicReply }}</span>
            </div>
            <div class="info-prop">
              <span class="info-title-2">内部备注：</span>
              <span>{{ projectInfo.internalRemark || "--" }}</span>
            </div>

            <div
              class="info-prop"
              v-if="projectInfo.departmentNameList.length > 0"
            >
              <span class="info-title-2">当前处理部门：</span>
              <span>{{ projectInfo.departmentNameList.join("、") }}</span>
            </div>

            <div
              class="info-prop"
              v-if="
                projectInfo.origin == 'issue' ||
                projectInfo.origin == 'resi_event'
              "
            >
              <span class="info-title-2">项目来源：</span>
              <a style="cursor: pointer" @click="handleWatchOrigin"
                >查看项目来源</a
              >
            </div>

            <div class="info-prop" v-if="projectInfo.projectStatus == 'closed'">
              <span class="info-title-2">项目评价：</span>
              <a style="cursor: pointer" @click="showedEvaluation = true"
                >查看项目评价</a
              >
            </div>

            <div class="info-prop">
              <span class="info-title-2">分类：</span>
              <fold-text
                v-if="projectCate.length > 0"
                style="width: 250px"
                :row="3"
              >
                <div :key="item.name" v-for="item in projectCate">
                  {{ item.name }}
                </div>
              </fold-text>
              <span style="width: 250px" v-else>--</span>

              <el-popover
                v-if="projectInfo.projectStatus == 'pending'"
                placement="bottom"
                width="400"
                height="400"
                v-model="visibleCatePanel"
              >
                <div class="f" style="min-height: 120px">
                  <h2>更改分类</h2>
                  <el-cascader
                    v-model="selectedCateData"
                    :options="cateOptions"
                    :props="{
                      multiple: true,
                      label: 'name',
                      value: 'id',
                      children: 'subCategory',
                    }"
                    clearable
                  ></el-cascader>
                  <el-button
                    style="margin-left: 10px"
                    size="small"
                    type="danger"
                    @click="updateProjectCate"
                    >确定</el-button
                  >
                </div>
                <div slot="reference">
                  <el-button size="small" type="">更改</el-button>
                </div>
              </el-popover>
            </div>
            <div class="info-prop">
              <span class="info-title-2">标签：</span>
              <fold-text
                v-if="projectTag.length > 0"
                style="width: 250px"
                :row="3"
              >
                <div :key="item.name" v-for="item in projectTag">
                  {{ item.name }}
                </div>
              </fold-text>
              <span style="width: 250px" v-else>--</span>

              <el-popover
                v-if="projectInfo.projectStatus == 'pending'"
                placement="bottom"
                width="400"
                height="400"
                v-model="visibleTagPanel"
              >
                <div class="f" style="min-height: 120px">
                  <h2>更改标签</h2>
                  <el-select
                    v-model="selectedTagData"
                    multiple
                    allow-create
                    filterable
                    placeholder="请选择"
                    @change="handleTagChange"
                  >
                    <el-option-group label="自定义标签">
                      <el-option
                        v-for="item in tagOptions.customized"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                    </el-option-group>

                    <el-option-group label="常用标签">
                      <el-option
                        v-for="item in tagOptions.defaulted"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                    </el-option-group>
                  </el-select>

                  <el-button
                    style="margin-left: 10px"
                    size="small"
                    type="danger"
                    @click="updateProjectTag"
                    >确定</el-button
                  >
                </div>
                <div slot="reference">
                  <el-button size="small" type="">更改</el-button>
                </div>
              </el-popover>
            </div>
          </div>

          <div
            class="m-btns"
            v-if="
              !projectInfo.processable || projectInfo.projectStatus != 'pending'
            "
          >
            <el-button size="" @click="handleClose">关闭</el-button>
          </div>
        </el-card>
        <el-card
          style="overflow: auto"
          v-if="
            projectInfo.processable && projectInfo.projectStatus == 'pending'
          "
        >
          <h3>处理</h3>
          <div class="m-fm">
            <el-form
              ref="fm"
              :inline="false"
              :model="fmData"
              :rules="dataRule"
              label-position="left"
              label-width="100px"
            >
              <el-form-item label="处理方式：" prop="operateType">
                <el-radio-group v-model="fmData.operateType">
                  <el-radio label="dispose">处理/响应</el-radio>
                  <el-radio label="close">结案</el-radio>
                  <el-radio label="turn">转其他机关/科室</el-radio>
                  <el-radio label="back" v-if="projectInfo.returnable"
                    >退回</el-radio
                  >
                </el-radio-group>
              </el-form-item>

              <el-form-item
                label="您的身份："
                prop="projectStaffId"
                v-if="myDepartmentList.length > 1"
              >
                <el-select
                  v-model.trim="fmData.projectStaffId"
                  placeholder="请选择"
                  class="resi-cell-select"
                >
                  <el-option
                    v-for="item in myDepartmentList"
                    :key="item.projectStaffId"
                    :label="item.departmentName"
                    :value="item.projectStaffId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                v-if="fmData.operateType == 'turn'"
                label="处理部门："
                prop="publicReply"
              >
                <el-popover
                  placement="bottom"
                  width="400"
                  height="400"
                  v-model="visibleStaffPanel"
                >
                  <div class="f">
                    <select-staff
                      @confirm="(ret) => (fmData.staffList = ret)"
                      @close="visibleStaffPanel = false"
                    />
                  </div>

                  <div slot="reference">
                    <a
                      v-if="fmData.staffList.length == 0"
                      style="cursor: pointer"
                      >点击选择</a
                    >
                    <a v-else style="cursor: pointer"
                      >已选 {{ fmData.staffList.length }} 人</a
                    >
                  </div>
                </el-popover>
              </el-form-item>

              <el-form-item
                v-if="fmData.operateType != 'back'"
                label="协办单位："
                prop="assistanceUnitIndex"
              >
                <el-select
                  v-model.trim="fmData.assistanceUnitIndex"
                  placeholder="请选择"
                  class="resi-cell-select"
                >
                  <el-option
                    v-for="(item, index) in assistanceUnitList"
                    :key="item.assistanceUnitId"
                    :label="item.assistanceUnitName"
                    :value="index"
                  >
                  </el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                v-if="fmData.operateType == 'back'"
                label="退回到："
                prop="projectProcessId"
              >
                <el-select
                  v-model.trim="fmData.projectProcessId"
                  placeholder="请选择"
                  class="resi-cell-select"
                >
                  <el-option
                    v-for="item in returnableList"
                    :key="item.projectProcessId"
                    :label="item.processor"
                    :value="item.projectProcessId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                v-if="fmData.operateType == 'close'"
                label="结案状态："
                prop="closedStatus"
              >
                <el-select
                  v-model.trim="fmData.closedStatus"
                  placeholder="请选择"
                  class="resi-cell-select"
                >
                  <el-option
                    v-for="item in resolveTypeList"
                    :key="item.closedStatus"
                    :label="item.name"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>

              <el-form-item
                v-if="fmData.operateType == 'close'"
                label="结案说明："
                prop="publicReply"
              >
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="您输入的结案说明会向居民公开展示"
                  v-model="fmData.publicReply"
                >
                </el-input>
              </el-form-item>

              <el-form-item label="内部备注：" prop="internalRemark">
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="fmData.internalRemark"
                >
                </el-input>
              </el-form-item>

              <el-form-item
                v-if="fmData.operateType != 'close'"
                label="图片/附件："
                prop="internalFile"
              >
                <el-upload
                  class="avatar-uploader"
                  :action="uploadUlr"
                  :data="{ customerId: customerId }"
                  :show-file-list="true"
                  :on-success="handleImgSuccess"
                  :on-remove="handleImgRemove"
                  :before-upload="beforeImgUpload"
                >
                  <i class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
              </el-form-item>

              <el-form-item
                v-if="fmData.operateType != 'close'"
                label="公开回复："
                prop="publicReply"
              >
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="fmData.publicReply"
                >
                </el-input>
              </el-form-item>
            </el-form>
          </div>
          <div class="m-btns">
            <el-button size="" style="margin-right: 50px" @click="handleClose"
              >关闭</el-button
            >
            <el-button size="" type="danger" @click="handleSubmit"
              >确定</el-button
            >
          </div>
        </el-card>
      </div>
      <div class="g-right">
        <el-card
          class="m-card"
          :style="styleFullHeight"
          style="overflow: auto"
          v-if="projectProcess.length > 0"
        >
          <h3>处理进展</h3>
          <div class="m-process">
            <div class="list">
              <div
                class="item"
                :class="index === 0 ? 'z-on' : ''"
                :key="item.processId"
                v-for="(item, index) in projectProcess"
              >
                <div class="item-row">
                  <div class="name">{{ item.processName }}</div>
                  <div class="date">
                    {{ item.processTime }}
                  </div>
                </div>

                <div class="detail">
                  <div class="detail-field">处理部门：</div>
                  <div class="detail-value">{{ item.departmentName }}</div>
                </div>

                <div class="detail" v-if="item.assistanceUnitName">
                  <div class="detail-field">协办单位：</div>
                  <div class="detail-value">{{ item.assistanceUnitName }}</div>
                </div>

                <div
                  class="detail"
                  v-if="item.processName != '转项目' && item.publicReply"
                >
                  <div class="detail-field">说 明：</div>
                  <div class="detail-value">
                    <fold-text :row="3">{{ item.publicReply }}</fold-text>
                  </div>
                </div>

                <div
                  class="detail"
                  v-if="item.processName != '转项目' && item.internalRemark"
                >
                  <div class="detail-field">内部备注：</div>
                  <div class="detail-value">
                    <fold-text :row="3">{{ item.internalRemark }}</fold-text>
                  </div>
                </div>
                <div class="detail">
                  <div class="attachement-list">
                    <a
                      :href="att.url"
                      target="_blank"
                      :key="att.url"
                      v-for="att in item.internalFile"
                    >
                      <i class="el-icon-folder-opened"></i>
                      {{ att.name }}
                    </a>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-card>
      </div>
    </div>

    <div v-if="pageType == 'origin-info'">
      <issue-info
        v-if="projectInfo.origin == 'issue'"
        @close="handleBackInfo"
        :issue-id="projectInfo.originId"
      />
      <event-info
        v-if="projectInfo.origin == 'resi_event'"
        @close="handleBackInfo"
        :event-id="projectInfo.originId"
      />
    </div>

    <!-- 修改弹出框 -->
    <el-dialog
      v-if="showedEvaluation"
      :visible.sync="showedEvaluation"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="formTitle"
      width="850px"
      top="5vh"
      class="dialog-h"
      @closed="showedEvaluation = false"
    >
      <project-evaluation :projectId="projectIdCopy"></project-evaluation>
    </el-dialog>
  </div>
</template>

<script>
import { requestPost } from "@/js/dai/request";
import foldText from "@/views/components/foldText";
import selectStaff from "@/views/components/selectStaff";
import issueInfo from "./issue-info";
import eventInfo from "./event-info";
import projectEvaluation from "./project-evaluation";
import dateFormat from "dai-js/tools/dateFormat";

function iniData() {
  return {
    pageType: "info",
    uploadUlr: window.SITE_CONFIG["apiURL"] + "/oss/file/uploadqrcodeV2",

    showedEvaluation: false,

    projectIdCopy: this.projectId,

    customerId: localStorage.getItem("customerId"),

    fmData: {
      operateType: "",

      assistanceUnitIndex: "",
      assistanceUnitId: "",
      assistanceUnitType: "",

      internalRemark: "",
      publicReply: "",
      internalFile: [],
      departmentName: "",
      projectStaffId: "",

      projectProcessId: "",

      closedStatus: "",

      staffList: "",
    },
    visibleStaffPanel: false,

    myDepartmentList: [],
    assistanceUnitList: [],
    returnableList: [],
    resolveTypeList: [
      {
        name: "已解决",
        value: "resolved",
      },
      {
        name: "无需解决",
        value: "unresolved",
      },
    ],

    projectProcess: [],

    projectInfo: {
      backGround: "",
      departmentList: [
        //   { departmentName: "南宁社区-南宁第二网格", staffList: ["周相成"] },
      ],
      departmentNameList: [],
      internalRemark: "",
      isSend: false,
      locateAddress: "",
      locateDimension: "",
      locateLongitude: "",
      origin: "",
      originId: "",
      platformIds: [],
      processable: false,
      projectId: "",
      projectStatus: "",
      projectTitle: "",
      publicReply: "",
      returnable: false,
    },

    issueInfo: {
      attitude: "",
      belongsGridName: "",
      issueIdea: "",
      issueInitiator: "",
      issueStatus: "",
      issueSuggestion: "",
      issueTitle: "",
      joinVote: true,
      projectId: "",
      projectStatus: false,
      publishIdeaFlag: false,
    },

    issueTrend: {},
    issueChartData: [],

    eventInfo: {
      eventTime: "",
      eventContent: "",
      eventAddress: "",
      gridName: "",
      isClosed: true,
      isResolve: true,
      isRollback: true,
      eventImgs: [],
      eventPerson: [],
      eventOrg: [],
      eventPeopleName: "",
      projectInfo: {
        projectId: "",
        operationName: "",
        operationTime: "",
        projectDeclare: "",
      },
    },

    projectCate: [],
    cateOptions: [],
    visibleCatePanel: false,
    selectedCateData: [],

    projectTag: [],
    tagOptions: [],
    visibleTagPanel: false,
    selectedTagData: [],
  };
}

export default {
  name: "projectInfo",
  props: {
    projectId: {
      type: String,
      default: "",
    },
    type: {
      type: String,
      default: "info",
    },
  },

  components: {
    foldText,
    issueInfo,
    eventInfo,
    projectEvaluation,
    selectStaff,
  },

  data: iniData,

  computed: {
    dataRule() {
      const {
        fmData: { operateType },
      } = this;
      let obj = (() => {
        return {
          operateType: [
            { required: true, message: "处理方式不能为空", trigger: "blur" },
          ],
          projectStaffId: [
            { required: true, message: "请选择您的身份", trigger: "blur" },
          ],
        };
      })();
      if (operateType != "") {
        if (operateType == "close") {
          obj.publicReply = [
            { required: true, message: "请填写结案说明", trigger: "blur" },
          ];
          obj.closedStatus = [
            { required: true, message: "请选择结案状态", trigger: "blur" },
          ];
        } else if (operateType == "turn") {
          obj.staffList = [
            { required: true, message: "请选择处理部门", trigger: "blur" },
          ];
        } else {
          obj.internalRemark = [
            { required: true, message: "请填写内部备注", trigger: "blur" },
          ];
        }
      }

      console.log(obj);
      if (this.$refs && this.$refs.fm) {
        this.$nextTick(() => {
          this.$refs["fm"].clearValidate();
        });
      }

      return obj;
    },

    styleFullHeight() {
      return {
        maxHeight: "calc(100vh - 120px)",
      };
    },

    styleHalfHeight() {
      return {
        maxHeight: "calc((100vh - 140px) / 2)",
      };
    },
  },

  watch: {
    projectId() {
      let data = iniData();
      Object.keys(data).forEach((k) => {
        this[k] = data[k];
      });
      this.getApiData();
    },
    "fmData.assistanceUnitIndex": function (val) {
      if (val === "") {
        this.fmData.assistanceUnitId = "";
        this.fmData.assistanceUnitType = "";
      } else {
        this.fmData.assistanceUnitId =
          this.assistanceUnitList[val].assistanceUnitId;
        this.fmData.assistanceUnitType =
          this.assistanceUnitList[val].assistanceUnitType;
      }
    },
    "fmData.projectStaffId": function (val) {
      if (val === "") {
        this.fmData.departmentName = "";
      } else {
        this.fmData.departmentName = this.myDepartmentList.find(
          (item) => item.projectStaffId == val
        )["departmentName"];
      }
    },
    selectedCateData(val) {
      const { cateOptions } = this;
      this.projectCate = val
        .filter((arr) => arr.length > 0)
        .map((arr) => {
          let ele1 = cateOptions.find((item) => item.id == arr[0]);
          let ele2 = ele1.subCategory.find((item) => item.id == arr[1]);
          return {
            id: ele2.id,
            name: ele1.name + "-" + ele2.name,
          };
        });
    },
    async selectedTagData(val) {
      const { tagOptions } = this;
      this.projectTag = await Promise.all(
        val.map(async (id) => {
          let ele = [...tagOptions.customized, ...tagOptions.defaulted].find(
            (item) => item.id == id || item.name == id
          );
          if (!ele) {
            await this.createTag(id);
            ele = [
              ...this.tagOptions.customized,
              ...this.tagOptions.defaulted,
            ].find((item) => item.name == id);
            if (!ele)
              return {
                id: "",
                name: ele.name,
              };
          }
          return {
            id: ele.id,
            name: ele.name,
          };
        })
      );
      this.projectTag = this.projectTag.filter((item) => item.id);
    },
  },

  mounted() {
    console.log(this.projectIdCopy);
    this.getApiData();
  },

  methods: {
    beforeImgUpload(file) {
      console.log(file);
      const isLt1M = file.size / 1024 / 1024 < 10;
      const srcType = file.type;
      const format = file.name.split(".").pop();

      if (!isLt1M) {
        this.$message.error("上传文件大小不能超过 10MB!");
        return false;
      }
      if (
        srcType.indexOf("image") == -1 &&
        srcType.indexOf("video") == -1 &&
        ["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"].indexOf(format) ==
          -1
      ) {
        this.$message.error("文档仅限pdf和office文件!");
        return false;
      }
      return true;
    },

    handleImgSuccess(res, file, fileList) {
      console.log("handleImgSuccess", file);
      if (res.code === 0 && res.msg === "success") {
        let format = file.name.split(".").pop();
        let srcType = file.raw.type;
        let type = "file";
        console.log("==============================srcType: ", srcType);
        if (srcType.indexOf("image") != -1) {
          type = "image";
        } else if (srcType.indexOf("video") != -1) {
          type = "video";
        }
        this.fmData.internalFile.push({
          format,
          name: file.name,
          size: file.size,
          type,
          url: res.data.url,
        });
        console.log(this.fmData.internalFile);
      } else {
        this.$message.error(res.msg);
      }
    },

    handleImgRemove(file) {
      console.log("handleImgRemove", file);
      if (file.response) {
        let index = this.fmData.internalFile.findIndex(
          (item) => item.url == file.response.data.url
        );
        this.fmData.internalFile.splice(index, 1);
      }
    },

    watchImg(src) {
      window.open(src);
    },

    handleClose() {
      this.$emit("close");
    },

    handleSubmit() {
      this.$refs["fm"].validate((valid, messageObj) => {
        if (valid) {
          this.beforeSubmit();
        } else {
        }
      });
    },

    beforeSubmit() {
      const {
        fmData: { operateType },
      } = this;
      if (operateType == "dispose") {
        this.submitDispose();
      } else if (operateType == "close") {
        this.submitClose();
      } else if (operateType == "turn") {
        this.submitTurn();
      } else if (operateType == "back") {
        this.submitBack();
      } else {
        return this.$message.error("请先选择处理方式");
      }
    },

    handleWatchOrigin() {
      this.pageType = "origin-info";
    },
    handleBackInfo() {
      this.pageType = "info";
    },

    //加载组织数据
    async submitBack() {
      const url = "/gov/project/trace/return-v2";
      const { fmData } = this;

      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.5)",
      });

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
        projectProcessId: fmData.projectProcessId,
        departmentName: fmData.departmentName,
        internalRemark: fmData.internalRemark,
        projectStaffId: fmData.projectStaffId,
        publicReply: fmData.publicReply,
        internalFile: fmData.internalFile,
      });

      loading.close();

      if (code === 0) {
        this.$emit("afterEdit");
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async submitClose() {
      const url = "/gov/project/trace/closeproject-v2";
      const { fmData } = this;

      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.5)",
      });

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
        closedStatus: fmData.closedStatus,
        departmentName: fmData.departmentName,
        internalRemark: fmData.internalRemark,
        projectStaffId: fmData.projectStaffId,
        publicReply: fmData.publicReply,
        internalFile: fmData.internalFile,
      });

      loading.close();

      if (code === 0) {
        this.$emit("afterEdit");
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async submitTurn() {
      const url = "/gov/project/trace/transfer-v2";
      const { fmData } = this;

      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.5)",
      });

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
        projectProcessId: fmData.projectProcessId,
        departmentName: fmData.departmentName,
        internalRemark: fmData.internalRemark,
        projectStaffId: fmData.projectStaffId,
        publicReply: fmData.publicReply,
        internalFile: fmData.internalFile,
        staffList: fmData.staffList,
      });

      loading.close();

      if (code === 0) {
        this.$emit("afterEdit");
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async submitDispose() {
      const url = "/gov/project/trace/response-v2";
      const { fmData } = this;

      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.5)",
      });

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
        departmentName: fmData.departmentName,
        internalRemark: fmData.internalRemark,
        projectStaffId: fmData.projectStaffId,
        publicReply: fmData.publicReply,
        internalFile: fmData.internalFile,
        assistanceUnitId: fmData.assistanceUnitId,
        assistanceUnitType: fmData.assistanceUnitType,
      });

      loading.close();

      if (code === 0) {
        this.$emit("afterEdit");
      } else {
        this.$message.error(msg);
      }
    },

    async getApiData() {
      await this.getProjectInfo();
      this.getProjectCate();
      this.getProjectProcess();
    },

    //加载组织数据
    async getProjectInfo() {
      const url = "/gov/project/trace/projectdetail";

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
      });

      if (code === 0) {
        this.projectInfo = data;
        if (data.projectStatus == "pending") {
          this.getMyDepartmentList();
          this.getAssistanceUnitList();
          if (data.returnable) {
            this.getReturnableList();
          }
        }
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async getReturnableList() {
      const url = "/gov/project/trace/returnablelist";

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
      });

      if (code === 0) {
        this.returnableList = data;
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async getMyDepartmentList() {
      const url = "/gov/project/trace/mydepartmentlist";

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
      });

      if (code === 0) {
        this.myDepartmentList = data;
        if (data.length == 1) {
          this.fmData.projectStaffId = data[0].projectStaffId;
        }
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async getAssistanceUnitList() {
      const url = "/heart/icpartyunit/assistanceUnitList";

      const { data, code, msg } = await requestPost(url, {
        // projectId: this.projectIdCopy,
      });

      if (code === 0) {
        this.assistanceUnitList = data;
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async getIssueInfo() {
      const url = "/resi/hall/issue/detail";

      const { data, code, msg } = await requestPost(url, {
        issueId: this.projectInfo.originId,
      });

      if (code === 0) {
        this.issueInfo = data;
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async getIssueTrend() {
      const url = "/resi/hall/issue/votingtrend";

      const { data, code, msg } = await requestPost(url, {
        issueId: this.projectInfo.originId,
      });

      if (code === 0) {
        this.issueTrend = data;
        let chartData = [];
        data.polyLine.forEach((item) => {
          let date = dateFormat(new Date(item.voteDate * 1000), "yyyy-MM-dd");
          // console.log("date:" + date);
          chartData.push(
            {
              date,
              value: item.supportIncrement,
              type: "支持",
            },
            {
              date,
              value: item.oppositionIncrement,
              type: "反对",
            }
          );
        });
        this.issueChartData = chartData;
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async getEventInfo() {
      const url = "/gov/project/resievent/eventdetail-icdata";

      const { data, code, msg } = await requestPost(url, {
        resiEventId: this.projectInfo.originId,
      });

      if (code === 0) {
        if (data.eventOrg && data.eventOrg.length > 0) {
          data.eventOrgShow = data.eventOrg.join("、");
        }
        if (data.eventPerson && data.eventPerson.length > 0) {
          data.eventPersonShow = data.eventPerson.join("、");
        }
        this.info = { ...data };
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async getProjectProcess() {
      const url = "/gov/project/trace/processlist-v2";

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
      });

      if (code === 0) {
        this.projectProcess = data.map((item) => {
          item.processTime = dateFormat(
            new Date(item.processTime * 1000),
            "yyyy-MM-dd hh:mm"
          );
          return item;
        });
      } else {
        this.$message.error(msg);
      }
    },

    async getProjectCate() {
      const url = "/gov/project/projectcategory/categorytaglist";

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
      });

      if (code === 0) {
        this.projectCate = data.categoryList;
        this.projectTag = data.tagList;
        if (this.projectInfo.projectStatus == "pending") {
          this.getCateOptions();
          this.getTagOptions();
        }
      } else {
        this.$message.error(msg);
      }
    },

    async getCateOptions() {
      const url = "/gov/issue/issueprojectcategorydict/list";

      const { data, code, msg } = await requestPost(url, {});

      if (code === 0) {
        this.cateOptions = data.map((item) => {
          item.subCategory.forEach((subitem) => {
            delete subitem.subCategory;
          });
          return item;
        });
      } else {
        this.$message.error(msg);
      }
    },

    async updateProjectCate() {
      const url = "/gov/project/projectcategory/save";
      const { projectCate } = this;
      if (projectCate.length == 0) {
        return this.$message.error("分类不能为空");
      }

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
        categoryList: projectCate,
      });

      if (code === 0) {
        this.$message.success("更改成功");
        this.visibleCatePanel = false;
        this.getTagOptions();
      } else {
        this.$message.error(msg);
      }
    },

    handleTagChange(val) {
      console.log(val);
    },

    async createTag(tagName) {
      const url = "/gov/issue/issuetags/add";

      const { data, code, msg } = await requestPost(url, {
        tagName,
      });

      if (code === 0) {
        this.tagOptions.customized.push({
          name: tagName,
          id: data.tagId,
        });
      } else {
        this.$message.error(msg);
      }
    },

    async getTagOptions() {
      const url = "/gov/issue/issueprojecttagdict/list";

      const { data, code, msg } = await requestPost(url, {
        categoryList: this.projectCate,
      });

      if (code === 0) {
        this.tagOptions = {
          customized: data.customized,
          defaulted: data.defaulted,
        };
        this.selectedTagData = this.projectTag.map((item) => item.id);
      } else {
        this.$message.error(msg);
      }
    },

    async updateProjectTag() {
      const url = "/gov/project/projecttags/save";
      const { projectTag } = this;

      const { data, code, msg } = await requestPost(url, {
        projectId: this.projectIdCopy,
        tagList: projectTag,
      });

      if (code === 0) {
        this.$message.success("更改成功");
        this.visibleTagPanel = false;
      } else {
        this.$message.error(msg);
      }
    },

    toUserInfo(item) {
      this.$router.push({
        path: `/main-shuju/visual-basicinfo-people/${item.icResiUserId}`,
      });
    },

    toProjectInfo(item) {
      console.log(item);
      this.projectIdCopy = item.projectId;
      // let data = iniData();
      // Object.keys(data).forEach((k) => {
      //   this[k] = data[k];
      // });
      this.getApiData();
    },
  },
};
</script>

<style
  lang="scss"
  src="@/assets/scss/modules/shequzhili/project-info.scss"
  scoped
></style>
