<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <breadcrumb :breadcrumbTitle="this.$route.meta.title"></breadcrumb>
        <el-col :span="24" class="container info">
          <el-col :span="24" class="top">
            <el-button type="primary" size="mini" @click="dialog = true">添加</el-button>
          </el-col>
          <el-col :span="24" class="list">
            <data-table :fields="fields" :opera="opera" :data="list" :total="total" @edit="toEdit" @delete="toDelete" @query="search"></data-table>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="dialog" title="增加菜单" @close="toClose" :destroy-on-close="true" width="50%">
      <data-form :data="form" :fields="formFields" :rules="rules" @save="turnSave">
        <template #custom="{item}">
          <template v-if="item.model == 'icon'">
            <el-radio-group v-model="form.icon">
              <el-radio v-for="(item, index) in iconlist" :key="index" :label="item.iconkey"><i :class="item.iconkey"></i></el-radio>
            </el-radio-group>
          </template>
        </template>
      </data-form>
    </el-dialog>
  </div>
</template>

<script>
import { iconmenu } from '@/util/iconmenu';
import breadcrumb from '@c/common/breadcrumb.vue';
import dataTable from '@/components/frame/filter-page-table.vue';
import dataForm from '@/components/frame/form.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  name: 'index',
  props: {},
  components: {
    breadcrumb,
    dataTable,
    dataForm,
  },
  data: function() {
    return {
      opera: [
        {
          label: '修改',
          icon: 'el-icon-edit',
          method: 'edit',
        },
        {
          label: '删除',
          icon: 'el-icon-delete',
          method: 'delete',
        },
      ],
      fields: [
        { label: '菜单名称', prop: 'title' },
        { label: '菜单地址', prop: 'index' },
        { label: '菜单图标', prop: 'icon' },
      ],
      list: [],
      total: 0,
      // 增加菜单
      dialog: false,
      formFields: [
        { label: '菜单名称', required: true, model: 'title' },
        { label: '菜单地址', required: true, model: 'index' },
        { label: '菜单图标', required: true, model: 'icon', custom: true },
      ],
      form: {},
      rules: {
        title: [{ required: true, message: '请输入菜单名称', trigger: 'blur' }],
        index: [{ required: true, message: '请输入菜单地址', trigger: 'blur' }],
        icon: [{ required: true, message: '请输入菜单图标', trigger: 'blur' }],
      },
      // 图标
      iconlist: iconmenu,
    };
  },
  created() {
    this.search();
  },
  methods: {
    // 查询列表
    async search({ skip = 0, limit = 10, ...info } = {}) {},
    // 修改
    toEdit({ data }) {
      console.log(data);
    },
    // 删除
    toDelete({ data }) {
      console.log(data);
    },
    // 增加菜单
    // 保存
    turnSave({ data }) {
      console.log(data);
    },
    // 取消增加
    toClose() {
      this.form = {};
      this.dialog = false;
    },
  },
  computed: {
    ...mapState(['user']),
  },
};
</script>

<style lang="less" scoped>
.main {
  .info {
    .top {
      text-align: right;
      margin: 15px 0;
    }
  }
}
</style>
