<template>
  <div class="detail-wrap">
    <el-form ref="editForm" :model="fileStoreArea">
      <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 v-if="!dataId" prop="storeAreaCode" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="fileStoreArea.storeAreaCode" clearable/>
                </el-form-item>
                <template v-else>
                  {{ fileStoreArea.storeAreaCode }}
                </template>
              </td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('工作区名称') }}
              </th>
              <td>
                <el-form-item prop="storeAreaName" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-input type="text" autocomplete="off" v-model="fileStoreArea.storeAreaName" clearable/>
                </el-form-item>
              </td>
            </tr>
            <tr>
              <th>
                <em class="f-red">*</em>
                {{ $t1('是否权限控制') }}
              </th>
              <td>
                <el-form-item prop="hasAuth" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-radio-group v-model="fileStoreArea.hasAuth">
                    <el-radio :label="1">{{ $t1('是') }}</el-radio>
                    <el-radio :label="0">{{ $t1('否') }}</el-radio>
                  </el-radio-group>
                </el-form-item>
              </td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('文件操作，是否发系统通知') }}
              </th>
              <td>
                <el-form-item prop="toNotify" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-radio-group v-model="fileStoreArea.toNotify">
                    <el-radio :label="1">{{ $t1('是') }}</el-radio>
                    <el-radio :label="0">{{ $t1('否') }}</el-radio>
                  </el-radio-group>
                </el-form-item>
              </td>
              <th>
                <em class="f-red">*</em>
                {{ $t1('文件下载，是否打水印') }}
              </th>
              <td>
                <el-form-item prop="toDownWatermark" :rules="[{ required: true, trigger: 'blur' }]">
                  <el-radio-group v-model="fileStoreArea.toDownWatermark">
                    <el-radio :label="1">{{ $t1('是') }}</el-radio>
                    <el-radio :label="0">{{ $t1('否') }}</el-radio>
                  </el-radio-group>
                </el-form-item>
              </td>
            </tr>
            <tr>
              <th>{{ $t1('备注') }}</th>
              <td colspan="5">
                <el-input type="textarea" :rows="2" :placeholder="$t1('请输入内容')" size="small"
                          v-model="fileStoreArea.note"
                          clearable></el-input>
              </td>
            </tr>
            <tr>
              <th>{{ $t1('创建人') }}</th>
              <td>{{ fileStoreArea.createBy }}</td>
              <th>{{ $t1('创建时间') }}</th>
              <td>{{ fileStoreArea.createDate }}</td>
              <th>{{ $t1('更新人') }}</th>
              <td>{{ fileStoreArea.modifyBy }}</td>
              <th>{{ $t1('更新时间') }}</th>
              <td>{{ fileStoreArea.modifyDate }}</td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </el-form>
  </div>
</template>

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