<template>
  <div class="detail-wrap">
    <el-form ref="editForm" :model="bdCompanyEnv">
      <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="bdService"
                    :rules="[{ required: true, trigger: 'blur' }]"
                  >
                    <el-select v-model="bdCompanyEnv.bdService">
                      <el-option value="dev" :label="$t1('测试')"></el-option>
                      <el-option value="uat" :label="$t1('UAT')"></el-option>
                      <el-option value="prod" :label="$t1('正式')"></el-option>
                    </el-select>
                  </el-form-item>
                </td>
                <th>
                  <em class="f-red">*</em>
                  {{ $t1("组织编码") }}
                </th>
                <td>
                  <el-form-item
                    prop="bdCompanyCode"
                    :rules="[{ required: true, trigger: 'blur' }]"
                  >
                    <el-input
                      type="text"
                      autocomplete="off"
                      v-model="bdCompanyEnv.bdCompanyCode"
                      clearable
                    />
                  </el-form-item>
                </td>
              </tr>
              <tr>
                <th>{{ $t1("组织备注") }}</th>
                <td colspan="5">
                  <el-input
                    type="textarea"
                    :rows="2"
                    :placeholder="$t1('请输入内容')"
                    size="small"
                    v-model="bdCompanyEnv.bdCompanyRemark"
                    clearable
                  ></el-input>
                </td>
              </tr>
              <tr>
                <th>{{ $t1("创建人") }}</th>
                <td>{{ bdCompanyEnv.createBy }}</td>
                <th>{{ $t1("创建时间") }}</th>
                <td>{{ bdCompanyEnv.createDate }}</td>
                <th>{{ $t1("更新人") }}</th>
                <td>{{ bdCompanyEnv.modifyBy }}</td>
                <th>{{ $t1("更新时间") }}</th>
                <td>{{ bdCompanyEnv.modifyDate }}</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "bd_company_envEdit",
  props: {
    _dataId: [String, Number],
    copyId: [String, Number],
  },
  components: {},
  data() {
    return {
      isEdit: false,
      tabIndex: "first",
      dataId: "",
      bdCompanyEnv: {
        enabled: true,
        connectTimeout: 10000,
        readTimeout: 60000,
        preScript: null,
        postScript: null,
        exeCompanyCode: null,
      },
      showCodeEditor: false,
    };
  },
  created() {
    if (this._dataId && !isNaN(this._dataId)) this.dataId = this._dataId;
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      if (this.copyId) {
        return;
      }
      if (this.dataId && !isNaN(this.dataId)) {
        this.isEdit = true;
        this.$commonHttp({
          url: USER_PREFIX + `/bd_company_env/get`,
          method: `post`,
          data: {
            id: this.dataId,
          },
          isLoading: true,
          modalStrictly: true,
          success: (res) => {
            this.bdCompanyEnv = res.objx || {};
            this.showCodeEditor = true;
          },
        });
      } else {
        this.showCodeEditor = true;
      }
    },
    saveData() {
      this.$refs.editForm.$baseValidate((valid) => {
        if (valid) {
          this.$baseConfirm(this.$t1("您确定要保存吗？")).then(() => {
            var url =
              USER_PREFIX +
              (this.isEdit ? `/bd_company_env/update` : `/bd_company_env/save`);
            this.$http({
              url: url,
              method: `post`,
              data: this.bdCompanyEnv,
              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,
                          copyId: null,
                        },
                      });
                    }
                  },
                });
              },
            });
          });
        }
      });
    },
  },
};
</script>
