<template>
  <div class="detail-wrap">
    <el-form ref="editForm" :model="wfAutoSubmitData">
      <div class="d-header clearfix">
        <div class="fl">
          <i class="el-icon-info"/>
          {{ $t1('查看历史记录') }}
        </div>
        <div class="fr">
          <el-button type="primary" plain class="button-sty" @click="$baseReload()" icon="el-icon-refresh-right">
            {{ $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>{{ $t1('流程名称') }}</th>
              <td>{{ wfAutoSubmitData.name }}</td>
              <th>{{ $t1('单据类型编码') }}</th>
              <td>{{ wfAutoSubmitData.objTypeCode }}</td>
              <th>{{ $t1('启动人') }}</th>
              <td>{{ wfAutoSubmitData.starterName }}</td>
              <th>{{ $t1('当前任务') }}</th>
              <td>{{ wfAutoSubmitData.taskName }}</td>
            </tr>
            <tr>
              <th>{{ $t1('当前任务用户') }}</th>
              <td>{{ wfAutoSubmitData.candidateNames }}</td>
              <th>{{ $t1('待执行时间') }}</th>
              <td>{{ wfAutoSubmitData.toExeTime }}</td>
              <th>{{ $t1('启动时间') }}</th>
              <td>{{ wfAutoSubmitData.createDate }}</td>
              <th></th>
              <td></td>
            </tr>
            <tr>
              <th>{{ $t1('处理结果') }}</th>
              <td>{{ resultMap[wfAutoSubmitData.result] }}</td>
            </tr>
            <tr>
              <th>{{ $t1('处理结果描述') }}</th>
              <td colspan="7">{{ wfAutoSubmitData.resultDesc }}</td>
            </tr>
            <tr>
              <th>{{ $t1('脚本内容') }}</th>
              <td colspan="7">
                <code-editor mode="java" :readonly="true" v-model="wfAutoSubmitData.script"
                             v-if="showCodeEditor"></code-editor>
              </td>
            </tr>
            <tr>
              <th>{{ $t1('创建人') }}</th>
              <td>{{ wfAutoSubmitData.createBy }}</td>
              <th>{{ $t1('创建时间') }}</th>
              <td>{{ wfAutoSubmitData.createDate }}</td>
              <th>{{ $t1('更新人') }}</th>
              <td>{{ wfAutoSubmitData.modifyBy }}</td>
              <th>{{ $t1('更新时间') }}</th>
              <td>{{ wfAutoSubmitData.modifyDate }}</td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'wfAutoSubmitDataEdit',
  props: {
    _dataId: [String, Number],
    serviceId: {
      type: String,
      default: ''
    }
  },
  components: {},
  data() {
    return {
      tabIndex: 0,
      isEdit: false,
      dataId: '',
      wfAutoSubmitData: {},
      showCompanyDialog: false,
      m1Option: {},
      serviceIds: [],
      resultMap: {0: this.$t1('未处理'), 1: this.$t1('处理成功'), 2: this.$t1('处理失败异常')},
      showCodeEditor: false
    };
  },
  computed: {
    current_prefix() {
      return '/' + this.serviceId;
    }
  },
  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: this.current_prefix + `/wf_auto_submit_datah/get`,
          method: `post`,
          data: {
            id: this.dataId
          },
          isLoading: true,
          modalStrictly: true,
          success: res => {
            this.wfAutoSubmitData = res.objx || {};
            this.showCodeEditor = true;
          }
        });
      }
    },
  }
};
</script>
