<template>
  <el-table-column :label="label" :prop="prop" :align="align" :min-width="minWidth" :formatter="dictFormatter">
    <template #default="{ row, $index }">
      <el-link :type="linkType((row.flow || {}).status)" :underline="false" @click="handleOpen(row)">{{
        dictFormatter((row.flow || {}).status)
      }}
      </el-link>
    </template>
  </el-table-column>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  name: "AuditStatusColumn",
  inject: ["main"],
  props: {
    type: {
      type: String,
      default: "",
    },
    selectable: {
      type: Function,
    },
    label: {
      type: String,
      default: "",
    },
    prop: {
      type: String,
    },
    minWidth: {
      type: Number,
      default: 0,
    },
    align: {
      type: String,
      default: "center",
    },
    businessIdProp: {
      type: String,
      default: "id",
    },
    recyclingProp: {
      type: String,
    },
    returnProp: {
      type: String,
    },
    temperatureProp: {
      type: String,
    },
    deliveryProp: {
      type: String,
    },
    certificateProp: {
      type: String,
    },
    rushProp: {
      type: String,
    },
    auditFlows: {
      type: Array,
      default: () => [],
    },
    /**
     * 模块类型--区分文件夹
     * */
    module: {
      type: String,
    },
    /**
     * 功能类型--区分文件夹
     * */
    func: {
      type: String,
    },
    /**
     * 附件类型--区分文件夹
     * */
    category: {
      type: String,
    },
  },
  data() {
    return {
      auditHistory: [],
    };
  },
  computed: {
    ...mapGetters(["dict"]),
    dicts() {
      const dicts = this.dict["audit_status"] || [];
      const res = [...dicts];
      return res;
    },
  },
  methods: {
    handleOpen(row) {
      if (Number(row[this.prop]) === this.AuditStatus.DRAFT) {
        return;
      }
      const businessId = row[this.businessIdProp];
      const auditFlows = this.auditFlows.join(",");
      const { module, func, category } = this;
      this.main.showAuditHistory(
        businessId,
        auditFlows,
        module,
        func,
        category
      );
    },
    dictFormatter(cellValue) {
      const target = this.dicts.filter(
        ({ value }) => String(value) === String(cellValue)
      );
      return target && target.length > 0 ? target[0].label : "";
    },
    linkType(status) {
      const {
        DRAFT,
        AUDITING,
        AUDITOR_ONE,
        AUDITOR_TWO,
        PASS,
        REJECT,
        ROLLBACK,
      } = this.AuditStatus;
      switch (Number(status)) {
        case DRAFT:
          return "info";
        case AUDITING:
        case AUDITOR_ONE:
        case AUDITOR_TWO:
          return "warning";
        case PASS:
          return "success";
        case REJECT:
          return "danger";
        case ROLLBACK:
          return "info";
        default:
          return "info";
      }
    },
  },
};
</script>

<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% - 100px);
  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: 100%;
}

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

.success {
  color: #419b07;
}

.fail {
  color: #e74a4a;
}

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

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

.container {
  max-height: 800px;
  min-height: 100px;
  overflow: auto;
}

.el-dialog__wrapper >>> .el-dialog .el-dialog__header {
  background-color: #304156;
}

.el-dialog__wrapper >>> .el-dialog .el-dialog__header .el-dialog__title {
  color: #ffffff !important;
}
</style>
