<template>
  <div class="basicInfo">
    <el-form ref="form" :model="form" label-width="110px" label-position="right">
      <ai-card title="基本信息">
        <template #content>
          <div class="ai-form">
            <el-form-item label="所属平台" prop="saasPlatformId" style="width: 100%;" :rules="[{ required: false, message: '请选择所属平台', trigger: 'change' }]">
              <el-select
                size="small"
                style="width: 100%;"
                placeholder="请选择所属平台"
                clearable
                @change="onChange"
                v-model="form.saasPlatformId">
                <el-option
                  v-for="(item, index) in sassList"
                  :key="index"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item  style="width: 100%;" label="一级菜单名称" prop="menuLevel1Name" :rules="[{ required: true, message: '请输入一级菜单名称', trigger: 'change' }]">
              <el-input size="small" placeholder="请输入一级菜单名称" :maxlength="8" v-model="form.menuLevel1Name"></el-input>
            </el-form-item>
            <el-form-item style="width: 100%;" label="二级菜单名称" prop="menuLevel2Lable" :rules="[{ required: true, message: '请输入二级菜单名称', trigger: 'change' }]">
              <el-input size="small" placeholder="请输入二级菜单名称" :maxlength="8" v-model="form.menuLevel2Lable"></el-input>
            </el-form-item>
            <el-form-item style="width: 100%;" label="权限列表名称" prop="menuLevel2Name" :rules="[{ required: true, message: '请输入权限列表名称', trigger: 'change' }]">
              <el-input size="small" placeholder="请输入权限列表名称" :maxlength="8" v-model="form.menuLevel2Name"></el-input>
            </el-form-item>
          </div>
        </template>
      </ai-card>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: 'basicInfo',

    model: {
      prop: 'value',
      event: 'change',
    },

    props: {
      instance: Function,
      dict: Object,
      value: Object
    },

    data () {
      return {
        form: {
          saasPlatformId: '',
          menuLeve1Style: '',
          saasPlatformName: '',
          menuLevel1Name: '',
          menuLevel2Lable: '',
          menuLevel2Name: ''
        },
        sassList: []
      }
    },

    watch: {
      value (v) {
        this.form = JSON.parse(JSON.stringify(v))
      }
    },

    mounted () {
      this.getSassList()
      this.form = JSON.parse(JSON.stringify(this.value))
    },

    methods: {
      onChange (e) {
        this.form.saasPlatformName = this.sassList.filter(v => v.id === e)[0].name
      },

      validate () {
        let result = false
        this.$refs.form.validate(valid => {
          result = valid
        })
        this.$emit('change', this.form)
        return result 
      },

      getSassList () {
        this.instance.post(`/app/appSaas/listAll`).then(res => {
          if (res.data) {
            this.sassList = res.data
          }
        })
      }
    }
  }
</script>

<style scoped lang="scss">
</style>
