<template>
  <el-dialog :title=" '查看算法'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
      label-width="80px" :disabled=true>
      <el-form-item label="版本名称" prop="versionName">
        <el-input v-model="dataForm.versionName" ></el-input>
      </el-form-item>

      <el-form-item label="父版本" >
         <el-input v-model="fatherversionName" ></el-input>
      </el-form-item>

      <el-form-item label="描述信息" prop="remark">
        <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 6}" placeholder="请输入内容" v-model="dataForm.remark">
        </el-input>

      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="visible = false">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { MessageBox } from 'element-ui'
import { Message } from "element-ui"
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        versionName: "",
        // 本模板的类别
        fatherversionId: null,
        remark: "",
      },
      fatherversionName: "",
    };
  },
  methods: {
    init(id) {
      this.fatherversionName= "",
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
      });
  
      if (this.dataForm.id) {
        this.$http({
          url: this.$http.adornUrl(`/version/info/${this.dataForm.id}`),
          method: "get",
          params: this.$http.adornParams(),
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.dataForm.versionName = data.version.versionName;
            this.dataForm.fatherversionId=data.version.fatherversionId;
            this.dataForm.remark = data.version.remark;
          }
        }).then(() => {
            this.$http({
            url: this.$http.adornUrl(`/version/info/${this.dataForm.fatherversionId}`),
            method: "get",
            params: this.$http.adornParams(),
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.fatherversionName = data.version.versionName;
            }
          })
        })
      }
  
    },
    // 以下4个函数是文件上传功能的
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      Message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return MessageBox.confirm(`确定移除 ${file.name}？`);
    },
  },
};
</script>
