<template>
  <div style="margin-top: 16px">
    <!--<CustomCard :show-header="false">-->
    <!--固定内容：审核日志      -->
    <template v-if="businessIds.length === 1">
      <first-level-header label="审核信息" style="margin-bottom: 0px" />
      <AuditLog :auditHistory="auditHistory" />
    </template>

    <!--固定内容：审核操作      -->
    <!--<first-level-header label="" />-->
    <Form :value="auditParams" ref="form">
      <Input label="审核意见" prop="remark" :class="areaClass" type="textarea" :maxlength="100" :span="12" :lg-span="16" :md-span="24" :sm-span="24" :xs-span="24" required />
      <el-col :lg="8" :md="8" :sm="12" :xs="24" style="width: 100%" />
      <!-- <FileUploadItem :span="12" :lg-span="16"
                      :md-span="24"
                      :sm-span="24"
                      :xs-span="24" :class="fileClass" label="附件" prop="attachmentList" :module="module" :func="func"
                      :category="category"/> -->
      <el-col :lg="8" :md="8" :sm="12" :xs="24" style="width: 100%" />
      <Input :class="userClass" label="审核人" style="margin-bottom: 16px" prop="auditUser" disabled />
    </Form>
    <FooterButtonBottom :showSubmit="false" :showSaveDraft="false" @cancel="cancel" @refuse="refuse" @pass="pass" showPass showRefuse>
      <template #floatLeft>
        <slot name="floatLeft"></slot>
      </template>
    </FooterButtonBottom>

    <!--</CustomCard>-->
    <el-dialog title="提示" :visible.sync="checkVisible" width="600px" :append-to-body="true">
      <div class="msg">
        <div class="msg-line"></div>
        <div class="msg-unmatch" style="margin-bottom: 16px">以下模块单据编号需要处理：</div>
        <el-table :data="checkData" id="msgTable" border max-height="340px" style="width: 100%" :row-style="{ height: '40px' }" :cell-style="{padding:0}" header-cell-class-name="tableHeadCell" header-row-class-name="tableHeadRow">
          <el-table-column prop="model" label="模块" width="120" align="center" />
          <el-table-column align="left" label="单据编号">
            <template slot-scope="scope">
              <div v-html="scope.row.msg"></div>
            </template>
          </el-table-column>
        </el-table>
        <el-button type="button" style="margin-left: 87.8%;margin-top:16px" @click="close()" class="msg-close">关闭
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import CustomCard from "@/components/CustomElement/CustomCard.vue";
import AuditLog from "./AuditLog.vue";
import AuditForm from "./AuditForm.vue";
import { auditBatch } from "@/api/audit/flow";
import moment from "moment";
import { isBlank } from "@/utils/common";

export default {
  components: {
    AuditForm,
    AuditLog,
    CustomCard,
  },
  props: {
    basicInfoLabel: {
      type: String,
      default: "表单信息",
    },
    dtlLabel: {
      type: String,
      default: "明细数据",
    },
    wholeLabel: {
      type: String,
      default: "",
    },
    classType: {
      type: String,
      default: "",
    },
    wholeShow: {
      type: Boolean,
      default: false,
    },
    auditFlow: {
      type: Number,
    },
    auditBatch: {},
    businessId: {},
    auditHistory: {
      type: Array,
    },
    /**
     * 模块类型--区分文件夹
     * */
    module: {
      type: String,
    },
    /**
     * 功能类型--区分文件夹
     * */
    func: {
      type: String,
    },
    /**
     * 附件类型--区分文件夹
     * */
    category: {
      type: String,
    },
    /**
     * 通过/驳回/撤回 之后需要跳转的页面
     *
     * */
    toPageUrl: {
      type: String,
      default: null,
    },
  },
  data() {
    return {
      auditParams: {
        auditTime: moment().format("YYYY-MM-DD HH:mm:ss"),
        auditUser: this.$store.getters.name,
        remark: "无",
      },
      loading: false,
      checkVisible: false,
      checkData: [],
    };
  },
  computed: {
    userClass() {
      if (this.classType === "eight") {
        return "eightChar";
      } else if (this.classType === "nine") {
        return "nineChar";
      } else if (this.classType === "ten") {
        return "tenChar";
      } else {
        return "detailInput";
      }
    },
    fileClass() {
      if (this.classType === "eight") {
        return "eightwholeSPan";
      } else if (this.classType === "nine") {
        return "ninewholeSPan";
      } else if (this.classType === "ten") {
        return "tenwholeSPan";
      } else {
        return "wholeSPan";
      }
    },
    areaClass() {
      if (this.classType === "eight") {
        return "eightdetailInputTextarea";
      } else if (this.classType === "nine") {
        return "ninedetailInputTextarea";
      } else if (this.classType === "ten") {
        return "tendetailInputTextarea";
      } else {
        return "detailInputTextarea";
      }
    },
    businessIds() {
      if (!this.businessId) return [];
      return typeof this.businessId === "number"
        ? [this.businessId]
        : this.businessId;
    },
  },
  watch: {},
  methods: {
    close() {
      this.checkVisible = false;
      this.checkData = [];
    },
    cancel() {
      this.back();
    },
    back() {
      if (!isBlank(this.toPageUrl)) {
        this.$tab.closeOpenPage(this.toPageUrl, false);
      } else {
        this.$tab.closePage();
        this.$router.go(-1);
      }
    },
    refuse() {
      this.handleAudit(this.AuditStatus.REJECT);
    },
    pass() {
      this.handleAudit(this.AuditStatus.PASS);
    },
    handleAudit(status) {
      if (this.loading) {
        return;
      }
      if (this.businessIds.length === 0) {
        this.$message.error("请选择需要审批的数据");
        return;
      }
      this.$refs["form"].validate().then((valid) => {
        if (valid) {
          this.loading = true;
          const { remark, attachmentList } = this.auditParams;
          const { auditFlow, module, func, category, businessIds } = this;
          const audit = this.auditBatch || auditBatch;
          audit({
            auditFlow,
            businessIds,
            status,
            module,
            func,
            category,
            remark,
            attachmentList,
          })
            .then((res) => {
              //2023-10-15 修改 驳回后，提示驳回成功
              if (res.data && res.data.length > 0) {
                this.checkData = [...res.data];
                this.checkVisible = true;
              } else {
                if (status == this.AuditStatus.REJECT) {
                  this.$message.success("驳回成功");
                } else {
                  this.$message.success("操作成功");
                }
                this.back();
              }
            })
            .finally(() => {
              this.loading = false;
            });
        }
      });
    },
  },

  created() {},
  mounted() {},
};
</script>

<style scoped>
::v-deep .el-card__body {
  height: 774px;
  padding: 16px 16px 16px 16px;
}

::v-deep .el-dialog__body {
  padding: 16px 16px 16px 16px;
}

::v-deep .el-dialog__header {
  background-color: #304156;
}

::v-deep .el-dialog__title {
  color: #ffffff !important;
}
</style>

