<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"
      :isAdd="true"
      @add="openPopup"
      :operationsDefaultLength="6"
    />
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
    <photo-edit
      :isShow="isPhotoShow"
      :curObj="curObj"
      @close="closePhotoPopup"
    />
    <theme-house-edit
      :isShow="isTHEShow"
      :curObj="curObj"
      @close="closeTHEPopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Index'
import PopupEdit from './components/popup/IndexEdit'
import PhotoEdit from './components/popup/PhotoEdit'
import ThemeHouseEdit from './components/popup/ThemeHouseEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
    PopupEdit,
    PhotoEdit,
    ThemeHouseEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'house.admestatelist',
      searchForm: null,
      isDtlShow: false,
      isPhotoShow: false,
      // noCreated: true,
      curObj: {},
      isTHEShow: false,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        const metro_type = item.metro_type ? item.metro_type.split(',') : []
        const metroTypeName = metro_type.map(v => {
          return arrToObj(this.$dictData.metro_type)[v]
        })
        item.metroTypeName = metroTypeName.join(',')
        const product_type = item.product_type ? item.product_type.split(',') : []
        const productTypeName = product_type.map(v => {
          return arrToObj(this.$dictData.product_type)[v]
        })
        item.productTypeName = productTypeName.join(',')
        const metro_line = item.metro_line ? item.metro_line.split(',') : []
        const metroLineName = metro_line.map(v => {
          return arrToObj(this.$dictData.metro_line)[v]
        })
        item.metroLineName = metroLineName.join(',')
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '楼盘名称', prop: 'estate_name' },
        { label: '图片', prop: 'pri_image', type: 'img' },
        { label: '所属区域', prop: 'area_type', type: 'flag', flags: arrToObj(this.$dictData.area_type) }, 
        // { label: '楼盘地址', prop: 'address', fullShow: true, minWidth: 200 },
        // { label: '地铁线路', prop: 'metroLineName'},
        // { label: '地铁站名', prop: 'metroTypeName'},
        { label: '产品类型', prop: 'productTypeName'},
        // { label: '周边医院', prop: 'hospital_type', type: 'flag', flags: arrToObj(this.$dictData.hospital_type)},
        // { label: '周边商圈', prop: 'high_street', type: 'flag', flags: arrToObj(this.$dictData.high_street)},
        // { label: '公园', prop: 'park_type', type: 'flag', flags: arrToObj(this.$dictData.park_type)},
        { label: '创建人', prop: 'create_by' },
        { label: '创建时间', prop: 'create_at' },
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 400, type: 'handle2', operations:
          [
            { label: '编辑信息', func: this.openPopup, btnType: 'primary' },
            { label: '编辑相册', func: this.openPhotoPopup, btnType: 'info' },
            { label: '楼盘动态', func: this.openNews, btnType: 'info' },
            { label: '模块主题', func: this.openTHEPopup, btnType: 'info' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.house.admestatedel({
          id: row.id,
          status: 2
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
    openNews (item) {
      this.$router.push('/house/news?id=' + item.id)
    },
    openPhotoPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isPhotoShow = true
    },
    closePhotoPopup(obj) {
      this.isPhotoShow = false
      if (obj) {
        this.fetchData()
      }
    },
    openPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isDtlShow = true
    },
    closePopup(obj) {
      this.isDtlShow = false
      if (obj) {
        this.fetchData()
      }
    },
    openTHEPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isTHEShow = true
    },
    closeTHEPopup(obj) {
      this.isTHEShow = false
      if (obj) {
        this.fetchData()
      }
    }
  }
}
</script>
