<template>
  <div>
    <nk-page-title title="${javaClassRef.getComment()}">
    </nk-page-title>
    <nk-form
      ref="NkForm"
      type="view"
      :formData="formData"
      :formColumns="formColumns"
      :refreshName="$route.query.refreshName"
    ></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 + 'Detail',
  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() {
    // 主键，唯一ID
    this.pkId = this.$route.query.id
    // 初始化页面的数据
    this.init()
  },
  methods: {
    /**
     * 初始化页面的数据
     */
    init() {
      ${javaClassRef.getClassName()}Api.detail(this.pkId)
        .then((res) => {
          this.formData = res
        })
        .catch((error) => {
          this.loading = false
          this.$notify({
            showClose: true,
            message: error.resultMsg,
            type: 'error'
          })
        })
    }
  }
}
</script>
<style lang="less" scoped></style>
