<template>
  <div class="detail-wrap">
    <el-form ref="editForm" :model="companyInfo">
      <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>
          <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="companyName" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="companyInfo.companyName" clearable/>
                </el-form-item>
              </td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('组织简称') }}
              </th>
              <td>
                <el-form-item prop="simpleName" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="companyInfo.simpleName" clearable/>
                </el-form-item>
              </td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('组织编码') }}
              </th>
              <td>{{ companyInfo.companyCode }}</td>
            </tr>
            <tr>
              <th>
                {{ $t1('组织默认首页') }}
              </th>
              <td colspan="3">
                <el-form-item prop="defaultHomePage" :rules="[{ required: false, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="companyInfo.defaultHomePage" clearable/>
                </el-form-item>
              </td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('组织唯一标志') }}
              </th>
              <td colspan="3">{{ companyInfo.uniqueIdentify }}</td>
            </tr>
            <tr>
              <th>{{ $t1('备注') }}</th>
              <td colspan="5">
                <el-input type="textarea" :rows="2" :placeholder="$t1('请输入内容')" size="small"
                          v-model="companyInfo.note"
                          clearable></el-input>
              </td>
            </tr>
            <tr>
              <th>logo</th>
              <td colspan="5">
                <baseUpload :limit="1" accept="image/png, image/jpeg" multi="false" :file.sync="companyInfo.logoUrl"
                            dataType="medium"></baseUpload>
              </td>
            </tr>
            <tr>
              <th>{{ $t1('创建人') }}</th>
              <td>{{ companyInfo.createBy }}</td>
              <th>{{ $t1('创建时间') }}</th>
              <td>{{ companyInfo.createDate }}</td>
              <th>{{ $t1('更新人') }}</th>
              <td>{{ companyInfo.modifyBy }}</td>
              <th>{{ $t1('更新时间') }}</th>
              <td>{{ companyInfo.modifyDate }}</td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'company_info:view',
  components: {},
  data() {
    return {
      tabIndex: 0,
      isEdit: false,
      companyInfo: {},
      showAreaDialog: false,
      activeName: 'first'
    };
  },
  created() {
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.isEdit = true;
      this.$commonHttp({
        url: USER_PREFIX + '/company_info/getCurrent',
        method: `post`,
        isLoading: true,
        modalStrictly: true,
        success: res => {
          this.companyInfo = res.objx || {};
        }
      });
    },
    saveData() {
      this.$refs.editForm.$baseValidate(valid => {
        if (valid) {
          this.$baseConfirm(this.$t1('您确定要保存吗？')).then(() => {
            var url = USER_PREFIX + '/company_info/update';
            this.$http({
              url: url,
              method: `post`,
              data: this.companyInfo,
              isLoading: true,
              success: res => {
                if (this.isEdit) {
                  //更新
                  this.$message({
                    message: res.content,
                    type: 'success',
                    duration: 500,
                    onClose: t => {
                      this.$baseReload();
                    }
                  });
                }
              }
            });
          });
        }
      });
    }
  }
};
</script>
