<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"
    />
    <dg-join
      :isShow="isDJShow"
      :curObj="curObj"
      @close="closeDJPopup" />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/DiscountGroup'
import DgJoin from './components/popup/DiscountGroupJoin'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
    DgJoin,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'other.admactivitybuyinglaunchlist',
      searchForm: null,
      isDtlShow: false,
      isPhotoShow: false,
      // noCreated: true,
      curObj: {},
      isTHEShow: false,
      isDJShow: 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: 'avatar', type: 'img' },
        { label: '昵称', prop: 'nickname'},
        { label: '手机号', prop: 'phone' },
        { label: 'hash', prop: 'hash' },
        { label: '发起时间', prop: 'create_at' },
        { label: '操作', width: 120, type: 'handle2', operations:
          [
            { label: '已助力人', func: this.openDJPopup, btnType: 'primary' },
            // { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    openDJPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isDJShow = true
    },
    closeDJPopup(obj) {
      this.isDJShow = false
      if (obj) {
        this.fetchData()
      }
    },
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.house.admestaterecyclepurge({
          id: row.id,
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
  }
}
</script>
