<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="3"
    >
    </table-list>
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
    <price-edit
      :isShow="isPriceShow"
      :curObj="curObj"
      @close="closePricePopup"
    />
    <help-rule
      :isShow="isHRShow"
      :curObj="curObj"
      @close="closeHRPopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Index'
import PopupEdit from './components/popup/IndexEdit'
import PriceEdit from './components/popup/IndexPriceEdit'
import HelpRule from './components/popup/OneImg'
import baseTable from '_m/baseTable.js'
export default {
  name: 'houseIndex',
  components: {
    SearchForm,
    PopupEdit,
    PriceEdit,
    HelpRule,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'house.admestatelist',
      searchForm: null,
      isDtlShow: false,
      isPriceShow: false,
      curObj: {},
      isHRShow: false,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        item.report_lock = item.report_lock + '天'
        item.lead_lock = item.lead_lock + '天'
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        // { label: '排序', prop: 'sort', type: 'input', width: 80},
        { label: '图片', prop: 'pri_image', type: 'img' },
        { label: '楼盘名称', prop: 'estate_name' },
        { label: '报备保护期', prop: 'report_lock' },
        { label: '带看保护期', prop: 'lead_lock' },
        { label: '所属区域', prop: 'area_type', type: 'flag', flags: arrToObj(this.$dictData.area_type) },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 220, type: 'handle2', operations:
          [
            { label: '编辑信息', func: this.openPopup, btnType: 'primary' },
            { label: '更新佣金', func: this.openPricePopup, btnType: 'success' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
            { label: '楼盘介绍', func: this.linkDesc, btnType: 'success' },
            { label: '一页纸', func: this.openHRPopup, btnType: 'success' },
            { label: '案场人员', func: this.linkGovern, btnType: 'info' },
            { label: '小程序客服', func: this.linkKefu, btnType: 'info' },
            { label: '楼盘管理员', func: this.linkAdmin, btnType: 'info' },
          ]
        }
      ]
    }
  },
  methods: {
    linkDesc (row) {
      this.$router.push(`/house/contentEdit?id=${row.id}`)
    },
    linkKefu (row) {
      this.$router.push(`/house/sale?id=${row.id}&name=${row.estate_name}`)
    },
    linkAdmin (row) {
      this.$router.push(`/house/admin?id=${row.id}&name=${row.estate_name}`)
    },
    linkGovern (row) {
      this.$router.push(`/house/govern?id=${row.id}&name=${row.estate_name}`)
    },
    // saveHandle (row) {
    //   this.$api.house.admestatesortedit({
    //     id: row.id,
    //     sort: row.sort,
    //   }).then(data => {
    //     this.$msgs(`已保存！`)
    //     this.fetchData()
    //   })
    // },
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.house.admestatedel({
          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()
      }
    },
    openPricePopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isPriceShow = true
    },
    closePricePopup(obj) {
      this.isPriceShow = false
      if (obj) {
        this.fetchData()
      }
    },
    
    openHRPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isHRShow = true
    },
    closeHRPopup(obj) {
      this.isHRShow = false
      if (obj) {
        this.fetchData()
      }
    },
    
  }
}
</script>
