<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <el-input v-model="query.bigItemCode" clearable placeholder="机型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
      <el-input v-model="query.itemCode" clearable placeholder="部品品番" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
      <el-input v-model="query.ns" clearable placeholder="纳所" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
      <el-input v-model="query.bp_type" clearable placeholder="大小物" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
      <AreaSelect :value-key="'id'" v-model="query.rAreaCode"  @change="getChangeAreaValue" :bexb="null"/>
      <PointCodeSelect :value-key="'id'" v-model="query.zPointCodes" :point_type="null"  :multiple=true />
      <el-input v-model="query.zPointCode" clearable placeholder="货位" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
      <rrOperation :crud="crud" />
      <crudOperation :permission="permission" :tableKey="this.$options.name">
          <el-button
                  slot="right"
                  class="filter-item"
                  type="primary"
                  size="mini"
                  @click="saveBomPrintD()"
                  icon="el-icon-document-add"
          >
            中大物标签
          </el-button>
        <el-button
            slot="right"
            class="filter-item"
            type="primary"
            size="mini"
            @click="saveBomPrintX()"
            icon="el-icon-document-add"
        >
          小物标签
        </el-button>
      </crudOperation>
      <!--表格渲染-->
      <el-table id="mytable" ref="table" border :height="crud.tableHeight" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler" >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="序号"  width="60" />
        <el-table-column prop="nsv" label="纳所"/>
        <el-table-column prop="code" label="部品品番" width="100"/>
        <el-table-column prop="pm" label="品名" width="150"/>
        <el-table-column prop="bonded" label="税别"/>
        <el-table-column prop="hw" label="货位" />
        <el-table-column prop="xz" label="箱种"/>
        <el-table-column prop="srs" label="收容数"/>
        <el-table-column prop="dxw" label="大小物"/>
        <el-table-column prop="supplier" label="供应商" width="120" :show-overflow-tooltip="true"/>
        <el-table-column prop="jx" label="机型"/>
        <el-table-column prop="tyl" label="台用量"/>
      </el-table>
      <!--分页组件-->
      <div style="position:absolute;right: 0">
      <pagination />
      </div>
    </div>
  </div>
</template>

<script>
import {exportExcel} from '@/components/TableToExcel/ExportExcel'
import {initData} from '@/api/data'
import crudBomAccount ,{queryBomPrintListD,queryBomPrintListX}from '@/api/bomAccount'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import bigItem from '@/api/bigItem'
import { getItemsList } from '@/api/item'
import DateRangePicker from "@/components/DateRangePicker/index.vue";
import { getAreas, queryAreaList } from '@/api/area'
import { getToken } from '@/utils/auth'
import DonMessage from '@/utils/message'
import Link from "@/layout/components/Sidebar/Link.vue";
import excelUtil from "@/api/tools/excelUtil"
import { formatDate } from '@/utils/commonUtils'
import {mapGetters} from "vuex";
import AreaSelect from "@/views/generic-component/AreaSelect.vue";
import PointSelect from "@/views/generic-component/PointSelect.vue";
import PointCodeSelect from "@/views/generic-component/PointCodeSelect.vue";
const defaultForm = { id: null, bigItem: null, supplier: null,item: null, contents: null, singles: null, rArea: null, cArea: null, outType: null, station_type: null, bp_type: null,  dept: null, enabled: null, createBy: null, updateBy: null, createTime: null, updateTime: null, description: null, ac: null, bonded: null, zPoint: { code: null }}
export default {
  name: 'BomAccountBq',
  components: {
    PointCodeSelect,
    PointSelect, AreaSelect, Link, DateRangePicker, pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['process_content', 'out_type', 'station_type', 'bp_type','bonded_type','ac_type','zdw_type'],
  cruds() {
    return CRUD({ title: 'BOM工位清单', url: 'api/bomAccount/queryBomPrintList', idField: 'id', sort: 'id,desc', crudMethod: { ...crudBomAccount },
      optShow: {
        add: false,
        edit: false,
        del: false,
        reset: true,
        download: false
      },
    })
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ])
  },
  data() {
    return {
      headers: { 'Authorization': getToken() },
      fileList: [],
      // 下拉框
      bigItemList: [],
      itemList: [],
      rAreaList: [],
      cAreaList: [],
      excelQueryParam: {
        excelConfigId: '912967151437389824',
        queryParam: {
          pageNo: 1,
          bomAccount__完成品番: null,
          bomAccount__完成品形式名: null,
          bomAccount__工位: null,
          bomAccount__部品品番: null,
          currentPageNo: 1,
          currentPageSize: 10,
          pageSize: 10
        }
      },}
  },
  mounted() {
    this.getBigItemList()
    this.getItemList()
    this.getRAreaList()
    this.getCAreaList()
    //计算界面高度

  },
  methods: {

    downingthisExcel() {
      this.crud.loading=true
      initData(this.crud.url,this.crud.getQueryParams2()).then(data => {
        this.crud.data=data.content
        setTimeout(() => {
          this.crud.loading=false
          exportExcel(this.$xlsx, this.$fileSaver,"Bom清单","mytable")
        }, 500)

      })
    },

    handleErr(err, file, fileList) {

      let myError = err.toString();//转字符串
      myError = myError.replace("Error: ", "") // 去掉前面的" Error: "
      myError = JSON.parse(myError);//转对象
      DonMessage.error("" + myError['message'])
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    getBigItemList() {
      bigItem.getBigItem(1).then(res => {
        this.bigItemList = res.map(function(obj) {
          if (obj.hasChildren) {
            obj.children = null
          }
          return obj
        })
      })
    },
    getRAreaList() {
      queryAreaList({enabled:true}).then(res=>{
        this.rAreaList = res
      })
      // getAreas().then(res => {
      //   this.rAreaList = res.map(function(obj) {
      //     if (obj.hasChildren) {
      //       obj.children = null
      //     }
      //     return obj
      //   })
      // })
    },
    getCAreaList() {
      queryAreaList({bexb:false,enabled:true}).then(res=>{
        this.cAreaList = res
      })
    },
    getItemList() {
      getItemsList().then(res => {
        this.itemList = res.map(function(obj) {
          if (obj.hasChildren) {
            obj.children = null
          }
          return obj
        })
      })
    },
    getChangeAreaValue(dben) {
      this.query.rAreaCode = dben.code;
    },
    saveBomPrintD() {
      console.log("打印中大物标签")
        queryBomPrintListD(this.crud.getQueryParams2()).then(res => {
            this.showEwmReportD();
        })
    },
    saveBomPrintX() {
      console.log("打印小物标签")
      queryBomPrintListX(this.crud.getQueryParams2()).then(res => {
        this.showEwmReportX();
      })
    },
      showEwmReportD(){
          this.$router.push({path:'/base-data/base-ware/point_print_d',query:{tableID: '打印中大物标签'}})
      },
      showEwmReportX(){
        this.$router.push({path:'/base-data/base-ware/point_print_x',query:{tableID: '打印小物标签'}})
      },
    //日期格式化
    getFormatDate(data){
      return  formatDate(data);
    },
    handleSuccess(response, file, fileList) {
      this.crud.notify('上传成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
      this.$refs.upload.clearFiles()
      this.crud.status.add = CRUD.STATUS.NORMAL
      this.crud.resetForm()
      this.crud.toQuery()
    },
    // 监听上传失败
    handleError(e, file, fileList) {
      const msg = JSON.parse(e.message)
      this.$notify({
        title: msg.message,
        type: 'error',
        duration: 2500
      })
      this.loading = false
    }
  }
}
</script>

<style scoped>

</style>
