<template>
  <div class="manage-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="网站信息" name="first">
        <el-form ref="form" :model="form" label-width="100px">
          <el-form-item label="网站名称">
            <el-input v-model="sys.name" placeholder="请输入内容"></el-input>
          </el-form-item>
          <el-form-item label="联系电话">
            <el-input
              v-model="sys.phone"
              type="textarea"
              placeholder="请输入内容"
            ></el-input>
          </el-form-item>
          <el-form-item label="关键字">
            <el-input
              v-model="sys.keyword"
              type="textarea"
              placeholder="请输入内容"
            ></el-input>
          </el-form-item>
          <el-form-item label="网站描述">
            <el-input type="textarea" placeholder="请输入内容"></el-input>
          </el-form-item>
          <el-form-item label="统计代码">
            <el-input
              v-model="sys.js"
              type="textarea"
              placeholder="请输入内容"
            ></el-input>
          </el-form-item>
          <el-form-item label="备案号">
            <el-input v-model="sys.code" placeholder="请输入内容"></el-input>
          </el-form-item>
          <el-form-item label="版权">
            <el-input
              v-model="sys.copyright"
              placeholder="请输入内容"
            ></el-input>
          </el-form-item>
        </el-form>
        <el-button type="primary" @click="submitSys">保存</el-button>
        <el-button type="primary" plain>返回</el-button>
      </el-tab-pane>
      <el-tab-pane label="菜单管理" name="second">
        <el-table
          ref="tableSort"
          v-loading="listLoading"
          :data="list"
          :element-loading-text="elementLoadingText"
          :height="height"
          @selection-change="setSelectRows"
        >
          <el-table-column
            prop="id"
            label="id"
            width="180"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="name"
            label="分类名称"
            width="500"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="path"
            label="地址"
            align="center"
          ></el-table-column>
          <el-table-column :label="$t('defalult.cz')" align="center">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">
              {{ $t('defalult.bj') }}
            </el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
            >
              删除
            </el-button>
          </el-table-column>
        </el-table>
        <vab-query-form>
          <vab-query-form-right-panel>
            <el-pagination
              :background="background"
              :current-page="queryForm.pageNo"
              :layout="layout"
              :page-size="queryForm.pageSize"
              :total="total"
              @current-change="handleCurrentChange"
              @size-change="handleSizeChange"
            ></el-pagination>
          </vab-query-form-right-panel>
        </vab-query-form>
      </el-tab-pane>
      <el-tab-pane label="项目管理" name="third">项目管理</el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { getList } from '@/api/menu';
export default {
  name: 'Setting',
  data() {
    return {
      activeName: 'first',
      layout: 'total, sizes, prev, pager, next, jumper',
      total: 0,
      input: '',
      textarea: '',
      list: [],
      background: true,
      listLoading: true,
      elementLoadingText: '正在加载...',
      queryForm: {
        pageNo: 1,
        pageSize: 20,
        title: '',
      },
    };
  },
  computed: {
    height() {
      return this.$baseTableHeight();
    },
  },
  mounted() {},
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
      console.log('name' + tab.name);
      if (tab.name == 'second') {
        this.fetchData();
      }
    },
    setSelectRows(val) {
      this.selectRows = val;
    },
    async fetchData() {
      this.listLoading = true;
      const { data, totalCount } = await getList(this.queryForm);
      this.list = data;
      this.total = totalCount;
      setTimeout(() => {
        this.listLoading = false;
      }, 500);
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
  },
};
</script>

<style lang="scss" scoped>
.manage-container {
  width: 100%;

  .el-form-item {
    width: 360px;
  }
  .el-button {
    margin-left: 0 !important;
  }
}
</style>
