<template>
  <vFormRender :formCode="formCode" :dataId.sync="dataId" :param="param"
               v-if="showEdit" visible-key="showEdit" :parent-target="_self"
               @reload="$reloadHandle"></vFormRender>
</template>
<script>

import vFormRender from "../../../../views/user/form/vform/render.vue";

export default {
  components: {vFormRender},
  data() {
    return {
      formCode: null,
      dataId: null,
      showEdit: false,
      param: {},
    }
  },
  created() {
    this.init()
  },
  methods: {
    parseViewParam() {
      let param = {};
      let rawParam = this.$attrs.param ?? this.$route.query.param;
      if (rawParam) {
        if (typeof rawParam === "string") {
          try {
            param = JSON.parse(rawParam) || {};
          } catch (e) {
            param = {};
          }
        } else if (typeof rawParam === "object") {
          param = { ...rawParam };
        }
      }
      return param;
    },
    init() {
      let formCode = this.$route.query.formCode || this.$attrs.formCode;
      let dataId = this.$route.query.dataId || this.$attrs.dataId || this.$attrs._dataId;
      this.param = this.parseViewParam();

      if (dataId && formCode) {
        this.formCode = formCode;
        this.dataId = Number(dataId);
        this.showEdit = true;
      }
    }
  }
}
</script>
<style scoped>

</style>
