<template>
  <div class="ManualMatch">
    <div class="matchContent">
      <div style="display: flex;min-height:100%;">
        <div class="returnReceiptPart">
          <div class="returnTop">
            <span class="returnType">
              <span @click="clickHelp" >
                <span title="帮助中心">
                  <i class='ark-icon ark-icon iconfont iconios-help-circle-outline' style="font-size: 26px;opacity: 0.7;color: var(--primary-color);"></i>
                </span>
              </span>
              <span>退货入库单</span>
            </span>
            <Button
              type="primary"
              @click="chooseReturnReceipt"
            >
            <!-- v-if="!isFromRefundOrder" -->
              选择入库单
            </Button>
          </div>
          <div
            v-if="returnReceipt.length == 0"
            class="emptyOrder"
          >
            <div>
              <img
                src="../../assets/image/emptyOrder.png"
                alt=""
              >
              <div class="emptyTip">
                请先选择一个退货入库单
              </div>
            </div>
          </div>
          <div
            v-else
            class="haveOrder"
          >
            <div
              class="baseBox"
              style="height: 211px"
            >
              <div class="baseMsgBox">
                <div
                  v-for="item in returnReceiptMsg1"
                  :key="item.key"
                  class="msgItem"
                >
                  <span class="msgTitle">{{ item.title }}</span>
                  <span
                    class="msgValue"
                    :title="returnReceipt[0][item.key]"
                  >{{ returnReceipt[0][item.key] }}</span>
                </div>
              </div>
              <div class="baseMsgBox">
                <div
                  v-for="item in returnReceiptMsg2"
                  :key="item.key"
                  class="msgItem"
                >
                  <span class="msgTitle">{{ item.title }}</span>
                  <span
                    class="msgValue"
                    :title="returnReceipt[0][item.key]"
                  >{{ returnReceipt[0][item.key] }}</span>
                </div>
              </div>
            </div>
            <div class="goodsTitle">
              <span>入库单商品信息</span>
              <Button
                :disabled="returnReceipt.length ==0 || returnOrder.length == 0"
                @click="autoMatch"
              >
                自动匹配
              </Button>
            </div>
            <div class="linkGoods">
              <Table
                :height="tableHeightOne"
                :columns="ReturnReceiptGoodsColumns"
                :data="ReturnReceiptGoodsData"
                class="getReturnTable returnReceiptGood"
              />
            </div>
            <div class="matchTitleList">
              <span style="color: #909399;">此次已匹配:</span>
              <span
                v-for="(item,index) in matchTitleList"
                :key="index"
                style="coloe: #4C4C4C;"
              >{{ item.SKU }}*{{ item.num }}</span>
            </div>
          </div>
        </div>
        <div class="fengediv" />
        <div class="returnOrderPart">
          <div class="returnTop">
            <span class="returnType">退换货单</span>
            <Button
              type="primary"
              :disabled="returnReceipt.length == 0"
              @click="chooseReturnOrder"
            >
            <!-- v-if="!isFromRefundOrder" -->
              选择退单
            </Button>
          </div>
          <div
            v-if="returnOrder.length == 0"
            class="emptyOrder"
          >
            <div>
              <img
                src="../../assets/image/emptyOrder.png"
                alt=""
              >
              <div class="emptyTip">
                请在选择入库单后选择需匹配的退换货单
              </div>
            </div>
          </div>
          <div
            v-else
            class="haveOrder"
          >
            <div
              class="baseBox lastBaseBox"
              style="height: 211px"
            >
              <div class="baseMsgBox">
                <div
                  v-for="item in returnOrderMsg1"
                  :key="item.key"
                  class="msgItem"
                >
                  <span class="msgTitle">{{ item.title }}</span>
                  <span
                    class="msgValue"
                    :title="returnOrder[0][item.key]"
                  >{{ returnOrder[0][item.key] }}</span>
                </div>
              </div>
              <div class="baseMsgBox">
                <div
                  v-for="item in returnOrderMsg2"
                  :key="item.key"
                  class="msgItem"
                >
                  <span class="msgTitle">{{ item.title }}</span>
                  <span
                    class="msgValue"
                    :title="returnOrder[0][item.key]"
                  >{{ returnOrder[0][item.key] }}</span>
                </div>
              </div>
            </div>
            <div class="goodsTitle">
              <span>退单商品信息</span>
            </div>
            <div class="linkGoods">
              <Table
                border
                :height="tableHeightOne"
                :columns="ReturnOrderGoodsColumns"
                :data="ReturnOrderGoodsData"
                class="getReturnTable"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="bottomBtnBox">
      <Button
        v-if="!isSureMatch"
        type="default"
        class="cancelBtn"
        :disabled="!isSureMatch"
        @click="cancelMatch"
      >
        取消匹配
      </Button>
      <Button
        v-else
        type="default"
        class="cancelAbleBtn"
        @click="cancelMatch"
      >
        取消匹配
      </Button>
      <Button
        v-if="!isSureMatch"
        :disabled="!isSureMatch"
        type="default"
        class="cancelBtn"
      >
        确认匹配
      </Button>
      <Button
        v-else
        :disabled="!isSureMatch"
        type="primary"
        class="sureBtn"
        :loading="addLoading"
        @click="handMatch"
      >
        确认匹配
      </Button>
    </div>

    <!-- 选择入库单弹框 -->
    <Modal
      v-model="selectReturnReceiptModal"
      title="选择入库单"
      title-align="left"
      width="1020"
      :mask="mask"
      :closable="closable"
      :mask-closable="maskClosable"
      :footer-hide="hideFoot"
      @on-cancel="cancelSelectReturnReceipt"
    >
      <div class="conditionContent">
        <div class="itemContent">
          <div class="itemLabel">
            入库单号
          </div>
          <Input
            v-model="selectReturnReceiptData.STORAGEINID"
            clearable
            @on-enter="searchGoodsData('ReturnReceipt')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            物流单号
          </div>
          <Input
            v-model="selectReturnReceiptData.LOGISTNUMBER"
            clearable
            @on-enter="searchGoodsData('ReturnReceipt')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            入库实体仓
          </div>
          <DropMultiSelectFilter
            ref="IESSTORE"
            single
            class="input_box"
            :data="IESSTOREList"
            :total-row-count="IESSTOREtotalRowCount"
            :show-colname-key="'isak'"
            :columns="columns"
            :auto-data="IESSTOREAutoData"
            @on-page-change="changePageShop($event,'IESSTORE')"
            @on-input-value-change="InputValueChangeShop($event,'IESSTORE')"
            @on-popper-show="searchShopData('IESSTORE')"
            @on-fkrp-selected="checkDataShop($event,'IESSTORE')"
            @on-focus="focusInputValueChangeShop($event,'IESSTORE')"
            @on-clear="clearDataShop('IESSTORE')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            物流公司
          </div>
          <DropMultiSelectFilter
            ref="Express"
            single
            class="input_box"
            :data="ExpressList"
            :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')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            买家昵称
          </div>
          <Input
            v-model="selectReturnReceiptData.USERNICK"
            clearable
            @on-enter="searchGoodsData('ReturnReceipt')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            姓名
          </div>
          <Input
            v-model="selectReturnReceiptData.RECEIVNAME"
            clearable
            @on-enter="searchGoodsData('ReturnReceipt')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            手机号
          </div>
          <Input
            v-model="selectReturnReceiptData.RECEIVMOBILE"
            clearable
            @on-enter="searchGoodsData('ReturnReceipt')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            电话
          </div>
          <Input
            v-model="selectReturnReceiptData.RECEIVPHONE"
            clearable
            @on-enter="searchGoodsData('ReturnReceipt')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            包含SKU
          </div>
          <Input
            v-model="selectReturnReceiptData.ALLSKU"
            clearable
            @on-enter="searchGoodsData('ReturnReceipt')"
          />
        </div>
      </div>
      <ShrinkOrExtend
        :form-data="originalOrderData"
        :height="shrinkHeight"
        :current-value="currentValue"
        @click="upOrDown(shrinkHeight)"
        @on-reset="resetGoodsData('ReturnReceipt')"
        @on-query="searchGoodsData('ReturnReceipt')"
      />
      <div class="returnTabs">
        入库单信息
      </div>
      <Table
        :height="tableHeight"
        :columns="ReturnReceiptColumns"
        :data="ReturnReceiptData"
        class="getReturnTable"
      />
      <div class="pageContent">
        <Page
          size="small"
          :current="ReturnReceiptCurrentPage"
          :page-size="pageSizeReturnReceipt"
          show-elevator
          :total="totalReturnReceipt"
          show-total
          show-sizer
          @on-change="changePageReturnReceipt"
          @on-page-size-change="changeSizeReturnReceipt"
        />
      </div>
    </Modal>
    <!-- 选择退单弹框 -->
    <Modal
      v-model="selectReturnOrderModal"
      title="选择退单"
      title-align="left"
      width="1020"
      :mask="mask"
      :closable="closable"
      :mask-closable="maskClosable"
      :footer-hide="hideFoot"
      @on-cancel="cancelSelectReturnOrder"
    >
      <div class="conditionContent">
        <div class="itemContent">
          <div class="itemLabel">
            退单编号
          </div>
          <Input
            v-model="selectReturnOrderData.REFUNDORDERID"
            clearable
            @on-enter="searchGoodsData('ReturnOrder')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            原订单编号
          </div>
          <Input
            v-model="selectReturnOrderData.ORIGINALORDERNO"
            clearable
            @on-enter="searchGoodsData('ReturnOrder')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            平台单号
          </div>
          <Input
            v-model="selectReturnOrderData.SOURCECODE"
            clearable
            @on-enter="searchGoodsData('ReturnOrder')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            物流公司
          </div>
          <DropMultiSelectFilter
            ref="ExpressOrder"
            single
            class="input_box"
            :data="ExpressList"
            :total-row-count="ExpresstotalRowCount"
            :show-colname-key="'isak'"
            :columns="columns"
            :auto-data="ExpressAutoData"
            @on-page-change="changePageShop($event,'ExpressOrder')"
            @on-input-value-change="InputValueChangeShop($event,'ExpressOrder')"
            @on-popper-show="searchShopData('ExpressOrder')"
            @on-fkrp-selected="checkDataShop($event,'ExpressOrder')"
            @on-focus="focusInputValueChangeShop($event,'ExpressOrder')"
            @on-clear="clearDataShop('ExpressOrder')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            物流单号
          </div>
          <Input
            v-model="selectReturnOrderData.SID"
            clearable
            @on-enter="searchGoodsData('ReturnOrder')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            买家昵称
          </div>
          <Input
            v-model="selectReturnOrderData.BUYER_NICK"
            clearable
            @on-enter="searchGoodsData('ReturnOrder')"
          />
        </div>
        <div class="itemContent">
          <div class="itemLabel">
            包含SKU
          </div>
          <Input
            v-model="selectReturnOrderData.ALLSKU"
            clearable
            @on-enter="searchGoodsData('ReturnOrder')"
          />
        </div>
      </div>
      <ShrinkOrExtend
        :form-data="originalOrderData"
        :height="shrinkHeight"
        :current-value="currentValue"
        @click="upOrDown(shrinkHeight)"
        @on-reset="resetGoodsData('ReturnOrder')"
        @on-query="searchGoodsData('ReturnOrder')"
      />
      <div class="returnTabs">
        退单信息
      </div>
      <Table
        :height="tableHeight"
        :columns="ReturnOrderColumns"
        :data="ReturnOrderData"
        class="getReturnTable"
      />
      <div class="pageContent">
        <Page
          size="small"
          :current="ReturnOrderCurrentPage"
          :page-size="pageSizeReturnOrder"
          show-elevator
          :total="totalReturnOrder"
          show-total
          show-sizer
          @on-change="changePageReturnOrder"
          @on-page-size-change="changeSizeReturnOrder"
        />
      </div>
    </Modal>
    <!-- 退单中没有匹配的商品数据 -->
    <Modal
      v-model="isShowSureForceMatch"
      mask
      :mask-closable="maskClosable"
      title="提示"
      title-align="left"
      class-name="showTipModel"
      width="470px"
      @on-ok="sureForceMatch"
      @on-cancel="cancelForceMatch"
    >
      <p style='color: #777;'><i class="iconfont iconbj_doubt fcWarning" />退单不存在该商品，若要强制匹配，请选择商品</p>
      <div class='NoForcedMatchList'>
        <RadioGroup vertical v-model="NoForcedMacthChoosed" @on-change="changeNoForcedMacthChoosedGood">
            <Radio v-for="(option, index) in NoForcedMatchList" :key="index" :label="option.ID">
              {{option.SKU}}
            </Radio>
          </RadioGroup>
      </div>
    </Modal>
  </div>
</template>

<script>
  import ShrinkOrExtend from '../customizedContent/shrinkOrExtend'; // 收缩伸展搜索条件组件
  // import R3 from '../../../static/r3/r3.publish/r3.min';
  const R3 = window.R3;

  const { network, urlSearchParams, store } = R3;
  export default {
    components: { ShrinkOrExtend },
    data() {
      return {
        isShowSureForceMatch: false,
        NoForcedMatchList: [], // 未进行强制匹配的退单sku商品
        NoForcedMacthChoosed: '', // 选择的强制匹配的sku商品的明细id
        NoForcedMacthChoosedGood: '', // 选择的强制匹配的sku商品的sku
        isSureMatch: false,
        addLoading: false,
        returnReceiptMsg1: [
          {
            title: '入库单号',
            key: 'ID'
          },
          {
            title: '物流单号',
            key: 'LOGISTNUMBER'
          },
          {
            title: '入库实体仓',
            key: 'IESSTOREID'
          },
          {
            title: '物流公司',
            key: 'LOGISTICSCOMPANYID'
          },
          {
            title: '买家昵称',
            key: 'USERNICK'
          },
        ], // 退货入库单基础信息参数
        returnReceiptMsg2: [
          {
            title: '姓名',
            key: 'RECEIVNAME'
          },
          {
            title: '手机号',
            key: 'RECEIVMOBILE'
          },
          {
            title: '电话',
            key: 'RECEIVPHONE'
          },
          {
            title: '入库单创建时间',
            key: 'CREATIONDATE'
          }, {
            title: '',
            key: ''
          }
        ],
        ReturnReceiptGoodsColumns: [
          {
            title: '商品名称',
            width: 150,
            tooltip: true,
            key: 'TITLE'
          },
          {
            title: 'SKU',
            key: 'IESSKUID'
          },
          {
            title: '国标码',
            key: 'GBCODE'
          },
          // {
          //   title: '入库唯一码',
          //   key: 'QRCODE',
          //   render: (h, params) => h(
          //     'div',
          //     {
          //       attrs: {
          //         title: params.row.QRCODE
          //       }
          //     },
          //     [params.row.QRCODE ? params.row.QRCODE : '']
          //   ),
          // },
          {
            title: '规格',
            key: 'NORMSDETAILNAMES'
          },
          {
            title: '数量',
            key: 'NUM'
          },
          {
            title: '商品标记',
            key: 'PRODUCTMARK'
          },
          {
            title: '操作',
            key: 'action',
            align: 'center',
            fixed: 'right',
            width: 100,
            render: (h, params) => {
              if (!params.row.isMatch) {
                return h('div', [
                  h('Button', {
                    props: {
                      type: 'text',
                      size: 'small',
                    },
                    style: {
                      color: '#63A4FE',
                      marginRight: '5px'
                    },
                    on: {
                      click: () => {
                        this.singleMatch(params);
                      }
                    }
                  }, '匹配')
                ]);
              }
              return h('div', [
                h('span', {
                  style: {
                    color: '#909399',
                    marginRight: '5px'
                  }
                }, '已匹配')
              ]);
            }
          }
        ], // 退货入库单关联商品表格表头
        ReturnReceiptGoodsData: [], // 退货入库单关联商品数据
        ReturnReceiptID: '', // 选择的入库单ID
        returnReceipt: [], // 退货入库单
        returnOrderMsg1: [
          {
            title: '退单编号',
            key: 'ID'
          },
          {
            title: '原订单编号',
            key: 'ORIGINALORDERNO'
          },
          {
            title: '平台单号',
            key: 'SOURCECODE'
          },
          {
            title: '物流公司',
            key: 'LOGISTICSCOMPANYANME'
          },
        ], // 退货入库单基础信息参数
        returnOrderMsg2: [
          {
            title: '物流单号',
            key: 'SID'
          },
          {
            title: '买家昵称',
            key: 'BUYER_NICK'
          },
          {
            title: '退单创建时间',
            key: 'CREATEFORMAT'
          }, {
            title: '',
            key: ''
          }
        ],
        ReturnOrderGoodsColumns: [
          {
            title: '商品名称',
            width: 150,
            tooltip: true,
            key: 'TITLE'
          },
          {
            title: 'SKU',
            key: 'SKU'
          },
          {
            title: '国标码',
            key: 'GBCODE'
          },
          {
            title: '规格',
            key: 'NORMSDETAILNAMES'
          },
          {
            title: '数量',
            key: 'NUM'
          },
          {
            title: '匹配数量',
            key: 'MATCHNUM'
          },
          {
            title: '残次数量',
            key: 'CANCINUM'
          },
          {
            title: '瑕疵数量',
            key: 'XIACINUM'
          },
        ], // 退货入库单关联商品表格表头
        ReturnOrderGoodsData: [], // 退货入库单关联商品数据
        ReturnOrderID: '', // 选择的退货单ID
        returnOrder: [], // 退换货单
        matchTitleList: [], // 此次已匹配结果

        selectReturnReceiptModal: false,
        selectReturnOrderModal: false,
        mask: true,
        closable: true,
        maskClosable: false,
        hideFoot: true,
        shrinkHeight: '90px',
        currentValue: false, // 默认收缩
        // 入库实体仓参数
        IESSTOREList: {}, // 入库实体仓下拉展示数据
        IESSTOREtotalRowCount: 0,
        IESSTOREcurrentIndex: 0, // 入库实体仓搜索初始index
        columns: ['name', 'value'], // 展现的组
        IESSTOREAutoData: [], // 入库实体仓模糊搜索的结果组

        // 物流公司参数
        ExpressList: {}, // 入库实体仓下拉展示数据
        ExpresstotalRowCount: 0,
        ExpresscurrentIndex: 0, // 入库实体仓搜索初始index
        ExpressAutoData: [], // 入库实体仓模糊搜索的结果组

        selectReturnReceiptData: {// 选择入库单搜索条件
          STORAGEINID: '', // 入库单号
          LOGISTNUMBER: '', // 物流单号
          IESSTOREID: [], // 入库实体仓
          LOGISTICSCOMPANYID: [], // 物流公司
          USERNICK: '', // 买家昵称
          RECEIVNAME: '', // 姓名
          RECEIVMOBILE: '', // 手机号
          RECEIVPHONE: '', // 电话
          ALLSKU: '', // 包含SKU
        },
        selectReturnOrderData: {// 选择退单搜索条件
          REFUNDORDERID: '', // 退单编号
          ORIGINALORDERNO: '', // 原订单编号
          SOURCECODE: '', // 平台单号
          LOGISTICSCOMPANYID: [], // 物流公司
          SID: '', // 物流单号
          BUYER_NICK: '', // 买家昵称
          // RECEIVNAME: '', // 姓名
          // RECEIVMOBILE: '', // 手机号
          // RECEIVPHONE: '', // 电话
          ALLSKU: '', // 包含SKU
        },
        originalOrderData: {
          ID: '', // 订单编号
          SOURCECODE: '', // 平台单号
          ALLSKU: '', // 所有SKU
          RECEIVMOBILE: '', // 收件人手机号码
          RECEIVNAME: '', // 收件人
          USERNICK: '', // 买家昵称
        },
        tableHeight: '298', // 弹框表格高度298
        tableHeightOne: '250', // 页面表格高度
        // 入库单列表
        totalReturnReceipt: 0, // 总条数
        currentReturnReceiptPage: 0, // 页码
        pageSizeReturnReceipt: 10, // 每页的条数
        ReturnReceiptCurrentPage: 1,
        ReturnReceiptColumns: [
          {
            title: '入库单号',
            key: 'ID'
          },
          {
            title: '物流单号',
            key: 'LOGISTNUMBER'
          },
          {
            title: '入库实体仓',
            key: 'IESSTOREID'
          },
          {
            title: '物流公司',
            key: 'LOGISTICSCOMPANYID'
          },
          {
            title: '买家昵称',
            key: 'USERNICK'
          },
          {
            title: '姓名',
            key: 'RECEIVNAME'
          },
          {
            title: '手机号',
            key: 'RECEIVMOBILE'
          },
          {
            title: '电话',
            key: 'RECEIVPHONE'
          },
          {
            title: '包含SKU',
            key: 'ALLSKU'
          },
          {
            title: '入库单创建时间',
            key: 'CREATIONDATE'
          },
          {
            title: '操作',
            key: 'action',
            align: 'center',
            fixed: 'right',
            width: 100,
            render: (h, params) => h('div', [
              h('Button', {
                props: {
                  type: 'text',
                  size: 'small',
                },
                style: {
                  color: '#63A4FE',
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    if (this.ReturnReceiptID && (this.ReturnReceiptID !== params.row.ID)) {
                      this.isSureMatch = false;
                      this.ReturnOrderID = '';
                      this.returnOrder = [];
                      // this.returnOrderMsg = [];
                      this.ReturnOrderGoodsData = [];
                      this.matchTitleList = [];
                      this.getReturnReceiptMsg(params.row);
                    } else if (this.ReturnReceiptID !== params.row.ID) {
                      this.getReturnReceiptMsg(params.row);
                    } else {
                      this.selectReturnReceiptModal = false;
                    }
                    this.resetGoodsData('ReturnReceipt');
                  }
                }
              }, '选择')
            ])
          }
        ],
        ReturnReceiptData: [], // 退单列表数据

        // 退单列表
        totalReturnOrder: 0, // 总条数
        currentReturnOrderPage: 0, // 页码
        pageSizeReturnOrder: 10, // 每页的条数
        ReturnOrderCurrentPage: 1,
        ReturnOrderColumns: [
          {
            title: '退单编号',
            key: 'ID'
          },
          {
            title: '原订单编号',
            key: 'ORIGINALORDERNO'
          },
          {
            title: '平台单号',
            key: 'SOURCECODE'
          },
          {
            title: '物流公司',
            key: 'LOGISTICSCOMPANYANME'
          },
          {
            title: '物流单号',
            key: 'SID'
          },
          {
            title: '买家昵称',
            key: 'BUYER_NICK'
          },
          {
            title: '包含SKU',
            key: 'ALLSKU'
          },
          {
            title: '退单创建时间',
            key: 'CREATEFORMAT'
          },
          {
            title: '操作',
            key: 'action',
            align: 'center',
            fixed: 'right',
            width: 100,
            render: (h, params) => h('div', [
              h('Button', {
                props: {
                  type: 'text',
                  size: 'small',
                },
                style: {
                  color: '#63A4FE',
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    // if (this.ReturnOrderID && (this.ReturnOrderID !== params.row.ID)) {
                      // this.isSureMatch = false;
                      // this.matchTitleList = [];
                      // this.getReturnReceiptGoods(this.ReturnReceiptID);
                    // }
                    this.isSureMatch = false;
                    this.matchTitleList = [];
                    this.getReturnReceiptGoods(this.ReturnReceiptID);

                    this.resetGoodsData('ReturnOrder');
                    this.getReturnOrderMsg(params.row);
                  }
                }
              }, '选择')
            ])
          }
        ],
        ReturnOrderData: [], // 选择商品数据
        isFromRefundOrder: false, // 是否从退换货单列表进入
      };
    },
    created() {
      this.getRefundOrderAndReceipt()
    },
    activated() {
      this.getRefundOrderAndReceipt();
    },
    methods: {
      clickHelp() {
        this.triggerAjax();
        window.open('https://burgeon.yuque.com/cgmq7t/cgv53l/dzoofe31v7fq2tvf?singleDoc#');
      },
      // 请求埋点
      triggerAjax() {
        const params = {
          MENUNAME: '三无包裹匹配',
          BUTTONNAME: '点击帮助',
        };
        network.post('/p/cs/button/clickCount', params);
      },
      getRefundOrderAndReceipt(){
        this.refundOrderId = this.$route.query.refundOrderId;
        // 如果从退换货单页面按钮过来，自动带出退换货单以及入库单信息
        if(this.refundOrderId){
          this.isFromRefundOrder = true;
          let params = {
            objId: this.refundOrderId
          }
          this.getReturnOrderList(this.refundOrderId);
          network.post('/p/cs/refund/query/storageinid',params).then(res => {
            if(res.data.code==0){
              if(res.data.data){
                this.getReturnReceiptList(res.data.data);
              }
            }
          })
        }else {
          this.isFromRefundOrder = false;
        }
      },
      // 点击入库单商品列表中匹配进行单条匹配
      singleMatch(param) {
        if (this.returnOrder.length == 0) {
          return this.$Message.warning('请先选择退单！');
        }
        let index = param.index;
        let row = param.row;
        let flag = false;
        // 遍历退单商品列表找到对应的商品;
        for (let i = 0; i < this.ReturnOrderGoodsData.length; i++) {
          if (this.ReturnOrderGoodsData[i].SKU == row.IESSKUID && (!(this.ReturnOrderGoodsData[i].MATCHNUM == this.ReturnOrderGoodsData[i].NUM) || this.ReturnOrderGoodsData[i].NUM == 0)) {
            // if ((this.ReturnOrderGoodsData[i].MATCHNUM == this.ReturnOrderGoodsData[i].NUM) || this.ReturnOrderGoodsData[i].NUM == 0) {
              // if(i != this.ReturnOrderGoodsData.length - 1){
                // continue;
              // }else {
                // return this.$Message.error('超出退单商品数量或退单不存在该商品，不允许匹配。');
              // }
            // }
            this.ReturnOrderGoodsData[i].MATCHNUM += 1;  // 更新退货单明细匹配数量
            this.ReturnOrderGoodsData[i].matchReturnReceiptGoodIndex.push(index);
            flag = true;
            this.isSureMatch = true;
            if (this.ReturnOrderGoodsData[i].QRCODE) {
              if (this.ReturnReceiptGoodsData[index].QRCODE !== null) {
                this.ReturnOrderGoodsData[i].QRCODE += `,${this.ReturnReceiptGoodsData[index].QRCODE}`;
              }
            } else {
              this.ReturnOrderGoodsData[i].QRCODE = this.ReturnReceiptGoodsData[index].QRCODE;
            }
            if (this.ReturnReceiptGoodsData[index].PRODUCTMARK == '瑕疵品') {
              this.ReturnOrderGoodsData[i].XIACINUM += 1;
              if (this.ReturnOrderGoodsData[i].XIACIQRCODE) {
                if (this.ReturnReceiptGoodsData[index].QRCODE !== null) {
                  this.ReturnOrderGoodsData[i].XIACIQRCODE += `,${this.ReturnReceiptGoodsData[index].QRCODE}`;
                }
              } else {
                this.ReturnOrderGoodsData[i].XIACIQRCODE = this.ReturnReceiptGoodsData[index].QRCODE;
              }
            } else if (this.ReturnReceiptGoodsData[index].PRODUCTMARK == '残次品') {
              this.ReturnOrderGoodsData[i].CANCINUM += 1;
              if (this.ReturnOrderGoodsData[i].CANCIQRCODE) {
                if (this.ReturnReceiptGoodsData[index].QRCODE !== null) {
                  this.ReturnOrderGoodsData[i].CANCIQRCODE += `,${this.ReturnReceiptGoodsData[index].QRCODE}`;
                }
              } else {
                this.ReturnOrderGoodsData[i].CANCIQRCODE = this.ReturnReceiptGoodsData[index].QRCODE;
              }
            }
            this.ReturnReceiptGoodsData[index].isMatch = true;
            let obj = {
              SKU: this.ReturnOrderGoodsData[i].SKU,
              num: 1
            };
            this.matchTitleList.push(obj);
            break;
          }
        }
        this.getAllMatchList();
        if (!flag) {
          this.NoForcedMatchList = [];
          this.ReturnOrderGoodsData.forEach((item) => {
            if(Number(item.MATCHNUM) < Number(item.NUM)){
              item.indexOne = index
              this.NoForcedMatchList.push(item);
            }
          })
          if(this.NoForcedMatchList.length == 1){
            this.NoForcedMacthChoosed = this.NoForcedMatchList[0].ID
            this.NoForcedMacthChoosedGood = this.NoForcedMatchList[0].SKU
          }
          if(this.NoForcedMatchList.length == 0){
            this.$Message.error('超出退单商品数量或退单不存在该商品，不允许匹配。');
          }else {
            this.isShowSureForceMatch = true;
          }          
        }
      },
      // 强制匹配的sku选择切换
      changeNoForcedMacthChoosedGood() {
        this.ReturnOrderGoodsData.forEach(item => {
          if(item.ID == this.NoForcedMacthChoosed){
            this.NoForcedMacthChoosedGood = item.SKU;
          }
        })
      },
      sureForceMatch() {
        console.log(this.NoForcedMacthChoosedGood)
        if(!this.NoForcedMacthChoosedGood){
          return this.$Message.warning('请选择商品！');
        }
        this.isSureMatch = true;
        for (let i = 0; i < this.ReturnOrderGoodsData.length; i++) {
          if (this.ReturnOrderGoodsData[i].SKU == this.NoForcedMacthChoosedGood) {
            if(Number(this.ReturnOrderGoodsData[i].MATCHNUM) < Number(this.ReturnOrderGoodsData[i].NUM)){
              if (this.ReturnOrderGoodsData[i].QRCODE) {
                if (this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].QRCODE !== null) {
                  this.ReturnOrderGoodsData[i].QRCODE += `,${this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].QRCODE}`;
                }
              } else {
                this.ReturnOrderGoodsData[i].QRCODE = this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].QRCODE;
              }
              if (this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].PRODUCTMARK == '瑕疵品') {
                this.ReturnOrderGoodsData[i].XIACINUM += 1;
                if (this.ReturnOrderGoodsData[i].XIACIQRCODE) {
                  if (this.ReturnReceiptGoodsData[index].QRCODE !== null) {
                    this.ReturnOrderGoodsData[i].XIACIQRCODE += `,${this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].QRCODE}`;
                  }
                } else {
                  this.ReturnOrderGoodsData[i].XIACIQRCODE = this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].QRCODE;
                }
              } else if (this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].PRODUCTMARK == '残次品') {
                this.ReturnOrderGoodsData[i].CANCINUM += 1;
                if (this.ReturnOrderGoodsData[i].CANCIQRCODE) {
                  if (this.ReturnReceiptGoodsData[index].QRCODE !== null) {
                    this.ReturnOrderGoodsData[i].CANCIQRCODE += `,${this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].QRCODE}`;
                  }
                } else {
                  this.ReturnOrderGoodsData[i].CANCIQRCODE = this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].QRCODE;
                }
              }
              this.ReturnOrderGoodsData[i].MATCHNUM += 1;
              this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].refundOrderItemId = this.NoForcedMacthChoosed;
              this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].isForcedMatching = true;
              this.ReturnReceiptGoodsData[this.ReturnOrderGoodsData[i].indexOne].isMatch = true;
              let obj = {
                SKU: this.ReturnOrderGoodsData[i].SKU,
                num: 1
              };
              this.matchTitleList.push(obj);
              this.NoForcedMacthChoosed = '';
              this.NoForcedMacthChoosedGood = '';
              break;
            }
          }
        }
      },
      cancelForceMatch() {
        this.isShowSureForceMatch = false;
        this.NoForcedMacthChoosed = '';
        this.NoForcedMacthChoosedGood = '';
      },
      // 点击自动匹配按钮
      autoMatch() {
        if (this.returnReceipt.length == 0) {
          return this.$Message.warning('请先选择入库单！');
        } if (this.returnOrder.length == 0) {
          return this.$Message.warning('请先选择退单！');
        }
        let flag = false;
        for (let i = 0; i < this.ReturnReceiptGoodsData.length; i++) {
          if (!this.ReturnReceiptGoodsData[i].isMatch) {
            for (let j = 0; j < this.ReturnOrderGoodsData.length; j++) {
              // && this.ReturnOrderGoodsData[j].MATCHNUM == 0
              if (this.ReturnOrderGoodsData[j].SKU == this.ReturnReceiptGoodsData[i].IESSKUID && (!(this.ReturnOrderGoodsData[j].MATCHNUM == this.ReturnOrderGoodsData[j].NUM) || this.ReturnOrderGoodsData[j].NUM == 0) ){ //&& (this.ReturnOrderGoodsData[j].MATCHNUM < this.ReturnOrderGoodsData[j].NUM)) {
                flag = true;
                this.isSureMatch = true;
                this.ReturnOrderGoodsData[j].MATCHNUM += 1;
                this.ReturnOrderGoodsData[j].matchReturnReceiptGoodIndex.push(i);
                if (this.ReturnOrderGoodsData[j].QRCODE) {
                  if (this.ReturnReceiptGoodsData[i].QRCODE !== null) {
                    this.ReturnOrderGoodsData[j].QRCODE += `,${this.ReturnReceiptGoodsData[i].QRCODE}`;
                  }
                } else {
                  this.ReturnOrderGoodsData[j].QRCODE = this.ReturnReceiptGoodsData[i].QRCODE;
                }
                if (this.ReturnReceiptGoodsData[i].PRODUCTMARK == '瑕疵品') {
                  this.ReturnOrderGoodsData[j].XIACINUM += 1;
                  if (this.ReturnOrderGoodsData[j].XIACIQRCODE) {
                    if (this.ReturnReceiptGoodsData[j].QRCODE !== null) {
                      this.ReturnOrderGoodsData[j].XIACIQRCODE += `,${this.ReturnReceiptGoodsData[i].QRCODE}`;
                    }
                  } else {
                    this.ReturnOrderGoodsData[j].XIACIQRCODE = this.ReturnReceiptGoodsData[i].QRCODE;
                  }
                } else if (this.ReturnReceiptGoodsData[i].PRODUCTMARK == '残次品') {
                  this.ReturnOrderGoodsData[j].CANCINUM += 1;
                  if (this.ReturnOrderGoodsData[j].CANCIQRCODE) {
                    if (this.ReturnReceiptGoodsData[j].QRCODE !== null) {
                      this.ReturnOrderGoodsData[j].CANCIQRCODE += `,${this.ReturnReceiptGoodsData[i].QRCODE}`;
                    }
                  } else {
                    this.ReturnOrderGoodsData[j].CANCIQRCODE = this.ReturnReceiptGoodsData[i].QRCODE;
                  }
                }
                this.ReturnReceiptGoodsData[i].isMatch = true;
                let obj = {
                  SKU: this.ReturnOrderGoodsData[j].SKU,
                  num: 1
                };
                this.matchTitleList.push(obj);
                break;
              }
            }
          }
        }
        this.getAllMatchList();
        if (flag) {
          this.$Message.success('匹配完成');
        } else {
          this.$Message.error('匹配失败：入库单和退单无相同商品');
        }
      },
      // 获取已匹配项合并数据
      getAllMatchList() {
        let keys = Array.from(new Set(this.matchTitleList.map(item => item.SKU)));
        this.matchTitleList = keys.map(key => ({ SKU: key, num: this.matchTitleList.filter(item => item.SKU == key).reduce((pre, cur) => pre + cur.num, 0) }));
      },
      // 取消匹配
      cancelMatch() {
        this.isSureMatch = false;
        this.matchTitleList = [];
        this.NoForcedMacthChoosed = '';
        this.NoForcedMacthChoosedGood = '';
        this.getReturnReceiptGoods(this.ReturnReceiptID);
        this.getReturnOrderGoods(this.ReturnOrderID);
      },
      // 点击选择入库单
      chooseReturnReceipt() {
        this.selectReturnReceiptModal = true;
        this.getReturnReceiptList();
      },
      // 通过选择入库单获得当前选中的入库单相关信息
      getReturnReceiptMsg(param) {
        console.log(param)
        this.selectReturnReceiptModal = false;
        let obj = param;
        this.returnReceipt[0] = obj;
        this.ReturnReceiptID = param.ID;
        this.getReturnReceiptGoods(param.ID);
      },
      // 获取入库单对应的商品信息
      getReturnReceiptGoods(ID) {
        network.post(`/p/cs/returnInStore/getStorageInById?id=${ID}`, {}).then(res => {
          let list = [];
          if (res.data.data.storageInProductPOList) {
            res.data.data.storageInProductPOList.forEach(item => {
              let obj = {
                ID: item.ID,
                TITLE: item.TITLE,
                IESSKUID: item.SKU,
                GBCODE: item.GBCODE,
                QRCODE: item.QRCODE, // item.QRCODE
                NORMSDETAILNAMES: item.normsdetailnames ? item.normsdetailnames : '',
                NUM: item.NUM,
                // eslint-disable-next-line no-nested-ternary
                PRODUCTMARK: item.PRODUCTMARK == 1 ? '正品' : item.PRODUCTMARK == 2 ? '瑕疵品' : item.PRODUCTMARK == 3 ? '残次品' : '',
                isMatch: item.ISMATCH == 0 ? false : true,
              };
              list.push(obj);
            });
            this.ReturnReceiptGoodsData = list;
          }
        });
      },
      // 获取入库单列表数据
      getReturnReceiptList(ID) {
        // let virtual = {
        //   searchdata: {
        //     table: 'V_OMSSTORAGEIN',
        //     range: this.pageSizeReturnReceipt,
        //     startindex: this.currentReturnReceiptPage,
        //     fixedcolumns: {
        //       STORAGEINID: this.selectReturnReceiptData.STORAGEINID,
        //       LOGISTNUMBER: this.selectReturnReceiptData.LOGISTNUMBER,
        //       IESWAREHOUSEID: this.selectReturnReceiptData.IESSTOREID[0],
        //       LOGISTICSCOMPANYID: this.selectReturnReceiptData.LOGISTICSCOMPANYID[0],
        //       USERNICK: this.selectReturnReceiptData.USERNICK,
        //       RECEIVNAME: this.selectReturnReceiptData.RECEIVNAME,
        //       RECEIVMOBILE: this.selectReturnReceiptData.RECEIVMOBILE,
        //       RECEIVPHONE: this.selectReturnReceiptData.RECEIVPHONE,
        //       ALLSKU: this.selectReturnReceiptData.ALLSKU,
        //       VIRSTATUS: ['=0', '=1']
        //     },
        //     column_include_uicontroller: true,
        //     isolr: false
        //   }
        // };
        let virtual = {
          fixedcolumns: {
            STORAGEINID: this.selectReturnReceiptData.STORAGEINID,
            LOGISTNUMBER: this.selectReturnReceiptData.LOGISTNUMBER,
            IESWAREHOUSEID: this.selectReturnReceiptData.IESSTOREID[0],
            LOGISTICSCOMPANYID: this.selectReturnReceiptData.LOGISTICSCOMPANYID[0],
            USERNICK: this.selectReturnReceiptData.USERNICK,
            RECEIVNAME: this.selectReturnReceiptData.RECEIVNAME,
            RECEIVMOBILE: this.selectReturnReceiptData.RECEIVMOBILE,
            RECEIVPHONE: this.selectReturnReceiptData.RECEIVPHONE,
            ALLSKU: this.selectReturnReceiptData.ALLSKU,
            VIRSTATUS: ['=0', '=1']
          },
          fkdrplist: {
            searchcols: ['IESWAREHOUSEID', 'USERNICK', 'ALLSKU', 'VIRSTATUS', 'CREATIONDATE', 'LOGISTNUMBER', 'CCP_IESSTOREID', 'REFUNDCHECKDATE', 'STORAGEINID', 'ORIGINALORDERNO', 'XCP_IESSTOREID', 'SOURCECODE', 'ID', 'ZP_IESSTOREID', 'REMARK', 'LOGISTICSCOMPANYID', 'RECEIVNAME', 'RECEIVMOBILE', 'RECEIVPHONE']
          },
          isdroplistsearch: true,
          range: this.pageSizeReturnReceipt,
          startindex: this.currentReturnReceiptPage,
          table: 'V_OMSSTORAGEIN'
        };
        if(ID){
          virtual.fixedcolumns.STORAGEINID = ID
        }
        network.post('/p/cs/list/query', virtual).then((res) => {
          // if (res.data.code == 0) {
          let list = [];
          res.data.rows.forEach(item => {
            let obj = {
              ID: item.ID.val,
              LOGISTNUMBER: item.LOGISTNUMBER.val,
              IESSTOREID: item.IESWAREHOUSEID ? item.IESWAREHOUSEID.val : '',
              LOGISTICSCOMPANYID: item.LOGISTICSCOMPANYID.val,
              USERNICK: item.USERNICK.val,
              RECEIVNAME: item.RECEIVNAME.val,
              RECEIVMOBILE: item.RECEIVMOBILE.val,
              RECEIVPHONE: item.RECEIVPHONE.val,
              ALLSKU: item.ALLSKU ? item.ALLSKU.val : '',
              CREATIONDATE: item.CREATIONDATE ? item.CREATIONDATE.val : '', // 需要改成入库单创建时间
            };
            list.push(obj);
          });
          if(ID) {
            this.isSureMatch = false;
            this.matchTitleList = [];
            this.getReturnReceiptMsg(list[0]);
          }
          this.totalReturnReceipt = res.data.total;
          this.ReturnReceiptData = list;
          // }
        });
      },
      // 点击选择退换货单
      chooseReturnOrder() {
        this.isSureMatch = false;
        this.selectReturnOrderModal = true;
        this.getReturnOrderList();
      },
      // 通过选择退单获得当前选中的退单相关信息
      getReturnOrderMsg(param) {
        this.selectReturnOrderModal = false;
        let obj = param;
        this.returnOrder[0] = obj;
        this.ReturnOrderID = param.ID;
        this.getReturnOrderGoods(param.ID);
      },
      // 获取退单对应的商品信息
      getReturnOrderGoods(ID) {
        let virtual = {
          fixedcolumns: { OMSRefundOrderId: ID },
          range: 1000,
          startindex: 0,
          table: 'T_V_OMSRECEDEORDERPRODUCT'
        };
        network.post('/p/cs/list/query', virtual).then(res => {
          let list = [];
          res.data.rows.forEach(item => {
            let obj = {
              ID: item.ID.val,
              TITLE: item.TITLE.val,
              SKU: item.SKU.val,
              GBCODE: item.GBCODE.val,
              QRCODE: '',
              NORMSDETAILNAMES: item.NORMSDETAILNAMES ? item.NORMSDETAILNAMES.val : '',
              NUM: item.REFUNDNUM.val,
              MATCHNUM: 0,
              CANCINUM: 0,
              XIACINUM: 0,
              CANCIQRCODE: '',
              XIACIQRCODE: '',
              matchReturnReceiptGoodIndex:[],
            };
            list.push(obj);
          });
          this.ReturnOrderGoodsData = list;
        });
      },
      // 获取退单列表数据
      getReturnOrderList(ID) {
        let virtual = {
          fixedcolumns: {
            ALLSKU: this.selectReturnOrderData.ALLSKU,
            BUYER_NICK: this.selectReturnOrderData.BUYER_NICK,
            LOGISTICSCOMPANYID: this.selectReturnOrderData.LOGISTICSCOMPANYID[0] ? this.selectReturnOrderData.LOGISTICSCOMPANYID[0] : '',
            ORIGINALORDERNO: this.selectReturnOrderData.ORIGINALORDERNO,
            REFUNDORDERID: this.selectReturnOrderData.REFUNDORDERID,
            SID: this.selectReturnOrderData.SID,
            SOURCECODE: this.selectReturnOrderData.SOURCECODE,
          },
          // range: this.pageSizeReturnOrder,
          size: this.pageSizeReturnOrder,
          page: this.ReturnOrderCurrentPage,
          // startindex: this.currentReturnOrderPage,
        };
        if(ID){
          virtual.fixedcolumns.REFUNDORDERID = ID;
        }
        // 标准接口改为定制接口
        network.post('/p/cs/returnInStore/getRefundOrder', virtual).then((res) => {
          if (res.data.code == 0) {
            let list = [];
            res.data.data.rows.forEach(item => {
              let obj = {
                ID: item.ID,
                ORIGINALORDERNO: item.ORIGINALORDERNO,
                SOURCECODE: item.SOURCECODE,
                LOGISTICSCOMPANYID: item.LOGISTICSCOMPANYID,
                LOGISTICSCOMPANYANME: item.LOGISTICSCOMPANYANME,
                SID: item.SID,
                BUYER_NICK: item.BUYER_NICK,
                ALLSKU: item.ALLSKU ? item.ALLSKU : '',
                // CREATED: item.CREATED ? item.CREATED : '', // 需要改成退单创建时间
                CREATEFORMAT: item.CREATEFORMAT ? item.CREATEFORMAT : '', // 需要改成退单创建时间
              };
              list.push(obj);
            });
            if(ID) {  // 如果是退换货单跳转，直接赋值
              this.getReturnOrderGoods(this.refundOrderId);
              this.matchTitleList = [];
              this.getReturnOrderMsg(list[0]);
            }
            this.totalReturnOrder = res.data.data.totalRowCount;
            this.ReturnOrderData = list;
          }
        });
        // let virtual = {
        //   searchdata: {
        //     table: 'T_V_OMSREFUNDORDERALL',
        //     range: this.pageSizeReturnOrder,
        //     startindex: this.currentReturnOrderPage,
        //     fixedcolumns: {
        //       REFUNDORDERID: this.selectReturnOrderData.REFUNDORDERID,
        //       ORIGINALORDERNO: this.selectReturnOrderData.ORIGINALORDERNO,
        //       SOURCECODE: this.selectReturnOrderData.SOURCECODE,
        //       LOGISTICSCOMPANYID: this.selectReturnOrderData.LOGISTICSCOMPANYID[0],
        //       SID: this.selectReturnOrderData.SID,
        //       BUYER_NICK: this.selectReturnOrderData.BUYER_NICK,
        //       ALLSKU: this.selectReturnOrderData.ALLSKU,
        //       VIRSTATUS: ['=10', '=20'],
        //     },
        //     column_include_uicontroller: true,
        //     isolr: false
        //   }
        // };
        // network.post('/p/cs/QueryList', urlSearchParams(virtual)).then((res) => {
        //   if (res.data.code == 0) {
        //     let list = [];
        //     res.data.data.row.forEach(item => {
        //       let obj = {
        //         ID: item.ID.val,
        //         ORIGINALORDERNO: item.ORIGINALORDERNO.val,
        //         SOURCECODE: item.SOURCECODE.val,
        //         LOGISTICSCOMPANYID: item.LOGISTICSCOMPANYID.val,
        //         SID: item.SID.val,
        //         BUYER_NICK: item.BUYER_NICK.val,
        //         ALLSKU: item.ALLSKU ? item.ALLSKU.val : '',
        //         CREATED: item.CREATED ? item.CREATED.val : '', // 需要改成退单创建时间
        //       };
        //       list.push(obj);
        //     });
        //     this.totalReturnOrder = res.data.data.totalRowCount;
        //     this.ReturnOrderData = list;
        //   }
        // });
      },
      // 选择入库单弹框中的筛选下拉框数据start
      // 单选下拉分页改变
      changePageShop(e, type) {
        if (type == 'IESSTORE') {
          this.IESSTOREcurrentIndex = (e - 1) * 10;
          this.searchShopData(type);
        } else if (type == 'Express' || type == 'ExpressOrder') {
          this.ExpresscurrentIndex = (e - 1) * 10;
          this.searchShopData(type);
        }
      },
      // 外键下拉框
      searchShopData(type) {
        let virtual = {};
        if (type === 'IESSTORE') {
          virtual = {
            searchdata: {
              isdroplistsearch: true,
              refcolid: 196675,
              startindex: this.IESSTOREcurrentIndex,
              range: 10
            }
          };
        } else if (type == 'Express' || type == 'ExpressOrder') {
          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) {
            if (type === 'IESSTORE') {
              this.IESSTOREtotalRowCount = res.data.data.totalRowCount;
              this.IESSTOREList = res.data.data;
              this.IESSTOREList.tabth = [
                {
                  agfilter: 'LIST',
                  col_id: 172419,
                  colname: 'ID',
                  datelimit: 'all',
                  display: 'text',
                  inputname: 'ID',
                  isagfilter: false,
                  isak: false,
                  isfilter: true,
                  ismodify: false,
                  isnotnull: false,
                  issubtotal: false,
                  isuppercase: false,
                  length: 20,
                  name: '编号',
                  orderno: 1,
                  scale: 0,
                  type: 'NUMBER'
                }, {
                  agfilter: 'LIST',
                  col_id: 193479,
                  colname: 'WAREHOUSENAME',
                  datelimit: 'all',
                  display: 'text',
                  inputname: 'WAREHOUSENAME',
                  isagfilter: true,
                  isak: true,
                  isfilter: true,
                  ismodify: true,
                  isnotnull: true,
                  issubtotal: false,
                  isuppercase: false,
                  length: 32,
                  name: '店仓名称',
                  orderno: 1,
                  type: 'STRING'
                }
              ];
              this.IESSTOREcurrentIndex = 0;
            } else if (type === 'Express' || type === 'ExpressOrder') {
              this.ExpresstotalRowCount = res.data.data.totalRowCount;
              this.ExpressList = res.data.data;
              this.ExpresscurrentIndex = 0;
            }
          }
        });
      },
      // 单选下拉模糊搜索数据
      InputValueChangeShop(e, type) {
        let virtual = {};
        if (type === 'IESSTORE') {
          virtual = {
            ak: e,
            colid: 196675,
            fixedcolumns: {}
          };
        } else if (type === 'Express' || type === 'ExpressOrder') {
          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);
            });
            if (type === 'IESSTORE') {
              this.IESSTOREAutoData = list;
            } else if (type === 'Express' || type === 'ExpressOrder') {
              this.ExpressAutoData = list;
            }
          }
        });
      },
      // 外键下拉框搜索
      focusInputValueChangeShop(e, type) {
        let virtual = {};
        if (type === 'IESSTORE') {
          virtual = {
            ak: e.target.value,
            colid: 196675,
            fixedcolumns: {}
          };
        } else if (type === 'Express' || type === 'ExpressOrder') {
          virtual = {
            ak: e.target.value,
            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);
            });
            if (type === 'IESSTORE') {
              this.IESSTOREAutoData = list;
            } else if (type === 'Express' || type === 'ExpressOrder') {
              this.ExpressAutoData = list;
            }
          }
        });
      },
      // 单选下拉选中
      checkDataShop(val, type) {
        let list = [];
        list.push(val[0].ID);
        if (type == 'IESSTORE') {
          this.selectReturnReceiptData.IESSTOREID = list;
        } else if (type === 'Express') {
          this.selectReturnReceiptData.LOGISTICSCOMPANYID = list;
        } else if (type === 'ExpressOrder') {
          this.selectReturnOrderData.LOGISTICSCOMPANYID = list;
        }
      },
      clearDataShop(type) {
        if (type == 'IESSTORE') {
          this.selectReturnReceiptData.IESSTOREID = [];
        } else if (type === 'Express') {
          this.selectReturnReceiptData.LOGISTICSCOMPANYID = [];
        } else if (type === 'ExpressOrder') {
          this.selectReturnOrderData.LOGISTICSCOMPANYID = [];
        }
      },
      // 选择入库单弹框中的筛选下拉框数据end

      // 取消选择入库单
      cancelSelectReturnReceipt() {
        this.resetGoodsData('ReturnReceipt');
        this.selectReturnReceiptModal = false;
      },
      // 取消选择退货单
      cancelSelectReturnOrder() {
        this.resetGoodsData('ReturnOrder');
        this.selectReturnOrderModal = false;
      },
      // 重置选择商品搜索条件
      resetGoodsData(type) {
        if (type == 'ReturnReceipt') {
          this.selectReturnReceiptData = {// 选择入库单搜索条件
            STORAGEINID: '', // 入库单号
            LOGISTNUMBER: '', // 物流单号
            IESSTOREID: [], // 入库实体仓
            LOGISTICSCOMPANYID: [], // 物流公司
            USERNICK: '', // 买家昵称
            RECEIVNAME: '', // 姓名
            RECEIVMOBILE: '', // 手机号
            RECEIVPHONE: '', // 电话
          };
          this.pageSizeReturnReceipt = 10;
          this.currentReturnReceiptPage = 0;
          this.ReturnReceitCurrentPage = 1;
          this.$refs.IESSTORE.inputValue = '';
          this.$refs.Express.inputValue = '';
        } else if (type == 'ReturnOrder') {
          this.selectReturnOrderData = {// 选择退单搜索条件
            REFUNDORDERID: '', // 退单编号
            ORIGINALORDERNO: '', // 原订单编号
            SOURCECODE: '', // 平台单号
            LOGISTICSCOMPANYID: [], // 物流公司
            SID: '', // 物流单号
            BUYER_NICK: '', // 买家昵称
            ALLSKU: '', // 包含SKU
          };
          this.pageSizeReturnOrder = 10;
          this.currentReturnOrderPage = 0;
          this.ReturnOrderCurrentPage = 1;
          this.$refs.ExpressOrder.inputValue = '';
        }
        this.searchGoodsData(type);
      },
      // 查询符合搜索条件的商品
      searchGoodsData(type) {
        if (type == 'ReturnReceipt') {
          this.currentReturnReceiptPage = 0;
          this.ReturnReceiptCurrentPage = 1;
          this.getReturnReceiptList();
        } else if (type == 'ReturnOrder') {
          this.currentReturnOrderPage = 0;
          this.ReturnOrderCurrentPage = 1;
          this.getReturnOrderList();
        }
      },
      // 选择入库单页码改变时触发
      changePageReturnReceipt(val) {
        // 1=>0 2=>10 3=>20
        this.ReturnReceiptCurrentPage = val;
        this.currentReturnReceiptPage = (val - 1) * this.pageSizeReturnReceipt;
        this.getReturnReceiptList();
      },
      // 选择入库单页数改变时触发
      changeSizeReturnReceipt(val) {
        this.ReturnReceiptCurrentPage = 1;
        this.pageSizeReturnReceipt = val;
        this.currentReturnReceiptPage = 0;
        this.getReturnReceiptList();
      },

      // 选择退单改变时触发
      changePageReturnOrder(val) {
        // 1=>0 2=>10 3=>20
        this.ReturnOrderCurrentPage = val;
        this.currentReturnOrderPage = (val - 1) * this.pageSizeReturnOrder;
        this.getReturnOrderList();
      },
      // 选择商品页数改变时触发
      changeSizeReturnOrder(val) {
        this.ReturnOrderCurrentPage = 1;
        this.pageSizeReturnOrder = val;
        this.currentReturnOrderPage = 0;
        this.getReturnOrderList();
      },

      upOrDown(height) {
        this.currentValue = !this.currentValue;
        document.getElementsByClassName('conditionContent')[0].style.maxHeight = this.currentValue ? height : '';
        this.tableHeight = this.currentValue ? '250' : '200';
      },

      // 确认匹配
      handMatch() {
        let storageInList = [];
        let refundOrderList = [];
        let isAllMatch = true;
        if (this.ReturnReceiptGoodsData.length > 0) {
          this.ReturnReceiptGoodsData.forEach(item => {
            let obj = {
              id: item.ID,
              num: item.NUM,
              sku: item.IESSKUID,
              status: item.isMatch ? 1 : 0,
              refundOrderItemId: item.refundOrderItemId ? item.refundOrderItemId:'',
              isForcedMatching: item.isForcedMatching ? true: false
            };
            if (!item.isMatch) {
              isAllMatch = false;
            }
            storageInList.push(obj);
          });
        }
        if (this.ReturnOrderGoodsData.length > 0) {
          this.ReturnOrderGoodsData.forEach(item => {
            let obj = {
              id: item.ID,
              matchNum: item.MATCHNUM==0?item.matchReturnReceiptGoodIndex.length:item.MATCHNUM,
              xiaciNum: item.XIACINUM,
              canciNum: item.CANCINUM,
              num: item.NUM,
              sku: item.SKU,
              qrCode: item.QRCODE,
              CCP_QRCODE: item.CANCIQRCODE,
              XCP_QRCODE: item.XIACIQRCODE,
              matchReturnReceiptGoodIndex: item.matchReturnReceiptGoodIndex
            };
            refundOrderList.push(obj);
          });
        }
        let param = {
          refundOrder: {
            refundOrderId: this.ReturnOrderID,
            originOrderId: this.returnOrder[0].ORIGINALORDERNO,
            sourceCode: this.returnOrder[0].SOURCECODE,
            refundOrderList,
          },
          storageIn: {
            storageInId: this.ReturnReceiptID,
            storageInList
          }
        };
        network.post('/p/cs/returnInStore/handMatch', param).then(res => {
          if (res.data.code == 0) {
            this.$Message.success(`手工匹配退单｛${this.ReturnOrderID}｝成功`);
            // 匹配成功后清空退货单
            this.ReturnOrderID = '';
            this.returnOrder = [];
            // this.returnOrderMsg = [];
            this.ReturnOrderGoodsData = [];
            this.matchTitleList = [];// 清空此次已匹配
            this.isSureMatch = false;// 是否匹配状态为否，此时底部按钮不可点击
            if (isAllMatch) {
              this.ReturnReceiptID = '';
              this.returnReceipt = [];
              // this.returnReceiptMsg = [];
              this.ReturnReceiptGoodsData = [];
            }
          }
        });
      }
    },
  };
</script>
<style lang='less'>
  .input_box.ark-fkrp-select {
    width: 100%;
  }
  .getReturnTable .ark-table-fixed-body {
    height: 100%;
  }
  .getReturnTable .ark-table th,.getReturnTable .ark-table td {
    height: 38px;
  }
  .getReturnTable .ark-table-fixed-right {
    box-shadow: -2px 0px 2px 0px rgba(127, 127, 127, 0.5);
  }
</style>
<style lang='less' scoped>
  .ManualMatch {
    position: relative;
    width: calc(100% + 30px);
    margin-left: -15px;
    margin-right: -15px;
    height: 100%;
    background: #F2F2F2;
    .matchContent {
      // display: flex;
      height: calc(100% - 70px);
      overflow-y: auto;
      overflow-x: hidden;
      .returnReceiptPart {
        width: calc(50% - 15px);
        background: #fff;
        margin-right: 12px;
        padding-bottom: 16px;
      }
      // .fengediv {
      //   width: 12px;
      //   // height: 160%;
      //   background: #F2F2F2;
      // }
      .returnOrderPart {
        width: 50%;
        background: #fff;
      }
      .returnTop {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 54px;
        padding: 0 16px;
        border-bottom: 1px solid #E6E6E6;
        .returnType {
          font-size: 16px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #4C4C4C;
          line-height: 22px;
        }
      }
      .emptyOrder {
        display: flex;
        align-items: center;
        justify-content: center;
        height: calc(100% - 55px);
        >div {
          text-align: center;
        }
        img {
          width: 80%;
        }
        .emptyTip {
          font-size: 12px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #909399;
          line-height: 17px;
        }
      }
      .haveOrder {
        .baseBox {
          display: flex;
          padding: 16px 16px 18px;
        }
        .lastBaseBox {
          padding-bottom: 53px;
        }
        .baseMsgBox {
          width: 50%;
          // margin: 16px 16px 50px;
          border: 1px solid #E1E1E1;
          .msgItem {
            display: flex;
            align-items: center;
            height: 35px;
            border-top: 1px solid #E1E1E1;
            .msgTitle {
              display: inline-block;
              padding: 0 16px;
              width: 120px;
              height: 33px;
              line-height: 34px;
              text-align: right;
              background: #F9FAFC;
              border-right: 1px solid #E1E1E1;
            }
            .msgValue {
              display: inline-block;
              width: calc(100% - 120px);
              padding: 0 16px;
              text-align: left;
              text-overflow: ellipsis;
              white-space: nowrap;
              overflow: hidden;
            }
          }
          .msgItem:first-child {
            border-top: none;
          }
        }
        .baseMsgBox:last-child {
          border-left: none;
        }
        .linkGoods {
          margin: 16px;
        }
      }
      .goodsTitle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 30px;
        margin: 12px 16px;
        span {
          display: inline-block;
          height: 14px;
          padding-left: 6px;
          color: #4C4C4C;
          border-left: 2px solid var(--primary-color);
        }
      }
    }
    .matchTitleList {
      padding: 0 16px;
    }
    .bottomBtnBox {
      position: absolute;
      z-index: 3;
      bottom: 0px;
      width: 100%;
      height: 62px;
      line-height: 62px;
      text-align: center;
      background: #fff;
      box-shadow: 0px -1px 3px 0px rgba(218, 218, 218, 0.5);
      .cancelBtn {
        width:80px;
        height: 30px;
        padding: unset;
        margin: 0 4px;
        color: #666666;
        background: #DADADA;
      }
      .cancelBtn:hover {
        border: 1px solid #DADADA;
      }
      .cancelAbleBtn {
        width:80px;
        height: 30px;
        padding: unset;
        margin: 0 4px;
        color: #666666;
        background: #fff;
        border: 1px solid #CBCBCB;
      }
      .sureBtn {
        width:80px;
        height: 30px;
        padding: unset;
        margin: 0 4px;
        color: #fff;
        background: var(--primary-color);
      }
    }
  }
  .returnTabs {
      width: 108px;
      height: 36px;
      text-align: center;
      line-height: 32px;
      margin-top: -7px;
      color: #1C73FF;
      border-left: 1px solid #DEDEDE;
      border-right: 1px solid #DEDEDE;
      border-top: 2px solid var(--primary-color);
  }
  .conditionContent {
    width: 100%;
    display: flex;
    max-height: 3000px;
    overflow: hidden;
    flex-wrap: wrap;
    padding-top: 8px;
    // justify-content: space-between;
    .itemContent {
      // width: calc((100% - 120px) / 3);
      width: calc(100% / 3);
      display: flex;
      align-items: center;
      // margin:0 20px 24px;
      margin: 0 0px 16px;
      .itemLabel {
        min-width: 84px;
        font-size: 12px;
        font-weight: 500;
        color: #4C4C4C;
        line-height: 17px;
        margin-right: 8px;
        text-align: right;
      }
      .posterType {
        width: calc(100% - 84px);
      }
    }
  }
  .pageContent {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
  }
  .NoForcedMatchList {
    padding-left: 34px;
    color: #000;
  }
</style>
