<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 white">
        <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-span">出入库明细</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 prop="bill_status" label="状态" align="center" width="110px" :formatter="bill_statusFormat" />
        <el-table-column show-overflow-tooltip prop="seq_no" 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" label="重量" :formatter="crud.formatNum3" align="center" />
        <el-table-column show-overflow-tooltip prop="assign_qty" label="已分配重量" :formatter="crud.formatNum3" align="center" />
        <el-table-column show-overflow-tooltip prop="unassign_qty" label="未分配重量" :formatter="crud.formatNum3" align="center" />
        <el-table-column prop="quality_scode" label="品质类型" align="center" width="110px" :formatter="quality_scodeFormat" />
        <el-table-column prop="source_bill_type" label="源单类型" align="center" width="130px" :formatter="invtypeFormat" />
        <el-table-column show-overflow-tooltip prop="source_bill_code" label="源单编号" align="center" />
        <el-table-column show-overflow-tooltip prop="qty_unit_name" 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'}"
      >
        <el-table-column show-overflow-tooltip prop="seq_no" label="明细序号" align="center" />
        <el-table-column  prop="box_no" 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="real_qty" label="出入库重量" :formatter="crud.formatNum3" align="center" />
        <el-table-column show-overflow-tooltip prop="struct_code" label="仓位编码" align="center" />
        <el-table-column show-overflow-tooltip prop="struct_name" label="仓位名称" align="center" />
        <el-table-column show-overflow-tooltip prop="task_code" label="任务号" align="center" />
        <el-table-column show-overflow-tooltip prop="point_code" label="出入库点" align="center" />
      </el-table>
    </el-card>
  </el-dialog>
</template>

<script>
import CRUD, { crud } from '@crud/crud'
import checkoutbill from '@/views/wms/st/outbill/checkoutbill'
export default {
  name: 'DivDialog',
  components: { },
  mixins: [crud()],
  dicts: ['io_bill_status', 'ST_QUALITY_SCODE', 'ST_IVT_LEVEL', 'is_used', 'is_usable'],
  props: {
    dialogShow: {
      type: Boolean,
      default: false
    },
    rowmst: {
      type: Object
    },
    openArray: {
      type: Array,
      default: () => { return [] }
    }
  },
  data() {
    return {
      dialogVisible: false,
      tableDtl: [],
      mstrow: {},
      tabledis: [],
      currentRow: {},
      invtypelist: []
    }
  },
  watch: {
    dialogShow: {
      handler(newValue) {
        this.dialogVisible = newValue
      }
    },
    openArray: {
      handler(newValue) {
        this.tableDtl = newValue
      }
    },
    rowmst: {
      handler(newValue) {
        this.mstrow = newValue
      }
    }
  },
  created() {
  },
  methods: {
    close() {
      this.currentRow = null
      this.tableDtl = []
      this.tabledis = []
      this.$emit('DivChanged')
      this.$emit('update:dialogShow', false)
    },
    bill_statusFormat(row) {
      return this.dict.label.io_bill_status[row.bill_status]
    },
    quality_scodeFormat(row) {
      return this.dict.label.ST_QUALITY_SCODE[row.quality_scode]
    },
    ivt_levelFormat(row) {
      return this.dict.label.ST_IVT_LEVEL[row.ivt_level]
    },
    is_activeFormat(row) {
      return this.dict.label.is_usable[row.is_active]
    },
    invtypeFormat(row) {
      for (const item of this.invtypelist) {
        if (item.code === row.source_bill_type) {
          return item.name
        }
      }
    },
    handleDtlCurrentChange(current) {
      if (current !== null) {
        this.currentRow = current
        this.tabledis = []
        checkoutbill.getOutBillDis({ 'iostorinvdtl_id': current.iostorinvdtl_id }).then(res => {
          this.tabledis = res
        }).catch(() => {
          this.tabledis = []
        })
      } else {
        this.mstrow.iostorinvdtl_id = ''
        this.currentRow = {}
        this.tabledis = []
      }
    },
    queryTableDtl() {
      checkoutbill.getOutBillDtl({ 'iostorinv_id': this.mstrow.iostorinv_id }).then(res => {
        this.tableDtl = res
      })
    },
    getOutBillDisDtl(iostorinvdtl_id) {
      checkoutbill.getOutBillDisDtl({ 'iostorinvdtl_id': 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>
