<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="3"
    />
    <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"
    />
    <help-rule
      :isShow="isHRShow"
      :curObj="curObj"
      @close="closeHRPopup"
    />
  </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 HelpRule from './components/popup/HelpRule'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
    PopupEdit,
    PhotoEdit,
    ThemeHouseEdit,
    HelpRule,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'house.admestatelist',
      searchForm: null,
      isDtlShow: false,
      isPhotoShow: false,
      // noCreated: true,
      curObj: {},
      isTHEShow: false,
      isHRShow: false,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        item.pri_image = this.IMadd(item.pri_image)
        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: 'sort', type: 'input', width: 80},
        { label: '楼盘名称', prop: 'estate_name', minWidth: 150, align: 'left' },
        { label: '图片', prop: 'pri_image', type: 'img' },
        { label: '所属区域', prop: 'area_type', type: 'flag', flags: arrToObj(this.$dictData.area_type) },
        { label: '浏览量', prop: 'view_count'}, 
        // { 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: 220, type: 'handle2', operations:
          [
            { label: '保存排序', func: this.saveHandle, btnType: 'success' },
            { label: '编辑信息', func: this.openPopup, btnType: 'primary' },
            { label: '编辑相册', func: this.openPhotoPopup, btnType: 'info' },
            { label: '楼盘动态', func: this.openNews, btnType: 'info' },
            { label: '历史成交价', func: this.openPrice, btnType: 'info' },
            { label: '模块主题', func: this.openTHEPopup, btnType: 'info' },
            { label: '竞品管理', func: this.openCompetePopup, btnType: 'info' },
            { label: '助力规则', func: this.openHRPopup, btnType: 'warning' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    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.admestatedel({
          id: row.id,
          status: 2
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
    openCompetePopup (item) {
      this.$router.push('/house/compete?id=' + item.id + '&name=' + item.estate_name)
    },
    openNews (item) {
      this.$router.push('/house/news?id=' + item.id)
    },
    openPrice (item) {
      this.$router.push('/house/price?id=' + item.id + '&name=' + item.estate_name)
    },
    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()
      }
    },
    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>
