<template>
  <div>
    <nk-page-title title="新增${javaClassRef.getComment()}">
      <el-button size="small" type="primary" @click="submit" :loading="loading">提交</el-button>
    </nk-page-title>
    <nk-form
      ref="NkForm"
      type="add"
      :formColumns="formColumns"
      :refreshName="$route.query.refreshName"
      @submit="submit"
      @choose="choose"
      @selectchange="selectOnChange"
    ></nk-form>
  </div>
</template>

<script>
import { ${javaClassRef.getClassName()}, ${javaClassRef.getClassName()}Api } from './${javaClassRef.getClassName()}.js'
import { InputSwitchBoolean } from '@common/form/input.js'

export default {
  name: ${javaClassRef.getClassName()}.moduleName + 'Add',
  components: {},
  data() {
    return {
      formColumns: [
#foreach( ${attrRef} in ${javaClassRef.getAttributes()} )
#if(${attrRef.getClassName().equals("TenantId")})
#elseif(${attrRef.getClassName().equals("Enabled")})
        {
          ...${javaClassRef.getClassName()}.Enabled,
          ...InputSwitchBoolean
        },
#else
        ${javaClassRef.getClassName()}.${attrRef.getClassName()},
#end
#end
      ],
      //数据源
      formData: {},
      //提交按钮loading
      loading: false
    }
  },
  computed: {
    formData: {
      get() {
        return this.${DOLLAR_MARK}refs['NkForm'].getFormData()
      },
      set(val) {
        this.${DOLLAR_MARK}refs['NkForm'].setFormData(val)
      }
    }
  },
  created() {
  },
  methods: {
    //选择触发钩子
    choose(item) {
      console.log(item)
    },
    //下拉框change钩子
    selectOnChange({ prop, value }) {},
    //switch change钩子
    switchOnChange({ prop, value }) {},
    /**
     * 关闭当前标签页，从哪来回哪去
     */
    goBack() {
      //参数flag:true关闭并刷新  false仅关闭不刷新
      this.$refs['NkForm'].back(true)
    },
    //提交表单
    submit() {
      this.loading = true
      this.$refs['NkForm']
        .validate()
        .then(() => {
          ${javaClassRef.getClassName()}Api.add(this.formData).then((res) => {
            this.$notify({
              message: this.$t('main.add') + '成功',
              type: 'success'
            })
            this.goBack()
            this.loading = false
          })
        })
        .catch(() => {
          this.loading = false
        })
    }
  }
}
</script>
<style lang="less" scoped></style>
