<template>
  <div class="detail-wrap">
    <el-form ref="editForm" :model="fieldValuesInvisible">
      <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>{{ $t1('隐藏定义编码') }}</th>
              <td>{{ fieldValuesInvisible.fvvCode }}</td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('是否启用') }}
              </th>
              <td>
                <el-radio-group v-model="fieldValuesInvisible.enabled">
                  <el-radio :label="true">{{ $t1('启用') }}</el-radio>
                  <el-radio :label="false">{{ $t1('禁用') }}</el-radio>
                </el-radio-group>
              </td>
            </tr>
            <tr>
              <th>
                <em class="f-red">*</em>
                {{ $t1('服务名') }}
              </th>
              <td>
                <el-form-item prop="applicationName" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="fieldValuesInvisible.applicationName" clearable/>
                </el-form-item>
              </td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('组织编码') }}
              </th>
              <td>
                <el-form-item prop="fvvCompanyCode" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="fieldValuesInvisible.fvvCompanyCode" clearable/>
                </el-form-item>
              </td>
            </tr>
            <tr>
              <th>
                <em class="f-red">*</em>
                {{ $t1('定义Url地址') }}
              </th>
              <td colspan="5">
                <el-form-item prop="url" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="fieldValuesInvisible.url" clearable/>
                </el-form-item>
              </td>
            </tr>
            <tr>
              <th>
                <em class="f-red">*</em>
                {{ $t1('隐藏的字段名') }}
              </th>
              <td colspan="5">
                <el-form-item prop="fieldNames" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="fieldValuesInvisible.fieldNames" clearable/>
                </el-form-item>
              </td>
              <td colspan="2"><span class="tips_1">{{ $t1('注：区分大小写，多个用逗号","隔开') }}</span></td>
            </tr>
            <tr>
              <th>
                <em class="f-red">*</em>
                {{ $t1('涉及的角色名') }}
              </th>
              <td colspan="5">
                <el-form-item prop="roleNames" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="fieldValuesInvisible.roleNames" clearable/>
                </el-form-item>
              </td>
              <td colspan="2"><span class="tips_1">{{ $t1('注：多个用逗号","隔开') }}</span></td>
            </tr>
            <tr>
              <th>{{ $t1('创建人') }}</th>
              <td>{{ fieldValuesInvisible.createBy }}</td>
              <th>{{ $t1('创建时间') }}</th>
              <td>{{ fieldValuesInvisible.createDate }}</td>
              <th>{{ $t1('更新人') }}</th>
              <td>{{ fieldValuesInvisible.modifyBy }}</td>
              <th>{{ $t1('更新时间') }}</th>
              <td>{{ fieldValuesInvisible.modifyDate }}</td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'report_datasourceEdit',
  props: {
    _dataId: [String, Number]
  },
  components: {},
  data() {
    return {
      isEdit: false,
      tabIndex: 'first',
      dataId: '',
      fieldValuesInvisible: {
        enabled: 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 + `/field_values_invisible/get`,
          method: `post`,
          data: {
            id: this.dataId
          },
          isLoading: true,
          modalStrictly: true,
          success: res => {
            this.fieldValuesInvisible = res.objx || {};
          }
        });
      } else {
        this.fieldValuesInvisible.enabled = true;
      }
    },
    saveData() {
      this.$refs.editForm.$baseValidate(valid => {
        if (valid) {
          this.$baseConfirm(this.$t1('您确定要保存吗？')).then(() => {
            var url = USER_PREFIX + (this.isEdit ? `/field_values_invisible/update` : `/field_values_invisible/save`);
            this.$http({
              url: url,
              method: `post`,
              data: this.fieldValuesInvisible,
              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>
