<template>
  <div class="detail-wrap">
    <el-form ref="editForm" :model="wfObjConfigItem">
      <div class="d-header clearfix">
        <div class="fl">
          <i class="el-icon-info"/>
          {{ dataId ? $t1('查看流程模版') : $t1('新增流程模版') }}
        </div>
        <div class="fr">
          <el-button type="primary" plain class="button-sty" @click="$baseReload()" icon="el-icon-refresh-right">
            {{ $t1('重置') }}
          </el-button>
          <el-button type="primary" class="button-sty" icon="el-icon-check" @click="saveData">{{ $t1('保存') }}
          </el-button>
        </div>
      </div>
      <div class="d-cont">
        <div class="d-item">
          <div class="title first"><b>{{ $t1('基本信息') }}</b></div>
          <table class="table-detail">
            <tbody>
            <tr>
              <th>
                <em class="f-red">*</em>
                {{ $t1('流程模版名称') }}
              </th>
              <td>
                <el-form-item prop="modelName" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input autocomplete="off" v-model="wfObjConfigItem.modelName" clearable/>
                </el-form-item>
              </td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('流程模版KEY') }}
              </th>
              <td>
                <el-form-item prop="modelKey" :rules="[{ required: true, trigger: 'blur' }]" v-if="!dataId">
                  <el-input autocomplete="off" v-model="wfObjConfigItem.modelKey" clearable/>
                </el-form-item>
                <template v-else>{{ wfObjConfigItem.modelKey }}</template>
              </td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('单据类型编码') }}
              </th>
              <td>
                {{ wfObjConfigItem.objTypeCode }}
              </td>
            </tr>
            <tr>
              <th>{{ $t1('创建人') }}</th>
              <td>{{ wfObjConfigItem.createBy }}</td>
              <th>{{ $t1('创建时间') }}</th>
              <td>{{ wfObjConfigItem.createDate }}</td>
              <th>{{ $t1('更新人') }}</th>
              <td>{{ wfObjConfigItem.modifyBy }}</td>
              <th>{{ $t1('更新时间') }}</th>
              <td>{{ wfObjConfigItem.modifyDate }}</td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'wfObjConfigItemEdit',
  props: {
    _dataId: [String, Number]
  },
  components: {},
  data() {
    return {
      tabIndex: 0,
      isEdit: false,
      dataId: '',
      wfObjConfigItem: {
        objConfigId: 0,
        objTypeCode: "scenewf"
      },
      showWfObjConfigDialog: false,
      configServiceId: null
    };
  },
  created() {
    if (this._dataId && !isNaN(this._dataId)) {
      this.dataId = this._dataId;
    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      if (this.dataId && !isNaN(this.dataId)) {
        this.isEdit = true;
        this.$commonHttp({
          url: USER_PREFIX + `/wf_obj_config_item/get`,
          method: `post`,
          data: {
            id: this.dataId
          },
          isLoading: true,
          modalStrictly: true,
          success: res => {
            this.wfObjConfigItem = res.objx || {};
          }
        });
      }
    },
    saveData() {
      this.$refs.editForm.$baseValidate(valid => {
        if (valid) {
          this.$baseConfirm(this.$t1('您确定要保存吗？')).then(() => {
            var url = USER_PREFIX + (this.isEdit ? `/wf_obj_config_item/update` : `/wf_obj_config_item/save`);
            this.$http({
              url: url,
              method: `post`,
              data: this.wfObjConfigItem,
              isLoading: true,
              success: res => {
                this.$message({
                  message: res.content,
                  type: 'success',
                  duration: 500,
                  onClose: t => {
                    if (this.isEdit) {
                      this.$baseReload();
                    } else {
                      this.$baseReload({
                        updateParam: {
                          _dataId: res.objx
                        }
                      });
                    }
                  }
                });
              }
            });
          });
        }
      });
    }
  }
};
</script>
