<template>
  <div>
    <m-filter :option="filter" @search="handleSearch" />
    <m-table
      class="mt-3"
      :loading="loading"
      :headers="headers"
      :items="items"
      :total="total"
      :show-select="false"
      :is-tools="false"
      :page-info="pageInfo"
      @pageHandleChange="pageHandleChange"
      @sort="handleSort"
    >
      <template #navBtn>
        <!-- <v-btn class="buttons mr-3" rounded elevation="5" color="primary" @click="handleTake" :loading="takeLoading">
          <v-icon left>mdi-camera</v-icon>
          拍照
        </v-btn> -->
        <UploadBtn
          class="buttons"
          rounded
          elevation="5"
          color="primary"
          accept="image/*"
          @change="handleImport"
        >
          <v-icon left>mdi-import</v-icon>
          导入
        </UploadBtn>
      </template>
    </m-table>
    <m-camera ref="camera" @rendered="takeLoading  = false"></m-camera>
  </div>
</template>

<script>
import UploadBtn from '@/components/UploadBtn'
import MFilter from '@/components/Filter'
import MTable from '@/components/List/table.vue'
import MCamera from '../components/MCamera'
export default {
  name: 'image-import',
  components: { MFilter, MTable, MCamera, UploadBtn },
  data () {
    return {
      takeLoading: false,
      loading: false,
      show: false,
      filter: {
        list: [
          { type: 'textField', value: '', label: '名称', key: 'name' },
          { type: 'autocomplete', value: null, label: '选择', key: 'type', items: [] }
        ]
      },
      queryData: {
        name: null
      },
      headers: [
        { text: '标题', align: 'start', value: 'title' },
        { text: '姓名', align: 'start', value: 'name' },
        { text: '来源', align: 'start', value: 'source' },
        { text: '创建日期', align: 'start', value: 'createDate' },
        { text: '操作', align: 'start', value: 'actions' }
      ],
      itemData: {},
      items: [],
      orders: [],
      pageInfo: {
        size: 10,
        current: 1
      },
      total: 0
    }
  },
  created () {
    this.init()
  },
  methods: {
    async init () {},
    handleSearch (val) {
      Object.assign(this.queryData, val)
      this.pageInfo.current = 1
      this.init()
    },
    handleImport () {
      this.itemData = {}
    },
    handleTake () {
      this.takeLoading = true
      this.$refs.camera.open()
    },
    async handleEdit (item) {
      this.itemData = item
    },
    handleDelete (ids) {
      if (Array.isArray(ids) && !ids.length) return this.$snackbar.warning('请选择要删除的选项')
      this.$confirm('提示', '是否删除该选项')
        .then(async () => {
          try {
            this.$snackbar.success('删除成功')
            this.init()
          } catch (error) {
            this.$snackbar.error('删除失败')
          }
        })
    },
    handleSubmit () {},
    pageHandleChange (page) {
      this.pageInfo.current = page
      this.init()
    },
    handleSort (val) {
      this.orders = val
      this.init()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
