<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"
    />
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Old'
import PopupEdit from './components/popup/OldEdit'
import baseTable from '_m/baseTable.js'
import xData from './mixin'
export default {
  name: 'old',
  components: {
    SearchForm,
    PopupEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'house.admoldhouselist',
      searchForm: null,
      isDtlShow: false,
      // noCreated: true,
      curObj: {},
      ...xData
    }
  },
  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: 'title' },
        { label: '主图', prop: 'pri_image', type: 'img' },
        { label: '总价', prop: 'price' },
        { label: '面积㎡', prop: 'area' },
        { label: '房源类型', prop: 'house_type', type: 'flag', flags: arrToObj(this.$dictData.house_type) },
        { label: '所属区域', prop: 'area_type', type: 'flag', flags: arrToObj(this.$dictData.area_type) },
        { label: '产品类型', prop: 'productTypeName'},
        { label: '房源地址', prop: 'address', fullShow: true, minWidth: 200 },
        // { label: '地铁线路', prop: 'metroLineName'},
        // { label: '地铁站名', prop: 'metroTypeName'},
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 120, type: 'handle2', operations:
          [
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.house.admoldhousedel({
          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()
      }
    }
  }
}
</script>
