<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="6"
    />
    <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'
import xData from './mixin'
export default {
  name: 'index',
  components: {
    SearchForm,
    PopupEdit,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'school.admschoollist',
      searchForm: null,
      isDtlShow: false,
      curObj: {},
      ...xData
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData,
        // {id: 1, aa: '南师附小', bb: require('@/assets/ex_test.jpg'), eee: '学校的具体地址~',  cc: '华润万象城', gg: '红谷滩区', hh: '华润物业', updateByName: 'liujq', updateTime: '2021-01-13 10:25'},
        // {id: 2, aa: '南师附小', bb: require('@/assets/ex_test.jpg'), eee: '学校的具体地址~',  cc: '华润万象城', gg: '红谷滩区', hh: '华润物业', updateByName: 'liujq', updateTime: '2021-01-13 10:25'},
        // {id: 3, aa: '南师附小', bb: require('@/assets/ex_test.jpg'), eee: '学校的具体地址~',  cc: '华润万象城', gg: '红谷滩区', hh: '华润物业', updateByName: 'liujq', updateTime: '2021-01-13 10:25'},
        // {id: 4, aa: '南师附小', bb: require('@/assets/ex_test.jpg'), eee: '学校的具体地址~',  cc: '华润万象城', gg: '红谷滩区', hh: '华润物业', updateByName: 'liujq', updateTime: '2021-01-13 10:25'},
        // {id: 5, aa: '南师附小', bb: require('@/assets/ex_test.jpg'), eee: '学校的具体地址~',  cc: '华润万象城', gg: '红谷滩区', hh: '华润物业', updateByName: 'liujq', updateTime: '2021-01-13 10:25'},
        // {id: 6, aa: '南师附小', bb: require('@/assets/ex_test.jpg'), eee: '学校的具体地址~',  cc: '华润万象城', gg: '红谷滩区', hh: '华润物业', updateByName: 'liujq', updateTime: '2021-01-13 10:25'},
      ]
      arr.map(item => {
        item.pri_image = this.IMadd(item.pri_image)
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '排序', prop: 'sort', type: 'input', width: 80},
        { label: '学校名称', prop: 'school_name', fullShow: true, minWidth: 200, align: "left" },
        { label: '所属区域', prop: 'area_type', type: 'flag', flags: arrToObj(this.$dictData.area_type) }, 
        { label: '图片', prop: 'pri_image', type: 'img' },
        { label: '学校地址', prop: 'address' },
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 200, type: 'handle2', operations:
          [
            { label: '保存排序', func: this.saveHandle, btnType: 'success' },
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    saveHandle (row) {
      this.$api.school.admschoolsortedit({
        id: row.id,
        sort: row.sort,
      }).then(data => {
        this.$msgs(`已保存！`)
        this.fetchData()
      })
    },
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.school.admschooldel({
          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>
