<template>
  <el-dialog
    :title="$t1('查看单据流程')"
    :append-to-body="true"
    :modal-append-to-body="true"
    :close-on-click-modal="false"
    :visible.sync="showWfDialog"
    :modal="false"
    custom-class="el-dialog dialog-style designer-dialog indexUse"
    width="100%"
    height="100%"
    top="0px"
    bottom="0px"
    :destroy-on-close="true"
    @close="wfClose"
  >
    <div id="containt">
      <component
        v-if="showWfContent && wfContent"
        :is="wfContent"
        visible-key="showWfContent"
        v-bind="param"
        :parent-target="_self"
        :defaultShowWfContent="true"
        :_viewType="1"
        @reload="$reloadHandle"
        :_handleCallback="handleCallback"
      ></component>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "wfContentDialog",
  props: {
    option: {
      type: Object,
      default: {},
    },
  },
  components: {},
  data() {
    return {
      param: {},
      wfContent: null,
      showWfContent: false,
      showWfDialog: true,
    };
  },
  created() {
    this.openWfDialog();
  },
  methods: {
    handleCallback(flag) {
      if ([1, 2, 3, 4].includes(flag)) {
        this.$http({
          url: USER_PREFIX + "/wf_diy_attribute/getValue",
          method: `post`,
          data: { attributeKey: "param4" },
          isLoading: true,
          success: (res) => {
            let val = res.objx || false;
            this.option._handleCallback && this.option._handleCallback(flag);
            if (val === true) {
              this.wfClose();
            }
          },
        });
      } else {
        this.option._handleCallback && this.option._handleCallback(flag);
      }
    },
    wfClose() {
      this.showWfDialog = false;
      this.$emit("update:visible", false);
      this.$emit("close");
    },
    openWfDialog() {
      let id = this.option.objId;
      let wfDataId = !id || typeof id == "object" ? 0 : Number(id);
      let param = this.option.param || {};
      if (this.option.url == "form") {
        let formCode = null;
        if (this.option.formCode) {
          formCode = this.option.formCode;
        } else {
          formCode = this.option.objTypeCode.substr(9);
        }
        this.param = Object.assign(param, {
          formCode: formCode,
          dataId: wfDataId,
        });
        let url = "/user/form/vform/render.vue";
        this.wfContent = require("@base/views" + url).default;
      } else {
        this.param = Object.assign(param, {
          _dataId: wfDataId,
        });
        let url = this.option.url + ".vue";
        this.wfContent = require("@/views" + url).default;
      }
      this.showWfContent = true;
    },
  },
};
</script>

<style scoped></style>
