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

<script>
export default {
  props: {},
  data() {
    return {
      showWfDialog2: false,
      wfUrl2: "",
      showWfContent: true,
      wfContent: null,
      wfDataId: "",
      param: {},
    };
  },
  methods: {
    getUrlParam(url) {
      var reg = /([^?&=]+)=([^?&=]+)/g,
        obj = {},
        str = url;
      url.replace(reg, function () {
        obj[arguments[1]] = arguments[2];
      });
      return obj;
    },
    notifyMessageRead(row, callback) {
      if (row.readed == 0) {
        this.$http({
          url: USER_PREFIX + `/notify_message/read`,
          method: `post`,
          data: [row.id],
          isLoading: true,
          loadingTarget: document.body,
          success: (res) => {
            callback && callback();
          },
        });
      } else {
        callback && callback();
      }
    },
    open(row, callback) {
      this.notifyMessageRead(row, () => {
        let turl = row.jumpContent;
        let wfUrl = turl.split("?")[0];
        let param = this.getUrlParam(turl);
        let wfDataId = param.dataId;
        if (!wfDataId) {
          wfDataId = 0;
        } else if (!isNaN(wfDataId)) {
          wfDataId = Number(wfDataId);
        }

        if (wfUrl == "form") {
          let formCode = null;
          if (param.formCode) {
            formCode = param.formCode;
          } else {
            formCode = param.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 = wfUrl + ".vue";
          let id = wfDataId;
          this.wfDataId = !id || typeof id == "object" ? 0 : id;
          // this.showWfDialog = true;
          this.showWfContent = true;
          this.wfContent = require("@/views" + url).default;
        }
        this.showWfDialog2 = true;

        callback && callback();
      });
    },
  },
};
</script>

<style scoped></style>
