<template>
  <div class="app-container">
    <search-form
      :list-loading="listLoading"
      @change="searchHandle"
    />
    <table-list
      :list-loading="listLoading"
      :data="tableData"
      :columns="listConfig"
      :current-page="currentPage"
      :page-size="pageSize"
      :total-records="totalRecords"
      @currentChange="pageHandle"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/AppClickLog'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'user.admwechatuserclicklist',
      searchForm: {},
      noCreated: true,
      isDtlShow: false,
      curObj: {},
      estateArr: [],
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        const fpUser = window.sessionStorage.getItem('fp_user') ? JSON.parse(window.sessionStorage.getItem('fp_user')) : {}
        if (fpUser.username === 'admin') {
          item.phones = item.phone
        } else {
          item.phones = item.phone.substring(0, 7) + '****'
        }
        item.params = this.decodeUnicode(item.params)
      })
      return arr
    }
  },
  created() {
    let estateArr = this.$storage('fp_estate_all')
    if (estateArr) {
      this.estateArr = JSON.parse(estateArr)
    } else {
      this.$api.base.admtargetname({type: 'estate'}).then(res => {
        this.estateArr = res || []
        this.$storage('fp_estate_all', JSON.stringify(res))
      })
    }
    this.searchForm = {
      path: '/pagesHouse/indexDtl'
    }
    this.fetchData()
  },
  mounted() {
    this.listConfig = {
      rows: [
        { label: '菜单点击路径', prop: 'path', type: 'flag', flags: arrToObj(this.$dictData.app_pages) },
        { label: '名称', prop: 'esName' },
        { label: '点击时间', prop: 'c_time' },
        { label: '头像', prop: 'avatar', type: 'img' },
        { label: '昵称', prop: 'nickname' },
        { label: '手机号', prop: 'phones' },
        { label: 'ip地址', prop: 'remote_ip' },
        { label: '参数', prop: 'params', fullShow: true },
        { label: '统计时间', prop: 'create_at' },
        // { label: '操作', width: 220, type: 'handle2', operations:
        //   [
        //     { label: '删除', func: this.delHandle, btnType: 'danger' },
        //   ]
        // }
      ]
    }
  },
  methods: {
    getMoreData () {
      let arr = [...this.tableData]
      arr.map(item => {
        const fpUser = window.sessionStorage.getItem('fp_user') ? JSON.parse(window.sessionStorage.getItem('fp_user')) : {}
        if (fpUser.username === 'admin') {
          item.phones = item.phone
        } else {
          item.phones = item.phone.substring(0, 7) + '****'
        }
        item.params = this.decodeUnicode(item.params)
        if (item.params.length > 0) {
          const pObj = JSON.parse(item.params)
          if(item.path === '/pagesHouse/indexDtl') {
            if (pObj.fromViews === 'search') {
              item.esName = `(搜索)${arrToObj(this.estateArr)[pObj.id]}`
            } else {
              item.esName = arrToObj(this.estateArr)[pObj.id]
            }
          }
        }
      })
      this.tableData = [...arr]
    },
    decodeUnicode (str) { 
      return unescape(str.replace(/\\/g, "%"))
    },
    delHandle (row) {
      this.$msg(`您确定要删除该用户吗？`, 'confirm', () => {
        this.$api.user.admwechatuserpurge({
          id: row.id,
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      })
    },
  }
}
</script>
