<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"
    />
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
    <popup-update
      :isShow="isUpdateShow"
      :curObj="curObj"
      @close="closeUpdatePopup"
    />
    <popup-record
      :isShow="isQShow"
      :curObj="curObj"
      @close="closeQPopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Trend'
import PopupEdit from './components/popup/TrendEdit'
import PopupUpdate from './components/popup/TrendUpdate'
import PopupRecord from './components/popup/TrendRecord'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
    PopupEdit,
    PopupUpdate,
    PopupRecord,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'house.admestatehousedynamiclist',
      searchForm: null,
      isDtlShow: false,
      curObj: {},
      isUpdateShow: false,
      isQShow: false,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData,]
      arr.map(item => {})
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        //  minWidth: 150, align: 'left'
        { label: '更新时间', prop: 'update_re' },
        { label: '楼盘名称', prop: 'estate_name' },
        { label: '所属区域', prop: 'area_type', type: 'flag', flags: arrToObj(this.$dictData.area_type) },
        { label: '产品类型', prop: 'product_type', type: 'flag', flags: arrToObj(this.$dictData.product_type) },
        { label: '户型面积', prop: 'house_square' },
        { label: '起价', prop: 'price_min' },
        { label: '封顶价', prop: 'price_max' },
        { label: '现场折扣', prop: 'scene_discount' },
        { label: '实际折扣', prop: 'actual_discount' },
        { label: '最新动态', prop: 'dynamic' },
        { label: '更新人', prop: 'update_by' },
        { label: '操作', width: 220, type: 'handle2', operations:
          [
            { label: '去更新', func: this.openUpdatePopup, btnType: 'success' },
            { label: '更新记录', func: this.openQPopup, btnType: 'primary' },
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle(row) {
      this.$msg(`您确定要删除该动态数据吗？`, 'confirm', () => {
        this.$api.house.admestatehousedynamicdel({
          id: row.id,
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
    openQPopup (row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isQShow = true
    },
    closeQPopup (obj) {
      this.isQShow = 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() 
      }
    },
    openUpdatePopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isUpdateShow = true
    },
    closeUpdatePopup(obj) {
      this.isUpdateShow = false
      if (obj) {
        this.fetchData() 
      }
    }
  }
}
</script>
