<template>
  <div>
    <el-card class="el-card">
      <el-form
          :inline="true"
          :model="filterQuery"
          class="query-form"
          size="mini"
      >
        <el-row>
          <el-form-item class="query-form-item">
            <el-input v-model="filterQuery.id" placeholder="单号"></el-input>
          </el-form-item>
          <el-form-item class="query-form-item">
            <el-select
                v-model="filterQuery.mainAction"
                placeholder="出入库类型"
            >
              <el-option label="全部" value=""></el-option>
              <el-option label="入库" value="WareHouseIn"></el-option>
              <el-option label="出库" value="WareHouseOut"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item class="query-form-item">
            <el-select v-model="filterQuery.action" placeholder="请选择扫码单据类型" clearable>
              <el-option
                  v-for="item in busTypes"
                  :key="item.name"
                  :label="item.name"
                  :value="item.action">
                <span style="float: left">{{ item.name }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="query-form-item">
<!--            <el-select v-model="filterQuery.locStorageCode" placeholder="请选择当前仓库" clearable="true"-->
<!--                       @change="invChange"-->
<!--                       size="mini">-->
<!--              <el-option-->
<!--                  v-for="item in storageList"-->
<!--                  :key="item.name"-->
<!--                  :label="item.name"-->
<!--                  :value="item.code">-->
<!--                <span style="float: left">{{ item.name }}</span>-->
<!--              </el-option>-->
<!--            </el-select>-->
          </el-form-item>
          <el-form-item class="query-form-item">
            <el-select v-model="filterQuery.invWarehouseCode" placeholder="请选择当前仓库" clearable="true"
                       size="mini"
                       @change="subInvChange">
              <el-option
                  v-for="item in subInvList"
                  :key="item.name"
                  :label="item.name"
                  :value="item.code">
                <span style="float: left">{{ item.name }}</span>
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item class="query-form-item">
            <span style="color: #000; margin-left: 10px; margin-right: 6px"
            >创建日期:</span
            >
            <el-date-picker
                :picker-options="pickerOptions"
                v-model="actDateRange"
                type="daterange"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button-group>
              <el-button type="primary" icon="el-icon-refresh" @click="onReset"></el-button>
              <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
              <!--                            <el-button type="primary" icon="search" @click="mergesOrders">合并单据</el-button>-->
            </el-button-group>
          </el-form-item>
        </el-row>
      </el-form>
      <el-table
          v-loading="loading"
          :data="list"
          style="width: 100%"
          @row-click="getOrderDetail"
          highlight-current-row
          @selection-change="handleSelectionChange"
      >
        <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column label="扫码单据类型" prop="billTypeName" width="120">
        </el-table-column>
        <el-table-column
            label="订单号"
            prop="id"
            show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column label="来源" prop="fromType">
          <template slot-scope="scope">
            <span>{{ fromTypeMap[scope.row.fromType] }}</span>
          </template>

        </el-table-column>
        <el-table-column label="往来单位" prop="fromCorp" width="250">
        </el-table-column>
        <el-table-column label="当前仓库" prop="invName" width="120">
        </el-table-column>
        <el-table-column label="当前分库" prop="subInvName" width="120">
        </el-table-column>
        <el-table-column label="所属科室" prop="deptName" width="120" v-if="enableDept">
        </el-table-column>
        <el-table-column
            label="创建时间"
            prop="actDate"
            width="150"
            show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span>{{ scope.row.actDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="校验状态" prop="contrastStatus" width="120">
          <template slot-scope="scope">
            <el-tag :type="(scope.row.contrastStatus === 1) | statusFilterType">
              {{ erpCheckStatus[scope.row.contrastStatus] }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="250">
          <template slot-scope="scope">
            <el-button
                type="text"
                size="small"
                @click.native.stop="repeatCheckClick(scope.row)"
                v-if="scope.row.status != 4"
            >重新校验
            </el-button
            >
            <el-button
                type="text"
                size="small"
                @click.native.stop="repeatPrintCheckClick(scope.row)"
                v-if="scope.row.status === 4"
            >重新提交
            </el-button
            >
            <el-button
                type="text"
                size="small"
                @click.native.stop="handleErrorDetail(scope.$index)"
            >校验信息
            </el-button
            >

          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="250">
          <template slot-scope="scope">
            <el-button
                type="text"
                size="small"
                @click.native.stop="intentDetail(scope.row)"
            >详情
            </el-button
            >
            <el-button
                type="text"
                size="small"
                @click.native.stop="deleteDialog(scope.row.id)"
            >删除
            </el-button
            >
            <el-button
                type="text"
                size="small"
                :disabled="scope.row.status == 4 && scope.row.contrastStatus == 2  "
                @click.native.stop="importOrder(scope.row)"
            >选择业务单据
            </el-button>

            <el-button
                type="text"
                size="small"
                @click.native.stop="revokeErrOrder(scope.row)"
            >撤回
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog
          title="导出PDF"
          :visible.sync="successOrderExportPDFSettingVisible"
          width="80%"
          v-if="successOrderExportPDFSettingVisible"
          @close='closeDialog'
      >
        <successOrderExportPDFSetting
            :closeDialog="closeDialog"
            :idQuery="idQuery"
        ></successOrderExportPDFSetting>
      </el-dialog>

      <el-pagination
          :page-size="filterQuery.limit"
          @current-change="handleCurrentChange"
          layout="prev, pager, next"
          :total="total"
          :current-page="filterQuery.page"
      ></el-pagination>
    </el-card>

    <el-card class="el-card" v-if="true" id="printJS-form">
      <el-table
          v-loading="loading"
          :row-class-name="tableRowClassName"
          :data="detailList"
          style="width: 100%"
      >
        <el-table-column label="序号" type="index"></el-table-column>

        <el-table-column
            label="产品通用名"
            prop="coName"
            width="150"
            :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
            label="包装规格"
            prop="packSpec"
            width="200"
            :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
            label="批次号"
            prop="batchNo"
            width="100"
            :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
            label="生产日期"
            prop="productDate"
            width="100"
            :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
            label="失效日期"
            prop="expireDate"
            width="100"
            :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
            label="单据数量"
            prop="erpCount"
            width="100"
            :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
            label="实际数量"
            prop="reCount"
            width="100"
            :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column label="扫码数量" prop="count"
                         width="100"></el-table-column>
        <el-table-column
            label="供应商"
            prop="supName"
            :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
            label="生产企业"
            prop="productCompany"
            width="150"
            :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
            label="注册/备案凭证号"
            prop="authCode"
            width="150"
            :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column label="操作" fixed="right" width="180">
          <template slot-scope="scope">
            <el-button
                type="text"
                size="small"
                :disabled="scope.row.bindRlFk != null "
                @click.native.stop="bindRl(scope.row)"
            >选择产品
            </el-button
            >
            <el-button
                type="text"
                size="small"
                :disabled=" scope.row.supId !='MUTI'"
                @click.native.stop="handleUnitClick(scope.row)"
            >选择供应商
            </el-button
            >
            <!--                         scope.row.supId !=null &&-->
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-dialog
        title="选择往来单位"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :visible.sync="dialogTableVisible"
        width="70%"
    >
      <el-form :inline="true" :model="query" class="query-form" size="mini">
        <el-form-item class="query-form-item">
          <el-input v-model="unitquery.key" placeholder="搜索"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
              type="primary"
              icon="search"
              @click.native.stop="getUnitList()"
          >查询
          </el-button
          >
          <el-button
              type="primary"
              icon="search"
              @click.native.stop="selectUnit()"
          >确定
          </el-button
          >
        </el-form-item>
      </el-form>

      <el-table
          v-loading="loading"
          :data="unitlist"
          style="width: 100%"
          @current-change="handleDetail"
      >
        <el-table-column label="序号" type="index" width="60" fixed></el-table-column>
        <el-table-column label="往来单位ID" prop="erpId"></el-table-column>
        <el-table-column
            label="往来单位名称"
            prop="name"
            show-overflow-tooltip
        ></el-table-column>
        <el-table-column
            label="往来单位简写"
            prop="spell"
            show-overflow-tooltip
        ></el-table-column>
        <el-table-column
            label="地址"
            prop="addr"
            show-overflow-tooltip
        ></el-table-column>
        <el-table-column label="状态" prop="status"></el-table-column>
        <el-table-column label="类型" prop="type"></el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog
        title="选择业务单据"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :visible.sync="addDialogVisible"
        width="80%"
        v-if="addDialogVisible"
    >
      <selectErpOrder
          v-on:closeManuDialog="closeManuDialog"
          :orderId="orderId"
          :orderAction="billAction"
          :curLocInv="curLocInv"
      ></selectErpOrder>
    </el-dialog>

    <el-dialog
        title="单号详情"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :visible.sync="codeDetailVisible"
        width="80%"
        v-if="codeDetailVisible"
    >
      <codeDetail
          :idQuery="idQuery"
          v-on:closeDetailDialog="closeDetailDialog"
      ></codeDetail>
    </el-dialog>


    <el-dialog
        title="绑定产品ID"
        :visible.sync="selectRlVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        width="80%"
        v-if="selectRlVisible"
    >
      <selectRlDialog
          :curRow="curRow"
          :closeBindDialog="closeBindDialog"
      ></selectRlDialog>
    </el-dialog>

    <el-dialog title="校验信息" :visible.sync="errDialogVisible" width="30%">
      <span>{{ errorDetail }}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="errDialogVisible = false"
        >关 闭</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  orderList,
  codeList,
  findAllByOrderId,
  updateUnit,
  filterOrder,
  deleteByOrderId,
  updateExportStatus,
  uploadOrder,
  mergeOrder,
  orderDetail, revokeOredr, updateBind
} from "../../api/warehouse/order";

import {updateBindSup} from "../../api/warehouse/order"

import {
  orderDetailPDFFromTemplateCode,
  orderDetailPDFFromTemplateFile,
  inspectionOrderDetailPDFFromTemplateCode,
  inspectionOrderDetailPDFFromTemplateFile
} from "../../api/itextpdf/itextpdf";
import {repeatCheck, repeatPrintCheck} from "../../api/erp/erpOrder";
import {getBasicUnitMaintains} from "@/api/basic/basicUnitMaintain";
import draggable from "vuedraggable";
import {saveAs} from "file-saver";
import codeDetail from "./code";
import store from "../../store";
import successOrderExportPDFSetting from "./successOrderExportPDF";
import {downloadInoutOrderSuccessPDF} from "../../api/itextpdf/itextpdf";
import selectErpOrder from "./DialogSelectErpOrder";
import selectRlDialog from "./DialogSelectRl";
import {getBussinessType} from "../../api/basic/bussinessType";
import {filterAllByUser} from "@/api/basic/invWarehouse";
import {getLocalJoinByUser} from "@/api/basic/busLocalType";
import {filterSubByInv} from "@/api/basic/invSubWarehouse";
import {selectSysParamByKey} from "@/api/param/systemParamConfig";

const formJson = {
  site_id: "",
  site_name: "",
  describe: "",
  ads: [],
};
export default {
  props: {
    isSelect: {
      type: Boolean,
      default: false,
    },
  },

  data() {
    return {
      query: {
        page: 1,
        limit: 20,
      },
      checkStatus: {
        1: "校验异常",
        0: "未校验",
        2: "正常",
      },
      erpCheckStatus: {
        // error: "校验异常",
        // null: "未校验",
        // success: "正常",
        1: "校验异常",
        0: "未校验",
        2: "校验成功",
      },
      fromTypeMap: {
        "1": "UDIMS平台",
        "2": "网页新增",
        "3": "pda即时校验",
        "4": "pda未校验",
        "5": "pc端扫码精灵",
        "6": "缺量补录单据",
        "7": "UDI供应商平台",
        "8": "平衡补录单据",
        "10": "手动补单"
      },
      busTypes: [],
      enableDept: false,
      //往来单位
      unitquery: {key: "", page: 1, limit: 20},
      unitlist: [],
      list: [],
      detailList: [],
      unitUpdateQuery: {
        id: "",
        fromCorpId: "",
        fromCorp: "",
      },
      billAction: null,
      actDateRange: [],
      filterQuery: {
        id: "",
        mainAction: null,
        action: null,
        page: 1,
        limit: 10,
        code: "",
        exportStatus: null,
        contrastStatus: 1,
        status: null,
        startTime: "",
        endTime: "",
        locStorageCode: this.$store.getters.locInvCode,
        invWarehouseCode: this.$store.getters.locSubInvCode,
      },
      detailQuery: {
        orderId: "",
      },
      deleteData: {
        id: "",
      },
      idQuery: {
        id: "",
      },
      curUnitRow: null,
      storageList: [],
      subInvList: [],
      curIndex: "",
      adListNoDataText: "无数据",
      queryAdIdAsyncLoading: false,
      codeDetailVisible: false,
      selectRlVisible: false,
      curRow: null,
      successOrderExportPDFSettingVisible: false,
      total: 0,
      loading: false,
      index: null,
      formName: null,
      orderId: "",
      curLocInv: null,
      formMap: {
        add: "新增",
        edit: "编辑",
      },
      exportQuery: {
        orderId: "",
        exportStatus: "",
      },

      uploadQuery: {
        orderId: "",
      },
      errorDetail: null,
      multipleSelection: [],
      dialogTableVisible: false,
      formLoading: false,
      formVisible: false,
      formData: formJson,
      deleteLoading: false,
      addDialogVisible: false,
      errDialogVisible: false,
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  components: {
    draggable,
    codeDetail,
    successOrderExportPDFSetting,
    selectErpOrder,
    selectRlDialog
  },
  methods: {
    onReset() {
      this.$router.push({
        path: "",
      });
      this.filterQuery = {
        id: "",
        mainAction: null,
        action: null,
        page: 1,
        limit: 10,
        code: "",
        exportStatus: null,
        contrastStatus: 1,
        status: null,
        startTime: "",
        endTime: "",
      };
      this.actDateRange = [];
      this.getList();
    },
    onSubmit() {
      if (this.actDateRange !== null) {
        this.filterQuery.startTime = this.actDateRange[0];
        this.filterQuery.endTime = this.actDateRange[1];
      } else {
        this.filterQuery.startTime = null;
        this.filterQuery.endTime = null;
      }
      this.filterQuery.page = 1;
      this.getList();
    },
    bindRl(val) {
      this.curRow = val;
      this.selectRlVisible = true;
    },

    closeBindDialog(id) {
      this.selectRlVisible = false;
      this.detailQuery = {
        orderId: id,
      };
      this.refresgOrderDetail();
    },

    handleSizeChange(val) {
      this.filterQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.filterQuery.page = val;
      this.getList();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    handleErrorDetail(poistion) {
      var mOrder = this.list[poistion];
      this.errorDetail = mOrder.remark;
      this.errDialogVisible = true;
    },

    mergesOrders() {
      let repeatData = this.multipleSelection;
      if (repeatData.length <= 1) {
        this.$message.warning("选择的订单需大于1");
        return;
      }
      let orderid = repeatData[0].id;
      let unit = repeatData[0].fromCorp;
      let action = repeatData[0].action;
      let orderList = [];
      repeatData.forEach((obj, index) => {
        if (unit !== obj.fromCorp) {
          this.$message.warning("往来单位不一致！");
          return;
        }
        if (action !== obj.action) {
          this.$message.warning("业务类型不一致！");
          return;
        }
        orderList.push(obj.id);
      });
      let tquery = {
        orderList: orderList,
      };

      this.$confirm(
          "所选择的订单将会合并到订单号为" + orderid + "的订单下",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
      )
          .then(() => {
            mergeOrder(tquery).then((response) => {
              if (response.code === 20000) {
                this.getList();
                this.$message({
                  type: "success",
                  message: "合并成功",
                });
              } else {
                this.$message.error(response.message);
              }
            });
          })
          .catch(() => {
          });
    },
    //获取订单列表
    getList() {
      this.loading = true;
      this.filterQuery.customerId = store.getters.customerId;
      filterOrder(this.filterQuery)
          .then((response) => {
            this.loading = false;
            if (response.code == 20000) {
              this.list = response.data.list || [];
              this.total = response.data.total || 0;
              this.detailList = [];
            } else {
              this.$message.error(response.message);
            }

          })
          .catch(() => {
            this.loading = false;
            this.list = [];
            this.total = 0;
          });
    },
    //业务明细表
    getOrderDetail(row) {
      this.loading = true;
      this.detailQuery = {
        orderId: row.id,
      };
      this.refresgOrderDetail();
    },
    repeatCheckClick(row) {
      let tQuery = {
        orderId: row.id,
      };
      this.loading = true;
      repeatCheck(tQuery)
          .then((response) => {
            this.loading = false;
            if (response.code === 20000) {
              this.$message.success(response.data);
              this.getList();
              this.detailQuery = {
                orderId: row.id,
              };
              this.refresgOrderDetail();
            } else {
              this.$message.error(response.message);
            }
          })
          .catch(() => {
            this.loading = false;
            this.getList();
            this.$message.error(response.message);
          });
    },
    getStorageName(code) {
      for (let i = 0; i < this.storageList.length; i++) {
        if (this.storageList[i].code === code) {
          return this.storageList[i].name;
        }
      }
    },
    getSubStorageName(code) {
      for (let i = 0; i < this.subInvList.length; i++) {
        if (this.subInvList[i].code === code) {
          return this.subInvList[i].name;
        }
      }
    },
    repeatPrintCheckClick(row) {
      let tQuery = {
        orderId: row.id,
      };
      this.loading = true;
      repeatPrintCheck(tQuery)
          .then((response) => {
            this.loading = false;
            if (response.code === 20000) {
              this.$message.success(response.data);
              this.getList();
              this.detailList = [];
              // this.detailQuery = {
              //     orderId: row.id,
              // };
              // this.refresgOrderDetail();
            } else {
              this.$message.error(response.message);
            }
          })
          .catch(() => {
            this.loading = false;
            this.getList();
            this.$message.error(response.message);
          });
    },

    revokeErrOrder(row) {
      let tQuery = {id: row.id};
      revokeOredr(tQuery)
          .then((response) => {
            this.loading = false;
            if (response.code === 20000) {
              this.$message.success(response.data);
              this.getList();
            } else {
              this.$message.error(response.message);
            }
          })
          .catch(() => {
            this.loading = false;
            this.getList();
            this.$message.error(response.message);
          });
    },

    refresgOrderDetail() {
      orderDetail(this.detailQuery)
          .then((response) => {
            this.loading = false;
            this.detailList = response.data || [];
          })
          .catch(() => {
            this.loading = false;
            this.detailList = [];
          });
    },

    handleUnitClick(row) {
      this.curIndex = row.id;
      this.curRow = row;
      this.dialogTableVisible = true;
    },
    getUnitList() {
      this.loading = true;
      getBasicUnitMaintains(this.unitquery)
          .then((response) => {
            this.loading = false;
            this.unitlist = response.data.page.list || [];
          })
          .catch(() => {
            this.loading = false;
          });
    },
    intentDetail(row) {
      this.codeDetailVisible = true;
      this.idQuery.id = row.id;
    },
    successOrderExportPDFSetting(row) {
      this.idQuery.id = '';
      if (this.$isNotBlank(row.id)) {
        this.idQuery.id = row.id;
      }
      this.successOrderExportPDFSettingVisible = true;
    },
    successOrderExportPDF(row) {
      let tQuery = {
        orderId: row.id,
        customerId: store.getters.customerId
      }
      this.loading = true;
      inspectionOrderDetailPDFFromTemplateFile(tQuery).then((response) => {
        if (response.code === 20000) {
          orderDetailPDFFromTemplateFile(tQuery).then((response) => {
            //将pdf文件转换为url。
            const binaryData = [];
            binaryData.push(response);
            //获取blob链接。
            let url = window.URL.createObjectURL(
                new Blob(binaryData, {type: "application/pdf"})
            );
            this.loading = false;
            window.open(url);//打开新标签页，预览pdf。
          }).catch(() => {
            this.loading = false;
          });
        } else {
          this.loading = false;
          this.$message.error(response.message);
        }
      }).catch(() => {
        this.loading = false;
      });
    },
    closeDialog() {
      this.successOrderExportPDFSettingVisible = false;
      this.getList();
    },

    selectUnit() {
      let query = {
        id: this.curRow.id,
        supId: this.curRow.erpId,
      };
      updateBindSup(query).then((response) => {
        if (response.code == 20000) {
          this.$message.success("绑定成功");
          this.getList();
          this.detailList = [];
        } else {
          this.$message.error("绑定失败");
        }
      }).catch(() => {

      });


      updateUnit(this.unitUpdateQuery)
          .then((response) => {
            this.dialogTableVisible = false;
            this.getList();
          })
          .catch(() => {
            this.dialogTableVisible = false;
          });
    },
    deleteOrders(data) {
      this.loading = true;
      this.deleteData.id = data;
      deleteByOrderId(this.deleteData)
          .then((response) => {

            if (response.code == 20000) {
              this.getList();
              this.refresgOrderDetail();
              this.$message({
                type: "success",
                message: "删除成功！",
              });
            } else if (response.code == 520) {
              this.$message.error("校验异常单据列表已不存在该扫码单据！");
              this.getList();
            }
          })
          .catch(() => {
          });
    },
    tableRowClassName({row, rowIndex}) {
      if (row.erpCount === row.count) {
        return "success-row";
      } else {
        return "warning-row";
      }
    },

    exportDialog(value) {
      var mOrder = value;
      if (mOrder.exportStatus === "已上传") {
        this.$confirm("该订单已修改, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
            .then(() => {
              this.uploadOrderDialog(mOrder);
            })
            .catch(() => {
            });
      } else if (mOrder.contrastStatus === 0) {
        this.$confirm("该订单校验异常, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
            .then(() => {
              this.uploadOrderDialog(mOrder);
            })
            .catch(() => {
            });
      } else if (mOrder.contrastStatus === null) {
        this.$confirm("该订单未校验, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
            .then(() => {
              this.uploadOrderDialog(mOrder);
            })
            .catch(() => {
            });
      } else {
        this.$confirm("是否确定修改ERP订单?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
            .then(() => {
              this.uploadOrderDialog(mOrder);
            })
            .catch(() => {
            });
      }
    },
    getActionName(action) {
      for (let i = 0; i < this.busTypes.length; i++) {
        if (this.busTypes[i].action === action) {
          return this.busTypes[i].name;
        }
      }
    },
    getStorage() {
      this.storageList = [];
      filterAllByUser()
          .then((response) => {
            this.storageList = response.data || [];
            if (this.storageList.length > 0) {
              this.getSubInvList();
              this.getList();
            }
          })
          .catch(() => {
          });
    },
    getBusType() {
      let query = {
        code: this.filterQuery.invWarehouseCode,
        enabled: true,
      };
      getLocalJoinByUser(query)
          .then((response) => {
            this.busTypes = response.data.list || [];
            this.filterQuery.billAction = this.busTypes[0].action;
            // this.getList();
          })
          .catch(() => {
          });
    },

    uploadOrderDialog(value) {
      this.uploadQuery = {
        orderId: value.id,
      };
      uploadOrder(this.uploadQuery)
          .then((response) => {
            if (response.code === 20000) {
              this.$message.success(response.data);
              this.getList();
            } else {
              this.$message.error(response.message);
            }
          })
          .catch(() => {
          });
    },

    deleteDialog(rowId) {
      this.$confirm("此操作将永久删除该订单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
          .then(() => {
            this.deleteOrders(rowId);
          })
          .catch(() => {
          });
    },
    closeDetailDialog(val) {
      this.codeDetailVisible = false;
    },
    closeManuDialog(val) {
      this.addDialogVisible = false;
      if (val) {
        this.$message.success("选入成功");
        this.refresgOrderDetail();
        this.getList();
      } else {
        this.$message.error("选入失败");
      }
    },
    handleDetail(row) {
      this.curUnitRow = row;
    },
    cancelDialog() {
      this.addDialogVisible = false;
    },
    importOrder(row) {
      this.orderId = row.id;
      this.billAction = row.action;
      this.curLocInv = row.locStorageCode;
      this.addDialogVisible = true;
    },
    invChange() {
      this.subInvList = [];
      this.filterQuery.invWarehouseCode = "";
      let query = {
        pcode: this.filterQuery.locStorageCode
      };
      filterSubByInv(query)
          .then((response) => {
            this.subInvList = response.data || [];
          })
          .catch(() => {
          });
    },

    getSubInvList() {
      let query = {
        // pcode: this.filterQuery.locStorageCode
        filter: 3
      };
      filterSubByInv(query)
          .then((response) => {
            this.subInvList = response.data || [];
            this.getList();
          })
          .catch(() => {
          });
    },

    subInvChange() {
      this.getBusType();
    }
  },
  filters: {
    statusFilterType(status) {
      const statusMap = {
        false: "success",
        true: "danger",
      };
      return statusMap[status];
    },
  },
  mounted() {
    document.body.ondrop = function (event) {
      event.preventDefault();
      event.stopPropagation();
    };
  },

  created() {
    this.getSubInvList();
    this.getBusType();
    let query = this.$route.query;
    this.query = Object.assign(this.query, query);
    this.query.limit = parseInt(this.query.limit);
    let end = new Date();
    let start = new Date();
    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
    this.actDateRange = [start, end];
    selectSysParamByKey({paramKey: "muti_inv_mode"}).then((res) => {
      if (res.code === 20000) {
        if (res.data.paramValue === "0") {
          this.enableDept = true;
        }
      }
    })
  },
};
</script>


<style>
.el-table .warning-row {
  background: #ffb5b5;
}

.el-table .success-row {
  background: #ffffff;
}
</style>
