<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="5"
    />
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/ClickRecord'
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.admcontactclicklist',
      searchForm: null,
      isDtlShow: false,
      // noCreated: true,
      curObj: {},
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {})
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '咨询客户', prop: 'nickname' },
        { label: '客户头像', prop: 'avatar', type: 'img' },
        { label: '点击类型', prop: 'click_type', type: 'flag', flags: arrToObj(this.$dictData.contact_click_type) },
        // { label: '目标类型', prop: 'target_type', type: 'flag', flags: arrToObj(this.$dictData.contact_target_type) },
        { label: '联系ID', prop: 'target_id', },
        { label: '置业经理', prop: 'sale_name' },
        { label: '置业经理头像', prop: 'sale_avatar', type: 'img' },
        { label: '创建时间', prop: 'create_at' },
        { label: '操作', width: 120, type: 'handle2', operations:
          [
            { label: '查看咨询房源', func: this.openPopup, btnType: 'primary' },
          ]
        }
      ]
    }
  },
  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) {
      this.curObj = {
        id: row.target_id
      }
      this.isDtlShow = true
    },
    closePopup(obj) {
      this.isDtlShow = false
      if (obj) {
        this.fetchData()
      }
    }
  }
}
</script>
