<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"
    />
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
    <cur-qrcode
      :isShow="isQrcodeShow"
      :curObj="curObj"
      @close="closeQrcodePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Index'
import PopupEdit from './components/popup/IndexEdit'
import CurQrcode from './components/popup/Qrcode'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
    PopupEdit,
    CurQrcode,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      isQrcodeShow: false,
      apiStr: 'other.admactivitylist',
      searchForm: null,
      isDtlShow: false,
      curObj: {},
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData,]
      arr.map(item => {})
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '楼盘名称', prop: 'estate_name' },
        { label: '活动内容', prop: 'remark' }, 
        { label: '分类', prop: 'activity_type', type: 'flag', flags: arrToObj(this.$dictData.activity_type	) },
        { label: '图片', prop: 'image', type: 'img' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 200, type: 'handle2', operations:
          [
            { label: '统计', func: this.linkDtl, btnType: 'success' },
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '二维码', func: this.openQrcodePopup, btnType: 'info' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    linkDtl (row) {
      this.$router.push(`/activity/dtl?name=${row.estate_name}${row.remark}&id=${row.id}&t=${row.activity_type}`)
    },
    delHandle(row) {
      this.$msg(`您确定要删除该活动吗？`, 'confirm', () => {
        this.$api.other.admactivitydel({
          id: row.id,
        }).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() 
      }
    },
    openQrcodePopup(row) {
      if (row && row.code) {
        this.curObj = row
        this.isQrcodeShow = true
      } else {
        this.$msg('未找到二维码')
      }
    },
    closeQrcodePopup(obj) {
      this.isQrcodeShow = false
      if (obj) {
        this.fetchData() 
      }
    }
  }
}
</script>
