<template>
  <el-dialog :visible.sync="dialog" :before-close="handleClose" append-to-body title="拣货确认-箱单库存记录" width="88%" top="20px">
    <!-- 搜索 -->
    <div class="head-container">
      <!-- 导出 -->
      <div style="display: inline-block;">
       <!-- <el-button
          :loading="downloadLoading"
          size="mini"
          class="filter-item"
          type="warning"
          icon="el-icon-download"
          @click="downloadMethod"
        >导出
        </el-button>
        <el-button
          :loading="downloadLoading"
          size="mini"
          class="filter-item"
          type="primary"
          icon="el-icon-potato-strips"
          @click="pickBarBack"
        >整单退拣
        </el-button>
        -->
        <el-button
          slot="right"
          class="filter-item"
          type="primary"
          size="mini"
          @click="xdckPickOut(tsakSelectData)"
        >
          拣货确认
        </el-button>



      </div>
    </div>
    <!--表格渲染-->
    <el-table :data="data" :height="dialogTableHight+'px'" :max-height="dialogTableHight+'px'" style="width: 100%;height:100%;margin-top: 10px;" border @selection-change="taskSelection">
      <el-table-column type="selection" width="55"/>
      <el-table-column type="index" :index="indexMethod" label="序号"/>
      <el-table-column prop="itemCode" label="物料编码"/>
      <el-table-column  prop="itemName" label="物料名称"/>
      <el-table-column prop="stockCode" label="箱单号"/>
      <el-table-column prop="bonded" label="税别"/>
      <el-table-column prop="pointCode" label="货位"/>
      <el-table-column prop="planQty" label="订单数量"/>
      <el-table-column prop="invQty" label="库存数量"/>
      <el-table-column prop="pickQty" label="出库数量"/>
    </el-table>
    <el-dialog :visible.sync="errorDialog" append-to-body title="异常详情" width="85%">
      <pre>{{ errorInfo }}</pre>
    </el-dialog>
    <!--分页组件-->
    <el-pagination
      :total="total"
      :current-page="page + 1"
      :page-size="6"
      style="margin-top:8px;"
      layout="total, prev, pager, next"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
  </el-dialog>
</template>

<script>
import crud from '@/mixins/crud'
import DateRangePicker from '@/components/DateRangePicker/index.vue'
import {queryPickTask} from "@/api/task";
import crudPickDetail from "@/api/pickDetail";
import DonMessage from "@/utils/message";
import CRUD from '@crud/crud'
import {pickBatch, pickWhole,xdckPickOut} from "@/api/pickTicket";
import {queryPickDetailXd} from "@/api/inventory";

export default {
  components: {DateRangePicker},
  mixins: [crud],
  dicts: ['task_status'],

  data() {

    return {
      pickDetailId: 0,
      title: '任务日志',
      errorInfo: '', errorDialog: false,
      enabledTypeOptions: [
        {key: 'true', display_name: '成功'},
        {key: 'false', display_name: '失败'}
      ],
      tsakSelectData: [],
      dialogTableHight: 0
    }
  },
  methods: {
    queryPickDetailXd(id) {
      queryPickDetailXd(id).then(res => {
        this.data = res;

        this.loading = false;
        this.pickDetailId = id;
        return true;
      })
    },
    taskSelection(data) {
      this.tsakSelectData = data
    },
    indexMethod(index) {
      return index * 1 + 1;
    },
    //整单拣货
    singlePick() {
      crudPickDetail.picking(this.pickDetailId).then(res => {
          this.$message.success(res)
          this.queryPickTask(this.pickDetailId)
        })
    },

    //拣货确认
    xdckPickOut(data) {
      if (this.tsakSelectData.length > 0) {
        let data_ = {invId: null, detailId: null}
        data_.invId = data[0].invId
        data_.detailId = this.pickDetailId
        xdckPickOut(data_).then(res => {
          this.$message.success(res)
          this.queryPickTask(this.pickDetailId)
        })
      }
    },
    handleClose(done) {
      done();
      this.$parent.shuaxin();//刷新父组件查询方法
    }
  }
}
</script>

<style scoped>
.java.hljs {
  color: #444;
  background: #ffffff !important;
}

::v-deep .el-dialog__body {
  padding: 0 20px 10px 20px !important;
}
</style>
