<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"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Index'
import baseTable from '_m/baseTable.js'
import xData from './mixin'
export default {
  name: 'index',
  components: {
    SearchForm,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'user.admwechatuserlist',
      searchForm: null,
      isDtlShow: false,
      curObj: {},
      ...xData
    }
  },
  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) + '****'
        }
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '头像', prop: 'avatar', type: 'img' },
        { label: '昵称', prop: 'nickname' },
        { label: '手机号', prop: 'phones' },
        { label: '注册时间', prop: 'create_at' },
        { label: '排序', prop: 'tag', type: 'input', width: 200},
        { label: '操作', width: 100, type: 'handle2', operations:
          [
            { label: '保存标签', func: this.saveHandle, btnType: 'primary' },
          ]
        }
      ]
    }
  },
  methods: {
    saveHandle(row) {
      this.$msg(`您确定要保存标签吗？`, 'confirm', () => {
        this.$api.user.admwechatuseredit({
          id: row.id,
          tag: row.tag,
        }).then(data => {
          this.$msgs(`已添加！`)
          this.fetchData()
        })
      })
    },
  }
}
</script>
