<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"
      :isAdd="true"
      @add="openPopup"
      :operationsDefaultLength="5"
    />
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
    <lottery-edit
      :isShow="isLEShow"
      :curObj="curObj"
      @close="closeLEPopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Theme'
import PopupEdit from './components/popup/ThemeEdit'
// import LotteryEdit from './components/popup/LotteryEdit2'
import LotteryEdit from './components/popup/LotteryList'
// import LotteryEdit from './components/popup/RoomPrice'
import baseTable from '_m/baseTable.js'
export default {
  name: 'old',
  components: {
    SearchForm,
    PopupEdit,
    LotteryEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    const mtArr = this.$dictData.module_type || []
    const curNavVal = mtArr.length > 0 ? mtArr[5].val : ''
    return {
      apiStr: 'house.admestatemodulelist',
      searchForm: {},
      isDtlShow: false,
      // noCreated: true,
      curObj: {},
      mtArr,
      curNavVal,
      isLEShow: false,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
      })
      return arr
    }
  },
  created() {
    this.searchForm = {
      module_type: this.curNavVal
    }
  },
  mounted() {
    this.getConfig()
  },
  methods: {
    getConfig () {
      if (this.curNavVal === 'yhjg' || this.curNavVal === 'zzyh') {
        this.listConfig = {
          rows: [
            { label: '楼盘名称', prop: 'estate_name' },
            { label: '模块主题', prop: 'module_type', type: 'flag', flags: arrToObj(this.$dictData.module_type) },
            { label: '排序', prop: 'sort' },
            { label: '更新人', prop: 'update_by' },
            { label: '更新时间', prop: 'update_at' },
            { label: '操作', width: 220, type: 'handle2', operations:
              [
                { label: '更新摇号信息', func: this.openLEPopup, btnType: 'success' },
                { label: '编辑', func: this.openPopup, btnType: 'primary' },
                { label: '删除', func: this.delHandle, btnType: 'danger' },
              ]
            }
          ]
        }
      } else {
        this.listConfig = {
          rows: [
            { label: '楼盘名称', prop: 'estate_name' },
            { label: '模块主题', prop: 'module_type', type: 'flag', flags: arrToObj(this.$dictData.module_type) },
            { 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' },
              ]
            }
          ]
        }
      }
    },
    navHandle () {
      this.getConfig()
      this.searchForm.module_type = this.curNavVal
      this.fetchData()
    },
    delHandle(row) {
      this.$msg(`您确定要删除该模块主题吗？`, 'confirm', () => {
        this.$api.house.admestatemoduledel({
          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()
      }
    },
    openLEPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isLEShow = true
    },
    closeLEPopup(obj) {
      this.isLEShow = false
      if (obj) {
        this.fetchData()
      }
    }
  }
}
</script>
