<template>
  <el-dialog :visible.sync="visible" title="选择资产编号" width="70%">
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      stripe
      @selection-change="handleSelection"
      :header-cell-style="{ background: '#EEEEEE', border: 'none' }"
    >
      <el-table-column label="" type="selection" width="50"> </el-table-column>
      <el-table-column label="序号" type="index" width="50"> </el-table-column>
      <el-table-column label="原料编码" prop="onlyCode"></el-table-column>
      <el-table-column label="包装编码" prop="num"></el-table-column>
      <el-table-column label="批次号" prop="batchNum"></el-table-column>
      <el-table-column label="物品编码" prop="assetCode"></el-table-column>
      <el-table-column label="名称" prop="assetName"></el-table-column>
      <el-table-column label="最小包装单元" align="center" prop="modelType">
        <template slot-scope="{ row, $index }">
          {{ row.measurementUnit }}{{ row.unit }} /{{ row.minPackUnit }}
        </template>
      </el-table-column>
      <el-table-column
        label="生产日期"
        prop="manufactureTime"
        width="200"
      ></el-table-column>
      <el-table-column label="采购日期" prop="procurementTime" width="200">
      </el-table-column>
    </el-table>

    <div slot="footer">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="confirm">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
  // import { getAssetLedgerDetail } from '@/api/stockManagement'
  export default {
    props: {
      tableHeader: {
        type: Array,
        default: () => []
      }
    },
    data() {
      return {
        visible: false,
        tableData: [],
        selectList: [],
        callback: null
      };
    },

    methods: {
      open(row, callback) {
        this.visible = true;
        this.callback = callback;
        this._getAssetLedgerDetail(row);
      },
      confirm() {
        if (!this.selectList?.length) {
          return this.$message.error('选择资产编号');
        }
        this.callback && this.callback(this.selectList);
        this.cancel();
      },
      cancel() {
        this.selectList = [];
        this.visible = false;
      },
      handleSelection(val) {
        this.selectList = val;
      },
      async _getAssetLedgerDetail({
        assetCode,
        assetType,
        measurementUnit,
        minPackUnit,
        unit
      }) {
        this.tableData = [];
        const res = await getAssetLedgerDetail({
          assetCode,
          assetType,
          measurementUnit,
          minPackUnit,
          unit
        });
        if (res?.success) {
          this.tableData = res.data;
        }
      }
    }
  };
</script>
