<template>
  <div class="app-container">
    <search-form
      :list-loading="listLoading"
      @change="searchHandle"
    />
    <el-tabs v-model="curNavVal" @tab-click="navHandle">
      <el-tab-pane :label="item.key" :name="item.val" v-for="(item, index) in mtArr" :key="index"></el-tab-pane>
    </el-tabs>
    <table-list
      :list-loading="listLoading"
      :data="tableData2"
      :columns="listConfig"
      :current-page="currentPage"
      :page-size="pageSize"
      :total-records="totalRecords"
      @currentChange="pageHandle"
      @sizeChange="sizeChange"
      :isAdd="true"
      @add="openPopup"
    />
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Theme'
import PopupEdit from './components/popup/ThemeEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'old',
  components: {
    SearchForm,
    PopupEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    const mtArr = this.$dictData.school_cate || []
    const curNavVal = mtArr.length > 0 ? mtArr[0].val : ''
    return {
      apiStr: 'school.admschoolmodulelist',
      searchForm: {},
      isDtlShow: false,
      // noCreated: true,
      curObj: {},
      mtArr,
      curNavVal,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
      })
      return arr
    }
  },
  created() {
    this.searchForm = {
      school_cate: this.curNavVal
    }
  },
  mounted() {
    this.listConfig = {
      rows: [
        { label: '学校名称', prop: 'school_name' },
        { label: '模块主题', prop: 'school_cate', type: 'flag', flags: arrToObj(this.$dictData.school_cate) },
        { label: '排序', prop: 'sort' },
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 120, type: 'handle2', operations:
          [
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    navHandle () {
      this.searchForm.school_cate = this.curNavVal
      this.fetchData()
    },
    delHandle(row) {
      this.$msg(`您确定要删除该模块主题吗？`, 'confirm', () => {
        this.$api.school.admschoolmoduledel({
          id: row.id,
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
    openPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isDtlShow = true
    },
    closePopup(obj) {
      this.isDtlShow = false
      if (obj) {
        this.fetchData()
      }
    }
  }
}
</script>
