<template>
  <div>
    <el-form ref="form" :rules="rules"  :model="form" label-width="120px">
      <el-form-item
          label="菜单名称："
          prop="label"
      >
        <el-input v-model.number="form.label"  placeholder="请输入菜单名称"></el-input>
      </el-form-item>
      <el-form-item
          label="父级菜单："
          prop="pid"
      >
      <el-cascader
      v-model="form.pid"
      :options="menulist"
      :props="{
                checkStrictly: true,
                value:'id',
                label:'label',
                children:'children',
              }" 
      clearable></el-cascader>
    </el-form-item>
      <el-form-item label="路由地址：" prop="url">
        <el-input v-model="form.url"  placeholder="输入路由地址" ></el-input>
      </el-form-item>
      <el-form-item label="图标：" prop="icon">
        <el-input v-model="form.icon"  placeholder="输入图标地址" ></el-input>
      </el-form-item>
      <el-form-item label="排序：" prop="sort">
        <el-input v-model="form.sort"  placeholder="输入排序" ></el-input>
      </el-form-item>
      <el-form-item label="是否外链：" prop="is_links">
        <el-switch
            v-model="form.is_links"
            :active-value="1"
            :inactive-value="0"
        >
        </el-switch>
      </el-form-item>
      <el-form-item label="是否隐藏：" prop="hidden">
        <el-switch
            v-model="form.hidden"
            :active-value="1"
            :inactive-value="0"
        >
        </el-switch>
      </el-form-item>
      <el-form-item>
        <div style="text-align: center">
          <el-button type="primary" @click="onSubmit" :disabled="Isdisabled" :loading="isloading">保存</el-button>
          <el-button style="color: #5075FC " @click="closeDlg">取消</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  props: {
    menuDataForm: {
      type: Object,
      default: () => {}
    },
    isloading:{
      type:Boolean,
      default: true
    },
    closeDlg:{
      type:Function
    }
  },
  data() {
    return {
      form: {
        label: '',
        url:"",
        icon:"",
        sort:"",
        is_links:"",
        hidden:"",
        pid:[0]
      },
      menulist: [],
      Isdisabled: false,
      rules: {
        label: [
          { required: true, message: '菜单名称必填' },
        ],
        url: [
          { required: true, message: '路由地址必填' }
        ],
        sort: [
          { pattern: /^[1-9]\d*$/, message: '排序值格式错误' },
        ]
      }
    }
  },
  mounted() {
    if(this.menuDataForm) {
      this.form = Object.assign({} , this.menuDataForm)
    }
    this.getRecursionMenu()
  },
  methods: {
    closeDlg() {
      // this.isloading = false
      console.log("edit提交")
      this.$emit('closeDlg',1)
    },
    onSubmit() {
      let that = this
      that.$refs['form'].validate((valid) => {
        if (valid) {
          this.$emit('menuSubmitClick', this.form)
        }
      })
    },
    getRecursionMenu(){
      let _t= this
      let parames = {}
      this.$api.pub.getMenuList(parames).then(res=>{
                if(res.code==200){
                  // id: 4, pid: 1, label: "权限设置"
                  // res.data.concat({"id":1,"label":"一级目录","children":[]});
                  // console.log(res.data)
                  _t.menulist = res.data
                }else{
                    this.$message.error("查询失败")
                }
            })
    },
    
  }
}
</script>
<style>
.el-cascader-node>.el-radio{
  margin-top:25px;
}
</style>
