<template>
  <div>
    <el-form :model="formData" class="order-el-form" ref="formData" label-width="120px">
      <el-card>

        <el-row :gutter="0" v-if="isLinkDisabled">
          <el-col :span="24" align="right">
            <div class="inv-hos-title">
            <span
              style="margin: 10px;color: #2d8cf0;font-size: 14px;"
            >部门&nbsp:&nbsp{{ this.userInfo.deptName }}</span>
              <span
                style="font-weight: 500;color:rgb(51 48 48); font-size: 14px; margin-right: 20px"
              >&nbsp&nbsp&nbsp&nbsp(用户&nbsp:&nbsp{{
                  this.userInfo.userName
                }})</span>
            </div>
          </el-col>
        </el-row>

        <!--  <el-alert-->
        <!--  style="margin-top: 15px"-->
        <!--  :title="msgTip"-->
        <!--  :closable="false"-->
        <!--  type="warning">-->
        <!--</el-alert>-->

        <el-row :gutter="0" style="margin-top: 15px">
          <el-col :span="24" align="right">
            <el-button-group>
              <el-button
                type="primary"
                :disabled="isSelectOrder"
                @click.native="nextCollectOrder()"
              >下一单据
              </el-button>
              <el-button
                type="primary"
                :disabled="isSelectOrder"
                @click.native="selectPrescribe()"
              >选入单据
              </el-button>
              <el-button
                type="primary"
                :disabled="formData.tagStatus<2"
                @click.native="saveDraftOrder()"
              >单据挂起
              </el-button>
              <el-button
                type="primary"
                :disabled="formData.tagStatus<2"
                @click.native="confirmFinishOrder()"
              >处理完成
              </el-button>

              <el-dropdown @command="handleCommand">
                <el-button type="primary">
                  更多功能<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item divided @click.native="handleClickOut('IoCreateOrderBlank')">工位上货</el-dropdown-item>
                  <el-dropdown-item divided @click.native="handleClickReturn('IoCreateOrderBlank')">工位退货
                  </el-dropdown-item>
                  <el-dropdown-item divided @click.native="handleClick('ioSplitFifoCodeBlank')">工位存量</el-dropdown-item>
                  <el-dropdown-item divided @click.native="handleClick('CollectOrderAllotBlank')">待处理单
                  </el-dropdown-item>
                  <el-dropdown-item divided @click.native="handleClick('CollectOrderEndBlank')">已完成单</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-button-group>
          </el-col>
        </el-row>

        <el-row style="margin-top: 15px">
          <el-col :span="6">
            <el-form-item prop="workPlaceCode" class="query-form-item" label="当前工位:">
              <el-select
                v-model="formData.workPlaceCode"
                placeholder="当前工位"
                style="width: 90%"
                :disabled="corpOrderIdDisabled"
                filterable
                @change="workPlaceCodeChange"
              >
                <el-option
                  v-for="item in curWorkPlaces"
                  :key="item.workplaceId"
                  :label="item.workplaceName"
                  :value="item.workplaceId"
                >
                  <span style="float: left">{{ item.workplaceName }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{
                      item.workplaceId
                    }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item prop="busType" class="query-form-item" label="业务类型:">
              <el-select v-model="formData.busType"
                         filterable
                         remote
                         @change="busTypeChange"
                         reserve-keyword
                         placeholder="请选择业务类型" clearable style="width: 90%">
                <el-option
                  v-for="item in busTypeList"
                  :key="item.documentTypeCode"
                  :label="item.busName"
                  :value="item.documentTypeCode"
                >
                  <span style="float: left">{{ item.busName }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.documentTypeCode }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6" v-if="this.formDataVisible != null &&  this.formDataVisible.scanType == 1">
            <el-form-item class="query-form-item" :label="this.formDataVisible.unitTittle + ':'">
              <el-select v-model="formData.fromCorp"
                         filterable
                         remote
                         reserve-keyword
                         placeholder="请选择往来单位" clearable style="width: 90%">
                <el-option
                  v-for="item in fromInvOptions"
                  :key="item.erpId"
                  :label="item.name"
                  :value="item.erpId"
                >
                  <span style="float: left">{{ item.name }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.code }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>

        <div style="border: 1px solid #ebeef5;border-radius: 2px;margin-top: 15px;padding: 15px">
          <el-row :gutter="0" style="margin-top: 5px">
            <el-col :span="20">
              <el-form-item prop="code" label="扫码录入:" label-width="80px">
                <el-input
                  id="inputer"
                  @focus="getInputFocus($event)"
                  @keypress.enter.native="enterKey($event)"
                  ref="inputRef"
                  style="ime-mode: disabled"
                  type="tel"
                  placeholder="请点击输入框进行扫码设置或者扫码录入"
                  v-model="scanCode"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button-group style="display: flex;">
                <el-button
                  type="primary"
                  size="mini"
                  icon="el-icon-plus"
                  @click.native.stop="addCode()"
                  style="margin-left: 15px"
                >添加
                </el-button>
                <el-button
                  type="primary"
                  size="mini"
                  icon="el-icon-delete"
                  @click.native.stop="clearCode()"
                >清空
                </el-button>
              </el-button-group>
            </el-col>
          </el-row>
          <el-alert
            :title="scanTitle"
            :type="scanResultType"
            :closable="false"
            :dangerouslyUseHTMLString="true"
            :description="result">
          </el-alert>

        </div>
        <el-descriptions title="单据信息" :column="4" border style="margin-top: 15px">
          <el-descriptions-item label="业务单号">{{ formData.billNo }}</el-descriptions-item>
          <el-descriptions-item label="往来信息">{{ formData.fromCorp }}</el-descriptions-item>
          <el-descriptions-item label="单据类型">{{ formData.busTypeName }}</el-descriptions-item>
          <el-descriptions-item label="来源系统">{{ formData.fromType }}</el-descriptions-item>
          <el-descriptions-item label="单据时间">{{ formData.billTime }}</el-descriptions-item>
          <el-descriptions-item label="单据备注">{{ formData.remark }}</el-descriptions-item>
        </el-descriptions>
      </el-card>

      <el-tabs type="border-card" style="margin: 15px">
        <el-tab-pane label="扫码详情">
          <prescribeOriginPanel
            v-if="panelALive"
            :prescribeData="curRow"
          ></prescribeOriginPanel>
        </el-tab-pane>
        <!--        <el-tab-pane label="扫码明细">-->
        <!--          <PanelOrderManuTagCode-->
        <!--            v-if="panelALive"-->
        <!--            :fifoSplit="3"-->
        <!--            :prescribeData="curRow"-->
        <!--            :refreshPanel="refreshCodesPanelP"-->
        <!--          ></PanelOrderManuTagCode>-->
        <!--        </el-tab-pane>-->
        <el-tab-pane label="拆零详情">
          <prescribeCodePanel
            v-if="panelALive"
            :prescribeData="curRow"
            :fifoSplit="1"
          ></prescribeCodePanel>
        </el-tab-pane>
        <el-tab-pane label="整取详情">
          <prescribeCodePanel
            v-if="panelALive"
            :prescribeData="curRow"
            :fifoSplit="2"
          ></prescribeCodePanel>
        </el-tab-pane>
        <el-tab-pane label="整单详情">
          <PanelOrderAllDetail
            v-if="panelALive"
            :prescribeData="curRow"
          ></PanelOrderAllDetail>
        </el-tab-pane>

      </el-tabs>

      <el-dialog
        title="选入业务单据"
        :visible.sync="selectPrescriptionVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        v-if="selectPrescriptionVisible"
        width="65%"
        append-to-body
      >
        <selectPrescribeDialog
          :workPlaceCode="this.formData.workPlaceCode"
          :busType="this.formData.busType"
          :fromCorp="this.formData.fromCorp"
          :confirmSelect="this.confirmSelect"
          :closeDialog="this.closeDialog"
        ></selectPrescribeDialog>
      </el-dialog>


      <el-dialog
        title="选择业务类型"
        :visible.sync="selectBusTypeDisabled"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        :show-close="false"
        v-if="selectBusTypeDisabled"
        width="65%"
        append-to-body
      >
        <el-row>
          <!--          <el-button v-for="(item, index) in busTypeList" :key="index" type="primary" plain @click="selectBusType(item.code)">{{ item.name }}</el-button>-->

          <el-col v-for="(info, index)  in busTypeList" :key="index" :xs="12" :sm="8" :md="8" :lg="6">
            <el-card :body-style="{margin:'20px'}"
                     style="margin:20px 20px 20px 20px;height: 200px;background-color: #e1f3fb;border-radius: 12px; position: relative;"

            >

              <div
                style="display: flex; justify-content: space-between; align-items: center; height: 46px; /* 约为 200px 的 1/3 */"
                @click="selectBusType(info.documentTypeCode)">
                <p style="font-size: 20px;background-color: #e1f3fb;font-weight: bold;">{{ info.busName }}</p>
                <!-- 假设你的信息对象中包含一个title属性 -->
                <!--            <div style="width: 60px; height: 60px;  display: flex; justify-content: center; align-items: center;">-->
                <!--              &lt;!&ndash; 二维码占位，这里用灰色方块代替 &ndash;&gt;-->
                <!--&lt;!&ndash;              <span>QR</span>&ndash;&gt;-->
                <!--              <div ref="qrcode" :id="'qrcode-'+index" style="width: 60px;height: 60px;"></div>-->

                <!--            </div>-->
              </div>
              <div style="flex: 1; display: flex; flex-direction: column; justify-content: flex-end; padding-top: 10px;"
                   @click="selectBusType(info.documentTypeCode)">
                <!-- 假设这里有一些信息内容 -->
                <p style="font-size: 14px;background-color: #e1f3fb">{{ info.documentTypeCode }}</p>
                <el-button type="primary" style="position: absolute; bottom: 20px; right: 20px;" icon="el-icon-thumb"
                           @click="selectBusType(info.documentTypeCode)">开始作业
                </el-button>

              </div>


            </el-card>
          </el-col>
        </el-row>
      </el-dialog>


    </el-form>
  </div>
</template>

<script>
import addOrder from "@/views/inout/DialogCreateOrder";
import errOrder from "@/views/inout/IoCreateErrorOrder";
import {executeFuc, getHead} from "@/utils/customConfig";
import {convertDate} from "@/utils/date";
import selectPrescribeDialog from "@/views/collect/selectCollectOrderDialog";
import PanelOrderManuTagCode from "./PanelOrderManuTagCode";
import prescribeOriginPanel from "./PannelOrderBiz";
import prescribeCodePanel from "./PanelOrderTagCode";
import PannelOrderBiz from "./PannelOrderBiz";
import {listPage} from "@/api/basic/workPlace/sysWorkplaceManage";
import {enterCodeWeb} from "@/api/inout/order";
import {draftOrder, finishOrder, startSplit, tagCode, updateOrder} from "@/api/collect/splitCreateOrder";
import {selectCorpList} from "@/api/basic/basicUnitMaintain";
import {delDrugLevel} from "@/api/basic/product/drugUdiinfos";
import {getCurOrder, getNextOrder, findByBill} from "@/api/collect/collectOrder";
import PanelOrderAllDetail from "@/views/collect/PanelOrderAllDetail";
import {getWorkBindBusTypes, removeBusTypeById} from '@/api/basic/workPlace/sysWorkplaceDocuments'

export default {
  /**
   * 处理处方
   */
  name: "prescribeTagCodeDeal",
  data() {
    return {
      fromInvOptions: [],
      //界面配置相关
      //患者处方
      loading: false,
      tableHeader: [],
      queryList: [],
      tableObj: [],
      fromList: [],
      convertDateFun: convertDate,
      //界面配置-------------end

      showSearch: true,
      filterQuery: {
        billNo: null,
        page: 1,
        limit: 10,
      },
      list: [],
      total: 0,
      defaultSort: {prop: 'createTime', order: 'desc'},
      formDataVisible: {
        scanType: null,
        unitTittle: "往来单位",
        corpType: 1,
      },
      curWorkPlaces: [],
      erpList: [],
      formData: {
        billNo: null,
        tagStatus: -1,
        invCode: null,
        busType: null,
        workPlaceCode: null,
        fromCorp: null,
        confirmFinish: false,
      },
      selectPrescriptionVisible: false,
      corpOrderIdDisabled: false,
      isLinkDisabled: false,
      selectBusTypeDisabled: false,
      userInfo: {
        inv: this.$store.getters.locInvName,
        deptName: this.$store.getters.locDeptName,
        userName: this.$store.getters.name,
        companyName: this.$store.getters.companyName,
      },
      curRow: null,
      panelALive: false,

      //扫码相关
      scanCode: "",
      isSuccess: false,
      scanTitle: "扫码结果:",
      result: "  \n",
      msgTip: "信息提醒：",
      originCode: "",
      checkSuccess: false,
      scanResultType: "success",
      isSelectOrder: false,
      isFinishOrder: true,
      busQuery: {
        busKey: '',
        workplaceCode: null,
        page: 1,
        limit: 100
      },
      busTypeList: [],
      busTypeTotal: 0,
    }
  },

  components: {
    addOrder,
    errOrder,
    selectPrescribeDialog,
    prescribeCodePanel,
    PanelOrderManuTagCode, prescribeOriginPanel,
    PannelOrderBiz,
    PanelOrderAllDetail
  },
  methods: {

    getBillNo(billNo) {
      let post = {
        billNo: billNo,
        workPlaceCode: this.workplaceId,
        page: 1,
        limit: 10,
      }
      findByBill(post).then(res => {
        if (res.code == 20000) {
          if (res.data.billNo != null) {
            this.formData = res.data
          }
        }
      })
    },
    selectBusType(val) {
      this.formData.busType = val
      this.selectBusTypeDisabled = false
      if (this.formData.workPlaceCode != null) {
        this.findCurOrder();
      }
    },
    getWorkBindBusTypes(workplaceId) {
      this.busQuery.workplaceCode = workplaceId
      getWorkBindBusTypes(this.busQuery).then(res => {
        if (res.code == 20000) {
          this.busTypeList = res.data.list
          this.busTypeTotal = res.data.total

          if (this.formData.billNo != null) {
            this.getBillNo(this.formData.billNo)
            this.startDeal();
          } else {
            if (this.busTypeList.length == 1) {
              let busType = this.busTypeList[0]
              this.formData.busType = this.busTypeList[0].documentTypeCode
              this.selectBusTypeDisabled = false
              this.formDataVisible = busType
              if (this.formDataVisible.scanType == 1) {
                this.findFromInvList("");
              }
            } else {
              this.formData.busType = null
            }
            this.findCurOrder();
          }

        }
        return
      })
    },
    findFromInvList(val) {
      let cQuery = {
        corpType: this.formDataVisible.corpType,
      };
      selectCorpList(cQuery)
        .then((response) => {
          this.fromInvOptions = response.data || [];
        })
        .catch(() => {
        });
    },
    workPlaceCodeChange(value) {
      this.getWorkBindBusTypes(value)
      return
    },

    busTypeChange(value) {
      let busType = this.busTypeList.find(item => item.documentTypeCode === value);
      this.formData.busType = busType.documentTypeCode
      this.selectBusTypeDisabled = false
      this.formDataVisible = busType
      if (this.formDataVisible.scanType == 1) {
        this.findFromInvList("");
      }
      this.findCurOrder();
    },

    handleClick(blankName) {
      // let url = window.location.origin+`#/tagCodeBlank?workplaceId=`+ this.stationList[index].workplaceId
      let url = window.location.origin + `#/` + blankName + `?workplaceId=` + this.workplaceId
      // this.$router.push( workplaceId)
      window.open(url, '_blank');
    },
    handleClickOut(blankName) {
      // let url = window.location.origin+`#/tagCodeBlank?workplaceId=`+ this.stationList[index].workplaceId
      let url = window.location.origin + `#/` + blankName + `?splitType=out&workplaceId=` + this.workplaceId
      // this.$router.push( workplaceId)
      window.open(url, '_blank');
    },
    handleClickReturn(blankName) {
      // let url = window.location.origin+`#/tagCodeBlank?workplaceId=`+ this.stationList[index].workplaceId
      let url = window.location.origin + `#/` + blankName + `?splitType=return&workplaceId=` + this.workplaceId
      // this.$router.push( workplaceId)
      window.open(url, '_blank');
    },
    //获取当前货位
    findCurWorkPlaces(val) {
      let query = {
        key: val,
        status: 1,
        // invCode: this.formData.invCode,
        page: 1,
        limit: 100,
      }
      listPage(query).then((res) => {
        this.curWorkPlaces = res.data.list || [];
        if (this.curWorkPlaces.length == 1 && this.formData.workPlaceCode == null) {
          this.formData.workPlaceCode = this.curWorkPlaces[0].workplaceId;
          this.workPlaceCodeChange(this.formData.workPlaceCode);
        }
      })
    },
    //界面配置相关------------
    executeFuc(row, type, clickFuc, value) {
      return executeFuc(this, row, type, clickFuc, value);
    },
    executeEval(row, expression, defaultRet) {
      if (expression) {
        return eval(expression);
      }
      return defaultRet;
    },
    ///界面配置相关------------end


    hideSearch() {
      this.showSearch = !this.showSearch;
    },

    refreshCodesPanel(_this) {
      _this.panelALive = false;
      _this.$nextTick(() => {
        _this.panelALive = true;
      });
    },
    refreshCodesPanelP() {
      let _this = this
      _this.panelALive = false;
      _this.$nextTick(() => {
        _this.panelALive = true;
      });
    },

    getInputFocus(event) {
      event.currentTarget.select();
    },

    enterKey() {
      this.checkSuccess = true;
      this.filterQuery.code = this.scanCode;
      let tQuery = {
        originCode: this.originCode,
        code: this.filterQuery.code.trim(),
      };
      enterCodeWeb(tQuery).then((response) => {
        if (response.code === 20000) {
          this.$refs.inputRef.focus();
          this.$refs.inputRef.select();
          this.isSuccess = true;
          this.printCodeResult(response.data, response.message)
          this.filterQuery.code = response.data.code;
          this.scanCode = ""
          this.originCode = ""

          this.addCode();
        } else {
          if (response.code == 502) {
            this.checkSuccess = false;
            this.isSuccess = false;
            this.printCodeResult(response.data, response.message)
            this.filterQuery.code = response.data.code;
            this.originCode = response.data.code;
            this.scanCode = ""
          } else if (response.code == 501) {
            this.checkSuccess = false;
            this.$message.error(response.message);
            this.scanCode = ""
          } else if (response.code == 503) {
            this.checkSuccess = false;
            this.isSuccess = false;
            this.printCodeResult(response.data, response.message)
            this.filterQuery.code = response.data.code;
            this.scanCode = ""
            this.$confirm(response.message, "提示", {
              type: "warning",
            })
              .then(() => {
                this.filterQuery.code = response.data.code;
                this.addCode();
              })
              .catch(() => {
                this.filterQuery.code = response.data.code;
              });
          } else if (response.code == 508) {
            this.originCode = "";
            this.filterQuery.code = "01" + response.data.nameCode;
            this.originCode = this.filterQuery.code;
          } else {
            this.scanCode = ""
            this.$alert(response.message, "提示", {
              confirmButtonText: "确定",
              type: "warning",
              closeOnClickModal: true,
              callback: (action) => {
                this.$refs.inputRef.focus();
                this.$refs.inputRef.select();
              },
            });
          }
        }
        this.loading = false;
      });
    },

    addCode() {
      if (this.$isBlank(this.filterQuery.code)) {
        this.filterQuery.code = this.scanCode.trim();
      }
      if (this.$isBlank(this.filterQuery.code) && this.$isBlank(this.scanCode)) {
        return;
      }
      if (this.$isNotBlank(this.scanCode)) {
        this.filterQuery.code = this.scanCode.trim();
      }
      let tagQuery = {
        workPlaceCode: this.formData.workPlaceCode,
        fromCorp: this.formData.fromCorp,
        billNo: this.formData.billNo,
        code: this.filterQuery.code.trim(),
        insert: this.formData.insert,
        busType: this.formData.busType,
      };
      tagCode(tagQuery).then(res => {
        this.loading = false
        if (res.code == 20000) {
          this.formData.tagStatus = 2;
          this.formData.insert = false;
          this.formData = res.data;
          this.curRow = this.formData;
          this.$refs.inputRef.focus();
          this.refreshCodesPanel(this);
        } else {
          if (res.code == 502) {
            this.$confirm(res.message + '是否强制添加?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.formData.insert = true;
              this.addCode();
            }).catch(() => {
            });
          } else {
            this.$refs.inputRef.focus();
            this.$message.error(res.message)
          }

        }
      }).catch(() => {
        this.loading = false
      })
    },

    saveDraftOrder() {
      this.$confirm('此操作将挂起当前正在处理单据，是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        draftOrder(this.formData).then(res => {
          this.loading = false
          if (res.code == 20000) {
            this.resetWork()
          }
        }).catch(() => {
          this.loading = false
        })
      }).catch(() => {
      });
    },

    confirmFinishOrder() {
      this.$confirm('是否确定完成此单据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.finishOrder()
      }).catch(() => {
      });
    },

    finishOrder() {
      finishOrder(this.formData).then(res => {
        this.loading = false
        if (res.code == 20000) {
          this.resetWork()
        } else if (res.code == 502) {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.formData.confirmFinish = true;
            this.finishOrder();
          }).catch(() => {
          });
        }
      }).catch(() => {
        this.loading = false
      })
    },


    updateOrder() {
      updateOrder(this.formData).then(res => {
        this.loading = false
      }).catch(() => {
        this.loading = false
      })

    },

    //选择单据
    selectPrescribe() {
      // console.log(this.formData.workPlaceCode)
      this.selectPrescriptionVisible = true;
    },

    //获取下一单据
    nextCollectOrder() {
      let nextQuery = {
        workPlaceCode: this.formData.workPlaceCode
      }
      getNextOrder(nextQuery).then(res => {
        this.loading = false
        if (res.code == 20000) {
          this.formData = res.data;
          this.startDeal();
        } else {
          this.$message.error(res.message)
        }
      }).catch(() => {
        this.loading = false
      })
    },


    findCurOrder() {
      let nextQuery = {
        workPlaceCode: this.formData.workPlaceCode,
        busType: this.formData.busType
      }
      getCurOrder(nextQuery).then(res => {
        this.loading = false
        if (res.code == 20000) {
          let temp = res.data;
          if (temp.tagStatus === -1) {
            this.$confirm('检测到当前工位存在挂起单据，是否继续上一次单据处理?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.formData = temp;
              this.startDeal();
            }).catch(() => {
            });
          } else if (temp.tagStatus === 2) {
            this.$confirm('检测到当前工位存在正在处理单据，是否继续上一次单据处理?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.formData = temp;
              this.startDeal();
            }).catch(() => {
            });
          }


        } else {
          // this.$message.error(res.message)
        }
      }).catch(() => {
        this.loading = false
      })
    },

    closeDialog() {
      this.selectPrescriptionVisible = false;
    },

    confirmSelect(row) {
      this.selectPrescriptionVisible = false;
      this.formData = row;
      this.startDeal();
    },

    startDeal() {
      this.curRow = this.formData;
      this.dealSplitOrder()
      this.formData.tagStatus = 2;
      this.updateOrder();
      this.refreshCodesPanel(this);
    },

    //开始拆零
    dealSplitOrder() {
      startSplit(this.formData).then(res => {
        this.loading = false
        if (res.code == 20000) {
          this.refreshCodesPanel(this);
        } else {

        }
      }).catch(() => {
        this.loading = false
      })
    },


    printCodeResult(data, message) {
      const resultParts = [];
      if (data.udi) {
        resultParts.push("层级标识: " + data.udi);
      }
      if (data.batchNo) {
        resultParts.push("批次号: " + data.batchNo);
      }
      if (data.produceDate) {
        resultParts.push("生产日期: " + data.produceDate);
      }
      if (data.expireDate) {
        resultParts.push("失效日期: " + data.expireDate);
      }
      if (data.serialNo) {
        resultParts.push("序列号: " + data.serialNo);
      }
      this.scanTitle = "扫码结果：" + data.code;
      this.result = resultParts.join(" , ");
      if (message == 'success') {
        this.scanResultType = "success";
      } else {
        this.scanResultType = "warning";
        this.result = this.result + "\n" + message;
      }
    },
    handleCommand(command) {
      // this.$message('click on item ' + command);
    },
    clearCode() {
      this.originCode = "";
      this.formData.code = "";
      this.scanCode = "";
      this.scanTitle = "扫码结果：";
      this.result = "";
    },

    /**
     * 重置
     */
    resetWork() {
      this.formData = {
        tagStatus: -1,
        workPlaceCode: this.formData.workPlaceCode,
        busType: this.formData.busType
      };
      this.curRow = null
      this.formData.confirmFinish = false;
      this.refreshCodesPanel(this)
    },


  },
  created() {
    getHead("prescribeTagCodeDeal", "1").then((re) => {
      // 处理返回的数据
      this.tableObj = re.data;
      this.tableHeader = re.data.tableList;
      this.queryList = re.data.queryList;
      this.fromList = re.data.fromList;
    });
    this.findCurWorkPlaces();
    this.formData.invCode = this.$store.getters.locInvCode;
    if (this.$route.query.billNo != null) {
      this.formData.billNo = this.$route.query.billNo
    }
    if (this.$route.query.workplaceId != null) {
      this.isLinkDisabled = true
      if (this.$route.query.billNo == null) {
        this.selectBusTypeDisabled = true
      }
      this.corpOrderIdDisabled = true
      this.workplaceId = Number(this.$route.query.workplaceId);
      this.formData.workPlaceCode = Number(this.$route.query.workplaceId);
      this.getWorkBindBusTypes(this.formData.workPlaceCode);
    }


  }

}
</script>

<style scoped>
.el-col {
  margin-top: -5px;
  margin-bottom: -5px;
}

.el-dropdown {
  vertical-align: top;
}

.el-dropdown + .el-dropdown {
  margin-left: 15px;
}

.el-icon-arrow-down {
  font-size: 12px;
}
</style>
