<template>
  <section class="app-main">
    <transition name="fade-transform" mode="out-in">
      <keep-alive :include="cachedViews">
        <router-view v-if="!$route.meta.link" :key="key"/>
      </keep-alive>
    </transition>
    <iframe-toggle/>
    <floating-component/>
    <DialogPage ref="auditStatusDialog" title="审批履历" maxWidth="500px" @close="auditHistory = []">
      <template>
        <div v-loading="loading" class="container">
          <div v-if="auditHistory && auditHistory.length > 0" v-for="item, index in auditHistory" style="font-size: 0;">
            <div class="left">
              <div class="step"><img :src="item.status == AuditStatus.AUDITING ? audit : finished" width="25px"/></div>
              <div class="line" v-if="index !== (auditHistory.length - 1)"
                   :style="{ height: item.remark ? '180px' : '30px' }"></div>
            </div>
            <div class="right">
              <div class="head">
                <span class="date" v-if="item.auditTime">{{
                    item.auditTime.split(' ')[0].replaceAll('-', '/')
                  }}<br/><span class="time">{{
                      item.auditTime.split(' ')[1]
                    }}</span></span>
                <span
                  :class="{ status: true, success: item.status == AuditStatus.PASS, fail: item.status == AuditStatus.REJECT, auditing: item.status == AuditStatus.AUDITING, }">
                  {{ item.desc }}
                  <img v-if="item.status == AuditStatus.AUDITING" :src="cuiban" width="25px"
                       style="position: absolute; top: 0; right: -50px;cursor: pointer;"
                       @click="handleAlert(item.taskId)"/>
                </span>

              </div>
              <div class="audit-info">
                <span class="name" v-if="item.auditUser">{{ item.nickName }}</span>
                <img :src="pin" width="25px" class="attachment"
                     v-if="item.auditUser &&item.attachmentList && item.attachmentList.length > 0"
                     @click="$refs.auditAttachmentDialog.open(null, { attachmentList: item.attachmentList })"/>
                <div class="remark" v-if="item.remark">{{ item.remark }}</div>
              </div>
            </div>
          </div>
          <Col v-if="auditHistory && auditHistory.length === 0" class="NoDataEmpty">
            <Row>
              <Col style="text-align: center">
                <el-image :src="require('@/assets/images/index/NoUnReadMsg.svg')"/>
              </Col>
              <Col style="text-align: center">
                <span class="noDataEmptyText">{{ $t('common.noDataEmptyText') }}</span>
              </Col>
            </Row>
          </Col>
        </div>
      </template>
    </DialogPage>
    <DialogPage ref="auditAttachmentDialog" title="附件" maxWidth="550px" disabled label-position="top">
      <FileUploadItem label="附件" prop="attachmentList" :module="module" :func="func" :category="category"/>
    </DialogPage>

    <DialogPage ref="dialog" :title="title()" maxWidth="800px" :disabled="disabled" label-position="top" :header="true">
      <FileUploadItem :button-style="{ marginLeft: '5px' }" :label="label" class="normalClass" :prop="prop"
                      :module="module" :func="func" :category="category" :disabled="disabled"/>
    </DialogPage>
    <DialogPage ref="dialogWatch" :title="title()" maxWidth="550px" :disabled="disabled" label-position="top"
                :header="true">
      <FileUploadItem :button-style="{ marginLeft: '5px' }" :label="label" class="watchClass" :prop="prop"
                      :module="module" :func="func" :category="category" :disabled="disabled"/>
    </DialogPage>
    <!--聊天室 图片预览-->
    <DialogPage class="chatRoomImage" ref="previewDialog" :modalAppendToBody="true" :appendToBody="true"
                :close-on-click-modal="true"
                :title="'图片预览'" maxWidth="550px" :disabled="disabled" label-position="top">
      <el-image :src="imageSrc"/>
    </DialogPage>


  </section>
</template>

<script>
import iframeToggle from "./IframeToggle/index";
import FloatingComponent from "../../components/FloatingComponent/index";
import {getAuditHistory, alertAudit} from "@/api/audit/flow.js";
import finished from "@/assets/audit/finished-green.png";
import audit from "@/assets/audit/auditing.png";
import cuiban from "@/assets/audit/cuiban.png";
import pin from "@/assets/audit/pin.png";
import DialogPage from "../../components/element/Dialog.vue";

export default {
  name: "AppMain",
  components: {DialogPage, FloatingComponent, iframeToggle},
  provide: function () {
    return {
      main: this,
    };
  },
  data() {
    return {
      loading: false,
      module: undefined,
      func: undefined,
      category: undefined,
      auditHistory: [],
      finished,
      audit,
      cuiban,
      pin,
      disabled: false,
      label: "",
      prop: "",
      imageSrc: "",
    };
  },
  computed: {
    cachedViews() {
      return this.$store.state.tagsView.cachedViews;
    },
    key() {
      return this.$route.path;
    },
  },
  mounted() {
    const dialog = document.getElementsByClassName("chatRoomImage")[0]
    dialog.addEventListener('click', (e) => {
      e.stopPropagation();
    })
  },
  methods: {
    showAuditHistory(businessId, auditFlows, isAgent) {
      if (isAgent) {
        return
      }
      this.loading = true;
      this.$refs.auditStatusDialog.open();
      getAuditHistory({businessId, auditFlows})
        .then((res) => {
          if (res.code === 200) {
            this.auditHistory = res.rows;
          }
        })
        .finally(() => (this.loading = false));
    },
    title() {
      return this.disabled ? "�鿴�ļ�" : "�ϴ�����";
    },
    handleAlert(taskId) {
      this.$modal.confirm('是否确认发送催办信息？').then(() => {
        alertAudit(taskId).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("催办成功");
          }
        });
      })
    },
    handleOpen(row, disabled, label, prop, module, func, category) {
      this.disabled = disabled;
      this.label = label;
      this.prop = prop;
      this.module = module;
      this.func = func;
      this.category = category;
      if (this.disabled === true) {
        this.$refs.dialogWatch.open(
          (form) => {
            this.$set(row, this.prop, form[this.prop]);
            this.showIcon = true;
          },
          {[this.prop]: row[this.prop]}
        );
      } else {
        this.$refs.dialog.open(
          (form) => {
            this.$set(row, this.prop, form[this.prop]);
            this.showIcon = true;
          },
          {[this.prop]: row[this.prop]}
        );
      }
    },
    // @Date 2024/7/4 14:47 @Author jubs 😀 @description:别删这个别删这个
    messagePreview(src) {
      this.imageSrc = src;
      this.$refs.previewDialog.open();
    },
  },
};
</script>

<style lang="scss" scoped>
.app-main {
  /* 50= navbar  50  */
  min-height: calc(80vh - 50px);
  width: 100%;
  position: relative;
  overflow: hidden;
  background: #f1f5f9;
}

.fixed-header + .app-main {
  padding-top: 50px;
}

.hasTagsView {
  .app-main {
    /* 84 = navbar + tags-view = 50 + 34 */
    //min-height: calc(100vh - 84px);
    min-height: calc(100vh - 94px);
  }

  .fixed-header + .app-main {
    padding-top: 84px;
  }
}
</style>

<style lang="scss">
// fix css style bug in open el-dialog
.el-popup-parent--hidden {
  .fixed-header {
    padding-right: 6px;
  }
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background-color: #c0c0c0;
  border-radius: 3px;
}
</style>

<style scoped>
.step {
  width: 25px;
  height: 25px;
  margin: auto;
  font-size: 14px;
  text-align: center;
  line-height: 25px;
}

.line {
  width: 1px;
  border-left: 1px solid #2a73ff;
  margin: 10px auto;
}

.left {
  width: 50px;
  display: inline-block;
}

.right {
  display: inline-block;
  width: calc(100% - 70px);
  vertical-align: top;
  font-size: 14px;
}

.head {
  font-size: 16px;
}

.date {
  display: inline-block;
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.85);
}

.time {
  font-size: 12px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.73);
}

.name {
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.85);
  line-height: 24px;
}

.status {
  float: right;
  line-height: 120%;
}

.audit-info {
  margin-top: 20px;
}

.success {
  color: #419b07;
}

.fail {
  color: #e74a4a;
}

.auditing {
  width: calc(100% - 50px);
  margin-right: 50px;
  position: relative;
}

.attachment {
  float: right;
  cursor: pointer;
}

.remark {
  margin-top: 10px;
  padding: 10px;
  height: 100px;
  overflow: auto;
  background: #f8f9fc;
  border-radius: 2px;
  border: 1px solid #e5e8f1;
}

.container {
  min-height: 150px;
}
</style>
