<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/Brand'
import PopupEdit from './components/popup/BrandEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'x',
  components: {
    SearchForm,
    PopupEdit
  },
  provide () {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  created () {},
  data () {
    return {
      apiStr: 'other.admbrandlist',
      searchForm: null,
      isPopupShow: false,
      // noCreated: true,
      curObj: {}
    }
  },
  mounted () {
    this.listConfig = {
      rows: [
        { label: '品牌', prop: 'brand_name' },
        { label: '品牌地图', prop: 'pri_image', type: 'img' },
        { 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.admbranddel({
          id: row.id,
        }).then(data => {
          this.$msgs(`删除成功！`)
          this.fetchData()
        })
      }, null, true)
    },
    linkDtl (row) {
      this.$router.push(`/ad/brandDtl?id=${row.id}&brand_name=${row.brand_name}`)
    },
    openPopup (row) {
      this.curObj = row || {}
      this.isPopupShow = true
    },
    closePopup (obj) {
      this.isPopupShow = false
      if (obj) {
        this.fetchData()
      }
    }
  }
}
</script>
