<template>
  <el-form ref="moduleInfoForm" :model="info" :rules="rules" label-width="150px">
    <el-row>
      <el-col :span="12">
        <el-form-item label="模块名称" prop="cName">
          <el-input placeholder="请输入类名" v-model="info.mDescribe"/>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="模块描述" prop="cName">
          <el-input placeholder="请输入类名" v-model="info.mName"/>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="备注">
          <el-input type="textarea" :rows="3" v-model="info.remark"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
  import {queryListModule} from "@/api/tool/module"
  export default {
    name: "ModuleInfoForm",
    props: {
      info: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        moduleList:[],
        rules: {
          packageName: [
            {required: true, message: "包名不能为空", trigger: "blur"},
          ],
          mId: [
            {required: true, message: "模块不能为空", trigger: "blur"},
          ],
          cName: [
            {required: true, message: "类名不能为空", trigger: "blur"},
          ],
          cDescribe: [
            {required: true, message: "类描述不能为空", trigger: "blur"},
          ],
          author: [
            {required: true, message: "作者不能为空", trigger: "blur"},
          ],
          email: [
            {required: true, message: "电子邮件不能为空", trigger: "blur"},
            {
              pattern: /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
              message: '电子邮件格式有误',
              trigger: "blur"
            },
          ],
        }
      };
    },
    created() {
      queryListModule().then(respone => {
        this.moduleList = respone.data
      })
    },
    methods:{
      transform() {
        var mid = this.info.mId
        var str = ''
        var start = true
        for (let i = 0; i < this.moduleList.length; i++) {
          if (mid == this.moduleList[i].id) {
            str = this.moduleList[i].mName
            start = false
          }
        }
        if (start) {
          str = ''
        }
        this.info.packageName = 'com.hchyun.' + str
      },
    }
  };
</script>
