<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"
      :operationsDefaultLength="6"
      :isAdd="true"
      @add="openPopup"
    >
    </table-list>
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/My'
import PopupEdit from './components/popup/IndexEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
    PopupEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'cust.admcustomerlist',
      searchForm: null,
      isDtlShow: false,
      curObj: {},
      isQShow: false,
      isAShow: false,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {})
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '姓名', prop: 'name' },
        { label: '手机号', prop: 'phone' },
        { label: '性别', prop: 'sex', type: 'tag', tags: arrToObj(this.$dictData.sex), tagTypeObj: {'male': 'primary', 'female': 'danger'} },
        { label: '备注', prop: 'demand', fullShow: true, minWidth: 200, align: 'left' },
        { label: '创建时间', prop: 'create_at' },
        { label: '操作', width: 120, type: 'handle2', operations:
          [
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle(row) {
      this.$msg(`您确定要删除该客户吗？`, 'confirm', () => {
        this.$api.cust.admcustomerdel({
          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>
