<template>
  <el-dialog
    append-to-body
    title="出入库单指令"
    :visible.sync="dialogVisible"
    destroy-on-close
    :show-close="false"
    fullscreen
    @close="close"
  >
    <el-row :gutter="20">
      <el-col :span="20" style="border: 1px solid #ffffff">
        <span />
      </el-col>
      <el-col :span="4">
        <span>
          <el-button icon="el-icon-close" size="mini" type="info" @click="dialogVisible = false">关闭</el-button>
        </span>
      </el-col>
    </el-row>
    <div class="crud-opts2">
      <span class="role-span2">出入库明细</span>
    </div>
    <el-card class="box-card" shadow="never" :body-style="{padding:'0'}">
      <!--表格渲染-->
      <el-table
        ref="table"
        :data="tableDtl"
        style="width: 100%;"
        max-height="300"
        border
        :highlight-current-row="true"
        :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
        @current-change="handleDtlCurrentChange"
      >
        <el-table-column show-overflow-tooltip prop="bill_code" label="出库单号" align="center" />
        <el-table-column show-overflow-tooltip prop="seq_no" label="明细序号" align="center" />
        <el-table-column show-overflow-tooltip prop="task_code" label="任务号" align="center" />
        <el-table-column show-overflow-tooltip prop="material_code" label="物料编码" align="center" />
        <el-table-column show-overflow-tooltip prop="material_name" label="物料名称" align="center" />
        <el-table-column show-overflow-tooltip prop="pcsn" label="批次号" align="center" />
        <el-table-column show-overflow-tooltip prop="plan_qty" :formatter="crud.formatNum3" label="重量" align="center" />
        <el-table-column show-overflow-tooltip prop="qty_unit_name" label="单位" align="center" />
        <el-table-column show-overflow-tooltip prop="start_point_code" label="起始位置" align="center" :formatter="start_point_codeFormat" />
        <el-table-column show-overflow-tooltip prop="point_code" label="目的位置" align="center" :formatter="point_codeFormat" />
        <el-table-column prop="work_status" label="任务状态" align="center" width="110px" :formatter="work_statusFormat" />
        <el-table-column show-overflow-tooltip prop="storagevehicle_code" label="载具号" align="center" />
      </el-table>
    </el-card>
    <div class="crud-opts2">
      <span class="role-span">作业明细</span>
    </div>
    <el-card class="box-card" shadow="never" :body-style="{padding:'0'}">
      <!--表格渲染-->
      <el-table
        ref="table2"
        :data="tabledis"
        style="width: 100%;"
        max-height="300"
        border
        :highlight-current-row="true"
        :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
        @current-change="handleDisCurrentChange"
      >
        <el-table-column show-overflow-tooltip prop="material_code" label="物料编码" align="center" />
        <el-table-column show-overflow-tooltip prop="material_name" label="物料名称" align="center" />
        <el-table-column show-overflow-tooltip prop="pcsn" label="批次号" align="center" />
        <el-table-column show-overflow-tooltip prop="storagevehicle_code" label="载具号" align="center" />
        <el-table-column show-overflow-tooltip prop="bucket_num" label="桶数" align="center" />
        <el-table-column show-overflow-tooltip prop="total_storage_qty" :formatter="crud.formatNum3" label="重量" align="center" />
        <el-table-column show-overflow-tooltip prop="start_point_code" label="起始位置" align="center" />
        <el-table-column show-overflow-tooltip prop="next_point_code" label="目的位置" align="center" />
        <el-table-column show-overflow-tooltip prop="task_code" label="任务号" align="center" />
        <el-table-column prop="taskdtl_type" label="任务类型" align="center" width="150px" :formatter="taskdtl_typeFormat" />
        <el-table-column prop="task_status" label="状态" align="center" width="110px" :formatter="task_statusFormat" />
      </el-table>
    </el-card>
  </el-dialog>
</template>

<script>

import { crud } from '@crud/crud'
import checkoutbill from '@/api/wms/st/core/outbill/checkoutbill'

export default {
  name: 'TaskDialog',
  components: { },
  mixins: [crud()],
  dicts: ['work_status', 'task_status', 'io_bill_status', 'SCH_TASK_TYPE_DTL'],
  props: {
    dialogShow: {
      type: Boolean,
      default: false
    },
    rowmst: {
      type: Object
    },
    openArray: {
      type: Array,
      default: () => { return [] }
    }
  },
  data() {
    return {
      dialogVisible: false,
      tableDtl: [],
      mstrow: {},
      tabledis: [],
      currentdtl: null,
      currentDis: {},
      rules: {
      }
    }
  },
  watch: {
    dialogShow: {
      handler(newValue) {
        this.dialogVisible = newValue
      }
    },
    openArray: {
      handler(newValue) {
        this.tableDtl = newValue
      }
    },
    rowmst: {
      handler(newValue) {
        this.mstrow = newValue
      }
    }
  },
  methods: {
    close() {
      this.$emit('update:dialogShow', false)
      this.currentDis = {}
      this.currentdtl = null
      this.tableDtl = []
      this.tabledis = []
      this.$emit('TaskChanged')
    },
    bill_statusFormat(row) {
      return this.dict.label.io_bill_status[row.bill_status]
    },
    taskdtl_typeFormat(row) {
      return this.dict.label.SCH_TASK_TYPE_DTL[row.taskdtl_type]
    },
    task_statusFormat(row) {
      return this.dict.label.task_status[row.task_status]
    },
    work_statusFormat(row) {
      return this.dict.label.work_status[row.work_status]
    },
    start_point_codeFormat(row) {
      if(row.io_type==='1'){
        return row.start_point_code
      }else if(row.io_type==='0'){
        return row.point_code
      }
    },
    point_codeFormat(row) {
      if(row.io_type==='1'){
        return row.point_code
      }else if(row.io_type==='0'){
        return row.start_point_code
      }
    },
    handleDtlCurrentChange(current) {
      if (current !== null) {
        this.tabledis = []
        this.currentdtl = current
        this.queryTableDdis()
      } else {
        this.tabledis = []
        this.currentdtl = {}
      }
    },
    handleDisCurrentChange(current) {
      this.currentDis = current
    },
    queryTableDtl() {
      this.tableDtl = []
      checkoutbill.getOutBillDis({ 'iostorinv_id': this.mstrow.iostorinv_id }).then(res => {
        this.tableDtl = res
      })
    },
    queryTableDdis() {
      if (this.currentdtl !== null) {
        checkoutbill.getOutBillTask({ 'iostorinvdtl_id': this.currentdtl.iostorinvdtl_id }).then(res => {
          this.tabledis = res
        }).catch(() => {
          this.tabledis = []
        })
      }
    }
  }
}
</script>

<style>
.crud-opts2 {
  padding: 0;
  display: -webkit-flex;
  display: flex;
  align-items: center;
}

.crud-opts2 .el-dialog__title2 {
  line-height: 24px;
  font-size:20px;
  color:#303133;
}

.crud-opts2 .role-span2 {
  padding: 0px 0px 20px 0px;
}
.crud-opts2 {
  padding: 10px 0px 0px 50px;
}

</style>
