<template>
  <div>
    <el-dialog
        title="编辑"
        class="dialog-mini"
        width="500px"
        @close="close"
        :visible.sync="dialogformVisible"
      >
        <el-form :model="ruleForm" :rules="rules" ref="form" style="max-height: 500px;overflow: auto;" label-width="90px" size="small">
          <el-form-item label="名称"  prop="dName">
            <el-input v-model="ruleForm.dName"></el-input>
          </el-form-item>
          <el-form-item label="值"  prop="dValue">
            <el-input v-model="ruleForm.dValue"></el-input>
          </el-form-item>
          <el-form-item label="所属模块" prop="pId">
            <el-select v-model="ruleForm.pId" placeholder="请选择" clearable  style="width: 100%;">
              <el-option
                v-for="item in parentOptions"
                :key="item.id"
                :label="item.dName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="ruleForm.remark"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="mini" @click="close" >取 消</el-button>
          <el-button size="mini" type="primary" @click="submitBtn('form')">确 定</el-button>
        </div>
      </el-dialog>
      
      
  
  </div>      
  </template>
  
  <script>
  import {getMethodCommon,postMethodCommon } from "@/api/common"; 
  
  
  export default {
      name: "shujutianbao",
      props:["id"],
      components:{
         
      },
      data() {
          return {
            dialogformVisible: true,
            ruleForm:{},
            rules:{
              dName: [
                { required: true, message: '请输入名称', trigger: 'blur' }
              ],
              dValue: [
                { required: true, message: '请输入值', trigger: 'blur' }
              ]
            },
            parentOptions:[]
             
          }
      },
      watch: {
        id: function (e) {
          this.getFormData()
        }
      },
      created() {
        this.getParentData()
        this.getFormData()
      },
      mounted(){
          
      },
      methods: {
        close(){
          this.$emit("close")
        },
        getParentData(){
          getMethodCommon("/AnalysisData/GetPidData").then(res =>{
            this.parentOptions = res.result
          })
        },
        getFormData(){
          getMethodCommon("/AnalysisData/GetSingleDataInfo",{id: this.id}).then(res =>{
            this.ruleForm = res.result
          })
        },
        submitBtn(formName){
          console.log('123',this.ruleForm)
          this.$refs[formName].validate((valid) => {
            if (valid) {
              this.submitClick();
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },
        submitClick(){
          postMethodCommon("/AnalysisData/EditDataInfo",this.ruleForm).then(res =>{
            if(res.code == 200){
              this.$emit("editSuccess");
              this.$message({
                type:"success",
                message: res.message
              })
            }
          })
        },
        
      
  
      }
  }
  </script>
  
  <style>
  .el-dialog__headerbtn{
    top: 0 !important;
  }
   
  /* 滚动条 */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }
  ::-webkit-scrollbar-thumb {
    height: 50px;
    background-color: #eee;
    -webkit-border-radius: 10px;
  }
  </style>
  