<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"
      :operationsDefaultLength="3"
    >
    </table-list>
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/All'
import PopupEdit from './components/popup/AllEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'houseAll',
  components: {
    SearchForm,
    PopupEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'house.admestateliblist',
      searchForm: null,
      isDtlShow: false,
      curObj: {},
      isHRShow: false,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        item.brokerageTag = item.brokerage_tag ? JSON.parse(item.brokerage_tag).join(',') : ''
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        // { label: '排序', prop: 'sort', type: 'input', width: 80},
        { label: '图片', prop: 'pri_image', type: 'img' },
        { label: '楼盘名称', prop: 'estate_name' },
        { label: '所属区域', prop: 'area_type', type: 'flag', flags: arrToObj(this.$dictData.area_type) },
        { label: '合作平台渠道', prop: 'brokerageTag' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 220, type: 'handle2', operations:
          [
            { label: '编辑信息', func: this.openPopup, btnType: 'primary' },
            { label: '渠道平台', func: this.linkBrokerage, btnType: 'info' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    linkBrokerage (row) {
      this.$router.push(`/house/brokerage?id=${row.id}&name=${row.estate_name}`)
    },
    // saveHandle (row) {
    //   this.$api.house.admestatesortedit({
    //     id: row.id,
    //     sort: row.sort,
    //   }).then(data => {
    //     this.$msgs(`已保存！`)
    //     this.fetchData()
    //   })
    // },
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.house.admestatelibdel({
          id: row.id,
          status: 2
        }).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()
      }
    },
    openHRPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isHRShow = true
    },
    closeHRPopup(obj) {
      this.isHRShow = false
      if (obj) {
        this.fetchData()
      }
    },
    
  }
}
</script>
