<template>
  <div class="page-contents">
    <nk-page-title title="${javaClassRef.getComment()}管理">
      <el-tooltip
        :open-delay="300"
        :enterable="false"
        content="添加${javaClassRef.getComment()}"
        placement="top"
        effect="light"
      >
        <el-button type="success" size="small" @click="onClickBtnAdd" icon="el-icon-tc-addAuth"
          >添加</el-button
        >
      </el-tooltip>
    </nk-page-title>

    <nk-list-page
      ref="listPage"
      :formColumns="formColumns"
      :tableData="tableData"
      :tableColumns="tableColumns"
      @ajax="getList"
    >
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <nk-button
            type="primary"
            icon="el-icon-edit"
            tipContent="编辑${javaClassRef.getComment()}"
            round
            @click="onClickBtnEdit(scope.row)"
          ></nk-button>
          <nk-button
            type="success"
            icon="el-icon-view"
            tipContent="查看${javaClassRef.getComment()}"
            round
            @click="onClickBtnDetail(scope.row)"
          ></nk-button>
          <nk-button
            type="danger"
            icon="el-icon-delete"
            tipContent="删除${javaClassRef.getComment()}"
            round
            @click="onClickBtnDeleteRow(scope.row)"
          ></nk-button>
        </template>
      </el-table-column>
    </nk-list-page>
  </div>
</template>

<script>
import { ${javaClassRef.getClassName()}, ${javaClassRef.getClassName()}Api } from './${javaClassRef.getClassName()}.js'
import { FmtEnabled, FmtTimeStamp } from '@common/grid/formatter.js'
import { InputSelectEnabledAll } from '@common/form/input.js'

export default {
  name: ${javaClassRef.getClassName()}.moduleName + 'List',
  created() {},
  components: {},
  watch: {
    //详情页返回刷新
    '$store.state.EditUpdate.alteration'(newVal) {
      if (newVal.position == ${javaClassRef.getClassName()}.moduleName) {
        this.$refs['listPage'].refresh()
      }
    }
  },
  data() {
    return {
      formColumns: [
// TODO 请自行注释或者删除不需要的查询条件
#foreach( ${attrRef} in ${javaClassRef.getAttributes()} )
#if(${attrRef.getClassName().equals("TenantId")})
#elseif(${attrRef.getClassName().equals("Enabled")})
        {
          ...${javaClassRef.getClassName()}.Enabled,
          ...InputSelectEnabledAll
        },
#else
        ${javaClassRef.getClassName()}.${attrRef.getClassName()},
#end
#end
      ],
      tableColumns: [
// TODO 请自行注释或者删除不需要展示的列
#foreach( ${attrRef} in ${javaClassRef.getAttributes()} )
#if(${attrRef.getClassName().equals("TenantId")})
#elseif(${attrRef.getClassName().equals("Enabled")})
        {
          ...${javaClassRef.getClassName()}.${attrRef.getClassName()},
          formatter: FmtEnabled
        },
#elseif(${attrRef.getJavaTypeName().equals("Date")})
        {
          ...${javaClassRef.getClassName()}.${attrRef.getClassName()},
          formatter: FmtTimeStamp
        },
#else
        ${javaClassRef.getClassName()}.${attrRef.getClassName()},
#end
#end
      ],
      //表格数据
      tableData: []
    }
  },
  methods: {
    // 查询列表
    getList(data) {
      ${javaClassRef.getClassName()}Api.query(data).then((res) => {
        this.tableData = res.records
        this.${DOLLAR_MARK}refs['listPage'].setPageTotal(res.recordCount)
      })
    },
    //点击“添加(新增)”按钮
    onClickBtnAdd() {
      this.${DOLLAR_MARK}router.push({
        name: '${javaClassRef.getClassName()}Add',
        query: {
          refreshName: this.${DOLLAR_MARK}route.name
        }
      })
    },
    //点击“编辑(修改)”按钮
    onClickBtnEdit(row) {
      this.${DOLLAR_MARK}router.push({
        name: '${javaClassRef.getClassName()}Edit',
        query: {
          id: row.id,
          refreshName: this.${DOLLAR_MARK}route.name
        }
      })
    },
    //点击“查看详情”按钮
    onClickBtnDetail(row) {
      this.${DOLLAR_MARK}router.push({
        name: '${javaClassRef.getClassName()}Detail',
        query: {
          id: row.id,
          refreshName: this.${DOLLAR_MARK}route.name
        }
      })
    },
    // 点击“删除”按钮
    onClickBtnDeleteRow(row) {
      this.${DOLLAR_MARK}confirm(`确定删除这条记录吗?`, '提示', {
        type: 'warning'
      })
        .then(() => {
          console.log()
          ${javaClassRef.getClassName()}Api.delete(row.id).then((res) => {
            this.${DOLLAR_MARK}notify({
              message: '删除成功',
              type: 'success'
            })
            this.${DOLLAR_MARK}refs['listPage'].refresh()
          })
        })
        .catch(() => {})
    }
  }
}
</script>
<style lang="less" scoped></style>

