<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"
    />
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/AppSale'
import PopupEdit from './components/popup/AppSaleEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
    PopupEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'user.admsaleuserlist',
      searchForm: null,
      isDtlShow: false,
      curObj: {},
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '置业经理', prop: 'sale_name' },
        { label: '头像', prop: 'sale_avatar', type: 'img' },
        { label: '联系电话', prop: 'sale_phone' },
        { label: '销售标签', prop: 'custom_tag'},
        { label: '微信昵称', prop: 'nickname'},
        { label: '微信头像', prop: 'avatar', type: 'img' },
        { label: '微信电话', prop: 'phone' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 200, type: 'handle2', operations:
          [
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle(row) {
      this.$msg(`您确定要删除该规则吗？`, 'confirm', () => {
        this.$api.user.admsaleuserdel({
          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()
      }
    }
  }
}
</script>
