<!--
 * @Descripttion:
 * @version:
 * @Author: fzq
 * @Date: 2022-03-04 20:54:54
 * @LastEditors: fzq
 * @LastEditTime: 2022-03-06 19:32:34
-->
<template>
  <div class="app-container">
    <head-form
      :placeholder-name="placeholderName"
      :key-name="keyName"
      :show-add="false"
      @getDataList="getList"
      @downl="downl"
    />
    <base-table
      :page="listQuery.current"
      :limit="listQuery.size"
      :table-config="tableProps"
      :table-data="list"
      :is-loading="listLoading"
    >
      <!-- <method-btn
        slot="handleBtn"
        :width="trueWidth"
        :method-list="tableBtn"
        @clickBtn="handleClick"
      /> -->
    </base-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getList()"
    />
    <!-- <storageBox-add v-if="addOrUpdateVisible" ref="addOrUpdate" :cache-id="listQuery.cacheId" @refreshDataList="getList" /> -->
  </div>
</template>

<script>import i18n from '@/lang'
import HeadForm from './components/HeadForm'
import BaseTable from '@/components/BaseTable'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { list, download } from '@/api/report-manage/report'
import substrateBtn from './components/substrateBtn.vue'
/**
 * 表格表头配置项 TypeScript接口注释
 * tableConfig<ConfigItem> = []
 *
 * Interface ConfigItem = {
 *  prop: string,
 *  label: string,
 *  width: string,
 *  align: string,
 *  subcomponent: function,
 *  filter: function
 * }
 *
 *
 */

const tableBtn = [
  {
    type: 'edit',
    btnName: 'btn.edit'
  },
  {
    type: 'delete',
    btnName: 'btn.delete'
  }
]
const tableProps = [
  {
    prop: 'code',
    label: i18n.t('module.report.inventory.code'),
    align: 'center'
  },
  {
    prop: 'status',
    label: i18n.t('module.report.inventory.status'),
    align: 'center'
  },
  {
    prop: 'inprocessCode',
    label: i18n.t('module.report.inventory.inprocessCode'),
    align: 'center'
  },
  {
    prop: 'nextprocessCode',
    label: i18n.t('module.report.inventory.nextprocessCode'),
    align: 'center'
  },
  {
    prop: 'currentLocation',
    label: i18n.t('module.report.inventory.currentLocation'),
    align: 'center'
  },
  {
    prop: 'storeTime',
    label: i18n.t('module.report.inventory.storeTime'),
    align: 'center'
  },
  {
    prop: 'orderName',
    label: i18n.t('module.report.inventory.orderName'),
    align: 'center'
  },
  {
    prop: 'substrateDetails',
    label: i18n.t('module.report.inventory.substrateDetails'),
    subcomponent: substrateBtn,
    align: 'center'
  }
]

export default {
  name: 'Inventory',
  components: { Pagination, BaseTable, HeadForm },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      addOrUpdateVisible: false,
      keyName: i18n.t('module.report.reportList.storageBoxNumber'),
      placeholderName: this.$t('module.report.reportList.queryFiltering'),
      tableBtn,
      trueWidth: 200,
      tableProps,
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        current: 1,
        size: 10,
        enabled: 1
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // handleClick(raw) {
    //   if (raw.type === 'delete') {
    //     this.$confirm(`${this.$t('module.basicData.visual.TipsBefore')}[${raw.data.storageBoxName}]?`, this.$t('module.basicData.visual.Tips'), {
    //       confirmButtonText: this.$t('module.basicData.visual.confirmButtonText'),
    //       cancelButtonText: this.$t('module.basicData.visual.cancelButtonText'),
    //       type: 'warning'
    //     }).then(() => {
    //       storageBoxDelete(raw.data.id).then(response => {
    //         this.$message({
    //           message: this.$t('module.basicData.visual.success'),
    //           type: 'success',
    //           duration: 1500,
    //           onClose: () => {
    //             this.getList()
    //           }
    //         })
    //       })
    //     }).catch(() => {})
    //   } else if (raw.type === 'edit') {
    //     this.addNew(raw.data.id)
    //   } else {
    //     this.addNew(raw.data.id, true)
    //   }
    // },
    getList(key) {
      this.listLoading = true
      this.listQuery.code = key
      // console.log(this.listQuery)
      list(this.listQuery).then(response => {
        console.log(response)
        if (response.data) {
          this.list = response.data
        } else {
          this.list.splice(0, this.list.length)
        }
        // this.total = response.data.total
        this.listLoading = false
      })
    },
    downl(key) {
      this.listLoading = true
      this.listQuery.code = key
      // console.log(this.listQuery)
      download(this.listQuery).then(res => {
        console.log(res)
        // const fileName = `${+new Date()}.xlsx`
        // const blob = new Blob([res], { type: 'application/vnd.ms-excel;charset=utf-8' })
        // if (navigator.msSaveBlob) {
        //   navigator.msSaveBlob(blob, fileName)
        // } else {
        //   const link = document.createElement('a')
        //   link.href = URL.createObjectURL(blob)
        //   link.download = fileName
        //   link.click()
        //   URL.revokeObjectURL(link.href)
        // }
      })
    }
    // 新增 / 修改
    // addNew(id) {
    //   this.addOrUpdateVisible = true
    //   this.$nextTick(() => {
    //     this.$refs.addOrUpdate.init(id, true)
    //   })
    // }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
