<template>
  <div>
    <el-table v-loading="loading" :data="detailList" style="width: 100%" border
              :row-style="rowStyle"
              row-key="id"
    >
      <el-table-column label="序号" type="index"></el-table-column>
      <el-table-column
        label="物资名称" width="150"
        prop="coName"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="规格型号" width="150"
        prop="spec"
      ></el-table-column>
      <el-table-column label="批次号" header-align="center">
        <el-table-column header-align="center"
                         label="手录" width="100"
                         prop="bbatchNo"
                         show-overflow-tooltip
        ></el-table-column>
        <el-table-column header-align="center"
                         label="扫码"
                         prop="sbatchNo" width="100"
                         show-overflow-tooltip
        ></el-table-column>
      </el-table-column>

      <el-table-column label="生产日期" header-align="center">
        <el-table-column header-align="center"
                         label="手录" width="100"
                         prop="bproductDate"
                         show-overflow-tooltip
        ></el-table-column>
        <el-table-column header-align="center"
                         label="扫码" width="100"
                         prop="sproductDate"
                         show-overflow-tooltip
        ></el-table-column>
      </el-table-column>

      <el-table-column label="失效日期" header-align="center">
        <el-table-column header-align="center"
                         label="手录" width="100"
                         prop="bexpireDate"
                         show-overflow-tooltip
        ></el-table-column>
        <el-table-column header-align="center"
                         label="扫码" width="100"
                         prop="sexpireDate"
                         show-overflow-tooltip
        ></el-table-column>
      </el-table-column>
      <el-table-column label="数量" header-align="center">
        <el-table-column
          header-align="center"
          label="单据数量" width="100"
          prop="count"
        ></el-table-column>
        <el-table-column
          header-align="center"
          label="扫码数量" width="100"
          prop="scanCount"
        ></el-table-column>
      </el-table-column>

      <el-table-column
        label="价格"
        prop="price" width="100"
      ></el-table-column>
      <el-table-column width="100" label="计量单位" prop="measname">
      </el-table-column>
      <el-table-column
        label="生产企业"
        prop="manufacturer" width="160"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        label="注册/备案号" width="160"
        prop="certCode"
        show-overflow-tooltip
      ></el-table-column>
    </el-table>
  </div>
</template>

<script>
import stockOrderNewSelectProduct from "./DialogSelectProduct";
import dialogInvProduct from "./DialogSelectInvProduct";
import {addBizProduct, getDetailBizs, updateBizProduct, delBizProduct} from "@/api/inout/orderDetailCode";
import {updateBizBind} from "@/api/inout/order";
import selectRlDialog from "@/views/inout/DialogSelectRl";
import DialogSelectUnit from "@/views/inout/DialogSelectUnit";
import {getCheckDetailList} from "@/api/inout/orderDetailBiz";

export default {
  name: "PanelCreateOrderCheckDetail",
  props: {
    idQuery: {
      type: Object,
      required: true,
    },
    refreshPanel: {
      type: Function,
      required: true,
    },
    refreshOrder: {
      type: Function,
      required: true,
    },
    viewType: {
      type: Object,
      required: true,
    },
    curBustype: {
      type: Object,
      required: true,
    },

  },
  data() {
    return {
      bizType: 1,
      loading: false,
      query: {
        orderId: null,
        code: "",
        corpOrderId: "",
      },
      detailList: [],
      total: 0,
      iCount: 0,
      selectProductVisible: false,
      selectInvProductVisible: false,
      thisData: {},
      selectedIndex: null,
      invQueryData: {
        invCode: null,
      },
      selectRlVisible: false,
      dialogTableVisible: false,
      curRow: null,
    };
  },
  components: {
    selectRlDialog, DialogSelectUnit,
    stockOrderNewSelectProduct,
    dialogInvProduct,
  },
  methods: {
    getOrderDetails() {
      this.loading = true;
      this.query.orderIdFk = this.idQuery.billNo;
      getCheckDetailList(this.query) //查找该单号下的所有条码
        .then((response) => {
          this.detailList = response.data || [];
          this.total = response.data || 0;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
          this.detailList = [];
          this.total = 0;
        });
    },

    rowChange(val) {
      this.currentRow = val;
      if (this.currentRow.batchNo == '')
        this.currentRow.batchNo = null;
      this.selectedIndex = val.index;
    },

    closeDialog(rData) {
      this.selectProductVisible = false;
      this.selectInvProductVisible = false;
      this.idQuery = rData;
      this.getOrderDetails();
    },

    closeDialogC2(rData) {
      this.idQuery = rData;
      this.selectInvProductVisible = false;
      this.getOrderDetails();
    },

    rowStyle({row, rowIndex}) {
      let rowBackground = {};
      if (!this.$isNotBlank(row.supId) || !this.$isNotBlank(row.bindRlFk)) {
        rowBackground.color = '#f60303';
        return rowBackground;
      }

      if (this.viewType == 1)
        return null;

      if (!row.checkSuccess) {
        rowBackground.color = '#f60303';
      }
      if (row.count != row.scanCount) {
        rowBackground.color = '#f60303';
      }
      return rowBackground;
    },

    tableRowClassName({row, rowIndex}) {
      row.index = rowIndex;
    },

    selectProductFunction() {
      this.thisData = this.idQuery;
      if (this.$isBlank(this.idQuery.action)) {
        this.$message.error("单据类型不能为空！")
        return;
      }
      if (this.$isBlank(this.idQuery.invCode)) {
        this.$message.error("当前仓库不能为空！");
        return;
      }

      if (this.$isBlank(this.idQuery.fromCorp) && this.$isBlank(this.idQuery.fromInvCode)) {
        this.$message.error("往来信息不能为空！");
        return;
      }
      if (this.curBustype.corpType == 3) {//内部科室
        this.invQueryData.invCode = this.idQuery.invCode;
        this.selectInvProductVisible = true;
      } else if (this.curBustype.corpType == 2) { //供应商信息
        this.selectProductVisible = true;
      } else if (this.curBustype.corpType === 1) {//客户信息
        this.invQueryData.invCode = this.idQuery.invCode;
        this.selectInvProductVisible = true;
      }

    },

    saveChange(row) {
      if (row.batchNo == '') {
        row.batchNo = null;
      }
      updateBizProduct(row)
        .then((response) => {
          this.loading = false;
          if (response.code === 20000) {
            this.$message.success("保存成功！");
            this.selectedIndex = null;
            this.refreshPanel();

          } else {
            this.$message.error(response.message);
          }
        })
        .catch(() => {
          this.loading = false;
          this.dataList = [];
          this.pageTotal = 0;
        });
    },

    copyDetail(row) {
      let data = {
        relId: row.bindRlFk,
        supId: row.supId,
        zczbhhzbapzbh: row.certCode,
        orderEntity: this.idQuery,
      }
      this.loading = true;
      addBizProduct(data)
        .then((response) => {
          this.loading = false;
          if (response.code === 20000) {
            this.getOrderDetails();
          } else {
            this.$message.error(response.message);
          }
        })
        .catch(() => {
          this.loading = false;
          this.dataList = [];
          this.pageTotal = 0;
        });
    },

    deleteDetail(row) {
      let data = {
        id: row.id,
      }
      this.loading = true;
      delBizProduct(data)
        .then((response) => {
          this.loading = false;
          if (response.code === 20000) {
            this.getOrderDetails();
          } else {
            this.$message.error(response.message);
          }
        })
        .catch(() => {
          this.loading = false;
          this.dataList = [];
          this.pageTotal = 0;
        });
    },
    bindRl(val) {
      this.curRow = val;
      this.selectRlVisible = true;
    },

    handleUnitClick(row) {
      this.curRow = row;
      this.dialogTableVisible = true;
    },

    selectBindRl(row) {
      let query = {
        id: this.curRow.id,
        bindRlFk: row.id,
      };
      updateBizBind(query).then((response) => {
          if (response.code == 20000) {
            this.$message.success("绑定成功");
            this.getOrderDetails();
          } else
            this.$message.error(response.message);
        }
      ).catch(() => {

      });
    },

    selectSupUnit(row) {
      let query = {
        id: this.curRow.id,
        supId: row.erpId,
      };
      updateBizBind(query).then((response) => {
        if (response.code == 20000) {
          this.$message.success("绑定成功");
          this.getOrderDetails();
        } else {
          this.$message.error(response.message);
        }
      }).catch(() => {
      });
    }
    ,


    closeBindDialog() {
      this.selectRlVisible = false;
      this.dialogTableVisible = false;
      this.refreshPanel();
    }
    ,
  }
  ,
  filters: {}
  ,

  watch: {
    'idQuery.billNo':
      {
        handler() {
          this.refreshOrder(this.idQuery);
        }
        ,
      }
  }
  ,

  mounted() {
    document.body.ondrop = function (event) {
      event.preventDefault();
      event.stopPropagation();
    };
  }
  ,
  created() {
    if (this.idQuery.billNo != null)
      this.getOrderDetails();
  }
  ,
}
;
</script>
<style scoped>
.el-table_fixed, el-table__fixed-right {
  height: 80% !important;
}

.el-table__fixed-body-wrapper {
  height: 80% !important;
}


.ao-text {
  width: 100%;
  font-size: 13px;
  font-family: "Microsoft YaHei";
  float: right;
  text-align: right;
  margin-top: 10px;
}

/**
解决el-input输入框 type=number时，输入中文光标上移问题
 */
.el-input__inner {
  line-height: 1px !important;
}

</style>



