<template>
  <el-dialog
    title="详情"
    :visible.sync="open"
    width="80%"
    :close-on-click-modal="false"
    @close="handleClose"
  >
    <div class="formContent" v-if="reload">
      <Com-table
        ref="table"
        :tableFormat="tableFormat"
        :tableData="tableData"
      ></Com-table>
    </div>
    <span slot="footer">
      <el-button @click="open = false">关 闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { queryOrgMaterialInfo, queryMaterialRationInfo } from "@/api/home";
export default {
  data() {
    return {
      open: false,
      tableFormat: [],
      tableData: [],
      currentRow: {},
      reload: true,
    };
  },
  methods: {
    handleInit({ data, tableFormat, type }) {
      this.reload = false;
      this.$nextTick(() => {
        this.reload = true;
      });
      this.tableFormat = [];
      this.tableData = [];
      this.tableFormat = tableFormat;
      this.currentRow = data;
      this.open = true;
      if (type === "commodityStockNum") {
        this.getData();
      } else {
        this.updateQuotValue();
      }
    },
    updateQuotValue() {
      let obj = {
        id: this.currentRow.id,
      };
      queryMaterialRationInfo(obj).then((res) => {
        if (res && res.code == 200) {
          this.tableData = res.data || [];
        }
      });
    },
    getData() {
      let obj = {
        orgNo: this.currentRow.orgNo,
        mtrlDes: this.currentRow.mtrlDes,
        mtrlNo: this.currentRow.mtrlNo,
      };
      queryOrgMaterialInfo(obj).then((res) => {
        if (res && res.code == 200) {
          this.tableData = res.data || [];
        }
      });
    },
    handleClose() {
      this.open = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.formContent {
  height: 500px;
}
::v-deep {
  .el-dialog__footer {
    text-align: center;
  }
}
</style>
