<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"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Del'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'house.admestaterecyclelist',
      searchForm: null,
      isDtlShow: false,
      isPhotoShow: false,
      // noCreated: true,
      curObj: {},
      isTHEShow: 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: '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: 'productTypeName'},
        { label: '创建人', prop: 'create_by' },
        { label: '创建时间', prop: 'create_at' },
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 120, type: 'handle2', operations:
          [
            { label: '恢复', func: this.reHandle, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.house.admestaterecyclepurge({
          id: row.id,
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
    reHandle(row) {
      this.$msg(`您确定要恢复该楼盘吗？`, 'confirm', () => {
        this.$api.house.admestaterecyclerollback({
          id: row.id,
        }).then(data => {
          this.$msgs(`已恢复！`)
          this.fetchData()
        })
      }, null, true)
    },
  }
}
</script>
