let modules = {};
modules = {
  props: {
    _dataId: [String, Number],
    formTemplate: Object
  },
  data() {
    return {
      isEdit: false,
      tabIndex: 'first',
      dataId: '',
      wfObjConfig: {
        objTypeCode: null,
        objTypeName: null,
        forms: true
      },
      showDialog: true
    };
  },
  computed: {
    current_prefix() {
      return this.wfObjConfig.serviceId ? '/' + this.wfObjConfig.serviceId : '';
    }
  },
  created() {
    if (this._dataId && !isNaN(this._dataId)) this.dataId = this._dataId;
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData(callback) {
      if (this.dataId && !isNaN(this.dataId)) {
        this.isEdit = true;
        this.$commonHttp({
          aes:true,
          url: this.current_prefix + `/wf_obj_config/get`,
          method: `post`,
          data: {
            id: this.dataId
          },
          isLoading: true,
          modalStrictly: true,
          success: res => {
            let row = res.objx || {};
            this.wfObjConfig = row;
            callback && callback(row);
          }
        });
      } else {
        let formTemplate = this.formTemplate;
        this.wfObjConfig.objTypeCode = formTemplate.objTypeCode;
        this.wfObjConfig.objTypeName = formTemplate.formName;
        this.wfObjConfig.serviceId = formTemplate.serviceName;
        this.wfObjConfig.url = "form";
      }
    },
    saveData() {
      this.$refs.editForm.$baseValidate(valid => {
        if (valid) {
          this.$baseConfirm(this.$t1('您确定要保存吗？')).then(() => {
            var url = this.current_prefix + (this.isEdit ? `/wf_obj_config/update` : `/wf_obj_config/save`);
            this.$http({
          aes:true,
              url: url,
              method: `post`,
              data: this.wfObjConfig,
              isLoading: true,
              success: res => {
                this.$message({
                  message: res.content,
                  type: 'success',
                  duration: 500,
                  onClose: t => {
                    this.dataId = res.objx;
                    this.getData((row) => {
                      this.close();
                      this.$emit('confirm', row)
                    })
                  }
                });
              }
            });
          });
        }
      });
    },
    close() {
      this.showDialog = false;
      this.$emit('update:visiable', false)
    }
  }
}
export default modules
