<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"
    />
    <dg-status
      :isShow="isDSShow"
      :curObj="curObj"
      @close="closeDSPopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/DiscountGroup'
import DgJoin from './components/popup/DiscountGroupJoin'
import DgStatus from './components/popup/DiscountGroupStatus'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
    DgJoin,
    DgStatus,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'other.admactivitybuyinglaunchlist',
      searchForm: null,
      isDtlShow: false,
      isPhotoShow: false,
      // noCreated: true,
      curObj: {},
      isTHEShow: false,
      isDJShow: false,
      isDSShow: false,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        if (Number(item.status) !== 2) item.noCan = true
      })
      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: 'status', type: 'tag', tags: arrToObj(this.$dictData.buying_status), tagTypeObj: {'1': 'info', '2': 'success', '3': 'danger'} },
        { label: '手机号', prop: 'phone' },
        { label: 'hash', prop: 'hash' },
        { label: '发起时间', prop: 'create_at' },
        { label: '操作', width: 200, type: 'handle2', operations:
          [
            { label: '已助用户', func: this.openDJPopup, btnType: 'success' },
            { label: '编辑状态', func: this.openDSPopup, btnType: 'primary' },
            // { label: '标记使用', func: this.markUsedHandle, btnType: 'warning', hide: 'noCan' },
          ]
        }
      ]
    }
  },
  methods: {
    openDSPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isDSShow = true
    },
    closeDSPopup(obj) {
      this.isDSShow = false
      if (obj) {
        this.fetchData()
      }
    },
    openDJPopup(row) {
      if (row && row.id) {
        this.curObj = row
      } else {
        this.curObj = {}
      }
      this.isDJShow = true
    },
    closeDJPopup(obj) {
      this.isDJShow = false
      if (obj) {
        this.fetchData()
      }
    },
    markUsedHandle(row) {
      this.$msg(`您确定要将此优惠标记为已使用吗？`, 'confirm', () => {
        this.$api.other.admactivitybuyinglaunchedit({
          id: row.id,
        }).then(data => {
          this.$msgs(`已标记！`)
          this.fetchData()
        })
      }, null, true)
    },
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.house.admestaterecyclepurge({
          id: row.id,
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
  }
}
</script>
