<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"
      :operationsDefaultLength="3"
    >
    </table-list>
    <popup-edit
      :isShow="isDtlShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Index'
import PopupEdit from './components/popup/IndexEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'shopIndex',
  components: {
    SearchForm,
    PopupEdit
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'shop.admstorelist',
      searchForm: null,
      isDtlShow: false,
      isPriceShow: false,
      curObj: {},
      isHRShow: false,
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        // item.report_lock = item.report_lock + '天'
        // item.lead_lock = item.lead_lock + '天'
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '排序', prop: 'sort'},
        { label: '签约', prop: 'signing', type: 'tag', tags: arrToObj(this.$dictData.sys_yesno), tagTypeObj: {'1': 'success', '2': 'danger'} },
        { label: '门头照片', prop: 'pri_image', type: 'img' },
        { label: '门店名称', prop: 'store_name' },
        { label: '门店品牌', prop: 'store_brand' },
        { label: '所属区域', prop: 'area_type', type: 'flag', flags: arrToObj(this.$dictData.area_type) },
        { label: '店员数量', prop: 'clerk_num' },
        { label: '店长', prop: 'store_manager' },
        { label: '店长电话', prop: 'manager_phone' },
        { label: '分销代码', prop: 'dept_code' },
        { label: '更新时间', prop: 'update_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.shop.admstoredel({
          id: row.id,
          status: 2
        }).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>
