<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main">
        <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @edit="toEdit"></data-table>
      </el-col>
    </el-row>
    <el-dialog title="菜单信息管理" width="40%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
      <data-form :data="form" :fields="formfields" :rules="rules" @save="toSave">
        <template #custom="{item}">
          <template v-if="item.model == 'menus'">
            <el-checkbox-group v-model="menus">
              <el-checkbox v-for="(i, index) in menuList" :key="index" :label="i">{{ i.title }}</el-checkbox>
            </el-checkbox-group>
          </template>
        </template>
      </data-form>
    </el-dialog>
  </div>
</template>

<script>
import dataTable from '@common/src/components/frame/filter-page-table.vue';
import dataForm from '@common/src/components/frame/form.vue';
import { iconmenu } from '@common/src/util/iconmenu';
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  name: 'index',
  props: {},
  components: {
    dataTable,
    dataForm,
  },
  data: function() {
    return {
      opera: [
        {
          label: '分配权限',
          method: 'edit',
        },
      ],
      fields: [
        { label: '用户名', prop: 'name' },
        { label: '机构名称', prop: 'deptname' },
      ],
      list: [
        {
          name: '年',
        },
      ],
      total: 0,
      // 分配权限
      dialog: false,
      formfields: [
        { label: '用户名', model: 'name' },
        { label: '机构名称', model: 'deptname' },
        { label: '权限', model: 'menus', custom: true },
      ],
      form: {},
      rules: {},
      // 菜单列表
      menuList: [
        {
          icon: 'el-icon-s-home',
          index: 'menu',
          title: '菜单管理',
        },
        {
          icon: 'el-icon-s-home',
          index: 'gly',
          title: '管理员管理',
        },
        {
          icon: 'el-icon-s-home',
          index: 'jg',
          title: '机构管理员',
        },
        {
          icon: 'el-icon-s-home',
          index: 'yw',
          title: '业务管理员',
        },
        {
          icon: 'el-icon-s-home',
          index: 'qx',
          title: '权限管理',
        },
        {
          icon: 'el-icon-s-home',
          index: 'user',
          title: '用户管理',
        },
      ],
      menus: [],
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    // 查询列表
    search({ skip = 0, limit = 10, ...info } = {}) {
      console.log('列表');
    },
    // 分配权限
    toEdit({ data }) {
      this.dialog = true;
      console.log('分配权限');
    },
    // 提交分配
    toSave({ data }) {
      data.menus = this.menus;
      console.log(data);
    },
    // 取消添加
    handleClose() {
      this.form = {};
      this.dialog = false;
      this.search();
    },
  },
  computed: {
    ...mapState(['user']),
  },
  watch: {},
};
</script>

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