<template>
  <div class="app-container">
    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="60%" v-dialogDrag append-to-body>
      <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="120px">
                    <el-form-item label="备注" prop="remark">
                      <el-input v-model="formData.remark" placeholder="请输入备注" />
                    </el-form-item>
                    <el-form-item label="资源名称" prop="docTitle">
                      <el-input v-model="formData.docTitle" placeholder="请输入资源名称" />
                    </el-form-item>
                    <el-form-item label="正文">
                      <Editor v-model="formData.docContent" :min-height="192"/>
                    </el-form-item>
                    <el-form-item label="摘要">
                      <Editor v-model="formData.docAbstract" :min-height="192"/>
                    </el-form-item>
                    <el-form-item label="译文">
                      <Editor v-model="formData.docContentTranslate" :min-height="192"/>
                    </el-form-item>
                    <el-form-item label="关键词" prop="docKeywords">
                      <el-input v-model="formData.docKeywords" placeholder="请输入关键词" />
                    </el-form-item>
                    <el-form-item label="作者" prop="docEditer">
                      <el-input v-model="formData.docEditer" placeholder="请输入作者" />
                    </el-form-item>
                    <el-form-item label="原文件名" prop="fileName">
                      <el-input v-model="formData.fileName" placeholder="请输入原文件名" />
                    </el-form-item>
                    <el-form-item label="文件来源" prop="sourcename">
                      <el-select v-model="formData.sourcename" placeholder="请选择文件来源">
                        <el-option v-for="dict in this.getDictDatas(DICT_TYPE.DIGITAL_FILE_SOURCENAME)"
                                   :key="dict.value" :label="dict.label" :value="dict.value" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="原文件后缀类型" prop="fileType">
                      <el-select v-model="formData.fileType" placeholder="请选择原文件后缀类型">
                        <el-option v-for="dict in this.getDictDatas(DICT_TYPE.DIGITAL_FILETYPE)"
                                   :key="dict.value" :label="dict.label" :value="dict.value" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="语种" prop="language">
                      <el-select v-model="formData.language" placeholder="语种">
                        <el-option v-for="dict in this.getDictDatas(DICT_TYPE.DIGITAL_FILE_LANGUAGE)"
                                   :key="dict.value" :label="dict.label" :value="dict.value" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="原文件路径" prop="filePath">
                      <el-input v-model="formData.filePath" placeholder="请输入原文件路径" />
                    </el-form-item>
<!--                    <el-form-item label="原文件创建日期" prop="fileCrtime">
                      <el-date-picker clearable v-model="formData.fileCrtime" type="date" value-format="timestamp" placeholder="选择原文件创建日期" />
                    </el-form-item>-->
                    <el-form-item label="原文件修改日期" prop="fileUpdatetime">
                      <el-date-picker clearable v-model="formData.fileUpdatetime" type="date" value-format="timestamp" placeholder="选择原文件修改日期" />
                    </el-form-item>
                    <el-form-item label="分类标签" prop="docLable">
                      <el-input v-model="formData.docLable" placeholder="请输入分类标签" />
                    </el-form-item>

        <el-form-item label="地域标签" prop="areaLable">
          <el-input v-model="formData.areaLable" placeholder="请输入地域标签" />
        </el-form-item>
        <el-form-item label="机构标签" prop="orgLable">
          <el-input v-model="formData.orgLable" placeholder="请输入机构标签" />
        </el-form-item>
        <el-form-item label="人物标签" prop="peopleLable">
          <el-input v-model="formData.peopleLable" placeholder="请输入人物标签" />
        </el-form-item>
        <el-form-item label="批次" prop="batchNo">
          <el-input v-model="formData.batchNo" placeholder="请输入批次" />
        </el-form-item>

                    <el-form-item label="文件年份" prop="fileYear">
                      <el-input v-model="formData.fileYear" placeholder="请输入文件年份" />
                    </el-form-item>
<!--                    <el-form-item label="数据唯一id" prop="docid">
                      <el-input v-model="formData.docid" placeholder="请输入数据唯一id" />
                    </el-form-item>-->
      </el-form>
              <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as OracleResourceApi from '@/api/manager/oracle';
  import Editor from '@/components/Editor';
      export default {
    name: "OracleResourceForm",
    components: {
          Editor,
                    },
    data() {
      return {
        // 弹出层标题
        dialogTitle: "",
        // 是否显示弹出层
        dialogVisible: false,
        // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
        formLoading: false,
        // 表单参数
        formData: {
                            id: undefined,
                            remark: undefined,
                            docTitle: undefined,
                            docContent: undefined,
                            docAbstract: undefined,
                            docContentTranslate: undefined,
                            docEditer: undefined,
                            fileName: undefined,
                            filePath: undefined,
                            fileType: undefined,
                            fileCrtime: undefined,
                            fileUpdatetime: undefined,
                            docLable: undefined,
                            areaLable: undefined,
                            orgLable: undefined,
                            peopleLable: undefined,
                            batchNo: undefined,
                            sourcename: undefined,
                            language: undefined,
                            fileYear: undefined,
                            docid: undefined,
        },
        // 表单校验
        formRules: {
        },
                        };
    },
    methods: {
      /** 打开弹窗 */
     async open(id) {
        this.dialogVisible = true;
        this.reset();
        // 修改时，设置数据
        if (id) {
          this.formLoading = true;
          try {
            const res = await OracleResourceApi.getOracleResource(id);
            this.formData = res.data;
            this.title = "修改oracle资源库管理";
          } finally {
            this.formLoading = false;
          }
        }
        this.title = "新增oracle资源库管理";
              },
      /** 提交按钮 */
      async submitForm() {
        // 校验主表
        await this.$refs["formRef"].validate();
                  this.formLoading = true;
        try {
          const data = this.formData;
                  // 修改的提交
          if (data.id) {
            await OracleResourceApi.updateOracleResource(data);
            this.$modal.msgSuccess("修改成功");
            this.dialogVisible = false;
            this.$emit('success');
            return;
          }
          // 添加的提交
          await OracleResourceApi.createOracleResource(data);
          this.$modal.msgSuccess("新增成功");
          this.dialogVisible = false;
          this.$emit('success');
        } finally {
          this.formLoading = false;
        }
      },
                      /** 表单重置 */
      reset() {
        this.formData = {
                            id: undefined,
                            remark: undefined,
                            docTitle: undefined,
                            docContent: undefined,
                            docAbstract: undefined,
                            docKeywords: undefined,
                            docContentTranslate: undefined,
                            docEditer: undefined,
                            fileName: undefined,
                            filePath: undefined,
                            fileType: undefined,
                            fileCrtime: undefined,
                            fileUpdatetime: undefined,
                            docLable: undefined,
                            areaLable: undefined,
                            orgLable: undefined,
                            peopleLable: undefined,
                            batchNo: undefined,
                            sourcename: undefined,
                            language: undefined,
                            fileYear: undefined,
                            docid: undefined,
        };
        this.resetForm("formRef");
      }
    }
  };
</script>
