<template>
  <div class="app-container">
    <div style="width: 50%">
      <ReleaseForm
        v-model="form"
        :showTitle="true"
        :formType="formType"
        :labelWidth="labelWidth"
        ref="releaseRef"
      />
    </div>
    <div :style="{ marginLeft: labelWidth + 'px' }">
      <el-button @click="submitForm(3)">审核拒绝</el-button>
      <el-button type="primary" @click="submitForm(2)">通过审核</el-button>
    </div>
  </div>
</template>
<script>
import ReleaseForm from "@/views/components/ReleaseForm";
export default {
  components: {
    ReleaseForm,
  },
  data() {
    return {
      formType: 2,
      labelWidth: 140,
      form: {
        id: undefined,
        mode: 1,
        title: undefined,
        industrys: [],
        customer: [],
        maturity: undefined,
        lead_standard: undefined,
        cooperation_mode: undefined,
        keywords: [],
        description: undefined,
        introduce: undefined,
        image: undefined,
        file: undefined,
      },
    };
  },
  methods: {
    submitForm(status) {
      console.log(this.form);
      if (this.$refs["releaseRef"].submitForm()) {
        const str =
          status == 2
            ? "<span style='color:green'>通过</span>"
            : "<span class='el-message-box__errormsg'>拒绝</span>";
        this.$prompt(`您将 ${str} 该数据审核，请输入处理备注`, "审核", {
          dangerouslyUseHTMLString: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          closeOnClickModal: false,
          inputType: "textarea",
          inputPattern: status == 2 ? "" : /^.{1,30}$/,
          inputErrorMessage: "请输入拒绝原因",
        })
          .then(({ value }) => {
            expertEdit(this.form).then((res) => {
              if (res.code == 200) {
                const query = {
                  id: this.form.id,
                  status,
                  remark: value,
                };
                expertExamine(query).then((res) => {
                  this.$store.dispatch("tagsView/delView", this.$route);
                  this.$router.go(-1);
                  this.$modal.msgSuccess("处理成功");
                });
              }
            });
          })
          .catch(() => {});
      } else {
        console.log("校验未通过");
      }
    },
  },
  created() {
    const { id } = this.$route.query;
    if (id) {
      agentDetail({ id }).then((res) => {
        this.form = res.data;
      });
    }
  },
};
</script>