<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="docKeywords">
          <el-input v-model="formData.docKeywords" placeholder="请输入关键词" />
        </el-form-item>
        <!-- <el-form-item label="是否索引" prop="docIsIndex">
          <div class="dqzt_css">当前状态：{{this.dqztdocIsIndex }}</div>
          <el-select style="float: left;" v-model="formData.docIsIndex" placeholder="是否索引">
            <el-option v-for="dict in this.getDictDatas" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item> -->
        <el-form-item label="docid" prop="docid" style="display: none;">
          <el-input v-model="formData.docid" value="" disabled />
        </el-form-item>
        <el-form-item label="uid" prop="uid" style="display: none;">
          <el-input v-model="formData.uid" disabled />
        </el-form-item>
        <el-form-item label="sourcename" prop="sourcename" style="display: none;">
          <el-input v-model="formData.sourcename" disabled />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm()">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as searchPageApi from '@/api/manager/digsearch';

  import Editor from '@/components/Editor';
      export default {
    name: "DigFtpSourceForm",
    components: {
          Editor,
                    },
    data() {
      return {
        // 弹出层标题
        dialogTitle: "",
        // 是否显示弹出层
        dialogVisible: false,
        // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
        formLoading: false,

        getDictDatas:[
          {
            label: '否',
            value: 0
          },
            {
            label: '是',
            value: 1
          },
        ],

        dqztdocIsIndex:undefined,

        // 表单参数
        formData: {
          docid: undefined,
          uid: undefined,
          docLable: '',
          docKeywords: '',
          docIsIndex: undefined,
          sourcename: undefined,
        },
        // 表单校验
        formRules: {
                        docTitle: [{ required: true, message: '资源名称不能为空', trigger: 'blur' }],
        },
                        };
    },
    methods: {

      /** 打开弹窗 */
      async open(docid, uid, doc_keywords,doc_isindex,sourcename) {
        this.dialogVisible = true;
        this.reset();
        if(doc_isindex == 0){
          this.dqztdocIsIndex = '否';
        }else{
          this.dqztdocIsIndex = '是';
        }

        this.formData.docKeywords = doc_keywords;
        this.formData.docid = docid;
        this.formData.uid = uid;
        this.formData.sourcename = sourcename;
        // 修改时，设置数据
        // if (formData) {
        //   this.formLoading = true;
        //   try {
        //     const res = formData;
        //     this.formData = res.data;
        //     this.title = "修改STF资源管理";
        //   } finally {
        //     this.formLoading = false;
        //   }
        // }
        // this.title = "新增STF资源管理";
              },
      /** 提交按钮 */
      async submitForm() {
        // 校验主表
        await this.$refs["formRef"].validate();
            this.formLoading = true;
        try {
          const data = this.formData;
          // 修改的提交
          if (data) {
            await searchPageApi.updateDigFtpSource(data);
            this.$modal.msgSuccess("修改成功");
            this.dialogVisible = false;
            this.$emit('success');
            return;
          }
        } finally {
          this.formLoading = false;
        }
      },
      /** 表单重置 */
      reset() {
        this.formData = {
                            docid: undefined,
                            uid: undefined,
                            docLable: undefined,
                            docKeywords: undefined,
                            docid: undefined,
                            sourcename: undefined,
        };
        this.resetForm("formRef");
      },
      // 是否索引
      // docIsIndexSwitch(doc_isindex){
      //   if(doc_isindex == 0 ){
      //   this.formData.docIsIndex = this.getDictDatas[0].value;
      //   }else{
      //   this.formData.docIsIndex = this.getDictDatas[1].value;
      //   }
      // }
    }
  };
</script>
<style scoped>
.dqzt_css{
  margin-right: 20px;
  width: auto;
  float: left;
}

</style>
