<template>
  <ts-form :data="data" :rules="rules" @submit="submitEvent" ref="xForm">
    <div slot="formCon">
      <ts-form-item field="pid">
        <ts-select
          :source="menuSource"
          v-model="data.pid"
          title="上级菜单"
          :emphasize="true"
          placeholder
          @selected="selected"
        ></ts-select>
      </ts-form-item>
      <ts-form-item field="menuname">
        <ts-input
          v-model="data.menuname"
          title="菜单名称"
          :emphasize="true"
          placeholder
          name="menuname"
        ></ts-input>
      </ts-form-item>
      <ts-form-item>
        <ts-switch
          title="菜单状态"
          v-model="status"
          on-label="启用"
          off-label="禁用"
          :on-value="1"
          :off-value="0"
        ></ts-switch>
      </ts-form-item>
      <!-- <div class="none">
        <ts-button id="addBiMenuAdd" type="submit" status="primary" ref="submit">提交</ts-button>
      </div> -->
    </div>
  </ts-form>
</template>

<script>
export default {
  name: 'biMenuAdd',
  props: ['biCustom', 'row', 'menuName'],
  data() {
    return {
      status: 1,
      data: {
        menuname: this.menuName,
        pid: ''
      },
      rules: {
        menuname: [{ required: true, message: '请输入菜单名称' }],
        pid: [{ required: true, message: '请输入上级菜单' }]
      },
      menuSource: {
        dataType: 'json',
        url: '/ts-system/menu/getMenu?menutype=2',
        method: 'get',
        data: [],
        treeType: 'normal',
        code: 'id',
        text: 'name',
        treeExpand: false,
        children: 'children',
        tree: true,
        isReq: true,
        isLoading: false
      }
    }
  },
  created() {},
  mounted() {},
  watch: {
    menuName: {
      handler(n) {
        this.data.menuname = n
      }
    }
  },
  methods: {
    //上级菜单
    selected(val) {
      this.$nextTick(() => {
        this.data.pid = val.id
        this.data.menulevel = val.menulevel
        this.data.syscode = val.userData.syscode
      })
    },
    // 表单提交验证
    submitEvent() {
      this.submit()
    },
    submit() {
      this.data.status = this.status
      this.$emit('submitClick', { formData: this.data, type: 'biMenuAdd' })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
