<template>
  <div>
    <BaseDialog
      :appendToBody="appendToBody"
      v-if="checkResult == -1"
      width="600px"
      :isShow.sync="isShow"
      title="确定审核不通过吗？"
      @opne="init"
      @submit="batchAudit"
    >
      <el-input
        :rows="6"
        type="textarea"
        placeholder="请输入不通过原因"
        v-model="checkReason"
      ></el-input>
    </BaseDialog>
  </div>
</template>

<script>
import { divideByMonthEditBo, divideByEditBo } from "@/api/financed/index";
export default {
  name: "remarks",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    info: {
      type: Object,
      default: () => {
        return {};
      },
    },
    appendToBody: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      checkReason: undefined,
    };
  },

  mounted() {},

  methods: {
    init() {
      this.checkReason = undefined;
    },
    backForm() {
      let { checkFrom, checkResult } = this.info;
      const key = this.isCommission ? "orderSn" : "divideLogId";
      let form = this.info[key].map((e) => {
        return {
          [key]: e,
          checkResult,
          checkReason: this.checkReason,
          checkFrom,
        };
      });
      return form;
    },
    batchAuditPass() {
      this.$confirm("确定审核通过吗？", "提示", {
        confirmButtonText: "确定通过",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.batchAudit();
      });
    },
    batchAudit() {
      const fn = this.isCommission ? divideByEditBo : divideByMonthEditBo;
      fn(this.backForm()).then(() => {
        this.$message.success(
          `批量审核${this.checkResult == -1 ? "不" : ""}通过成功!`
        );
        this.isShow = false;
        this.$emit("search");
      });
    },
  },
  computed: {
    isShow: {
      get() {
        return this.dialogVisible;
      },
      set(val) {
        this.$emit("update:dialogVisible", false);
      },
    },
    checkResult() {
      return this.info.checkResult;
    },
    isCommission() {
      return !!this.info.isCommission;
    },
  },
  watch: {
    isShow(val) {
      if (val && this.checkResult == 1) {
        this.batchAuditPass();
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
