<template>
  <div class="ScanningStorageIn">
    <div class="scanInTopBg">
      <div class="storageBoxLeft">
        <p style="margin:22px 0 8px;color:#CBCED5">入库仓库：</p>
        <span style="color:#CBCED5">默认入库逻辑仓：</span><span class="storageValue">{{ StorageForm.defaultStorage && StorageForm.defaultStorage.label }}</span>
        <!-- <span style="color:#CBCED5">瑕疵品入库逻辑仓：</span><span class="storageValue">{{ StorageForm.defectiveGoodsStorage && StorageForm.defectiveGoodsStorage.label }}</span> -->
        <!-- <span style="color:#CBCED5">残次品入库逻辑仓：</span><span class="storageValue">{{ StorageForm.imperfectionsStorage && StorageForm.imperfectionsStorage.label }}</span> -->
      </div>
      <div
        class="storageBoxRight"
        @click="showStorageModal"
      >
        <Icon type="ios-create-outline" />
        编辑入库仓库
      </div>
    </div>
    <div class="scanInContent">
      <!-- 注意事项 -->
      <div class="scanInWarning">
        <div class="warningTitle">
          <img
            src="../../assets/image/warningIcon.png"
            alt=""
          >
          <span>注意：</span>
          <Icon
            v-if="isOpen"
            color="#979797"
            type="ios-arrow-down"
            @click="toggleArrow"
          />
          <Icon
            v-else
            color="#979797"
            type="ios-arrow-up"
            @click="toggleArrow"
          />
        </div>
        <div
          v-if="isOpen"
          class="warningText"
        >
          <p>1.如果退回商品和申请商品不符,请将实际退回商品扫描入库,然后再点击【强制入库】。</p>
          <p>2.自动匹配指匹配出退货入库商品后，不再逐一扫描商品，此单直接入库成功；在匹配到退单或订单后可操作。</p>
          <p>3.自动提交开关打开后，当实际入库商品与需入库商品完全一致时，入库单将自动提交。如关闭开关，则不会自动提交</p>
          <p>4.如有瑕疵/残次品，请先对商品进行标记再扫描入库</p>
        </div>
      </div>
      <!-- 扫描项 -->
      <div class="scanningBox">
        <!-- <div class="imgBorder left-top-border" /> -->
        <!-- <div class="imgBorder right-top-border" /> -->
        <!-- <div class="imgBorder right-bottom-border" /> -->
        <!-- <div class="imgBorder left-bottom-border" /> -->
        <div class="scanningSqure">
          <div class="squreTop">
            <div class="squreTopScan">
              <img
              src="../../assets/image/scanIcon.png"
              alt=""
              >
              <span>请先扫描<span class="blueTitle">扫描单号</span>和<span class="blueTitle">商品SKU</span></span>
              <span class="autoSubmit">自动提交</span><i-switch
                v-model="autoSubmit"
                @on-change="changeAutoSubmit"
              />
            </div>
            <div class="squreTopColor">
              <arkButton type="dropdown" class='dropButtonMenu' :data='["颜色标签","取消标签"]' @clickMenu='clickMenu'>颜色标签</arkButton>
              <span class='colorSqure'>
                <span class="colorItem" v-for='(item,index) in colorList' :key='index' :style="{display: 'inline-block',width:'12px',height:'12px',borderRadius:'2px',marginLeft:'7px','background':item.color}" :title='item.text'></span>
              </span>
            </div>
          </div>
          <div class="squreBottom">
            <Form
              class='scanBoxForm'
              ref="formInline"
              :model="formInline"
              :label-width="70"
              label-position='left'
              inline
            >
              <FormItem label="扫描单号">
                <Tooltip
                  max-width="400"
                  content="支持扫描退货物流单号、原订单编号、原订单平台单号、退单编号；强制入库功能只支持按物流单号扫描"
                  placement="right"
                >
                  <img
                    style="display:flex;position:relative;top: 4px;right: 7px;width:16px"
                    class="img-framelanflag"
                    src="../../assets/icon/help.png"
                  >
                </Tooltip>
                <Input
                  ref="expressEnter"
                  v-model.trim="formInline.expressCode"
                  type="text"
                  autofocus
                  placeholder="请先扫描"
                  @on-enter="CheckLogisticsNoBefore"
                />
              </FormItem>
              <FormItem label="商品SKU">
                <Tooltip
                  max-width="400"
                  content="支持扫描商品SKU条码、国标码、唯一码"
                  placement="top"
                >
                  <img
                    style="display:flex;position:relative;top: 4px;right: 7px;width:16px"
                    class="img-framelanflag"
                    src="../../assets/icon/help.png"
                  >
                </Tooltip>
                <Input
                  ref="SKUEnter"
                  v-model.trim="formInline.SKUCode"
                  type="text"
                  placeholder="请先扫描"
                  @on-enter="getSKUByCode"
                />
              </FormItem>
                <Button
                  type="primary"
                  style="width: 104px;height: 38px;margin-left: 10px;"
                  @click="compulsoryWarehouseBefore"
                  :loading='loading'
                  v-if='showForcePower'
                >
                  强制入库
                </Button>
            </Form>
          </div>
        </div>
        <div class="returnGoodsSqure">
          <div class="returnGoodsNum">
            <span class='lineSpan'>退货商品总数量</span><span class='lineSpan'>{{ReturnGoodsNum}}</span>
          </div>
          <div class="returnGoodsNum">
            <span class='lineSpan'>是否换货</span><span class='lineSpan'>{{ExchangeFlag?'是':'否'}}<span v-if='ExchangeFlag' class='exchangeDetailBtn' @click='exchangeDetail'>换货详情</span></span>
            </div>
        </div>
      </div>
      <!-- 退货入库商品详情 -->
      <div class="linkGoods">
        <Button
          class="autoBtn"
          :disabled="!haveOrder || isQrcode"
          :loading='loading'
          v-if='showAutoPower'
          @click="autoMatch"
          title="操作后系统会自动将退单商品的已退数量更新为应退数量并自动入库完成"
        >
          <img
            v-if="haveOrder && !isQrcode"
            src="../../assets/image/refresh.png"
            style="width: 14px;vertical-align: middle;margin-top: -3px;"
            alt=""
          >
          <img
            v-else
            src="../../assets/image/refreshunable.png"
            style="width: 14px;vertical-align: middle;margin-top: -3px;"
            alt=""
          >
          自动匹配
        </Button>
        <foldPanel
          v-model="linkGoodsStatus"
          title="退货入库商品详情"
        >
          <div
            slot="content"
            class="block"
          >
            <!-- <Table
              :height="tableHeightOne"
              :columns="linkGoodsColumns"
              :data="linkGoodsData"
              class="getReturnTable"
            /> -->
            <arkCommonTableByAgGrid
              ref="ag"
              :height="`${tableHeightOne}px`"
              :columns="agColumns"
              :data="linkGoodsData"
              :renderParams="agRenderParams"
              :options="{
                rowHeight: 65
              }"
              class="getReturnTable"></arkCommonTableByAgGrid>
          </div>
        </foldpanel>
      </div>
      <!-- 入库单信息 -->
      <div class="scanInStorageOrderMsg">
        <foldPanel
          title="入库单信息"
        >
          <div
            slot="content"
            class="block"
          >
            <div class="conditionContent">
              <div class="itemContent">
                <div class="itemLabel">
                  退回物流公司
                </div>
                <DropMultiSelectFilter
                  ref="Express"
                  single
                  class="input_box"
                  :data="ExpressList"
                  :default-selected="defaultSelected"
                  :total-row-count="ExpresstotalRowCount"
                  :show-colname-key="'isak'"
                  :columns="columns"
                  :auto-data="ExpressAutoData"
                  @on-page-change="changePageShop($event,'Express')"
                  @on-input-value-change="InputValueChangeShop($event,'Express')"
                  @on-popper-show="searchShopData('Express')"
                  @on-fkrp-selected="checkDataShop($event,'Express')"
                  @on-focus="focusInputValueChangeShop($event,'Express')"
                  @on-clear="clearDataShop('Express')"
                />
                <!-- <Input
                  v-model="scanInStorageOrderMsg.expressName"
                  clearable
                /> -->
              </div>
              <div class="itemContent">
                <div class="itemLabel" style="display: flex;justify-content: flex-end;">
                  扫描单号
                  <Tooltip
                    max-width="200"
                    theme="light"
                    :content="explainContent"
                    transfer
                    placement="bottom"
                  >
                  <img
                  class="img-framelanflag"
                  src="../../assets/icon/Tips.png"
                  >
                  </Tooltip>
                </div>
                <Input
                  v-model="scanInStorageOrderMsg.expressCode"
                  clearable
                />
              </div>
              <div class="itemContent">
                <div class="itemLabel" style="display: flex;justify-content: flex-end;">
                  物流单号
                </div>
                <Input
                  v-model="scanInStorageOrderMsg.logistics_number"
                  clearable
                />
              </div>
              <div class="itemContent">
                <div class="itemLabel" style="display: flex;justify-content: flex-end;">
                  手机号
                  <Tooltip
                    max-width="200"
                    theme="light"
                    :content="explainContent"
                    transfer
                    placement="bottom"
                  >
                  <img
                  class="img-framelanflag"
                  src="../../assets/icon/Tips.png"
                  >
                  </Tooltip>
                </div>
                <Input
                  v-model="scanInStorageOrderMsg.customerMobile"
                  clearable
                />
              </div>
              <div class="itemContent">
                <div class="itemLabel">
                  平台
                </div>
                <Select transfer v-model="scanInStorageOrderMsg.customerPlatform" :filterable='scanInStorageOrderMsg.customerPlatform?false:true' clearable :disabled="disabled" @on-change="selectPlatform" @on-clear="selectPlatform"  @on-query-change="getPlatformList">
                    <Option v-for="item in platformList" :value="item.value" :key="item.value">{{ item.label }}</Option>
                </Select>
              </div>
              <div class="itemContent">
                <div class="itemLabel">
                  店铺
                </div>
                <Select transfer v-model="scanInStorageOrderMsg.customerShop" :filterable='scanInStorageOrderMsg.customerPlatform?false:true' clearable :disabled="hasPlatform" @on-query-change="getShopList">
                    <Option v-for="item in shopList" :value="item.value" :key="item.value">{{ item.label }}</Option>
                </Select>
              </div>
              <div class="itemContent">
                <div class="itemLabel">
                  买家昵称
                </div>
                <Input
                  v-model="scanInStorageOrderMsg.customerNickName"
                  clearable
                />
              </div>
              <div class="itemContent">
                <div class="itemLabel">
                  姓名
                </div>
                <Input
                  v-model="scanInStorageOrderMsg.customerName"
                  clearable
                />
              </div>
              <div class="itemContent">
                <div class="itemLabel">
                  电话
                </div>
                <Input
                  v-model="scanInStorageOrderMsg.customerPhone"
                  clearable
                />
              </div>
              <div class="itemContent">
                <div class="itemLabel">
                  发件地址
                </div>
                <Input
                  v-model="scanInStorageOrderMsg.customerAddr"
                  clearable
                />
              </div>
              <div class="itemContent">
                <div class="itemLabel">
                  备注
                </div>
                <Input
                  v-model="scanInStorageOrderMsg.remark"
                  type="textarea"
                  :rows="3"
                  clearable
                />
              </div>
            </div>
          </div>
        </foldpanel>
      </div>
      <!-- 退货单/原订单信息 -->
      <div class="OrderMsg">
        <foldPanel
          v-model="OrderStatus"
          title="退货单/原订单信息"
        >
          <div
            slot="content"
            class="block"
          >
            <div class="conditionContent oldOrderContent"  v-if='haveOrder'>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  退回物流公司
                </div>
                <span>{{ oldOrderMsg.shipper_name }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  退回物流单号
                </div>
                <span>{{ oldOrderMsg.expressCode }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  手机号
                </div>
                <span>{{ oldOrderMsg.phone }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  系统退单编号
                </div>
                <span>{{ oldOrderMsg.retureOrderCode }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  原单单号
                </div>
                <span>{{ oldOrderMsg.orderCode }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  原平台单号
                </div>
                <span>{{ oldOrderMsg.sourceCodes }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  平台
                </div>
                <span>{{ oldOrderMsg.platform }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  店铺
                </div>
                <span>{{ oldOrderMsg.shop }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  买家昵称
                </div>
                <span>{{ oldOrderMsg.buyer_nick }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  姓名
                </div>
                <span>{{ oldOrderMsg.user_name }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  电话
                </div>
                <span>{{ oldOrderMsg.tel }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  发件地址
                </div>
                <span>{{ oldOrderMsg.delivery_address }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  发货仓库
                </div>
                <span>{{ oldOrderMsg.warehouse_name }}</span>
              </div>
              <div
                class="itemContent"
              >
                <div class="itemLabel">
                  备注
                </div>
                <span>{{ oldOrderMsg.remark }}</span>
              </div>
            </div>
          </div>
        </foldpanel>
      </div>
    </div>
    <!-- 入库仓库弹框 -->
    <!-- :closable="closable" -->
    <Modal
      v-model="selectStorageInModal"
      title="入库仓库"
      title-align="left"
      width="450"
      :closable='closable'
      :mask="mask"
      :mask-closable="maskClosable"
      :footer-hide="hideFoot"
      @on-cancel="closeChooseStoreDialog"
    >
      <div class="chooseStorageForm">
        <Form
          ref="formValidate"
          :model="StorageForm"
          :rules="ruleValidate"
          :label-width="135"
          class="chooseStorageBox"
        >
          <FormItem
            label="入库实体仓"
            prop="physicalStorage"
          >
            <!-- v-model="StorageForm.physicalStorage.value" -->
            <Select
              label-in-value
              filterable
              placeholder="请选择仓库"
              v-model="StorageForm.physicalStorage && StorageForm.physicalStorage.value"
              @on-change="changePhysicalStorage"
            >
              <Option v-for="item in physicalStorageList" :key="item.value" :value="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>
          <FormItem
            label="默认入库逻辑仓"
            prop="defaultStorage"
          >
            <!-- v-model="StorageForm.defaultStorage.value" -->
            <Select
              label-in-value
              filterable
              placeholder="请选择仓库"
              :disabled='!StorageForm.physicalStorage.value'
              v-model="StorageForm.defaultStorage && StorageForm.defaultStorage.value"
              @on-change="changeDefaultStorage"
            >
              <Option v-for="item in storageList" :key="item.value" :value="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem>
          <!-- <FormItem
            label="瑕疵品/残次品仓库"
            prop="isOpenOtherGoods"
          >
            <i-switch
              :disabled='!StorageForm.physicalStorage.value'
              v-model="StorageForm.isOpenOtherGoods"
              @on-change="changeIsOpenOtherGoods"
            />
          </FormItem> -->
          <!-- <FormItem
            v-if="StorageForm.isOpenOtherGoods && StorageForm.physicalStorage.value"
            label="瑕疵品入库逻辑仓"
            prop="defectiveGoodsStorage"
          >
            <Select
              label-in-value
              filterable
              placeholder="请选择仓库"
              v-model="StorageForm.defectiveGoodsStorage && StorageForm.defectiveGoodsStorage.value"
              @on-change="changeDefectiveStorage"
            >
              <Option v-for="item in storageList" :key="item.value" :value="item.value">{{ item.label }}</Option>>
            </Select>
          </FormItem> -->
          <!-- <FormItem
            v-if="StorageForm.isOpenOtherGoods && StorageForm.physicalStorage.value"
            label="残次品入库逻辑仓"
            prop="defectiveGoodsStorage"
          >
            <Select
              label-in-value
              filterable
              placeholder="请选择仓库"
              v-model="StorageForm.imperfectionsStorage && StorageForm.imperfectionsStorage.value"
              @on-change="changeImperfectionsStorage"
            >
              <Option v-for="item in storageList" :key="item.value" :value="item.value">{{ item.label }}</Option>
            </Select>
          </FormItem> -->
        </Form>
      </div>
      <div class="bottomBtnBox">
        <Button
          type="primary"
          size="small"
          class="sureBtn"
          @click="sureStorage"
        >
          确定
        </Button>
      </div>
    </Modal>
    <!-- 录入商品不在退单/订单的商品列表中弹框 -->
    <Modal
      v-model="isShowSureEnterGood"
      mask
      :mask-closable="maskClosable"
      title="提示"
      title-align="left"
      class-name="showTipModel"
      width="470px"
      @on-ok="sureEnterGood"
      @on-cancel="cancelEnterGood"
    >
      <p><i class="iconfont iconbj_doubt fcWarning " />{{ TipTitle }}</p>
    </Modal>
     <!-- 录入商品不在退单/订单的商品列表中弹框,参数限制不允许强制出库 -->
    <Modal
      v-model="isShowSureEnterGoodOne"
      mask
      :mask-closable="maskClosable"
      title="提示"
      title-align="left"
      class-name="showTipModel showTipModelOne"
      width="470px"
    >
      <p><i class="iconfont iconbj_doubt fcWarning " />{{ TipTitleOne }}</p>
    </Modal>
    <!-- 换货详情弹框exchangeDetailModel -->
    <Modal
      v-model="exchangeDetailModel"
      title="换货商品详情"
      width="1000"
      :mask="mask"
      :closable="closable"
      :mask-closable="maskClosable"
      :footer-hide="hideFoot">
      <div style = 'height:300px;overflow-y:auto;'>
        <Table
        class='exchangeDetailTable'
        :columns="exchangeDetailColumns"
        :data="ExchangeGoodsList"
        highlight-row
        ></Table>
      </div>
    </Modal>
    <!-- 颜色标签弹框 -->
    <Modal
      v-model="colorTagModel"
      :title="colorTagTitle"
      width="520"
      :mask="mask"
      :closable="closable"
      :mask-closable="maskClosable"
      :footer-hide="hideFoot">
      <div
        class="modifyComColorTag"
      >
        <Form
          ref="formInlineColor"
          :model="formInlineColor"
          :rules="ruleInlineColor"
          :label-width="60"
          label-position="left"
        >
          <FormItem
            label="说明"
            prop="colorExplain"
            class="LOGISTICSCOMPNAYNAME"
          >
            <Select
              label-in-value
              @on-change="changecolorExplain"
            >
              <Option
                v-for="item in colorExplainList"
                :key="item.value"
                :value="item.value"
              >
                {{ item.label }}
              </Option>
            </Select>
          </FormItem>
          <FormItem
            label="颜色"
            prop="colorValue"
            disabled
            class="LOGISTICSCOMPNAYNAME"
          >
            <ColorPicker
              v-model="formInlineColor.colorValue"
              disabled
            />
          </FormItem>
        </Form>
        <div class="bottomBtnBox">
          <Button
            size="small"
            class="cancelBtn"
            ghost
            @click="cancelColor"
          >
            取消
          </Button>
          <Button
            :loading="loading"
            type="primary"
            size="small"
            class="sureBtn"
            @click="handleColorTag"
          >
            确认
          </Button>
        </div>
      </div>
    </Modal>
    <!-- 声音提示 -->
    <!-- 扫描商品编码 -->
    <audio
      id="audioscanoutok"
      preload="auto"
    >
      <source :src="urlscanoutok">
    </audio>
    <!-- 扫描物流单号 -->
    <audio
      id="audioscanExpress"
      preload="auto"
    >
      <source :src="urlscanExpress">
    </audio>
    <!-- 入库成功 -->
    <audio
      id="audiosuccess"
      preload="auto"
    >
      <source :src="urlsuccess">
    </audio>
    <!-- 入库失败 -->
    <audio
      id="audioerror"
      preload="auto"
    >
      <source :src="urlerror">
    </audio>
    <!-- 提示音 -->
    <audio
      id="audiosacnOk"
      preload="auto"
    >
      <source :src="urlsacnOk">
    </audio>
  </div>
</template>

<script>
  // import R3 from '../../../static/r3/r3.publish/r3.min';
  const R3 = window.R3;
  import foldPanel from '../customizedContent/FoldPanel.vue';

  const { network, urlSearchParams, store } = R3;
  export default {
    components: { foldPanel },
    data() {
      return {
        loading: false,
        urlerror: '', // error:失败
        urlsacnOk: '', // sacnOk：单纯提示
        urlscanExpress: '', // scanExpress：扫描物流单
        urlscanoutok: '', // scanoutok：扫描商品
        urlsuccess: '', // success：成功
        // urlerror: '../../../iframe/Scripts/mp3/error.mp3', // error:失败
        // urlsacnOk: '../../../iframe/Scripts/mp3/sacnOk.mp3', // sacnOk：单纯提示
        // urlscanExpress: '../../../iframe/Scripts/mp3/scanExpress.mp3', // scanExpress：扫描物流单
        // urlscanoutok: '../../../iframe/Scripts/mp3/scanoutok.mp3', // scanoutok：扫描商品
        // urlsuccess: '../../../iframe/Scripts/mp3/success.mp3', // success：成功
        audioType: '',
        isOpen: true,
        linkGoodsStatus: true,
        scanInStorageOrderStatus: true,
        OrderStatus: true,
        haveOrder: false,
        isReturnOrderFlag: true,

        colorTagModel: false, //颜色标签弹框显示
        colorTagTitle: '颜色标签', //颜色标签弹框标题
        colorExplainList: [], // 存储已有的颜色标签
        colorOldList: [],
        formInlineColor: {
          colorValue: '',
          colorExplain: '',
        },
        ruleInlineColor: {
          colorValue: [
            { required: true, message: '请选择颜色', trigger: 'blur' }
          ],
          colorExplain: [
            { required: true, message: '请填写说明', trigger: 'blur' }
          ],
        },
        addColorList: [],

        colorTypeList: [
          {
            label: '颜色标签',
            value: 1
          },
          {
            label: '取消标签',
            value: 2
          }
        ], // 颜色标签类型
        colorList: [], // 已有颜色列表
        // 物流公司参数
        ExpressList: {}, // 入库仓库下拉展示数据
        ExpresstotalRowCount: 0,
        ExpresscurrentIndex: 0, // 入库仓库搜索初始index
        ExpressAutoData: [], // 入库仓库模糊搜索的结果组
        columns: ['name', 'value'], // 展现的组
        defaultSelected: [],

        // 选择仓库弹框
        selectStorageInModal: false,
        mask: true,
        closable: true,
        maskClosable: false,
        hideFoot: true,
        StorageForm: {
          physicalStorage: {
            value: '',
            label: ''
          },
          defaultStorage: {
            value: '',
            label: ''
          },
          // isOpenOtherGoods: false,
          // defectiveGoodsStorage:  {
          //   value: '',
          //   label: ''
          // },
          // imperfectionsStorage:  {
          //   value: '',
          //   label: ''
          // },
        },
        ruleValidate: {
          physicalStorage: [
            { required: true, message: '请选择入库实体仓', trigger: 'blur'}
          ],
          defaultStorage: [
            { required: true, message: '请选择默认入库仓库', trigger: 'blur' }
          ],
          // isOpenOtherGoods: [
          //   { required: true, message: '请选择瑕疵品/残次品仓库', trigger: 'blur' }
          // ],
          // defectiveGoodsStorage: [
          //   { required: true, message: '请选择瑕疵品仓库', trigger: 'blur' }
          // ],
          // imperfectionsStorage: [
          //   { required: true, message: '请选择残次品仓库', trigger: 'blur' }
          // ]
        },
        physicalStorageList: [], //入库实体仓列表数据
        storageList: [], // 仓库列表数据
        autoSubmit: true, // 是否自动提交
        formInline: {
          expressCode: '',
          SKUCode: ''
        },
        scanInStorageOrderMsg: {
          expressName: [],
          expressCode: '',
          customerNickName: '',
          customerName: '',
          customerMobile: '',
          customerPhone: '',
          customerPlatform: '', //平台
          customerShop:'',//店铺
          customerAddr: '',
          remark: ''
        },
        explainContent:'在强制入库时必填',
        platformList:[],
        shopList:[],
        isExpress:false,//判断是否由快递单号带出
        hasPlatform:true,
        disabled:false,//根据运单号带出信息时,不可编辑
        tableHeight: 400,
        tableHeightOne: 250,
        markOptions: [ // 商品标记
          {
            name: '正品',
            value: 1
          },
          {
            name: '瑕疵品',
            value: 2
          },

          {
            name: '残次品',
            value: 3
          }
        ],
        linkGoodsColumns: [
          {
            title: '商品图片',
            key: 'pic_url',
            width: 76,
            render: (h,params) => {
              return h(
                'img',
                {
                  attrs: {
                    src: params.row.pic_url?params.row.pic_url:'../../../static/img/camera.jpg',
                  },
                  style: {
                    height: '60px',
                    width: '60px'
                  },
                  on: {
                    mouseover: (e) => {
                      const value = params.row.pic_url
                      var img=document.createElement("img");
                      img.id='previewImg'
                      img.src=value?value:'../../../static/img/camera.jpg'
                      img.style.height='200px'
                      img.style.width='200px'
                      img.style.position='fixed'
                      img.style.zIndex='999'

                      const windowHeight = $(window).height();
                      const scrollTop = $(window).scrollTop();
                      img.style.bottom = 10 + windowHeight - scrollTop -  $(e.target).offset().top + 'px'
                      img.style.left= -30 + $(e.target).offset().left + 'px'
                      $('body').append(img)
                    },
                    mouseout: () => {
                      $("#previewImg").remove();
                    }
                  },
                },
              );
            }
          },
          {
            title: '商品名称',
            key: 'title'
          },
          {
            title: '商品编码',
            key: 'productcode'
          },
          {
            title: '商品SKU',
            key: 'sku_no'
          },
          {
            title: '规格',
            key: 'normsdetailnames'
          },
          {
            title: '国标码',
            key: 'gbcode'
          },
          {
            title: '原唯一码',
            key: 'qrcode'
          },
          {
            title: '入库唯一码',
            key: 'stoInQrcode',
            render: (h,params) => {
              return h(
                'div',
                {
                  style: {
                    color: params.row.stoInQrcodeColor == 'green'?'green':'orange'
                  },
                },
                [params.row.stoInQrcode]
              );
            }
          },
          {
            title: '商品标记',
            align: 'left',
            key: 'productRemark',
            width: 150,
            render: (h, params) => {
              const vm = this;
              return h('Select', {
                         style: {
                           zIndex: 999
                         },
                         props: {
                           transfer: true,
                           value: params.row.productRemark, // 获取选择的下拉框的值
                         },
                         on: {
                           'on-change': (e) => {
                             vm.linkGoodsData[params.index].productRemark = e;
                           }
                         }
                       },
                       vm.markOptions.map(item => h('Option', {
                         props: {
                           value: item.value, // 绑定的值
                         }
                       }, item.name)));
            }
          },
          {
            title: '应入数量',
            key: 'qty',
            width: 76
          },
          {
            title: '扫描数量',
            key: 'scanInNum',
            width: 76
          },
        ], // 扫描商品表格表头
        linkGoodsData: [], // 扫描商品数据
        TipTitle: '', // 扫描商品提示信息
        isShowSureEnterGood: false, // 明细中不存在该商品
        TipTitleOne: '', // 扫描商品提示信息
        isShowSureEnterGoodOne: false, // 明细中不存在该商品
        // showCancel:false,
        singleGoodValue: '',
        scanGoodMsg: {},

        // 原退单/订单信息
        oldOrderMsg: {
          retureOrderCode: '', // 退单编号
          orderCode: '', // 原订单编号
          expressCode: '', // 退回物流单号
          sourceCodes: '', // 原平台单号
          user_name: '', // 姓名
          tel: '', // 电话
          remark: '', // 备注
          phone: '', // 手机号
          delivery_address: '', // 收件地址
          platform:'',//平台
          shop:'',//店铺
          buyer_nick: '', // 买家昵称
          shipper_name: '', // 退回物流公司
          warehouse_name: '', // 发货仓库
        },
        isFirst: true, // 是否初始化页面
        // CutRight: '', // 商品SKU右侧截断位数
        // CutLeft: '', // 商品SKU左侧截断位数
        InStoreToDefault: false, // 扫描入库退回至店铺默认退货仓,默认为否
        onlyReturnQRCODE: false, // 是否开启仅支持退单/订单中商品唯一码入库
        onlySKUControl: false, // 是否开启仅支持唯一码入库
        isQrcode: false, // 订单明细中商品是否唯一码管控

        ReturnGoodsNum: '', // 退货商品总数量
        ExchangeFlag: false, // 是否换货

        exchangeDetailModel: false, // 换货详情弹框
        exchangeDetailColumns: [
          {
            title: '退换货单编号',
            align: 'center',
            key: 'refundId'
          },
          {
            title: '平台换货单号',
            align: 'center',
            key: 'disputeId'
          },
          {
            title: '商品名称',
            align: 'center',
            key: 'title'
          },
          {
            title: '商品编码',
            align: 'center',
            key: 'productcode'
          },
          {
            title: 'SKU',
            align: 'center',
            key: 'sku'
          },
          {
            title: '国际码',
            align: 'center',
            key: 'gbcode'
          },
          {
            title: '规格',
            align: 'center',
            key: 'normsdetailnames'
          },
          {
            title: '换货数量',
            align: 'center',
            key: 'refundnum'
          },
          {
            title: '库位',
            align: 'center',
            key: 'storesite'
          },
        ],
        ExchangeGoodsList: [], // 换货商品详情列表

        scanTypeCode: '', // 扫描的退回单号
        isInStore_byProductcode: true, // 串款是否允许强制入库
        unMatchRefundShowTips: false, // 扫描入库匹配不到售后单是否提示

        unInstoreRefundNeNum:true, // 扫描入库数量不一致是否允许强制入库
        warehouse_id:"", // 订单原发货仓id
        showForcePower: false, // 强制入库按钮权限
        showAutoPower: false, // 自动匹配按钮权限
      };
    },
    created() {
      this.getPermission('force'); // 获取强制入库的功能权限
      this.getPermission('auto'); // 获取自动匹配的功能权限
      this.getOMSSOUNDSET();
      this.getParamsList(); // 获取系统参数
      this.getPhysicalStorageList();
      this.getPlatformList(); //获取平台列表
      this.getOnlyReturnQRCODE();
    },
    mounted() {
      this.getStorage();
      this.$refs.expressEnter.focus();
    },
    computed: {
      agColumns() {
        const columns = this.linkGoodsColumns.map(item => {
          return {
            ...item,
            field: item.key,
            headerName: item.title,
            suppressMenu: true,
            tdAlign: 'left'
          }
        })
        return columns
      }
    },
    watch: {
      'formInline.expressCode': {
        // 使用新的物流单号时，清空商品sku
        handler(newVal, oldVal) {
          if (newVal != oldVal) {
            this.formInline.SKUCode = ''
          }
        },
      },
    },
    methods: {
      getPermission(type){
        if(type == 'force') {
          let params = {
            "ad_table_id": 0,
            "ad_action_id": 4036
          }
          network.post('/p/cs/group/have/permission', params).then((res) => {
            if(res.data.code == 0){
              this.showForcePower = res.data.data
            }
          })
        }else if(type == 'auto'){
          let params = {
            "ad_table_id": 0,
            "ad_action_id": 4037
          }
          network.post('/p/cs/group/have/permission', params).then((res) => {
            if(res.data.code == 0){
              this.showAutoPower = res.data.data
            }
          })
        }
      },
      agRenderParams(cellData) {
        let renderComponent = null
        if (cellData.field === 'pic_url') {
          renderComponent = {
              renderContainer: 'CellRenderByFunction', // 设置渲染方式为render函数
              renderComponent: (h,params) => {
                return h(
                  'img',
                  {
                    attrs: {
                      src: params.row.pic_url?params.row.pic_url:'../../../static/img/camera.jpg',
                    },
                    style: {
                      height: '60px',
                      width: '60px'
                    },
                    on: {
                      mouseover: (e) => {
                        const value = params.row.pic_url
                        var img=document.createElement("img");
                        img.id='previewImg'
                        img.src=value?value:'../../../static/img/camera.jpg'
                        img.style.height='200px'
                        img.style.width='200px'
                        img.style.position='fixed'
                        img.style.zIndex='999'

                        const windowHeight = $(window).height();
                        const scrollTop = $(window).scrollTop();
                        img.style.bottom = 10 + windowHeight - scrollTop -  $(e.target).offset().top + 'px'
                        img.style.left= -30 + $(e.target).offset().left + 'px'
                        $('body').append(img)
                      },
                      mouseout: () => {
                        $("#previewImg").remove();
                      }
                    },
                  },
                );
              }
          }
        }
        if(cellData.field === 'stoInQrcode') {
          renderComponent = {
            renderContainer: 'CellRenderByFunction',
            renderComponent: (h,params) => {
              return h(
                'div',
                {
                  style: {
                    color: params.row.stoInQrcodeColor == 'green'?'green':'orange'
                  },
                },
                [params.row.stoInQrcode]
              );
            }
          }
        }
        if(cellData.field === 'productRemark') {
          renderComponent = {
            renderContainer: 'CellRenderByFunction',
            renderComponent: (h, params) => {
              const vm = this;
              return h('Select', {
                         style: {
                           zIndex: 999
                         },
                         props: {
                           transfer: true,
                           value: params.row.productRemark, // 获取选择的下拉框的值
                         },
                         on: {
                           'on-change': (e) => {
                             vm.linkGoodsData[params.index].productRemark = e;
                           }
                         }
                       },
                       vm.markOptions.map(item => h('Option', {
                         props: {
                           value: item.value, // 绑定的值
                         }
                       }, item.name)));
            }
          }
        }
        return renderComponent
      },

      getOMSSOUNDSET() {
          let virtual={
              range: 100,
              startindex: 0,
              table: 'T_OMSSOUNDSET',
              fkdrplist: {
                searchcols: ['TYPE_NAME', 'ID', 'SOUND_ID', 'URL']
              },
              isdroplistsearch: true,
          }
          network.post('/p/cs/list/query', virtual).then((res) => {
              res.data.rows.forEach(row => {
                  if(row.TYPE_NAME.val == '提示'){
                    this.urlsacnOk = row.URL.val
                  }else if(row.TYPE_NAME.val == '成功'){
                    this.urlsuccess = row.URL.val
                  }else if(row.TYPE_NAME.val == '失败'){
                    this.urlerror = row.URL.val
                  }else if(row.TYPE_NAME.val == '扫描商品'){
                    this.urlscanoutok = row.URL.val
                  }else if(row.TYPE_NAME.val == '扫描物流'){
                    this.urlscanExpress = row.URL.val
                  }
              })
              console.log(this.urlscanExpress)
          })
      },
      clickMenu(val) {
        this.colorTagTitle = val;
        this.colorTagModel=true;
        this.getColorExplainList();
      },
      getColorExplainList() {
        this.colorExplainList = [];
        let virtual = {
          searchdata: {
            table: 'T_IESCOLOR_MARK',
            startindex: 0,
            range: 200,
            fixedcolumns: {},
            column_include_uicontroller: true,
            isolr: false
          }
        };
        network.post('/p/cs/QueryList', urlSearchParams(virtual)).then((res) => {
          res.data.data.row.forEach(item => {
            let obj = {
              label: item.REMARK.val,
              // value: item.CVALUE.val
              value: item.ID.val
            };
            this.colorExplainList.push(obj);
          });
          this.colorOldList = res.data.data.row;
        });
      },
      changecolorExplain(val) {
        this.formInlineColor.colorExplain = val.label;
        this.formInlineColor.id = val.value;
        this.colorOldList.forEach(item => {
          if (item.ID.val == val.value) {
            this.formInlineColor.colorValue = JSON.parse(item.CVALUE.val).color;
          }
        });
      },
      cancelColor() {
        this.colorTagModel = false;
        this.formInlineColor = { // 重置颜色弹框
          colorValue: '',
          colorExplain: '',
        }
      },
      handleColorTag() {
        if (!this.formInlineColor.colorExplain) {
          return this.$Message.warning('请选择说明');
        }
        let params = {};
        let url = '';
        if(this.colorTagTitle == '颜色标签') {
          let obj = {
            id: this.formInlineColor.id,
            color: this.formInlineColor.colorValue,
            text: this.formInlineColor.colorExplain
          }
          this.addColorList.push(obj);
          this.colorList = this.distinct1([...this.colorList,...this.addColorList],'color');
          this.cancelColor();
        }else if(this.colorTagTitle == '取消标签') {
          if(this.oldOrderMsg.retureOrderCode){
            params = {
              type: 3,
              ids: this.oldOrderMsg.retureOrderCode.split(','),
              color: [this.formInlineColor.colorValue]
            }
            url = '/p/cs/color/mark/rel/cancel/linkage'
          } else {
            params = {
              type: 1,
              ids: this.oldOrderMsg.orderCode.split(','),
              color: [this.formInlineColor.colorValue]
            }
            url = '/p/cs/color/mark/rel/cancel'
          }
          network.post(url,params).then(res => {
            if(res.data.code == 0){
              this.cancelColor();
              this.getBillColorList();
              this.$Message.success('取消颜色标签成功')
            }else {
              this.$Message.error(res.datd.message);
            }
          })
        }
      },
      // 添加标签,只针对入库单
      addColorTagaAfterBill(id) {
          let params = {
            type: 2,
            ids: [id],
            colorIds: this.addColorList.map(item => {return item.id})
          }
          let url = '/p/cs/color/mark/rel/linkage'
          network.post(url,params).then(res => {
            if(res.data.code == 0){
              this.colorList = []; //置空色块
              this.addColorList = []; // 置空之前设置的色块
              this.cancelColor();
              // this.getBillColorList();
              this.$Message.success('添加颜色标签成功')
            }else {
              this.$Message.error(res.datd.message);
            }
          })
      },
      // 无新增标签，通知入库单合并退换货单的颜色标签
      refoColorTagAfterBill(id) {
          let params = {
            id: id
          }
          let url = '/p/cs/color/mark/rel/linkage/returnInStore'
          network.post(url,params).then(res => {
            if(res.data.code == 0){
              this.colorList = []; //置空色块
              this.addColorList = []; // 置空之前设置的色块
              this.cancelColor();
            }else {
              this.$Message.error(res.datd.message);
            }
          })
      },
      // 查看换货详情
      exchangeDetail(){
        this.exchangeDetailModel = true;
      },
      getPlatformList(query){
         let virtual={
          fixedcolumns: query?{PLATFORMNAME:query}:{},
          range: 1000,
          startindex: 0,
          table: 'T_V_OMSPLATFORM'
        }
        network.post('/p/cs/list/query', virtual).then((res) => {
           this.platformList= res.data.rows.map(i=>{
              return {
                label:i.PLATFORMNAME.val,
                value:i.ID.val
              }
            })
        })
      },
      selectPlatform(val){
        if(this.scanInStorageOrderMsg.customerPlatform){
          if(this.isExpress){
            this.isExpress=false
          }else{
            this.hasPlatform=false
            this.getShopList() //获取店铺列表
          }

        }else{
          this.scanInStorageOrderMsg.customerShop=''
          this.disabled=false
          this.hasPlatform=true
        }
      },
      getShopList(query){
        if(this.scanInStorageOrderMsg.customerPlatform){
          let virtual={
            fixedcolumns: query?{SHOPTITLE:query,PLATFORM:this.scanInStorageOrderMsg.customerPlatform}:{PLATFORM:this.scanInStorageOrderMsg.customerPlatform},
            range: 1000,
            startindex: 0,
            table: 'T_IESSHOP'
          }
          network.post('/p/cs/list/query', virtual).then((res) => {
            this.shopList= res.data.rows.map(i=>{
                return {
                  label:i.SHOPTITLE.val,
                  value:i.ID.val
                }
              })
          })
        }

      },

      closeChooseStoreDialog() {
        this.selectStorageInModal = false;
        this.getStorage();
      },
      reset() {
        this.formInline = {
          expressCode: '',
          SKUCode: ''
        };
        this.haveOrder = false;
        this.clearMsg();
      },
      clearMsg() {
        this.getPlatformList() //重新获取平台列表
        this.defaultSelected = [];
        this.scanInStorageOrderMsg = {
          expressName: [],
          expressCode: '',
          customerNickName: '',
          customerName: '',
          customerMobile: '',
          customerPhone: '',
          customerPlatform: '', //平台
          customerShop:'',//店铺
          customerAddr: '',
          remark: ''
        };
        if(this.scanInStorageOrderMsg.customerPlatform){
          this.hasPlatform=false
        }else{
          this.scanInStorageOrderMsg.customerShop=''
          this.hasPlatform=true
        }
        this.linkGoodsData = [];
        this.oldOrderMsg = {
          retureOrderCode: '', // 退单编号
          orderCode: '', // 原订单编号
          expressCode: '', // 退回物流单号
          sourceCodes: '', // 原平台单号
          user_name: '', // 姓名
          tel: '', // 电话
          remark: '', // 备注
          phone: '', // 手机号
          delivery_address: '', // 收件地址
          platform:'',//平台
          shop:'',//店铺
          buyer_nick: '', // 买家昵称
          shipper_name: '', // 退回物流公司
        };
        this.ReturnGoodsNum = 0
        this.ExchangeFlag = false
      },

      // 获取当前设置的系统参数
      getParamsList(type) {
        network.post('/p/cs/getSysParams', {}).then(res => {
          if (res.data.code == 0) {
            let allParamsList = []
            res.data.data.forEach(item => {
              allParamsList=[...allParamsList,...item.sysParam]
            })
            allParamsList.forEach(param => {
              if(param.paraName == 'InStoreToDefault'){
                this.InStoreToDefault = param.paraValue;
                if(!this.InStoreToDefault || this.InStoreToDefault == 'false' || this.InStoreToDefault == 'False' || this.InStoreToDefault == 'FALSE'){
                  this.recordLoginTime(); // 判断用户是否当日第一次进入页面
                }
              }
              if(param.paraName == 'isInStore_byProductcode'){
                if(!param.paraValue || param.paraValue == 'false' || param.paraValue == 'False' || param.paraValue == 'FALSE'){
                  this.isInStore_byProductcode = false
                }else {
                  this.isInStore_byProductcode = true
                }
              }
              if(param.paraName == 'unMatchRefundShowTips'){
                if(!param.paraValue || param.paraValue == 'false' || param.paraValue == 'False' || param.paraValue == 'FALSE'){
                  this.unMatchRefundShowTips = false
                }else {
                  this.unMatchRefundShowTips = true
                }
              }
              if(param.paraName == 'unInstoreRefundNeNum'){
                if(!param.paraValue || param.paraValue == 'false' || param.paraValue == 'False' || param.paraValue == 'FALSE'){
                  this.unInstoreRefundNeNum = false
                }else {
                  this.unInstoreRefundNeNum = true
                }
              }
            })
          }
        })
      },
      // 获取当前用户选择的仓库
      getStorage() {
        let firstDate = localStorage.getItem('firstDate') ? JSON.parse(localStorage.getItem('firstDate')) : [];
        let id = JSON.parse(window.localStorage.getItem('userInfo')).id;
        let obj = {
          value: '',
          label: ''
        }
        if (firstDate.length > 0) {
          for (let i = 0; i < firstDate.length; i++) {
            if (firstDate[i].id == id) {
              if (firstDate[i].storageList) {
                this.StorageForm.physicalStorage = firstDate[i].storageList.physicalStorage;
                this.StorageForm.defaultStorage = firstDate[i].storageList.defaultStorage ? JSON.parse(JSON.stringify(firstDate[i].storageList.defaultStorage)):obj;
                // this.StorageForm.isOpenOtherGoods = firstDate[i].storageList.isOpenOtherGoods;
                // this.StorageForm.defectiveGoodsStorage = JSON.parse(JSON.stringify(!firstDate[i].storageList.isOpenOtherGoods ? firstDate[i].storageList.defaultStorage : firstDate[i].storageList.defectiveGoodsStorage));
                // this.StorageForm.imperfectionsStorage = JSON.parse(JSON.stringify(!firstDate[i].storageList.isOpenOtherGoods ? firstDate[i].storageList.defaultStorage : firstDate[i].storageList.imperfectionsStorage));
              }else {
                // this.selectStorageInModal = true;
              }
            }
          }
        }
      },
      // 获取物流公司列表
      getExpressList() {
        let virtual = {
          searchdata: {
            isdroplistsearch: true,
            refcolid: 196700,
            startindex: 0,
            range: 10,
          }
        };
        network.post('/p/cs/QueryList', urlSearchParams(virtual)).then((res) => {
          if (res.data.code == 0) {
            this.ExpresstotalRowCount = res.data.data.totalRowCount;
            this.ExpressList = res.data.data;
            this.ExpresscurrentIndex = 0;
          }
        });
      },
      // 判断是否今日第一次进入该页面
      recordLoginTime() {
        let firstDate = localStorage.getItem('firstDate') ? JSON.parse(localStorage.getItem('firstDate')) : [];
        // 获取当前时间（年月日）
        let now = new Date().toLocaleDateString();
        // 转换成时间戳
        let time = Date.parse(new Date(now));
        let id = JSON.parse(window.localStorage.getItem('userInfo')).id;
        let obj = {
          time,
          id,
        };
        let isHaveId = false;
        if (firstDate.length > 0) {
          for (let i = 0; i < firstDate.length; i++) {
            if (firstDate[i].id == id) {
              isHaveId = true;
              if (time > firstDate[i].time) {
                // this.selectStorageInModal = true;
                this.showStorageModal();
                firstDate[i].time = time;
                localStorage.removeItem('task');
                localStorage.setItem('firstDate', JSON.stringify(firstDate));
              }
              break;
            }
          }
          if (!isHaveId) {
            // this.selectStorageInModal = true;
            this.showStorageModal();
            firstDate.push(obj);
            localStorage.removeItem('task');
            localStorage.setItem('firstDate', JSON.stringify(firstDate));
          }
        } else {
          // this.selectStorageInModal = true;
          this.showStorageModal();
          firstDate.push(obj);
          localStorage.removeItem('task');
          localStorage.setItem('firstDate', JSON.stringify(firstDate));
        }
      },
      // 弹框
      showStorageModal() {
        this.getStorageList(this.StorageForm.physicalStorage.value);
        this.selectStorageInModal = true;
        setTimeout(() => {
          this.getStorage()
          // this.selectStorageInModal = true;
        },500)
      },
      // 注意展开关闭
      toggleArrow() {
        this.isOpen = !this.isOpen;
      },
      // changeIsOpenOtherGoods(val) {
      //   if (!val && this.storageList.length > 1) {
      //     this.StorageForm.defectiveGoodsStorage = '';
      //     this.StorageForm.imperfectionsStorage = '';
      //   }
      // },
      // 自动提交
      changeAutoSubmit(val) {
        console.log(this.autoSubmit);
      },
      // 获取入库实体仓列表
      getPhysicalStorageList() {
        // network.post('/p/cs/QueryList', urlSearchParams({
        //   searchdata: {
        //     table:"T_IESWAREHOUSE",
        //     startindex:0,
        //     range:1000,
        //     fixedcolumns:{},
        //     column_include_uicontroller:true,
        //     isolr:false
        //   }
        // })).
        network.post('/p/cs/store/getStoreList',{}).then(res => {
          let list = [];
          res.data.data.forEach(item => {
            let obj = {
              label: item.WAREHOUSENAME,
              value: item.ID
            };
            list.push(obj);
          });
          if(res.data.data.length == 1){
            this.StorageForm.physicalStorage = list[0];
            this.getStorageList(this.StorageForm.physicalStorage.value)
          }
          this.physicalStorageList = list;
        })
      },
      // 获取仓库列表
      getStorageList(val) {
        if(val){
            network.post('/p/cs/store/getStoreByhouseId', {ID:val}).then(res => {
            if(res.data.data && res.data.data.length > 0){
              let list = [];
              res.data.data.forEach(item => {
                let obj = {
                  label: item.STORENAME,
                  value: item.ID
                };
                list.push(obj);
              });
              if(res.data.data.length == 1){
                this.StorageForm.defaultStorage = list[0];
                // this.StorageForm.defectiveGoodsStorage = list[0];
                // this.StorageForm.imperfectionsStorage = list[0];
                this.StorageForm.defaultStorage = JSON.parse(JSON.stringify(this.StorageForm.defaultStorage))
                // this.StorageForm.defectiveGoodsStorage = JSON.parse(JSON.stringify(this.StorageForm.defectiveGoodsStorage))
                // this.StorageForm.imperfectionsStorage = JSON.parse(JSON.stringify(this.StorageForm.imperfectionsStorage))
              } else if(!this.isFirst){
                this.StorageForm.defaultStorage = {
                  value: '',
                  label: ''
                };
                // this.StorageForm.defectiveGoodsStorage = {
                //   value: '',
                //   label: ''
                // };
                // this.StorageForm.imperfectionsStorage = {
                //   value: '',
                //   label: ''
                // };
              }
              this.isFirst = false;
              this.storageList = list;
            }else {
              this.StorageForm.defaultStorage = {
                  value: '',
                  label: ''
                };
                // this.StorageForm.defectiveGoodsStorage = {
                //   value: '',
                //   label: ''
                // };
                // this.StorageForm.imperfectionsStorage = {
                //   value: '',
                //   label: ''
                // };
              this.storageList = [];
            }
          });
        }
      },
      // 选择入库实体仓
      changePhysicalStorage(val) {
        if(this.StorageForm.physicalStorage !== val.value){
          this.StorageForm.physicalStorage = val;
          this.getStorageList(val.value);
        }
      },
      // 选择默认仓库
      changeDefaultStorage(val) {
        if(val){
          this.StorageForm.defaultStorage = val;
        }else {
          this.StorageForm.defaultStorage = {
            value: '',
            label: ''
          }
        }
      },
      // 选择瑕疵品仓库
      // changeDefectiveStorage(val) {
      //   this.StorageForm.defectiveGoodsStorage = val;
      // },
      // 选择残次品仓库
      // changeImperfectionsStorage(val) {
      //   this.StorageForm.imperfectionsStorage = val;
      // },
      // 确认入库仓库
      sureStorage() {
        if (!this.StorageForm.physicalStorage || this.StorageForm.physicalStorage.value == '') {
          return this.$Message.warning('请选择入库实体仓');
        }
        if (!this.StorageForm.defaultStorage || this.StorageForm.defaultStorage.value == '') {
          return this.$Message.warning('请选择默认入库仓库');
        }
        // if (this.StorageForm.isOpenOtherGoods) {
        //   if (!this.StorageForm.defectiveGoodsStorage || this.StorageForm.defectiveGoodsStorage.value == '') {
        //     return this.$Message.warning('请选择瑕疵品入库仓库');
        //   } if (!this.StorageForm.imperfectionsStorage ||this.StorageForm.imperfectionsStorage.value == '') {
        //     return this.$Message.warning('请选择残次品入库仓库');
        //   }
        // } else {
        //   this.StorageForm.defectiveGoodsStorage = JSON.parse(JSON.stringify(this.StorageForm.defaultStorage));
        //   this.StorageForm.imperfectionsStorage = JSON.parse(JSON.stringify(this.StorageForm.defaultStorage));
        // }
        this.$refs.expressEnter.focus();
        this.selectStorageInModal = false;
        let firstDate = localStorage.getItem('firstDate') ? JSON.parse(localStorage.getItem('firstDate')) : [];
        let id = JSON.parse(window.localStorage.getItem('userInfo')).id;
        if (firstDate.length > 0) {
          for (let i = 0; i < firstDate.length; i++) {
            if (firstDate[i].id == id) {
              let obj = {
                physicalStorage: this.StorageForm.physicalStorage,
                defaultStorage: this.StorageForm.defaultStorage,
                isOpenOtherGoods: this.StorageForm.isOpenOtherGoods,
                defectiveGoodsStorage: '',  //this.StorageForm.defectiveGoodsStorage
                imperfectionsStorage:'', // this.StorageForm.imperfectionsStorage
              };
              firstDate[i].storageList = obj;
              break;
            }
          }
          localStorage.removeItem('task');
          localStorage.setItem('firstDate', JSON.stringify(firstDate));
        }
      },
      // 扫描物流单获取信息前判断是否物流单号已经存在退货入库单中
      CheckLogisticsNoBefore(val){
        console.log(val)
        let haveUnFinishFlag = false; // 判断上一单是否扫描完成
        if(this.linkGoodsData.length > 0){
          for(let i=0;i<this.linkGoodsData.length;i++){
            if(this.linkGoodsData[i].scanInNum < this.linkGoodsData[i].qty){
              haveUnFinishFlag = true;
              break;
            }
          }
        }
        console.log(haveUnFinishFlag)
        if(haveUnFinishFlag){
          this.aplayAudio('sacnOk');
          this.$Modal.fcWarning({
            title: '提示',
            mask: true,
            showCancel: true,
            content: '商品未全部入库完成，是否要继续扫描下一张退单？',
            onOk:()=>{
              this.CheckLogisticsNo(val)
            },
            onCancel:()=>{
              this.formInline.expressCode = this.oldScanLogisticsNo
            }
          })
        }else {
          this.CheckLogisticsNo(val)
        }
      },
      CheckLogisticsNo(val) {
        if (val.target.value == '') {
          return this.$Message.warning('退回单号不能为空！');
        }
        let param = {
          logistics_no: val.target.value.trim()
        };
        network.post('/p/cs/returnInStore/checkLogisticsNo', param).then(res => {
          if(res.data.code == 0){
            if(res.data.data.isExistLogistics == 1){
              this.$Modal.fcWarning({
                title: '提示',
                mask: true,
                showCancel: true,
                content: '此物流单号已入库，是否重复强制入库？',
                onOk:()=>{
                  this.getExpressCode(val);
                  this.$refs.SKUEnter.focus();
                },
                onCancel:()=> {
                  this.reset()
                }
              })
            }else {
              this.getExpressCode(val)
            }
          }
        })
      },
      // 扫描物流单获取信息
      getExpressCode(val) {
        this.scanTypeCode = val.target.value.trim();
        this.isReturnOrderFlag = true;
        if (val.target.value == '') {
          return this.$Message.warning('退回单号不能为空！');
        }
        this.sureClick('scanExpress');
        let param = {
          logistics_no: val.target.value.trim()
        };
        this.warehouse_id = ''
        network.post('/p/cs/logistics/queryItemByLogisticsNo', param).then(res => {
          if(res.data.code == 0){
            this.addColorList = []; // 置空之前设置的色块
            this.ReturnGoodsNum = 0;
            this.ExchangeFlag = false;
            if(this.scanInStorageOrderMsg.expressCode !== val.target.value.trim()){
              this.clearMsg();
            }
            // let isReturnOrderFlag = true;
            this.oldOrderMsg.retureOrderCode = '';
            this.oldOrderMsg.orderCode = '';
            // this.oldOrderMsg.expressCode = val.target.value.trim();
            this.scanInStorageOrderMsg.expressCode = val.target.value.trim();
            if (res.data.data == '' || res.data.data == null) {
              this.linkGoodsData = [];
              this.retureOrderCode = '';
              this.orderCode = '';
              this.haveOrder = false;
              // this.clearMsg();
              this.oldOrderMsg.expressCode = val.target.value.trim();
              // this.scanInStorageOrderMsg.expressCode = val.target.value.trim();
              // this.sureClick('sacnOk');
              this.sureClick('error');
              this.$Message.error({
                    content: '未找到退换货单或订单，如需继续入库，可扫描商品进行强制入库',
                    duration: 3
              });
            } else if (!res.data.data.list || res.data.data.list.length == 0) {
              this.linkGoodsData = [];
              this.retureOrderCode = '';
              this.orderCode = '';
              this.haveOrder = false;
              // this.clearMsg();
              this.oldOrderMsg.expressCode = val.target.value.trim();
              // this.scanInStorageOrderMsg.expressCode = val.target.value.trim();
              // this.sureClick('sacnOk');
              this.sureClick('error');
              this.$Message.error({
                    content: '未找到退换货单或订单，如需继续入库，可扫描商品进行强制入库',
                    duration: 3
              });
            } else {
              if(res.data.data.list[0].bill_type == 1){
                if(this.unMatchRefundShowTips){
                  this.$Modal.fcWarning({
                      title: '提示',
                      mask: true,
                      showCancel: true,
                      content: '该物流单为拒收类型，入库后会生成拒收类型退货单，是否继续？',
                      onOk:()=>{
                        this.AfterScanExpresscode(res)
                      },
                      onCancel:()=>{
                        this.reset()
                      }
                  });
                }else {
                   this.AfterScanExpresscode(res)
                }
              }else {
                this.AfterScanExpresscode(res)
              }
            }
          }
        });
      },
      AfterScanExpresscode (res) {
        let list = [];
        let bill_nos = [];
              let ori_order_ids = [];
              let source_codes = [];
              this.haveOrder = true;
              this.$refs.SKUEnter.focus();
              if(!this.InStoreToDefault || this.InStoreToDefault == 'false' || this.InStoreToDefault == 'False' || this.InStoreToDefault == 'FALSE'){

              }else {
                this.StorageForm.physicalStorage = {
                  // res.data.data.ext.
                  label: res.data.data.ext.warehouse_name,
                  value: res.data.data.ext.warehouse_id
                }; // 获取到退单/订单所属店铺的实体仓（默认退回仓）
                if(res.data.data.ext.warehouse_id){
                  this.warehouse_id = res.data.data.ext.warehouse_id
                  this.getStorageList(res.data.data.ext.warehouse_id)
                }
              }
              // this.StorageForm.defaultStorage = ''; // 获取到退单/订单所属店铺的实体仓对应的逻辑仓
              if (res.data.data.list[0].bill_type == 1) {
                this.sureClick('sacnOk');
                this.isReturnOrderFlag = false;
                this.$Message.info('未找到退换货单，自动带出原订单信息!');
              }
              this.bill_type = res.data.data.list[0].bill_type
              for(let i=0;i<res.data.data.list.length;i++){
                if(res.data.data.list[i].isQrcode){
                  this.isQrcode = true;
                  break;
                }else {
                  this.isQrcode = false;
                }
              }
              res.data.data.list.forEach(item => {
                bill_nos.push(item.bill_id);
                ori_order_ids.push(item.ori_order_id);
                source_codes.push(item.source_code);
                if (item.qty > 1) {
                  let qrcodeList = item.qrcode?item.qrcode.split(','):[];
                  for (let i = 0; i < item.qty; i++) {
                    let obj = JSON.parse(JSON.stringify(item));
                    obj.qty = 1;
                    obj.productRemark = 1;
                    obj.scanInNum = 0;
                    obj.qrcode = qrcodeList[i]?qrcodeList[i]:'';
                    list.push(obj);
                  }
                } else {
                  let obj = item;
                  obj.productRemark = 1;
                  obj.scanInNum = 0;
                  list.push(obj);
                }
              });
              this.linkGoodsData = list;
              // 退货单/原订单信息
              if (this.isReturnOrderFlag) {
                this.oldOrderMsg.retureOrderCode = this.unique(bill_nos).join(',');
                this.oldOrderMsg.orderCode = this.unique(ori_order_ids).join(',');
                if(res.data.data.refundOrderProductDTOList && res.data.data.refundOrderProductDTOList.length > 0){
                  res.data.data.refundOrderProductDTOList.forEach(item => {
                    this.ReturnGoodsNum = Number(this.ReturnGoodsNum) +Number(item.refundnum)
                  })
                }
                // this.ReturnGoodsNum = res.data.data.refundOrderProductDTOList.length;
                this.ExchangeFlag = res.data.data.refundExchangeOrderProductDTOList && res.data.data.refundExchangeOrderProductDTOList.length>0?true:false;
                this.ExchangeGoodsList = res.data.data.refundExchangeOrderProductDTOList;
              } else {
                if(res.data.data.list && res.data.data.list.length > 0){
                  res.data.data.list.forEach(item => {
                    this.ReturnGoodsNum = Number(this.ReturnGoodsNum) +Number(item.qty)
                  })
                }
                // this.ReturnGoodsNum = res.data.data.list.length;
                this.ExchangeFlag = false;
                this.ExchangeGoodsList = [];
                this.oldOrderMsg.orderCode = this.unique(bill_nos).join(',');
              }
              // this.oldOrderMsg.orderCode = this.unique(ori_order_ids).join(',');
              this.oldOrderMsg.sourceCodes = this.unique(source_codes).join(',');
              this.oldOrderMsg.buyer_nick = res.data.data.ext.buyer_nick;
              this.oldOrderMsg.delivery_address = res.data.data.ext.delivery_address;
              this.oldOrderMsg.phone = res.data.data.ext.phone;
              this.oldOrderMsg.remark = res.data.data.ext.remark;
              this.oldOrderMsg.tel = res.data.data.ext.tel;
              this.oldOrderMsg.user_name = res.data.data.ext.user_name;
              this.oldOrderMsg.shipper_name = res.data.data.ext.shipper_name;
              this.oldOrderMsg.expressCode = res.data.data.ext.logistics_no;
              const stores = new Set()
              res.data.data.list.forEach(item => {
                stores.add(item.warehousename)
              })
              this.oldOrderMsg.warehouse_name = Array.from(stores).join(','); // 实体仓
              // 入库单信息
              let listExpress = [];
              let obj = {
                ID: res.data.data.ext.shipper_id,
                Label: res.data.data.ext.shipper_name
              };
              listExpress.push(obj);
              this.scanInStorageOrderMsg.expressName = listExpress;
              this.defaultSelected = listExpress;
              this.scanInStorageOrderMsg.customerNickName = res.data.data.ext.buyer_nick;
              this.scanInStorageOrderMsg.customerName = res.data.data.ext.user_name;
              this.scanInStorageOrderMsg.customerMobile = res.data.data.ext.phone;
              this.scanInStorageOrderMsg.customerPhone = res.data.data.ext.tel;
              // this.scanInStorageOrderMsg.logistics_number = res.data.data.ext.logistics_no; // 扫描带出物流单号赋值给入库单信息的物流单号
              let plat_form=res.data.data.ext.plat_form?res.data.data.ext.plat_form.toString():''
              let plat_form_name=res.data.data.ext.plat_form_name
              let shop_title=res.data.data.ext.shop_title
              let shop_id=res.data.data.ext.shop_id.toString()
              if(plat_form){
                this.isExpress=true//由快递单号带出
                this.disabled=true
                this.platformList=[
                  {
                    label:plat_form_name,
                    value:plat_form
                  }
                ]
                this.scanInStorageOrderMsg.customerPlatform=plat_form;//平台
                this.oldOrderMsg.platform=plat_form_name//退货单，原订单信息平台
              }else{
                this.disabled=false
              }
              if(shop_id){
                this.hasPlatform=true
                this.shopList= [
                  {
                    label:shop_title,
                    value:shop_id
                  }]
                this.scanInStorageOrderMsg.customerShop=shop_id//店铺
                this.oldOrderMsg.shop=shop_title//退货单，原订单信息店铺
              }else{
                this.hasPlatform=false
              }
              this.getBillColorList();
      },
      getBillColorList() {
        let params = {};
        if(this.oldOrderMsg.retureOrderCode){
          params = {
            type: 3,
            ids: this.oldOrderMsg.retureOrderCode.split(',')
          }
          network.post('/p/cs/color/mark/rel/list',params).then(res => {
            if(res.data.code == 0){
              let colorList = [];
              res.data.data.forEach(item => {
                colorList = [...colorList,...item.color_block];
              })
              colorList = [...colorList,...this.addColorList]
              colorList = this.distinct1(colorList,'color')
              this.colorList = colorList;
            }
          })
        }else {
          // params = {
          //   type: 1,
          //   ids: this.oldOrderMsg.orderCode.split(',')
          // }
        }

      },
      // 数组指定字段去重
      distinct1(arr,key){
          var newobj = {},newArr = [];
          for(var i=0;i<arr.length;i++){
              var item = arr[i];
            if(!newobj[item[key]]){
                  newobj[item[key]] = newArr.push(item);
            }
          }
          return newArr;
      },
      // 扫描商品SKU获取信息
      getSKUByCode(val) {
        if (val.target.value == '') {
          return this.$Message.warning('商品SKU（国标码）不能为空！');
        }
        let param = {}
        param = {
          sku: val.target.value.trim()
        };

        network.post('/p/cs/return_and_storage/query/sku', param).then(res => {
          if (res.data.code == 0) {
            if(res.data.data){
              this.sureClick('scanoutok');
              this.scanGoodMsg = res.data.data;
              if(res.data.data.wareHousingSkuItemVOList){
                let qrcode = res.data.data.wareHousingSkuItemVOList[0].qrcode;
                this.singleMatch(res.data.data.SKU, qrcode, res.data.data.PRODUCTCODE);
              }else {
                this.singleMatch(res.data.data.SKU,'', res.data.data.PRODUCTCODE);
              }
            }else {
              this.sureClick('error');
              this.$Message.error(res.data.message);
            }
          }
        });
      },
      // 自动匹配
      autoMatch() {
        this.linkGoodsData.forEach(item => {
          item.scanInNum = 1;
        });
        let scan_goods = [];
        if (this.linkGoodsData.length > 0) {
          this.linkGoodsData.forEach(item => {
            if (item.scanInNum !== 0) {
              let obj = {
                quality_mark: item.productRemark,
                sku: item.sku_no,
                qrcode: item.stoInQrcode,
              };
              scan_goods.push(obj);
            }
          });
        }
        let params = {
          create_type: '2',
          logistics_no: this.scanTypeCode, // this.scanInStorageOrderMsg.expressCode
          logistics_number: this.scanInStorageOrderMsg.logistics_number,// 客户手动输入物流单号
          default_store: this.StorageForm.defaultStorage.value,
          flaw_store: '', //this.StorageForm.defectiveGoodsStorage.value
          defective_store: '', //this.StorageForm.imperfectionsStorage.value
          shipper_id: this.scanInStorageOrderMsg.expressName.length > 0 ? this.scanInStorageOrderMsg.expressName[0].ID : '',
          shipper_name: this.scanInStorageOrderMsg.expressName.length > 0 ? this.scanInStorageOrderMsg.expressName[0].Label : '',
          buyer_nick: this.scanInStorageOrderMsg.customerNickName,
          user_name: this.scanInStorageOrderMsg.customerName,
          phone: this.scanInStorageOrderMsg.customerMobile,
          tel: this.scanInStorageOrderMsg.customerPhone,
          delivery_address: this.scanInStorageOrderMsg.customerAddr,
          remark: this.scanInStorageOrderMsg.remark,
          scan_goods,
          plat_form:this.scanInStorageOrderMsg.customerPlatform,//平台
          shop_id:this.scanInStorageOrderMsg.customerShop//店铺
        };
        this.returnInStore(params);
      },
      // 获取当前配置项，是否开启仅支持退单/订单中商品唯一码入库
      getOnlyReturnQRCODE() {
        network.get('/p/cs/platform/config/qr_code_control').then(res => {
          if(res.data.code == 0){
            this.onlySKUControl = res.data.data.RETURN_AND_STORAGE[2].configValue == 'true'?true:false
            this.onlyReturnQRCODE = res.data.data.RETURN_AND_STORAGE[3].configValue == 'true'?true:false
          }
        })
      },
      // 单个扫描商品编码匹配
      singleMatch(val,qrcode,productcode) {
        this.getOnlyReturnQRCODE();
        let flag = false;
        let haveSKU = false; // 表格中包含当前sku
        let haveQrcode = false;  //当前匹配项唯一码相同但唯一码已被匹配
        let haveQrcodeIsMatch = false; //当前匹配项唯一码相同但sku已被匹配
        let count = 0; //唯一码匹配时当前列表循环无此唯一码的条数，判断再次遍历列表的参数
        this.singleGoodValue = val;
        if (this.haveOrder && this.linkGoodsData.length > 0) {
          if(qrcode){
            for (let i = 0; i < this.linkGoodsData.length; i++) {
              if(this.linkGoodsData[i].qrcode == qrcode){
                if(this.linkGoodsData[i].scanInNum == 0){
                  this.linkGoodsData[i].scanInNum = 1;
                  this.linkGoodsData[i].stoInQrcode = qrcode;
                  flag = true;
                  this.formInline.SKUCode = ''
                  haveSKU = false;
                  break;
                }else {
                  haveQrcodeIsMatch = true;
                  break;
                }
              }else {
                count ++;
                if(this.linkGoodsData[i].stoInQrcode == qrcode){
                  haveQrcodeIsMatch = true;
                  break;
                }
              }
            }
          } else {
            let count3 = 0; // 扫入的是sku码，遍历列表,同sku存在已被匹配的条数
            let count4 = 0; // 扫入sku，但不存在列表中
            for (let i = 0; i < this.linkGoodsData.length; i++) {
              if(this.linkGoodsData[i].sku_no == val && this.linkGoodsData[i].scanInNum == 0){
                this.linkGoodsData[i].scanInNum = 1;
                this.linkGoodsData[i].stoInQrcode = qrcode;
                flag = true;
                this.formInline.SKUCode = ''
                haveSKU = false;
                break;
              } else if (this.linkGoodsData[i].sku_no == val && this.linkGoodsData[i].scanInNum > 0) {
                count3 ++;
              } else {
                count4 ++;
              }
            }
            if(!qrcode && count3 > 0 && (count3 + count4) == this.linkGoodsData.length){
              this.TipTitle = '当前商品已扫描过，是否继续？';
              this.isShowSureEnterGood = true;
            }else if(!qrcode && count4 == this.linkGoodsData.length){
              let isCTMFlag = false;
              for (let i = 0; i < this.linkGoodsData.length; i++) {
                if(this.linkGoodsData[i].productcode == productcode){
                  isCTMFlag = true;
                  break;
                }
              }
              if(this.isInStore_byProductcode || (!this.isInStore_byProductcode && isCTMFlag)){
                this.TipTitle = '当前商品不存在，是否继续？';
                this.isShowSureEnterGood = true;
              }else {
                this.TipTitleOne = '串款商品不允许入库，如需入库请修改系统参数！';
                this.isShowSureEnterGoodOne = true;
                // this.$Modal.warning({
                //   title: '提示',
                //   content: '串款商品不允许入库，如需入库请修改系统参数！'
                // });
              }
            }
          }
          if((this.haveOrder && qrcode && count == this.linkGoodsData.length && !this.onlyReturnQRCODE)){
            let count5 = 0; // 扫描唯一码，能匹配到同sku，但是同sku的都已被匹配
            let count6 = 0; // 扫描唯一码，不能匹配到同sku
            for (let i = 0; i < this.linkGoodsData.length; i++) {
              if (this.linkGoodsData[i].sku_no == val && this.linkGoodsData[i].scanInNum == 0) {
                  this.linkGoodsData[i].scanInNum = 1;
                  this.linkGoodsData[i].stoInQrcode = qrcode;
                  flag = true;
                  this.formInline.SKUCode = ''
                  haveSKU = false;
                  break;
              }else if(this.linkGoodsData[i].sku_no == val && this.linkGoodsData[i].scanInNum > 0){
                count5 ++
              }else {
                count6 ++
              }
            }
            if(!haveQrcodeIsMatch && count5 > 0 && (count5+count6) == this.linkGoodsData.length){
              this.TipTitle = '当前商品已扫描过，是否继续？';
              this.isShowSureEnterGood = true;
            }else if(!haveQrcodeIsMatch && count6 == this.linkGoodsData.length){
              let isCTMFlag = false;
              for (let i = 0; i < this.linkGoodsData.length; i++) {
                if(this.linkGoodsData[i].productcode == productcode){
                  isCTMFlag = true;
                  break;
                }
              }
              if(this.isInStore_byProductcode || (!this.isInStore_byProductcode && isCTMFlag)){
                this.TipTitle = '当前商品不存在，是否继续？';
                this.isShowSureEnterGood = true;
              }else {
                this.TipTitleOne = '串款商品不允许入库，如需入库请修改系统参数！';
                this.isShowSureEnterGoodOne = true;
                // this.$Modal.warning({
                //   title: '提示',
                //   content: '串款商品不允许入库，如需入库请修改系统参数！'
                // });
              }
            }
          }else if(this.haveOrder && qrcode && count == this.linkGoodsData.length && this.onlyReturnQRCODE){
            let HasqrcodeOne = false;
            for (let i = 0; i < this.linkGoodsData.length; i++) {
              if(this.linkGoodsData[i].stoInQrcode == qrcode){
                HasqrcodeOne = true;
                break;
              }
            }
            if(!HasqrcodeOne){
              this.TipTitle = '当前设置仅支持退单/订单中商品唯一码入库，无可匹配唯一码，是否继续？';
              this.isShowSureEnterGood = true;
            }
            // return this.$Message.warning('当前已开启仅支持退单/订单中商品唯一码入库，当前扫描唯一码不存在！')
          }
          if(haveQrcodeIsMatch){
            let NewqrcodeList = []
            let countTwo = 0; // 原唯一码对应的商品已被匹配，扫入的是唯一码
            this.linkGoodsData.forEach(item => {
              NewqrcodeList.push(item.stoInQrcode)
            })
            if(NewqrcodeList.indexOf(qrcode) > -1){
              this.$Message.warning('已经录入过该唯一码，不允许重复录入！')
            }else{
              for (let i = 0; i < this.linkGoodsData.length; i++) {
                if (this.linkGoodsData[i].sku_no == val  && this.linkGoodsData[i].scanInNum == 0) {
                    this.linkGoodsData[i].scanInNum = 1;
                    this.linkGoodsData[i].stoInQrcode = qrcode;
                    flag = true;
                    this.formInline.SKUCode = ''
                    haveSKU = false;
                    break;
                } else {
                  countTwo ++;
                }
              }
              if(countTwo == this.linkGoodsData.length){
                  this.TipTitle = '当前唯一码商品已被匹配，是否继续？';
                  this.isShowSureEnterGood = true;
                // return this.$Message.warning('该唯一码对应商品已被匹配！')
              }
            }
          }
         if (this.autoSubmit) {
            let autoSubmitOpen = false;
            for(let i=0;i<this.linkGoodsData.length;i++){
              if(this.linkGoodsData[i].scanInNum == this.linkGoodsData[i].qty && this.linkGoodsData[i].bill_id){
                autoSubmitOpen = true;
              }else {
                autoSubmitOpen = false;
                break;
              }
            }
            if (autoSubmitOpen) {
              let scan_goods = [];
              if (this.linkGoodsData.length > 0) {
                this.linkGoodsData.forEach(item => {
                  if (item.scanInNum !== 0) {
                    let obj = {
                      quality_mark: item.productRemark,
                      sku: item.sku_no,
                      qrcode: item.stoInQrcode,
                    };
                    scan_goods.push(obj);
                  }
                });
              }
              let params = {
                create_type: '2',
                logistics_no: this.scanTypeCode, // this.scanInStorageOrderMsg.expressCode
                logistics_number: this.scanInStorageOrderMsg.logistics_number,// 客户手动输入物流单号
                default_store: this.StorageForm.defaultStorage.value,
                flaw_store: '', //this.StorageForm.defectiveGoodsStorage.value
                defective_store: '', //this.StorageForm.imperfectionsStorage.value
                shipper_id: this.scanInStorageOrderMsg.expressName.length > 0 ? this.scanInStorageOrderMsg.expressName[0].ID : '',
                shipper_name: this.scanInStorageOrderMsg.expressName.length > 0 ? this.scanInStorageOrderMsg.expressName[0].Label : '',
                buyer_nick: this.scanInStorageOrderMsg.customerNickName,
                user_name: this.scanInStorageOrderMsg.customerName,
                phone: this.scanInStorageOrderMsg.customerMobile,
                tel: this.scanInStorageOrderMsg.customerPhone,
                delivery_address: this.scanInStorageOrderMsg.customerAddr,
                remark: this.scanInStorageOrderMsg.remark,
                plat_form:this.scanInStorageOrderMsg.customerPlatform,//平台
                shop_id:this.scanInStorageOrderMsg.customerShop,//店铺
                scan_goods,
              };
              this.returnInStore(params);
              this.formInline.SKUCode = ''
            }
          }
        } else {
          let canAddFlag = false;
          for(let i=0;i<this.linkGoodsData.length;i++) {
            if(this.linkGoodsData[i].stoInQrcode && (this.linkGoodsData[i].stoInQrcode == qrcode)){
              canAddFlag = true;
            }
          }
          if(canAddFlag){
            this.$Message.warning('已经录入过该唯一码，不允许重复录入！')
          }else {
             this.addGoodToTable();
          }
        }
        this.linkGoodsData.forEach(item => {
          if(item.stoInQrcode){
            if(item.qrcode == item.stoInQrcode){
              item.stoInQrcodeColor = 'green'
            } else {
              item.stoInQrcodeColor = 'orange'
            }
          }
        })
        this.$refs.ag.api.setRowData(this.linkGoodsData)
      },
      // 强制入库
      compulsoryWarehouseBefore() {
        if(this.unInstoreRefundNeNum) {
          this.compulsoryWarehouse()
        }else {
          let unCompulsoryWarehouse = false;
          for(let i=0;i<this.linkGoodsData.length;i++){
            if(this.linkGoodsData[i].qty != this.linkGoodsData[i].scanInNum){
              unCompulsoryWarehouse = true;
              break;
            }
          }
          console.log(unCompulsoryWarehouse)
          if(unCompulsoryWarehouse){
            return this.$Message.error('当前应入数量与扫描数量不一致，不允许强制入库'); // 当前应入数量与扫描数量不一致，不允许强制入库
          }else {
            this.compulsoryWarehouse();
          }
        }
      },
      compulsoryWarehouse() {
        if (!this.haveOrder) {
          if (this.scanInStorageOrderMsg.expressCode == '') {
            this.sureClick('error');
            return this.$Message.error('扫描单号必填'); // 退回物流单号
          }else {
            this.canHandle();
          }
        }else {
          this.canHandle();
        }
      },
      canHandle(){
        let scan_goods = [];
        if (this.linkGoodsData.length > 0) {
          this.linkGoodsData.forEach(item => {
            if (item.scanInNum !== 0) {
              let obj = {
                quality_mark: item.productRemark,
                sku: item.sku_no,
                qrcode: item.stoInQrcode,
              };
              scan_goods.push(obj);
            }
          });
        }
        let params = {
          create_type: '2',
          logistics_no: this.scanTypeCode?this.scanTypeCode:this.scanInStorageOrderMsg.expressCode, // this.scanInStorageOrderMsg.expressCode
          logistics_number: this.scanInStorageOrderMsg.logistics_number,// 客户手动输入物流单号
          default_store: this.StorageForm.defaultStorage.value,
          flaw_store: '', // this.StorageForm.defectiveGoodsStorage.value
          defective_store: '', //this.StorageForm.imperfectionsStorage.value
          shipper_id: this.scanInStorageOrderMsg.expressName.length > 0 ? this.scanInStorageOrderMsg.expressName[0].ID : '',
          shipper_name: this.scanInStorageOrderMsg.expressName.length > 0 ? this.scanInStorageOrderMsg.expressName[0].Label : '',
          buyer_nick: this.scanInStorageOrderMsg.customerNickName,
          user_name: this.scanInStorageOrderMsg.customerName,
          phone: this.scanInStorageOrderMsg.customerMobile,
          tel: this.scanInStorageOrderMsg.customerPhone,
          delivery_address: this.scanInStorageOrderMsg.customerAddr,
          remark: this.scanInStorageOrderMsg.remark,
          scan_goods,
          plat_form:this.scanInStorageOrderMsg.customerPlatform,//平台
          shop_id:this.scanInStorageOrderMsg.customerShop,//店铺
          isForcePut: true // 是否强制入库
        };
        this.returnInStore(params);
      },
      // 执行入库操作 returnInStroe/create
      returnInStore(params) {
        this.loading = true;
        network.post('/p/cs/returnInStroe/create', params).then(res => {
          if (res.data.code == 0) {
            if(this.addColorList.length > 0){
              this.addColorTagaAfterBill(res.data.data);
            }else {
              this.refoColorTagAfterBill(res.data.data);
            }
            this.sureClick('success');
            if (this.isReturnOrderFlag) {
              // this.$Message.success('入库成功！');
              this.$Message.success({
                render: h => {
                  return h('span',
                  {
                    style: {
                      fontSize:'16px',
                    },
                  },
                  [
                      '入库成功！',
                  ])
                },
                duration: 5,
              });
            } else {
              // this.$Message.success('入库成功！生成退换货单成功！');
              this.$Message.success({
                render: h => {
                  return h('span',
                  {
                    style: {
                      fontSize:'16px',
                    },
                  },
                  [
                      '入库成功！生成退换货单成功！',
                  ])
                },
                duration: 5,
              });
            }
            this.loading = false;
            this.$refs.expressEnter.focus();
            this.reset();
            if(this.InStoreToDefault=='true' || this.InStoreToDefault=='True' || this.InStoreToDefault=='TRUE'){ // 如果是扫描订单或者退单带出的仓库，入库成功后清空
              this.StorageForm.physicalStorage = {
                value: '',
                label: ''
              };
              this.StorageForm.defaultStorage = {
                value: '',
                label: ''
              };
            }
          } else {
            this.loading = false;
            this.sureClick('error');
          }
        });
      },
      sureEnterGood() {
        this.addGoodToTable();
        this.isShowSureEnterGood = false;
      },
      addGoodToTable() {
        let obj = {
          title: this.scanGoodMsg.SKUNAME,
          productcode: this.scanGoodMsg.PRODUCTCODE,
          sku_no: this.scanGoodMsg.SKU,
          normsdetailnames: this.scanGoodMsg.NORMSDETAILNAMES,
          gbcode: this.scanGoodMsg.GBCODE,
          productRemark: 1,
          qty: 1,
          scanInNum: 1,
          pic_url: this.scanGoodMsg.pic_url
        };
        if(this.scanGoodMsg.wareHousingSkuItemVOList && this.scanGoodMsg.wareHousingSkuItemVOList[0].qrcode){
          obj.stoInQrcode = this.scanGoodMsg.wareHousingSkuItemVOList[0].qrcode
        }else {
           obj.stoInQrcode = '';
        }
        this.linkGoodsData.unshift(obj)
        this.formInline.SKUCode = ''
      },
      cancelEnterGood() {
        this.formInline.SKUCode = ''
        this.isShowSureEnterGood = false;
      },
      cancelEnterGood() {
        this.formInline.SKUCode = ''
        this.isShowSureEnterGoodOne = false;
      },

      // 选择入库单弹框中的筛选下拉框数据start
      // 单选下拉分页改变
      changePageShop(e) {
        this.ExpresscurrentIndex = (e - 1) * 10;
        this.searchShopData();
      },
      // 外键下拉框
      searchShopData() {
        let virtual = {
          searchdata: {
            isdroplistsearch: true,
            refcolid: 196700,
            startindex: this.ExpresscurrentIndex,
            range: 10,
          }
        };
        network.post('/p/cs/QueryList', urlSearchParams(virtual)).then((res) => {
          if (res.data.code == 0) {
            this.ExpresstotalRowCount = res.data.data.totalRowCount;
            this.ExpressList = res.data.data;
            this.ExpresscurrentIndex = 0;
          }
        });
      },
      // 单选下拉模糊搜索数据
      InputValueChangeShop(e) {
        let virtual = {
          ak: e,
          colid: 196700,
          fixedcolumns: {}
        };
        network.post('/p/cs/fuzzyquerybyak', urlSearchParams(virtual)).then((res) => {
          if (res.data.code == 0) {
            let list = [];
            res.data.data.forEach(item => {
              let obj = {
                value: item.value,
                id: item.id
              };
              list.push(obj);
            });
            this.ExpressAutoData = list;
          }
        });
      },
      // 外键下拉框搜索
      focusInputValueChangeShop(e) {
        let virtual = {
          ak: e.target.value,
          colid: 192215,
          fixedcolumns: {}
        };
        network.post('/p/cs/fuzzyquerybyak', urlSearchParams(virtual)).then((res) => {
          if (res.data.code == 0) {
            let list = [];
            res.data.data.forEach(item => {
              let obj = {
                value: item.value,
                id: item.id
              };
              list.push(obj);
            });
            this.ExpressAutoData = list;
          }
        });
      },
      // 单选下拉选中
      checkDataShop(val) {
        let list = [];
        list.push(val[0]);
        this.scanInStorageOrderMsg.expressName = list;
      },
      clearDataShop() {
        this.scanInStorageOrderMsg.expressName = [];
      },
      // 选择入库单弹框中的筛选下拉框数据end

      // 去重
      unique(arr) {
        const res = new Map();
        return arr.filter((arr) => !res.has(arr) && res.set(arr, 1));
      },
      // 提示音
      aplayAudio(type) {
        let audio = '';
        if (type == 'sacnOk') { // 单纯提示
          audio = document.getElementById('audiosacnOk');
        } else if (type == 'scanExpress') { // 扫描物流单
          audio = document.getElementById('audioscanExpress');
        } else if (type == 'success') { // 成功
          audio = document.getElementById('audiosuccess');
        } else if (type == 'error') { // 失败
          audio = document.getElementById('audioerror');
        } else if (type == 'scanoutok') { // 扫描商品
          audio = document.getElementById('audioscanoutok');
        }
        // 从头播放
        audio.currentTime = 0;
        audio.load();
        audio.play();
      },
      sureClick(type) {
        this.aplayAudio(type);
      }
    },
  };
</script>
<style lang='less'>
  .exchangeDetailTable .ark-table th,.exchangeDetailTable  .ark-table td {
    height: 46px;
  }
  .exchangeDetailTable .ark-table th {
    border-bottom: none;
  }
  .img-framelanflag{
      cursor: pointer;
      margin-left:4px;
      width: 16px;
  }
  .chooseStorageBox .ark-select-single .ark-select-selection {
    height: 32px;
    .ark-select-input {
      height: 32px;
      line-height: 30px;
    }
  }
  .chooseStorageBox .ark-select-single .ark-select-selection .ark-select-placeholder, .chooseStorageBox .ark-select-single .ark-select-selection .ark-select-selected-value {
    height: 32px;
    line-height: 30px;
  }
  .squreBottom .ark-form {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }
  .squreBottom .ark-form .ark-form-item-label {
    color: #333333;
    height: 38px;
    line-height: 18px;
  }
  .squreBottom .ark-form .ark-form-item-content {
    display: flex;
    align-items: center;
  }
  .squreBottom .ark-input {
    width: 260px;
    height: 38px;
    border: 1px solid #DADADA;
  }
  .squreBottom .ark-form-item:first-child {
    margin-right: 20px;
  }
  .itemContent .ark-input:not(textarea) {
    // width: 240px;
    height: 32px;
  }
  // .itemContent:last-child .ark-input {
  //   width: 480px;
  // }
  .showTipModel .fcWarning {
    color:#f7b901;
    font-size: 24px;
    margin-right: 10px;
    vertical-align: middle;
  }
  .showTipModel p {
    height: 50px;
    line-height: 50px;
  }
  .showTipModel .ark-modal-footer .ark-btn {
    border: 1px solid var(--primary-color);
    background: #fff;
    color: var(--primary-color);
  }
  .showTipModelOne .ark-modal-footer .ark-btn:first-child {
    display: none;
  }

  .squreTopColor .ark-select {
    width: 32px;
  }
  .squreTopColor .ark-select-single .ark-select-selection {
    background: unset;
    border: none;
  }
  .squreTopColor .ark-select-visible .ark-select-selection {
    box-shadow: unset;
  }
  .squreTopColor .ark-select-single .ark-select-selection .ark-select-placeholder, .squreTopColor .ark-select-single .ark-select-selection .ark-select-selected-value {
    display: none;
  }
  .dropButtonMenu .ark-bcl-button.ark-btn-fcdefault, .dropButtonMenu .ark-bcl-button.ark-btn-dropdown {
    color: #333;
    border: none;
    padding: unset;
    background: unset;
    line-height: 18px;
  }

   .modifyComColorTag .LOGISTICSCOMPNAYNAME .ark-input-wrapper {
    display: flex;
    border: 1px solid #d8d8d8;
    border-radius: 2px;
    height: 34px;
  }
  .modifyComColorTag .LOGISTICSCOMPNAYNAME .ark-input-wrapper .ark-input {
    height: 32px;
    border: none;
  }
  .modifyComColorTag .LOGISTICSCOMPNAYNAME .ark-input-icon {
    margin-top: 3px;
  }
  .modifyComColorTag .LOGISTICSCOMPNAYNAME .ark-color-picker-focused {
    box-shadow: unset;
  }
  .modifyComColorTag .LOGISTICSCOMPNAYNAME .ark-select-single .ark-select-selection {
    height: 34px;
  }
  .modifyComColorTag .LOGISTICSCOMPNAYNAME  .ark-select-single .ark-select-selection .ark-select-placeholder, .modifyComColorTag .LOGISTICSCOMPNAYNAME  .ark-select-single .ark-select-selection .ark-select-selected-value {
    height: 34px;
    line-height: 34px;
  }
</style>
<style lang='less' scoped>
    .ScanningStorageIn {
      min-width: 1380px;
      height: 100%;
    }
    .scanInTopBg {
      // position: fixed;
      display: flex;
      justify-content: space-between;
      width: calc(100% + 30px); //50px
      height: 130px;
      // margin-top: -12px;
      margin-left: -15px; // 25px
      padding: 0 15px ;
      color: #fff;
      background: url('../../assets/image/scanTopBg.png');
      background-repeat: no-repeat;
      background-size: 100%;
      .storageValue {
        border-right: 1px solid #CBD1DB;
        padding-right: 16px;
        margin-left: 8px;
        margin-right: 16px;
      }
      .storageValue:last-child {
        border-right: none;
      }
      .storageBoxRight {
        cursor: pointer;
        height: 20px;
        line-height: 20px;
        padding-top: 36px;
        i {
          margin-top: -4px;
        }
      }
    }
    .scanInContent {
      width: 100%;
      min-height: calc(100% - 70px);
      background: #fff;
      margin-top:-50px;
      padding: 24px;
      .scanInWarning {
        padding: 16px;
        background: #D5E7FF;
        .warningTitle {
          display: flex;
          align-items: center;
          img {
            width: 14px;
            height: 14px;
            margin-right: 6px;
          }
          span {
            color: #0046B9;
          }
        }
        .warningText {
          padding-left: 16px;
          margin-top: 6px;
          color: #0046B9;
          p {
            line-height: 18px;
          }
        }
      }
      .scanningBox {
        display: flex;
        position: relative;
        height: 222px;
        margin-top: 24px;
        // padding: 25px;
        .imgBorder {
          position: absolute;
          width: 30px;
          height: 30px;
        }
        .left-top-border {
          top: 0;
          left: 0;
          border-left: 1px solid #C8CAD7;
          border-top: 1px solid #C8CAD7;
          border-radius: 8px 0 0 0;
        }
        .right-top-border {
          top: 0;
          right: -1px;
          border-right: 1px solid #C8CAD7;
          border-top: 1px solid #C8CAD7;
          border-radius: 0 8px 0 0;
        }
        .left-bottom-border {
          bottom: 0;
          left: 0;
          border-bottom: 1px solid #C8CAD7;
          border-left: 1px solid #C8CAD7;
          border-radius: 0 0 0 8px;
        }
        .right-bottom-border {
          bottom: 0;
          right: -1px;
          border-right: 1px solid #C8CAD7;
          border-bottom: 1px solid #C8CAD7;
          border-radius: 0 0 8px 0;
        }

        .scanningSqure {
          width: 78%;
          height: 168px;
          background: #F5F6FA;
          padding: 40px 20px 0 20px;
          .squreTop {
            display: flex;
            align-items: center;
            justify-content: space-between;
            .squreTopScan {
              display: flex;
              align-items: center;
              img {
                width: 24px;
                height: 24px;
                margin-right: 8px;
              }
              .blueTitle {
                color:#2B7BFE;
              }
              .autoSubmit {
                margin-right: 8px;
              }
            }
            .squreTopColor {
              display: flex;
              align-items: center;
              // width: 200px;
              height: 26px;
              padding: 0 16px;
              background: #B7C0E2;
              border-radius: 3px;
              span.colorTitle {
                color: #333;
              }
            }
          }
          .squreBottom {
            display: flex;
            // justify-content: center;
            // padding: 34px 70px 0;
            padding-top: 34px;
          }
        }
        .returnGoodsSqure {
          width: 22%;
          height: 168px;
          margin-left: 10px;
          background: #F5F6FA;
          padding-top: 54px;
          .returnGoodsNum {
            display: flex;
            width: 100%;
            padding:0 4%;
            span.lineSpan {
              display: inline-block;
              width: 50%;
              height: 36px;
              padding: 0 10px;
              text-align: center;
              line-height: 36px;;
              border: 1px solid #DADADA;
              background: #fff;
            }
          }
          .returnGoodsNum .lineSpan:first-child {
            text-align: right;
            color: #818181;
            font-size: 14px;
          }
          .returnGoodsNum .lineSpan:last-child {
            text-align: left;
          }
          .returnGoodsNum:first-child .lineSpan:first-child {
              border-bottom: none;
              border-right: none;
          }
          .returnGoodsNum:first-child .lineSpan:last-child {
              border-bottom: none;
              color: #333;
              font-size: 18px;
          }
          .returnGoodsNum:last-child .lineSpan:first-child {
              border-right: none;
          }
          .returnGoodsNum:last-child .lineSpan:last-child {
              color: #333;
              font-size: 14px;
          }
          .exchangeDetailBtn {
            color: #2B7BFE;
            margin-left: 24px;
            cursor: pointer;
          }
        }
      }
      .OrderMsg {
        .orderMsgBox {
          display: flex;
          .orderMsgItem {
            display: flex;
            font-size: 12px;
            line-height: 17px;
            color: #444444;
            margin-right: 190px;
            max-width: 500px;
            img {
              width: 48px;
              height: 48px;
              margin-right: 16px;
            }
            .MsgValue {
              font-size: 14px;
              line-height: 20px;
              color: #4C4C4C;
              margin-top: 8px;
            }
          }
        }
      }
    }
    .linkGoods {
      position: relative;
      margin-top: 24px;
      .autoBtn {
        position: absolute;
        right: 0;
        top: 0;
        z-index: 2;
        width: 98px;
        height: 28px;
        text-align: center;
        margin-top: 2px;
        margin-right: 24px;
        padding-left: 0;
        padding-right: 0;
      }
    }
    .conditionContent {
      width: 100%;
      display: flex;
      max-height: 3000px;
      overflow: hidden;
      flex-wrap: wrap;
      padding-top: 8px;
      .itemContent {
        width: calc(100%  / 3);
        display: flex;
        align-items: center;
        margin: 0 0px 16px;
        .itemLabel {
          // min-width: 80px;
          min-width: 150px;
          font-size: 12px;
          font-weight: 500;
          color: #4C4C4C;
          line-height: 17px;
          margin-right: 8px;
          text-align: right;
        }
        .posterType {
          width: calc(100% - 84px);
        }
      }
      .itemContent:last-child {
        width: calc(100% / 3 * 2);
      }
    }
    .oldOrderContent {
      .itemContent {
        .itemLabel {
          color: #909399;
        }
        span {
          word-wrap: break-word;
          word-break: break-all;
        }
      }
    }
    .chooseStorageForm {
      padding-right: 30px;
    }
    .bottomBtnBox {
      width: calc(100% + 32px);
      margin: 16px auto 0px;
      margin-left: -16px;
      text-align: center;
      border-top: 1px solid #DEDEDE;
      padding-top: 16px;
      .cancelBtn,.sureBtn {
        width: 72px;
        height: 32px;
        font-size: 12px;
      }
      .cancelBtn {
        color: #909399;
        border: 1px solid #DADADA;
        margin-right: 8px;
      }
    }
</style>
