<template>
  <div class="app-container">
    <search-form
      :list-loading="listLoading"
      @change="searchHandle"
    />
    <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/List'
import PopupEdit from './components/popup/listEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'list',
  components: {
    SearchForm,
    PopupEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'other.admmapcoordinlist',
      searchForm: {},
      isDtlShow: false,
      curObj: {},
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        if (
            item.uuid === '96512a54-4d3c-457e-a33f-3ea27c963bd0' // 区域
            || item.uuid === '954a527b-e460-4b67-bd39-7adcfa3c2def'   // 默认
            || item.uuid === '95542ff1-8176-4267-8344-2aa7f1034ac5' // 初中
            || item.uuid === '95542fdc-b542-4582-9be2-9ab8005728d3' // 小学
          ) {
          item.isSys = true
        }
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: 'ID', prop: 'uuid'},
        { label: '标题', prop: 'title'},
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 120, type: 'handle2', operations:
          [
            { label: '详情', func: this.linkDtl, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger', hide: 'isSys', },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.other.admmapcoordindel({
          uuid: row.uuid,
        }).then(() => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
    linkDtl(row) {
      this.$router.push(`/map/dtl?e=1&id=${row.uuid}`)
    },
    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>
