<template>
  <div class="app-container">
    <search-form/>
    <table-list
      :listLoading="listLoading"
      :data="tableData2"
      :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/BrandDtl'
import PopupEdit from './components/popup/BrandDtlEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'x',
  components: {
    SearchForm,
    PopupEdit
  },
  provide () {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data () {
    return {
      apiStr: 'other.admbranddatalist',
      searchForm: null,
      isPopupShow: false,
      noCreated: true,
      curObj: {},
      curId: '',
    }
  },
  computed: {
    tableData2 () {
      let arr = [...this.tableData]
      arr.map(item => {
        if (Number(item.system) === 1) item.nosys = true
      })
      return arr
    }
  },
  mounted () {
    this.listConfig = {
      rows: [
        { label: '排序', prop: 'sort' },
        { label: '楼盘ID', prop: 'estate_id' },
        { label: '楼盘', prop: 'estate_name' },
        { label: '宣传图', prop: 'pri_image', type: 'img' },
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 200, type: 'handle2',
          operations: [
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger', hide: 'nosys' },
          ]
        }
      ]
    }
    const query = this.$route.query
    if (query.id) {
      this.searchForm = {
        id: query.id
      }
      this.fetchData()
    }
  },
  methods: {
    delHandle (row) {
      const msgHtml = `确定要删除该楼盘吗？`
      this.$msg(msgHtml, 'confirm', ()=> {
        this.$api.other.admbranddatadel({
          id: row.id,
        }).then(data => {
          this.$msgs(`删除成功！`)
          this.fetchData()
        })
      }, null, true)
    },
    openPopup (row) {
      this.curObj = row || {}
      this.isPopupShow = true
    },
    closePopup (obj) {
      this.isPopupShow = false
      if (obj) {
        this.fetchData()
      }
    }
  }
}
</script>
