<template>
  <div v-if="form">
    <main-top></main-top>
    <editcon
      :key="type"
      ref="child"
      :type="type"
      :rule="rule"
      :justshow="true"
      :form="form"
      @cancel="backList"
      @save="determine"
    >
      <template slot-scope="{ form }" slot="content">
        <component :data="form" :is="cp" :roleList="roleList" />
      </template>
    </editcon>
  </div>
</template>

<script>
import vdetail from "./componets/detail";

import { formKey, rules } from "./data";
import {getDetail} from "@/configue/api";

export default {
  components: {
    vdetail
  },
  data() {
    let { type, id } = this.$route.params;
    console.log(type, id);
    return {
      val:'museum',
      type,
      id:String(id),
      form: '',
      roleList:[]
    };
  },
  computed: {
    cp() {
      return "v" + this.type;
    },
    rule() {
      return rules[this.type];
    },
  },
  mounted() {
    this.getDetail()
  },
  methods: {
    validate(cb) {
      let child = this.$refs.child;
      child.$refs[this.type].validate(async (valid) => {
        if (valid) {
          if (status == 2) {
            this.$confirm("请再次确认是否进行此审核操作？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(async () => {
                cb();
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "已取消",
                });
              });
          } else {
            cb();
          }
        }
      });
    },
    cancel() {
      this.$router.back();
    },
    determine() {
     
    },

    async getDetail(){
      if(this.id == 'none'){
        this.form = this.cloneObject(formKey[this.$route.params.type])
      } else{
        await getDetail(this.val,{id:this.id},res=>{
          this.form = {...this.form,...res.data}

        })
      }
    }
  },
};
</script>
