<template>
  <div class="app-container">
    <search-form
      :listLoading="listLoading"
      @change="searchHandle"
      @add="openPopup"
    />
    <table-list
      :operationsDefaultLength="3"
      :listLoading="listLoading"
      :data="tableData"
      :columns="listConfig"
      :currentPage="currentPage"
      :pageSize="pageSize"
      :totalRecords="totalRecords"
      @currentChange="pageHandle"
      @sizeChange="sizeChange"
      :isAdd="true"
      @add="openPopup"
    />
    <popup-edit
      :isShow="isPopupShow"
      :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: 'basePublicDictSys',
  components: {
    SearchForm,
    PopupEdit
  },
  provide () {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  created () {},
  data () {
    return {
      apiStr: 'other.admthemelist',
      searchForm: null,
      isPopupShow: false,
      // noCreated: true,
      curObj: {}
    }
  },
  mounted () {
    this.listConfig = {
      rows: [
        { label: '开始时间', prop: 'start_at' },
        { label: '结束时间', prop: 'end_at' },
        { label: '主题名称', prop: 'theme_name' },
        { label: '备注说明', prop: 'remark', fullShow: true },
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 230, type: 'handle2',
          operations: [
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '管理内容详情', func: this.linkDtl, btnType: 'success' },
            { label: '删除', func: this.delHandle, btnType: 'danger', hide: 'nosys' },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle (row) {
      const msgHtml = `确定要删除该主题吗？`
      this.$msg(msgHtml, 'confirm', ()=> {
        this.$api.other.admthemedel({
          id: row.id,
        }).then(data => {
          this.$msgs(`删除成功！`)
          this.fetchData()
        })
      }, null, true)
    },
    linkDtl (row) {
      this.$router.push(`/base/themeDtl?theme_name=${row.theme_name}&id=${row.id}`)
    },
    openPopup (row) {
      this.curObj = row
      this.isPopupShow = true
    },
    closePopup (obj) {
      this.isPopupShow = false
      if (obj) {
        this.fetchData()
      }
    }
  }
}
</script>
