<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"
      :operationsDefaultLength="5"
    />
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Index'
import PopupEdit from './components/popup/IndexEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'Index',
  components: {
    SearchForm,
    PopupEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'house.admoldhouselist',
      searchForm: null,
      isDtlShow: false,
      // noCreated: true,
      curObj: {},
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        item.pri_image = this.IMadd(item.pri_image)
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '排序', prop: 'sort', type: 'input', width: 80},
        { label: '楼盘', prop: 'estate_name' },
        { label: '浏览数', prop: 'view_count' },
        { label: '置业经理', prop: 'sale_name' },
        { label: '标题', prop: 'title' },
        { label: '主图', prop: 'pri_image', type: 'img' },
        { label: '详细地址', prop: 'detail_address', fullShow: true, minWidth: 100 },
        { label: '总价', prop: 'price' },
        { label: '面积㎡', prop: 'area' },
        { label: '房源类型', prop: 'house_type', width: 100, fullShow: true, type: 'flag', flags: arrToObj(this.$dictData.house_type) },
        { label: '所属区域', prop: 'area_type', type: 'flag', flags: arrToObj(this.$dictData.area_type) },
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '创建人', prop: 'create_by' },
        { label: '创建时间', prop: 'create_at' },
        { label: '操作', width: 200, type: 'handle2', operations:
          [
            { label: '保存排序', func: this.saveHandle, btnType: 'success' },
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    saveHandle (row) {
      this.$api.house.admoldhousesortedit({
        id: row.id,
        sort: row.sort,
      }).then(data => {
        this.$msgs(`已保存！`)
        this.fetchData()
      })
    },
    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>
