<!--
 * @Author: xiachao 958053195@qq.com
 * @Date: 2024-06-12 11:11:44
 * @LastEditors: xiachao 958053195@qq.com
 * @LastEditTime: 2024-08-07 18:06:26
 * @FilePath: \ruoyi-ui\src\views\afterSaleOrder\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container order-index">
    <el-tabs v-model="activeName" @tab-click="tabClick">
      <el-tab-pane label="全部" name="0"> </el-tab-pane>
      <el-tab-pane name="PENDING_RETURN_PACKAGES">
        <span slot="label">待签收回寄包裹{{ tabNum[0] }} </span>
      </el-tab-pane>
      <el-tab-pane name="AWAITING_FINANCE_APPROVAL">
        <span slot="label">待财务复核{{ tabNum[1] }}</span>
      </el-tab-pane>
      <el-tab-pane name="AWAITING_SUPERVISOR_APPROVAL">
        <span slot="label">待客服主管复核{{ tabNum[2] }}</span>
      </el-tab-pane>
      <el-tab-pane name="PENDING_REFUNDS">
        <span slot="label">待退款{{ tabNum[3] }}</span>
      </el-tab-pane>
      <el-tab-pane name="CONFIRM_SEND">
        <span slot="label">待回传换货发货信息{{ tabNum[4] }}</span>
      </el-tab-pane>
      <el-tab-pane name="REJECT_PACKAGE">
        <span slot="label">打回退货包裹{{ tabNum[5] }}</span>
      </el-tab-pane>
    </el-tabs>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
      class="mini-form"
    >
      <el-form-item label="申请时间:" prop="dateType">
        <el-date-picker
          v-model="queryParams.dateRange"
          style="width: 220px"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="店铺:" prop="shopCodes">
        <el-select
          multiple
          filterable
          v-model="queryParams.shopCodes"
          placeholder="请选择"
          clearable
          style="width: 155px"
        >
          <el-option
            v-for="dict in channelList"
            :key="dict.channelCode"
            :label="dict.channelName"
            :value="dict.channelCode"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="电商平台:" prop="platformNos">
        <el-select
          multiple
          filterable
          v-model="queryParams.platformNos"
          placeholder="请选择"
          clearable
          style="width: 155px"
        >
          <el-option
            v-for="dict in platformLists"
            :key="dict.platformNo"
            :label="dict.platformName"
            :value="dict.platformNo"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="售后单类型:" prop="afterSalesTypes">
        <el-select
          multiple
          filterable
          v-model="queryParams.afterSalesTypes"
          placeholder="请选择"
          clearable
          style="width: 155px"
        >
          <el-option
            v-for="dict in orderTypeList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        label="售后单状态:"
        v-if="activeName == '0'"
        prop="afterSalesStatusEnums"
      >
        <el-select
          multiple
          filterable
          v-model="queryParams.afterSalesStatusEnums"
          placeholder="请选择"
          clearable
          style="width: 155px"
        >
          <el-option
            v-for="dict in orderStateList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="平台售后单号:" prop="afterSalesPlatformCode2" label-width="100px">
        <el-input
          v-model="queryParams.afterSalesPlatformCode2"
          placeholder="多个平台售后单号使用逗号隔开"
          style="width: 155px"
          clearable
          @input="(value) => copySkus(value, 'afterSalesPlatformCode2')"
        />
      </el-form-item>
      <el-form-item label="订单编码:" prop="orderNos2">
        <el-input
          v-model.trim="queryParams.orderNos2"
          placeholder="请输入平台单号/管易单号，多个逗号分隔"
          style="width: 155px"
          clearable
          @input="(value) => copySkus(value, 'orderNos2')"
        />
      </el-form-item>
      <el-form-item label="售后单编号:" prop="afterSalesNos2">
        <el-input
          v-model.trim="queryParams.afterSalesNos2"
          placeholder="请输入售后单编号"
          style="width: 155px"
          clearable
        />
      </el-form-item>

      <el-form-item label="商品编码:" prop="skuNos2">
        <el-input
          v-model="queryParams.skuNos2"
          placeholder="多个商品编码使用逗号隔开"
          style="width: 155px"
          clearable
          @input="(value) => copySkus(value, 'skuNos2')"
        />
      </el-form-item>
      <el-form-item label="商品名称:" prop="skuNo" v-show="showForm">
        <LoadMoreSelect
          :skuNo="queryParams.skuNo"
          style="width: 155px"
          @queryParams="(val) => (queryParams.skuNo = val)"
        />
      </el-form-item>
      <el-form-item label="品牌:" prop="brandNos" v-show="showForm">
        <el-select
          v-model="queryParams.brandNos"
          filterable
          placeholder="品牌"
          clearable
          multiple
          style="width: 155px"
        >
          <el-option
            v-for="(dict, index) in brandNameList2"
            :key="dict.brandCode"
            :label="dict.brandName"
            :value="dict.brandCode"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="串码:" prop="serials2" v-show="showForm">
        <el-input
          v-model="queryParams.serials2"
          placeholder="请输入完整串码，多个逗号分开"
          clearable
          style="width: 155px"
          @input="(value) => copySkus(value, 'serials2')"
        />
      </el-form-item>
      <el-form-item
        label="退货物流单号:"
        prop="returnExpressNos2"
        v-show="showForm"
        label-width="100px"
      >
        <el-input
          v-model="queryParams.returnExpressNos2"
          placeholder="请输入完整快递单号，多个逗号分开"
          clearable
          style="width: 155px"
          @input="(value) => copySkus(value, 'returnExpressNos2')"
        />
      </el-form-item>
      

      <el-form-item label="退款类型:" prop="refundTypes" v-show="showForm">
        <el-select
          multiple
          filterable
          v-model="queryParams.refundTypes"
          placeholder="请选择"
          clearable
          style="width: 155px"
        >
          <el-option
            v-for="dict in refundTypeList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        label="退款原因:"
        prop="afterSalesReasonEnums"
        v-show="showForm"
      >
        <el-select
          multiple
          filterable
          v-model="queryParams.afterSalesReasonEnums"
          placeholder="请选择"
          clearable
          style="width: 155px"
          allow-create
        >
          <el-option
            v-for="dict in refundReasonList"
            :key="dict.label"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="标签:" prop="tags" v-show="showForm">
        <el-select
          multiple
          filterable
          v-model="queryParams.tags"
          placeholder="请选择"
          clearable
          style="width: 155px"
        >
          <el-option
            v-for="dict in orderLabelList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否代发:" prop="hasSupplier" v-show="showForm">
        <el-select
          v-model="queryParams.hasSupplier"
          placeholder="请选择"
          clearable
          style="width: 155px"
        >
          <el-option
            v-for="dict in whetherShippingList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="代发供货商:" prop="supplierNos" v-show="showForm">
        <el-select
          multiple
          filterable
          v-model="queryParams.supplierNos"
          placeholder="请选择"
          clearable
          style="width: 155px"
        >
          <el-option
            v-for="dict in shippingSupplierList"
            :key="dict.supplierCode"
            :label="dict.supplierName"
            :value="dict.supplierCode"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="购买会员:" prop="vipName" v-show="showForm">
        <el-input
          v-model="queryParams.vipName"
          placeholder="请输入关键字"
          clearable
          style="width: 155px"
        />
      </el-form-item>
      <el-form-item label="对接客服:" prop="customerService" v-show="showForm">
        <el-input
          v-model="queryParams.customerService"
          placeholder="请输入关键字"
          clearable
          style="width: 155px"
        />
      </el-form-item>
      

      <el-form-item>
        <el-button
          type="text"
          :icon="!showForm ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
          size="mini"
          @click="zkForm"
          >{{ showForm ? "收起" : "展开" }}</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="addAsOrder"
          v-hasPermi="['after:sale:add']"
          >新增售后单</el-button
        >

        <el-button type="primary" plain size="mini" @click="openDialog(0)" v-hasPermi="['after:sale:cwfh']"
          >财务批量复核</el-button
        >
        <el-button type="primary" plain size="mini" @click="openDialog(1)" v-hasPermi="['after:sale:kfzgplfh']"
          >客服主管批量复核</el-button
        >
        <el-button type="primary" plain size="mini" @click="openDialog(2)" v-hasPermi="['after:sale:plqrtk']"
          >批量确认退款</el-button
        >
        <el-button type="primary" plain size="mini" @click="openDialog(3)" v-hasPermi="['after:sale:plqrhcfhxx']"
          >批量确认回传发货信息</el-button
        >
        <el-button type="warning" plain size="mini" @click="openDialog(4)" v-hasPermi="['after:sale:plzf']"
          >批量作废</el-button
        >
        <el-button
          type="warning"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['after:sale:drshd']"
          >导入售后单</el-button
        >
        <el-button
          type="success"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['after:sale:export']"
          >导出</el-button
        >
        <el-dropdown size="mini" @command="handleCommand" v-hasPermi="['after:sale:pldb']">
          <span class="el-dropdown-link">
            批量打标<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="5">仓库签收退货标记</el-dropdown-item>
            <el-dropdown-item command="6">财务复核标记</el-dropdown-item>
            <el-dropdown-item command="7">客服主管复核标记</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        :columns="columns"
        @sort="sortCol"
        @columnsChange="columnsChange"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      ref="proTable"
      :height="tableHeight"
      border
      v-loading="loading"
      :data="postList"
      :key="randomKey"
      @sort-change="sortChange"
      @selection-change="handleSelectionChange"
      row-key="platformCode"
    >
      <el-table-column
        type="selection"
        width="55"
        align="left"
        :reserve-selection="true"
      />
      <el-table-column
        v-for="(item, index) in columns"
        v-if="item.visible"
        :key="index"
        :label="item.label"
        :min-width="item.width || '90'"
        :align="item.align || 'left'"
        :fixed="item.fixed || false"
        :sortable="item.sortable?'custom':false"
        :prop="item.prop"
      >
        <template slot-scope="scope" >
          <template v-if="item.label == '售后订单商品'">
            <div v-show="scope.row.platformCode">
              <el-tooltip class="item" content="Top center" placement="top">
                <div slot="content" style="width: auto">
                  {{scope.row.platformCode}}<i
                    class="el-icon-document-copy"
                    v-show="scope.row.platformCode"
                    @click="copyText(scope.row.platformCode)"
                    ></i>
                </div>
                <div class="table-overflow">订单:{{scope.row.platformCode}}</div>
              </el-tooltip>
            </div>
            <div
              class="good-box"
              v-for="(item, index) in scope.row.items"
              :key="index"
            >
              <el-tooltip class="item" content="Top center" placement="top">
                <div slot="content" style="width: auto">
                  商品名称：{{ item.skuName }}
                  <i
                    class="el-icon-document-copy"
                    @click="copyText(item.skuName)"
                  ></i>
                  <br />
                  商品编码：{{ item.skuNo }}
                  <i
                    class="el-icon-document-copy"
                    @click="copyText(item.skuNo)"
                  ></i>
                </div>
                <div class="table-overflow">商品:{{ item.skuName }}</div>
              </el-tooltip>
            </div>
          </template>
          <template v-else-if="item.label == '店铺'">
            {{ scope.row.platformName }}/{{ scope.row.shopName }}
          </template>
          <template v-else-if="item.label == '售后单类型'">
            {{ typefilter(scope.row.afterSalesType, orderTypeList) }}
          </template>
          <template v-else-if="item.label == '售后单状态'">
            {{ typefilter(scope.row.afterSalesStatus, orderStateList) }}
          </template>
          <template v-else-if="item.label == '退款类型'">
            {{ typefilter(scope.row.refundType, refundTypeList) }}
          </template>
          <template v-else-if="item.label == '标签'">
            {{ typefilter(scope.row.tag, orderLabelList) }}
          </template>
          <template v-else-if="item.label == '售后原因'">
            {{ scope.row.refundReason || "--" }}
          </template>
          <template v-else-if="item.label == '是否给用户退款'">
            {{ scope.row.hasRefundUser == "1" ? "是" : "否" }}
          </template>
          <template v-else-if="item.label == '是否代发'">
            {{ scope.row.hasSupplier == "1" ? "是" : "否" }}
          </template>
          <template v-else-if="item.label == '包裹回寄地址'">
            {{ typefilter(scope.row.refundAddressType, sendBackLandList) }}
          </template>
          
          <template v-else-if="item.label == '售后金额'">
            ￥{{ $numFormat(scope.row.asAmount) }}
          </template>
          <template v-else-if="item.label == '售后单编号'">
              <el-tooltip class="item" content="Top center" placement="top">
                <div slot="content" style="width: auto">
                  {{scope.row.afterSalesNo}}<i
                    class="el-icon-document-copy"
                    v-show="scope.row.afterSalesNo"
                    @click="copyText(scope.row.afterSalesNo)"
                    ></i>
                </div>
                <div class="table-overflow">{{scope.row.afterSalesNo}}</div>
              </el-tooltip>
              <el-tooltip class="item" content="Top center" placement="top">
                <div slot="content" style="width: auto">
                  平台：{{scope.row.afterSalesPlatformCode}}<i
                    class="el-icon-document-copy"
                    v-show="scope.row.afterSalesPlatformCode"
                    @click="copyText(scope.row.afterSalesPlatformCode)"
                    ></i>
                </div>
                <div class="table-overflow">平台：{{scope.row.afterSalesPlatformCode}}</div>
              </el-tooltip>
          </template>
          <template v-else>
            {{ scope.row[item.prop] }}
          </template>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="180"
        fixed="right"
        align="center"
        prop="status"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="showDetail(scope.row)" v-hasPermi="['after:sale:detail']"
            >详情</el-button
          >
          <el-button
            size="mini"
            v-show="
              (scope.row.afterSalesType == 'REFUND_MONEY_GOODS' &&
                (scope.row.afterSalesStatus == 'PENDING_RETURN_PACKAGES' ||
                  scope.row.afterSalesStatus == 'PART_SIGN')) ||
              (scope.row.afterSalesType == 'EXCHANGE_GOOD' &&
                (scope.row.afterSalesStatus == 'PENDING_RETURN_PACKAGES' ||
                  scope.row.afterSalesStatus == 'PART_SIGN'))
            "
            @click="handleOption(scope.row, 1)"
            type="text"
            v-hasPermi="['after:sale:qshjbg']"
            >签收回寄包裹</el-button
          >
          <!-- <el-button size="mini" type="text">撤销</el-button> -->
          <el-button
            size="mini"
            type="text"
            v-show="
              (scope.row.afterSalesType == 'ONLY_REFUND' &&
                scope.row.afterSalesStatus == 'AWAITING_SUPERVISOR_APPROVAL') ||
              (scope.row.afterSalesType == 'REFUND_MONEY_GOODS' &&
                (scope.row.afterSalesStatus == 'PENDING_RETURN_PACKAGES' ||
                  scope.row.afterSalesStatus == 'PART_SIGN' ||
                  scope.row.afterSalesStatus == 'REJECT_PACKAGE')) ||
              (scope.row.afterSalesType == 'EXCHANGE_GOOD' &&
                (scope.row.afterSalesStatus == 'PENDING_RETURN_PACKAGES' ||
                  scope.row.afterSalesStatus == 'PART_SIGN' ||
                  scope.row.afterSalesStatus == 'AWAITING_FINANCE_APPROVAL' ||
                  scope.row.afterSalesStatus == 'REJECT_PACKAGE'))
            "
            @click="handleOption(scope.row, 2)"
            v-hasPermi="['after:sale:cjbj']"
            >超级编辑</el-button
          >
          <el-button
            size="mini"
            v-show="
              scope.row.afterSalesStatus == 'PENDING_REFUNDS' &&
              (scope.row.afterSalesType == 'REFUND_MONEY_GOODS' ||
                scope.row.afterSalesType == 'COMPENSATION_REFUND')
            "
            @click="handleOption(scope.row, 3)"
            type="text"
            v-hasPermi="['after:sale:qrtk']"
            >确认退款</el-button
          >
          <el-button
            size="mini"
            v-show="
              scope.row.afterSalesStatus == 'AWAITING_FINANCE_APPROVAL' &&
              scope.row.afterSalesType == 'EXCHANGE_GOOD'
            "
            @click="handleOption(scope.row, 4)"
            type="text"
            v-hasPermi="['after:sale:cwfh']"
            >财务复核</el-button
          >
          <el-button
            size="mini"
            v-show="
              scope.row.afterSalesStatus == 'AWAITING_SUPERVISOR_APPROVAL' &&
              (scope.row.afterSalesType == 'FIRST_REFUND' ||
                scope.row.afterSalesType == 'ONLY_REFUND')
            "
            @click="handleOption(scope.row, 5)"
            type="text"
            v-hasPermi="['after:sale:kfzgfh']"
            >客服主管复核</el-button
          >
          <el-button
            size="mini"
            v-show="
              (scope.row.afterSalesType == 'ONLY_REFUND' &&
                scope.row.afterSalesStatus == 'AWAITING_SUPERVISOR_APPROVAL') ||
              (scope.row.afterSalesType == 'REFUND_MONEY_GOODS' &&
                (scope.row.afterSalesStatus == 'PENDING_RETURN_PACKAGES' ||
                  scope.row.afterSalesStatus == 'REJECT_PACKAGE')) ||
              (scope.row.afterSalesType == 'EXCHANGE_GOOD' &&
                (scope.row.afterSalesStatus == 'PENDING_RETURN_PACKAGES' ||
                  scope.row.afterSalesStatus == 'REJECT_PACKAGE'))
            "
            @click="handleOption(scope.row, 6)"
            type="text"
            v-hasPermi="['after:sale:zf']"
            >作废</el-button
          >
          <el-button
            size="mini"
            v-show="
              scope.row.afterSalesStatus == 'PENDING_CHANGE' &&
              scope.row.afterSalesType == 'EXCHANGE_GOOD'
            "
            @click="handleOption(scope.row, 7)"
            type="text"
            v-hasPermi="['after:sale:qshjbg']"
            >确认换货发货</el-button
          >
          <el-button
            size="mini"
            v-show="
              scope.row.afterSalesStatus == 'CONFIRM_SEND' &&
              scope.row.afterSalesType == 'EXCHANGE_GOOD'
            "
            @click="handleOption(scope.row, 8)"
            type="text"
            v-hasPermi="['after:sale:plqrhcfhxx']"
            >确认回传发货信息</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      class="fixed-pagination"
    />

    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess2"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!-- <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div> -->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link
            type="primary"
            :underline="false"
            style="font-size: 12px; vertical-align: baseline"
            @click="importTemplate"
            >下载模板</el-link
          >
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="upload.isUploading" @click="submitFileForm">导 入</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="推送聚链代发"
      :visible.sync="jlVisible"
      width="1000px"
      append-to-body
      :center="true"
    >
      <!-- <Jldetail :ids="ids" :jlVisible="jlVisible" @close="closeJl" /> -->
    </el-dialog>

    <el-dialog
      title="物流信息"
      width="600px"
      :visible.sync="showDeliveryExpressDialog"
      top="50px"
      :center="true"
      class="abdialog"
    >
      <el-timeline>
        <el-timeline-item
          placement="top"
          v-for="(express, index) in expressTimeLine"
          :key="index"
          type="success"
          :timestamp="express.time"
        >
          <el-card>
            <p style="margin: 0">{{ express.context }}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>

      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="showDeliveryExpressDialog = false"
          >返回</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :title="`确认执行${confirmList[confirmIndex]}`"
      :visible.sync="confirmReview"
      width="550px"
      append-to-body
      :center="true"
    >
      <el-form
        ref="confirmReview"
        size="small"
        :model="confirmReviewForm"
        label-width="60px"
      >
        <el-form-item label="备注:" prop="remark">
          <el-input
            v-model="confirmReviewForm.remark"
            placeholder="填写备注，最多100个字"
            clearable
            rows="4"
            type="textarea"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmFnc" v-loading="confirmLoading"
          >通 过</el-button
        >
        <el-button @click="confirmReview = false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="请选择销售订单"
      :visible.sync="addVisible"
      width="550px"
      append-to-body
      :center="true"
    >
      <el-form
        ref="confirmReview2"
        size="small"
        :model="addViewFrom"
        label-width="150px"
      >
        <el-form-item label="输入平台订单号:" prop="platformCode ">
          <el-input
            v-model="addViewFrom.platformCode"
            placeholder="输入平台订单号"
            clearable
            type="text"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addVisible = false">取 消</el-button>
        <el-button type="primary" :loading="goAddLoading" @click="goAdd"
          >确 认</el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      title="选择平台订单号"
      :visible.sync="addVisible2"
      width="550px"
      append-to-body
      :center="true"
    >
      <el-table
        ref="addVisibleTable"
        border
        :data="addTableList"
        @select="handleSelectionChange2"
      >
        <el-table-column type="selection" width="55" align="left" />
        <el-table-column
          label="平台单号"
          min-width="140"
          align="left"
          prop="platformCode"
        />
        <el-table-column
          label="管易销售订单号"
          min-width="140"
          align="left"
          prop="erpCode"
        />
        <el-table-column
          label="订单状态"
          min-width="140"
          align="left"
          prop="orderStatus"
        >
          <template slot-scope="scope">
            {{ typefilter(scope.row.orderStatus, orderStatusList) }}
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="goAddLoading" @click="goAdd2"
          >确 认</el-button
        >
        <el-button @click="addVisible2 = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { platformList, queryJulianSupplier } from "@/api/order/index";
import {
  orderQuerySelect,
  orderQuery,
  afterSalesConfirmFinance,
  afterSalesConfirmCustomer,
  afterSalesConfirmRefund,
  afterSalesConfirmSend,
  afterSalesConfirmCancel,
  orderQueryPage,
  orderQueryCount,
  batchTage,
} from "@/api/afterSalesOrder/index";
import { getBrandNameList } from "@/api/goods/index";
import { saleTargetChannelList } from "@/api/saleConfig/saleTarget";
import LoadMoreSelect from "@/components/LoadMoreSelect/index";
import { getToken } from "@/utils/auth";
import { newDownload } from "@/utils/newRequest";

var domain = window.location.hostname;

export default {
  name: "/afterSaleOrder/index",
  components: {
    LoadMoreSelect,
    // Jldetail,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      saveLoading: false,
      goAddLoading: false,
      // 选中数组
      ids: [],
      rows: [],
      channelList: [],
      addTableList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      addVisible: false,
      addVisible2: false,
      // 总条数
      total: 0,
      total2: 0,
      // 岗位表格数据
      postList: [{ afterSalesNo: "11" }],
      postList2: [],
      brandNameList2: [],
      goodsText: "",
      title: "新增订单",
      fileList: [],
      platformLists: [],
      orderNumberList: [],
      addViewFrom: {
        platformCode: "",
      },
      tabNum: ["(0)", "(0)", "(0)", "(0)", "(0)", "(0)"],
      // 是否显示弹出层
      open: false,
      open2: false,
      open3: false,
      goodsVisible: false,
      saveGoodsLoading: false,
      submitLoading: false,
      jlVisible: false,
      detailVisible: false,
      activeName: "0",
      activeName2: "1",
      geoData: [],
      presentText: [],
      presentText2: "",
      presentText3: [],
      showForm: false,
      showDeliveryExpressDialog: false,
      expressTimeLine: [],
      exForm: {
        userName: "",
        userMobile: "",
        userAddress: "",
        userAddress2: "",
      },
      sendBackLandList: [
        { label: "自有仓库", value: "SELF_WAREHOUSE" },
        { label: "代发供货商", value: "SUPPLIER" },
      ],
      orderStateList: [
        { label: "待客服主管复核", value: "AWAITING_SUPERVISOR_APPROVAL" },
        { label: "待接收退货包裹", value: "PENDING_RETURN_PACKAGES" },
        { label: "部分退货", value: "PART_SIGN" },
        { label: "待财务复核", value: "AWAITING_FINANCE_APPROVAL" },
        { label: "待换货", value: "PENDING_CHANGE" },
        { label: "已换货", value: "CONFIRM_SEND_CALLBACK" },
        { label: "待回传发货信息", value: "CONFIRM_SEND" },
        { label: "待退款", value: "PENDING_REFUNDS" },
        { label: "已退款/已处理", value: "REFUNDED" },
        { label: "打回退货包裹", value: "REJECT_PACKAGE" },
        { label: "取消", value: "CANCEL" },
      ],
      refundTypeList: [
        { label: "极速退款", value: "FIRST_REFUND" },
        { label: "正常售后退款", value: "NORMAL_RETURN" },
        { label: "激活返现", value: "ACTIVATE_CASHBACK" },
        { label: "报备特殊补偿", value: "SPECIAL_COMPENSATION" },
        { label: "售后补款", value: "AFTER_SALES_COMPENSATION" },
        { label: "体验补偿", value: "TRIAL_COMPENSATION" },
      ],
      refundReasonList: [
        { label: "7天无理由", value: "SEVEN_DAY_RETURN" },
        { label: "质量问题", value: "QUALITY_ISSUES" },
        { label: "换货", value: "EXCHANGE_GOOD" },
        { label: "退差价", value: "RETURN_PRICE_DIFFERENCE" },
        { label: "退运费", value: "RETURN_SHIPPING_FEE" },
      ],
      orderLabelList: [
        { label: "仓库签收退货标记", value: "1" },
        { label: "客服主管复核标记", value: "2" },
        { label: "财务复核标记", value: "3" },
      ],
      whetherShippingList: [
        { label: "是", value: 1 },
        { label: "否", value: 0 },
      ],
      shippingSupplierList: [],
      addIds: [],
      afterSalesNosList: [],
      submitFileFormLoading: false,
      orderTypeList: [
        { label: "极速退款", value: "FIRST_REFUND" },
        { label: "仅退款", value: "ONLY_REFUND" },
        { label: "退货退款", value: "REFUND_MONEY_GOODS" },
        { label: "换货", value: "EXCHANGE_GOOD" },
        { label: "补偿退款", value: "COMPENSATION_REFUND" },
      ],
      businessTypeList: [
        { label: "电商销售", value: "0" },
        { label: "抛货", value: "1" },
        { label: "内购", value: "2" },
        { label: "代发", value: "3" },
        { label: "内部交易", value: "4" },
      ],
      orderStatusList: [
        { label: "草稿", value: "-2" },
        { label: "待制单审核", value: "-1" },
        { label: "待平台风控审核", value: "10" },
        { label: "待审单", value: "0" },
        { label: "待配货", value: "4" },
        { label: "待发货", value: "1" },
        { label: "已发货", value: "2" },
        { label: "已签收", value: "5" },
        { label: "已取消", value: "3" },

        // {label:'飞书草稿',value:'6'},
        // {label:'飞书待审批',value:'7'},
        // {label:'飞书审批结束/待复核',value:'8'},
        // {label:'审核驳回',value:'9'},
      ],
      afterSaleTypeList: [
        { label: "极速退款", value: "1" },
        { label: "仅退款", value: "2" },
        { label: "退货退款", value: "3" },
      ],
      afterSaleStatusList: [
        { label: "售后处理中", value: "1" },
        { label: "已退款", value: "2" },
        { label: "已退款未退货", value: "3" },
        { label: "已退款已退货", value: "3" },
        { label: "已退货未退款", value: "3" },
      ],
      payStatusList: [
        { label: "未付款", value: "0" },
        { label: "已付款", value: "1" },
      ],
      invoiceStatusList: [
        { label: "等待中", value: "-1" },
        { label: "待开票", value: "0" },
        { label: "开票中", value: "1" },
        { label: "开票成功", value: "2" },
        { label: "开票失败", value: "3" },
      ],
      deliveryTypeList: [
        { label: "自有仓发货", value: "1" },
        { label: "聚链代发", value: "2" },
        { label: "由你代发", value: "3" },
        { label: "线下代发", value: "4" },
      ],
      dateTypeList: [
        { label: "下单时间", value: "1" },
        { label: "支付时间", value: "2" },
        { label: "接入管易时间", value: "3" },
        { label: "审单时间", value: "4" },
        { label: "配货时间", value: "5" },
        { label: "发货时间", value: "6" },
        { label: "揽件时间", value: "7" },
        { label: "签收时间", value: "8" },
      ],
      abnormalTagList: [
        { label: "超期未收款", value: "1" },
        { label: "电商平台发货同步失败", value: "2" },
        { label: "管易发货失败", value: "3" },
        { label: "退货未入仓", value: "4" },
      ],
      refundReasonList: [
        { label: "7天无理由", value: "SEVEN_DAY_RETURN" },
        { label: "质量问题", value: "QUALITY_ISSUES" },
        { label: "换货", value: "EXCHANGE_GOOD" },
        { label: "退差价", value: "RETURN_PRICE_DIFFERENCE" },
        { label: "退运费", value: "RETURN_SHIPPING_FEE" },
      ],
      timeoutTagList: [
        { label: "审单逾期", value: "1" },
        { label: "配货逾期", value: "2" },
        { label: "仓库发货逾期", value: "3" },
        { label: "快递揽件逾期", value: "4" },
        { label: "退货入仓逾期", value: "5" },
        { label: "湘商整体发货逾期", value: "6" },
      ],
      bussinessFlagList: [{ label: "标记聚链代发", value: "1" }],
      pushOrderStatusList: [
        { label: "已推送聚链代发", value: "1" },
        { label: "撤销聚链代发", value: "1" },
      ],
      deliveryStatusList: [
        { label: "未发货", value: "0" },
        { label: "部分发货", value: "1" },
        { label: "全部发货", value: "2" },
      ],
      // 查询参数
      queryParams: {
        afterSalesNos: [],
        afterSalesNos2: "",
        afterSalesReasonEnums: [],
        afterSalesStatusEnums: [],
        afterSalesTypes: [],
        brandNos: [],
        customerService: "",
        endDate: "",
        endTime: "",
        hasSupplier: "",
        orderBy: [],
        orderByType: "",
        orderNos: [],
        orderNos2: "",
        platformNos: [],
        refundTypes: [],
        returnExpressNos: [],
        returnExpressNos2: "",
        serials: [],
        serials2: "",
        shopCodes: [],
        skuNo: "",
        skuNos: [],
        skuNos2: "",
        startDate: "",
        startTime: "",
        supplierNos: [],
        tags: [],
        vipName: "",
        pageNum: 1,
        pageSize: 10,
        afterSalesPlatformCodes:[],
        afterSalesPlatformCode2:'',
      },
      orderForm: {
        channel: "TO_B",
        payType: "FIRST_MONEY",
        businessType: "JETTISON",
        invoiceType: "NORMAL",
        invoiceCatalogue: "ELECTRONIC",
        invoiceTitleType: "PERSONAL",
        needInvoice: "0",
        approveCode: "",
        businessMan: "",
        buyVip: "",
        deptCode: "",
        deptName: "",
        invoiceTitle: "",
        item: [],
        orderTime: "",
        perPayTime: "",
        platformCode: "",
        proofName: "",
        proofPath: "",
        ratepayerCode: "",
        receiveInvoiceAddress: "",
        receiveInvoiceAddress2: "",
        receiveInvoiceCity: "",
        receiveInvoiceDistrict: "",
        receiveInvoicePhone: "",
        receiveInvoiceProvince: "",
        receiverAddress: "",
        receiverAddress2: "",
        receiverCity: "",
        receiverDistrict: "",
        receiverInvoice: "",
        receiverName: "",
        receiverPhone: "",
        receiverProvince: "",
        registerAccount: "",
        registerAddress: "",
        registerBank: "",
        registerPhone: "",
        salerRemark: "",
        userRemark: "",
        warehouseCode: "",
        warehouseName: "",
      },
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        configMonth: "",
        packageFee: "",
        packageMaterialFeeList: [],
        packageTreeFee: "",
        warehouseFee: "",
      },
      skuItems: [],
      confirmList: [
        "财务复核",
        "客服主管复核",
        "退款",
        "回传发货信息",
        "作废",
        "仓库签收退货标记",
        "财务复核标记",
        "客服主管复核标记",
      ],
      timer: null,
      attrOpen: false,
      title2: "",
      chartLading: true,
      loadDataStatus: true,
      tableHeight: "auto",
      tableTotal: 0,
      tableTotal2: 0,
      logTableList: [],
      attrLists: [],
      form2: {
        dateRange: [],
      },
      props: {
        value: "adcode",
        label: "name",
        children: "districts",
      },
      orderByType: '',
      sorts: [],
      fileAction: process.env.VUE_APP_BASE_API_NEW + "/activitie/upload/file",
      columns: [
        {
          key: 1,
          label: "售后单编号",
          width: "140",
          prop: "afterSalesNo",
          align: "left",
          fixed: "left",
          visible: true,
        },
        {
          key: 2,
          label: "店铺",
          width: "140",
          prop: "shopName",
          sortable: true,
          visible: true,
        },
        {
          key: 3,
          label: "售后订单商品",
          width: "210",
          prop: "items",
          visible: true,
        },
        {
          key: 4,
          label: "售后单类型",
          width: "110",
          prop: "afterSalesType",
          sortable: true,
          visible: true,
        },
        {
          key: 5,
          label: "售后单状态",
          width: "110",
          prop: "afterSalesStatus",
          sortable: true,
          visible: true,
        },
        {
          key: 6,
          label: "退款类型",
          width: "110",
          prop: "refundType",
          sortable: true,
          visible: true,
        },
        {
          key: 7,
          label: "是否给用户退款",
          width: "120",
          prop: "hasRefundUser",
          visible: true,
        },
        {
          key: 8,
          label: "售后原因",
          width: "120",
          prop: "refundReason",
          visible: true,
        },
        {
          key: 9,
          label: "售后数量",
          width: "110",
          prop: "asNum",
          visible: true,
        },
        {
          key: 10,
          label: "售后金额",
          width: "100",
          prop: "asAmount",
          sortable: true,
          visible: true,
        },
        {
          key: 11,
          label: "购买会员",
          width: "100",
          prop: "vipName",
          visible: true,
        },
        {
          key: 12,
          label: "收货人",
          width: "90",
          prop: "userName",
          visible: true,
        },
        {
          key: 13,
          label: "收货手机号",
          width: "100",
          prop: "userMobile",
          visible: true,
        },
        {
          key: 14,
          label: "对接客服",
          width: "90",
          prop: "customerService",
          visible: true,
        },
        {
          key: 15,
          label: "申请时间",
          width: "150",
          prop: "createdTime",
          sortable: true,
          visible: true,
        },
        // {
        //   key: 16,
        //   label: '售后状态',
        //   width: '90',
        //   prop: 'afterSaleTypeName',
        //   visible: true,
        //   hidden: true
        // },
        {
          key: 16,
          label: "标签",
          width: "90",
          prop: "tag",
          visible: true,
        },
        {
          key: 17,
          label: "是否代发",
          width: "100",
          prop: "hasSupplier",
          visible: true,
        },
        {
          key: 18,
          label: "代发供货商",
          width: "120",
          prop: "supplierName",
          visible: true,
        },
        {
          key: 19,
          label: "包裹回寄地址",
          width: "120",
          prop: "refundAddressType",
          visible: true,
        },
        // {
        //   key: 19,
        //   label: "订单操作超时标记",
        //   width: "130",
        //   prop: "createdTime",
        //   visible: true,
        // },
        // {
        //   key: 20,
        //   label: "订单异常标记",
        //   width: "120",
        //   prop: "createdTime",
        //   visible: true,
        // },
      ],
      randomKey: Math.random(),
      pickerOptions: {
        shortcuts: [
          {
            text: "最近三天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近半个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API_NEW + "/afterSales/order/import",
      },
      brandNameList: [],
      customerList: [],
      warehouseLists: [],
      operationLogList: [],
      deptList: [],
      tags1: [],
      tags2: [],
      orderId: "",
      confirmReview: false,
      confirmReviewForm: {
        remark: "",
      },
      confirmIndex: 0,
      confirmLoading: false,
    };
  },
  created() {
    // if (localStorage.getItem("orderIndex-query")) {
    //   this.queryParams = JSON.parse(localStorage.getItem("orderIndex-query"));
    //   this.queryParams.pageNum = 1;
    //   this.queryParams.pageSize = 10;
    // }
    this.initTime()

    this.getList();
    this.getDept();
  },
  activated() {
    this.getList();
  },
  mounted() {},
  methods: {
    tabClick() {
      this.$refs.proTable.clearSelection();
      if (this.activeName === "0") {
        this.queryParams.afterSalesStatusEnums = [];
        this.queryParams.afterSalesTypes = []
      } else {
        if(this.activeName=='PENDING_RETURN_PACKAGES'){
          this.queryParams.afterSalesStatusEnums = ['PENDING_RETURN_PACKAGES','PART_SIGN'];
          this.queryParams.afterSalesTypes = ['REFUND_MONEY_GOODS','EXCHANGE_GOOD']
        }
        if(this.activeName=='AWAITING_FINANCE_APPROVAL'){
          this.queryParams.afterSalesStatusEnums = ['AWAITING_FINANCE_APPROVAL'];
          this.queryParams.afterSalesTypes = ['EXCHANGE_GOOD']
        }
        if(this.activeName=='AWAITING_SUPERVISOR_APPROVAL'){
          this.queryParams.afterSalesStatusEnums = ['AWAITING_SUPERVISOR_APPROVAL'];
          this.queryParams.afterSalesTypes = ['FIRST_REFUND', 'ONLY_REFUND'];
        }
        if(this.activeName=='PENDING_REFUNDS'){
          this.queryParams.afterSalesStatusEnums = ['PENDING_REFUNDS'];
          this.queryParams.afterSalesTypes = ['REFUND_MONEY_GOODS','COMPENSATION_REFUND']
        }
        
        if(this.activeName=='CONFIRM_SEND'){
          this.queryParams.afterSalesStatusEnums = ['CONFIRM_SEND'];
          this.queryParams.afterSalesTypes = ['EXCHANGE_GOOD']
        }
        if(this.activeName=='REJECT_PACKAGE'){
          this.queryParams.afterSalesStatusEnums = ['REJECT_PACKAGE'];
          this.queryParams.afterSalesTypes = ['REFUND_MONEY_GOODS','EXCHANGE_GOOD']
        }
      }
      this.getList();
    },
    zkForm() {
      this.showForm = !this.showForm;
      if (!this.showForm) {
        this.$nextTick(() => {
          const height =
            window.innerHeight - this.$refs.queryForm.$el.offsetHeight - 260;
          this.tableHeight = height + "px";
        });
      }
    },
    sortCol(value) {
      value.forEach((item) => {
        if (item.fixc) {
          item.fixed = "left";
        } else {
          item.fixed = "";
        }
      });
      this.columns = value;
      this.randomKey = Math.random();
    },
    columnsChange(){
      this.randomKey = Math.random();
    },
    showDetail(row) {
      // this.detailVisible = true;
      this.$router.push(
        "/afterSalesOrderDetails?afterSalesNo=" + row.afterSalesPlatformCode
      );
    },
    getDept() {
      platformList().then((res) => {
        if (res.status == 200) {
          this.platformLists = res.data.platformListResDTOS;
        }
      });
      saleTargetChannelList().then((res) => {
        if (res.status == 200) {
          this.channelList = res.data || [];
        }
      });
      getBrandNameList().then((res) => {
        this.brandNameList2 = res.data;
      });
      queryJulianSupplier().then(res=>{
        if(res.status==200){
          this.shippingSupplierList = res.data;
        }
      });
    },
    typefilter(value, list) {
      const data = list.find((item) => {
        return item.value == value;
      });
      return data ? data.label : "";
    },
    handleCommand(command) {
      this.openDialog(command);
    },
    copySkus(value, row, type) {
      // row = value.replace(/\s+/g, ',');
      // row = value.trim().split(/\s+/).join(',');
      if (type == 2) {
        this.goodsText = value.trim().split(/\s+/).join(",");
      } else {
        this.$set(this.queryParams, row, value.trim().split(/\s+/).join(","));
      }
    },
    handleOption(row, type) {
      if (type == 1) {
        this.$router.push("/signForPackage?afterSalesNo=" + row.afterSalesPlatformCode);
      } else if (type == 2) {
        this.$router.push("/editAsOrder?afterSalesNo=" + row.afterSalesPlatformCode);
      } else if (type == 3) {
        this.openDialog(2, row);
      } else if (type == 4) {
        this.openDialog(0, row);
      } else if (type == 5) {
        this.openDialog(1, row);
      } else if (type == 6) {
        this.openDialog(4, row);
      } else if (type == 7) {
        this.$router.push("/confirmExchange?afterSalesNo=" + row.afterSalesPlatformCode);
      } else if (type == 8) {
        this.openDialog(3, row);
      }
    },
    deleteRow(row, index) {
      this.skuItems.splice(index, 1);
    },
    handleImport() {
      this.upload.title = "售后单导入";
      this.upload.open = true;
    },
    sortChange({ column, prop, order }){
      if(order){
        this.sorts = [];
        this.sorts.push(prop);
        if(order=='ascending'){
          this.orderByType = 0;
        }else if(order=='descending'){
          this.orderByType = 1;
        }
      }else{
        this.sorts = [];
      }
      this.getList();
    },
    getList() {
      this.loading = true;
      this.formatData();

      this.queryParams.orderByType = this.orderByType;
      this.queryParams.orderBy = this.sorts;
      orderQueryPage(this.queryParams)
        .then((response) => {
          if (response.status == 200) {
            this.postList = response.data.list;
            this.total = response.data.total;

            this.postList.forEach((item) => {
              item.asNum = 0;
              item.asAmount = 0;
              if (item.items) {
                item.items.forEach((i) => {
                  item.asNum += i.requestedRefundQuantity;
                  item.asAmount += i.requestedRefundAmount;
                });
              }else{
                item.asNum = 0;
                item.asAmount = item.refundAmount;
              }
            });
          }

          this.randomKey = Math.random();

          this.loading = false;
          this.$nextTick(() => {
            const height =
              window.innerHeight - this.$refs.queryForm.$el.offsetHeight - 260;
            this.tableHeight = height + "px";
            console.log(this.tableHeight);
          });
        })
        .catch((err) => {
          this.loading = false;
        });

      orderQueryCount(this.queryParams).then((res) => {
        if (res.status == 200) {
          res.data.forEach((item) => {
            if (item.afterSalesStatus == "PENDING_RETURN_PACKAGES") {
              this.$set(this.tabNum, 0, `(${item.qty})`);
            }
            if (item.afterSalesStatus == "AWAITING_FINANCE_APPROVAL") {
              this.$set(this.tabNum, 1, `(${item.qty})`);
            }
            if (item.afterSalesStatus == "AWAITING_SUPERVISOR_APPROVAL") {
              this.$set(this.tabNum, 2, `(${item.qty})`);
            }
            if (item.afterSalesStatus == "PENDING_REFUNDS") {
              this.$set(this.tabNum, 3, `(${item.qty})`);
            }
            if (item.afterSalesStatus == "CONFIRM_SEND") {
              this.$set(this.tabNum, 4, `(${item.qty})`);
            }
            if (item.afterSalesStatus == "REJECT_PACKAGE") {
              this.$set(this.tabNum, 5, `(${item.qty})`);
            }
          });
        }
      });
    },
    formatData() {
      if (this.queryParams.afterSalesNos2) {
        this.queryParams.afterSalesNos =
          this.queryParams.afterSalesNos2.split(",");
      } else {
        this.queryParams.afterSalesNos = [];
      }
      if (this.queryParams.orderNos2) {
        this.queryParams.orderNos = this.queryParams.orderNos2.split(",");
      } else {
        this.queryParams.orderNos = [];
      }
      if (this.queryParams.returnExpressNos2) {
        this.queryParams.returnExpressNos =
          this.queryParams.returnExpressNos2.split(",");
      } else {
        this.queryParams.returnExpressNos = [];
      }
      if (this.queryParams.serials2) {
        this.queryParams.serials = this.queryParams.serials2.split(",");
      } else {
        this.queryParams.serials = [];
      }
      if (this.queryParams.skuNos2) {
        this.queryParams.skuNos = this.queryParams.skuNos2.split(",");
      } else {
        this.queryParams.skuNos = [];
      }
      if (this.queryParams.dateRange && this.queryParams.dateRange.length > 0) {
        this.queryParams.startDate = this.queryParams.dateRange[0];
        this.queryParams.endDate = this.queryParams.dateRange[1];
      }
      if (this.queryParams.afterSalesPlatformCode2) {
        this.queryParams.afterSalesPlatformCodes = this.queryParams.afterSalesPlatformCode2.split(",");
      } else {
        this.queryParams.afterSalesPlatformCodes = [];
      }
    },
    dowaLoadBill(row) {
      window.open(
        "https://newfirst.oss-cn-shanghai.aliyuncs.com/" + row.filePath
      );
    },
    goProcure(url) {
      // this.$router.push({
      //   path: url
      // });
      window.open(url);
    },
    sellPriceChange(value, row) {
      if (row.sellPrice && row.sellQty) {
        row.profit =
          (parseFloat(row.sellPrice) - parseFloat(row.cost)) *
          parseFloat(row.sellQty);
        row.profitRate2 =
          ((
            ((parseFloat(row.sellPrice) - parseFloat(row.cost)) /
              parseFloat(row.cost)) *
            100
          ).toFixed(2) != "Infinity"
            ? (
                ((parseFloat(row.sellPrice) - parseFloat(row.cost)) /
                  parseFloat(row.cost)) *
                100
              ).toFixed(2)
            : 0) + "%";
        row.profitRate =
          (parseFloat(row.sellPrice) - parseFloat(row.cost)) /
            parseFloat(row.cost) !=
          "Infinity"
            ? (parseFloat(row.sellPrice) - parseFloat(row.cost)) /
              parseFloat(row.cost)
            : 0;
        let tableTotal = 0,
          tableTotal2 = 0;
        this.skuItems.forEach((item) => {
          tableTotal += parseFloat(item.sellPrice) * parseFloat(item.sellQty);
          tableTotal2 +=
            (parseFloat(item.sellPrice) - parseFloat(item.cost)) *
            parseFloat(item.sellQty);
        });
        this.tableTotal = tableTotal;
        this.tableTotal2 = tableTotal2;
      }
    },
    payTypeChange() {
      if (this.orderForm.payType == "FIRST_PRODUCT") {
        this.orderForm.proofPath = "";
        this.orderForm.proofName = "";
      } else {
        this.orderForm.perPayTime = "";
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = [];
      this.afterSalesNosList = [];
      selection.forEach((item) => {
        // item.orderListDetailDTOList.forEach(i=>{
        //   this.ids.push(i.orderId);
        // })
        this.ids.push(item);
        this.afterSalesNosList.push(item.afterSalesNo);
      });
    },
    handleSelectionChange2(selection, row) {
      this.addTableList.forEach(item=>{
        if(item.erpCode!=row.erpCode){
          this.$refs.addVisibleTable.toggleRowSelection(item, false);
        }
      })
      this.addIds = [{
          erpCode: row.erpCode,
          platformCode: row.platformCode,
        }];
    },
    copyText(text) {
      window.navigator.clipboard
        .writeText(text)
        .then(() => {
          // this.$message.success("复制成功");
          this.$message({
            message: "复制成功",
            type: "success",
            customClass: "phone-message",
            center: true,
          });
        })
        .catch((error) => {
          // this.$message.warning("复制失败");
          this.$message({
            message: "复制失败",
            type: "warning",
            customClass: "phone-message",
            center: true,
          });
        });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.$refs.proTable.clearSelection();
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        afterSalesNos: [],
        afterSalesNos2: "",
        afterSalesReasonEnums: [],
        afterSalesStatusEnums: [],
        afterSalesTypes: [],
        brandNos: [],
        customerService: "",
        endDate: "",
        endTime: "",
        hasSupplier: "",
        orderBy: [],
        orderByType: "",
        orderNos: [],
        orderNos2: "",
        platformNos: [],
        refundTypes: [],
        returnExpressNos: [],
        returnExpressNos2: "",
        serials: [],
        serials2: "",
        shopCodes: [],
        skuNo: "",
        skuNos: [],
        skuNos2: "",
        startDate: "",
        startTime: "",
        supplierNos: [],
        tags: [],
        vipName: "",
        afterSalesPlatformCodes:[],
        afterSalesPlatformCode2:'',
        pageNum: 1,
        pageSize: 10,
      };
      this.resetForm("queryForm");
      this.initTime()
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.orderForm = {
        channel: "TO_B",
        payType: "FIRST_MONEY",
        businessType: "JETTISON",
        invoiceType: "NORMAL",
        invoiceCatalogue: "ELECTRONIC",
        invoiceTitleType: "PERSONAL",
        needInvoice: "0",
        approveCode: "",
        businessMan: "",
        buyVip: "",
        deptCode: "",
        deptName: "",
        invoiceTitle: "",
        item: [],
        orderTime: "",
        perPayTime: "",
        platformCode: "",
        proofName: "",
        proofPath: "",
        ratepayerCode: "",
        receiveInvoiceAddress: "",
        receiveInvoiceAddress2: "",
        receiveInvoiceCity: "",
        receiveInvoiceDistrict: "",
        receiveInvoicePhone: "",
        receiveInvoiceProvince: "",
        receiverAddress: "",
        receiverAddress2: "",
        receiverCity: "",
        receiverDistrict: "",
        receiverInvoice: "",
        receiverName: "",
        receiverPhone: "",
        receiverProvince: "",
        registerAccount: "",
        registerAddress: "",
        registerBank: "",
        registerPhone: "",
        salerRemark: "",
        userRemark: "",
        warehouseCode: "",
        warehouseName: "",
      };
      this.fileList = [];
      this.tableTotal = 0;
      this.tableTotal2 = 0;
      this.goodsText = "";
      this.resetForm("addForm");
      this.skuItems = [];

      this.open = true;
      this.title = "新增订单";
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess2(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
          response.msg +
          "</div>",
        "导入结果",
        { dangerouslyUseHTMLString: true }
      );
      this.getList();
    },
    handleRemove() {
      this.orderForm.proofPath = "";
      this.orderForm.proofName = "";
    },
    /** 导出按钮操作 */
    handleExport() {
      const data = { ...this.queryParams };
      delete data.pageNum;
      delete data.pageSize;
      //delete data.orderType;
      delete data.orderStatus;
      newDownload(
        "/afterSales/order/export",
        data,
        `售后单列表_${new Date().getTime()}.xlsx`
      );
    },
    /** 下载模板操作 */
    importTemplate() {
      // this.newDownload(
      //   "spu/importTemplate",
      //   {},
      //   `spu_template_${new Date().getTime()}.xlsx`
      // );
      window.location.href =
        "https://newfirst.oss-cn-shanghai.aliyuncs.com/template/%E5%94%AE%E5%90%8E%E5%AF%BC%E5%85%A5%20%E6%A8%A1%E6%9D%BF.xlsx";
    },
    addAsOrder() {
      this.addViewFrom.platformCode = "";
      this.addVisible = true;
    },
    goAdd() {
      if (this.addViewFrom.platformCode == "") {
        this.$message.warning("请填写单号");
        return false;
      }
      this.goAddLoading = true;
      orderQuerySelect({
        platformCode: this.addViewFrom.platformCode.trim(),
      }).then((res) => {
        if (res.status == 200) {
          this.addTableList = res.data;
          if(this.addTableList){
            if (this.addTableList.length == 1) {
              this.goAdd2(this.addTableList[0]);
            } else {
              this.addVisible2 = true;
              this.goAddLoading = false;
            }
          }else{
            this.$message.waring('单据不存在，请重新输入');
            this.goAddLoading = false;
          }
        }
      }).catch(err=>{
        this.goAddLoading = false;
      });
    },
    goAdd2(addIds) {
      if (!addIds && this.addIds.length == 0) {
        this.$message.warning("请选择单据");
        return false;
      }
      this.goAddLoading = true;
      orderQuery({
        erpCode: addIds.erpCode ? addIds.erpCode : this.addIds[0].erpCode,
        platformCode: addIds.platformCode
          ? addIds.platformCode
          : this.addIds[0].platformCode,
      })
        .then((res) => {
          if (res.status == 200) {
            sessionStorage.setItem("addAsOrder-data", JSON.stringify(res.data));
            sessionStorage.setItem("addAsOrder-new", 'true');
            this.$router.push({ path: "/addAsOrder" });
          }
          this.goAddLoading = false;
          this.addVisible = false;
          this.addVisible2 = false;
        })
        .catch((err) => {
          this.goAddLoading = false;
          this.addVisible = false;
          this.addVisible2 = false;
        });
    },
    openDialog(index, row) {
      if (row) {
        this.afterSalesNosList = [row.afterSalesPlatformCode];
      }
      if (this.afterSalesNosList.length == 0) {
        this.$message.warning("请选择单据");
        return false;
      }

      let messageList = [
        "只有售后单状态为“换货-待财务复核”的售后单才能财务复核。",
        "只有售后单状态为“极速退款-待客服主管复核、仅退款-待客服主管复核、内部工单-待客服主管复核”的售后单才能客服主管复核。",
        "只有售后单状态为“退货退款-待退款”、“补偿退款-待退款”的售后单才能确认退款。",
        "只有售后单状态为“换货-待回传发货信息”的售后单才能确认回传发货信息。",
        "只有售后单状态为“仅退款-待客服主管复核”、“退货退款-待接收退货包裹”、“退货退款-打回退货包裹”、“补偿退款-待接收退货包裹”、“补偿退款-打回退货包裹”、“补偿退款-待财务审核”的售后单才能作废",
        "请选择退货退款/换货类型且需要仓库签收退货的售后单",
        "请选择需要财务复核的售后单",
        "请选择需要客服主管复核的售后单",
      ];

      this.confirmIndex = index;

      if (!row) {
        const ids = [];
        if (index == 0) {
          this.ids.forEach((item) => {
            if (
              item.afterSalesStatus == "AWAITING_FINANCE_APPROVAL" &&
              item.afterSalesType == "EXCHANGE_GOOD"
            ) {
              ids.push(item)
            }
          });
        }

        if (index == 1) {
          this.ids.forEach((item) => {
            if (
              item.afterSalesStatus == "AWAITING_SUPERVISOR_APPROVAL" &&
              (item.afterSalesType == "FIRST_REFUND" ||
                item.afterSalesType == "ONLY_REFUND")
            ) {
              ids.push(item)
            }
          });
        }

        if (index == 2) {
          this.ids.forEach((item) => {
            if (
              item.afterSalesStatus == "PENDING_REFUNDS" &&
              (item.afterSalesType == "REFUND_MONEY_GOODS" ||
                item.afterSalesType == "COMPENSATION_REFUND")
            ) {
              ids.push(item)
            }
          });
        }

        if (index == 3) {
          this.ids.forEach((item) => {
            if (
              item.afterSalesStatus == "PENDING_REFUNDS" &&
              item.afterSalesType == "EXCHANGE_GOOD"
            ) {
              ids.push(item)
            }
          });
        }

        if (index == 4) {
          this.ids.forEach((item) => {
            if (
              (item.afterSalesType == "ONLY_REFUND" &&
                item.afterSalesStatus == "AWAITING_SUPERVISOR_APPROVAL") ||
              (item.afterSalesType == "REFUND_MONEY_GOODS" &&
                (item.afterSalesStatus == "PENDING_RETURN_PACKAGES" ||
                  item.afterSalesStatus == "REJECT_PACKAGE")) ||
              (item.afterSalesType == "EXCHANGE_GOOD" &&
                (item.afterSalesStatus == "PENDING_RETURN_PACKAGES" ||
                  item.afterSalesStatus == "REJECT_PACKAGE"))
            ) {
              ids.push(item)
            }
          });
        }

        if (index == 5) {
          for (let i = 0; i < this.ids.length; i++) {
            if (
              (this.ids[i].afterSalesType == "REFUND_MONEY_GOODS" &&
                (this.ids[i].afterSalesStatus == "PENDING_RETURN_PACKAGES" ||
                  this.ids[i].afterSalesStatus == "PART_SIGN")) ||
              (this.ids[i].afterSalesType == "EXCHANGE_GOOD" &&
                (this.ids[i].afterSalesStatus == "PENDING_RETURN_PACKAGES" ||
                  this.ids[i].afterSalesStatus == "PART_SIGN"))
            ) {
              ids.push(this.ids[i]);
            }
          }
          
        }

        if (index == 6) {
          for (let i = 0; i < this.ids.length; i++) {
            if (
              this.ids[i].afterSalesStatus == "AWAITING_SUPERVISOR_APPROVAL"
            ) {
              ids.push(this.ids[i]);
            }
          }
        }

        if (index == 7) {
          for (let i = 0; i < this.ids.length; i++) {
            if (this.ids[i].afterSalesStatus == "AWAITING_FINANCE_APPROVAL") {
              ids.push(this.ids[i]);
            }
          }
        }

        if (ids.length == 0) {
          this.$message.warning(messageList[this.confirmIndex]);
          return false;
        }

      }

      this.confirmReviewForm.remark = "";
      this.confirmReview = true;
    },
    confirmFnc() {
      let fnc,
        params,
        fncList = [
          afterSalesConfirmFinance,
          afterSalesConfirmCustomer,
          afterSalesConfirmRefund,
          afterSalesConfirmSend,
          afterSalesConfirmCancel,
          batchTage,
          batchTage,
          batchTage,
        ];
      fnc = fncList[this.confirmIndex];
      console.log(this.afterSalesNosList);
      if(this.confirmIndex==5||this.confirmIndex==6||this.confirmIndex==7){
        params = {
          afterSalesPlatformCodes: this.afterSalesNosList,
          remark: this.confirmReviewForm.remark,
          tag: this.confirmIndex==5?'1':(this.confirmIndex==7?'2':(this.confirmIndex==6?'3':''))
        };
      }else{
        params = {
          afterSalesPlatformCodes: this.afterSalesNosList,
          remark: this.confirmReviewForm.remark,
          tag: this.confirmIndex==1?'2':(this.confirmIndex==0?'3':(this.confirmIndex==2?'':''))
        };
      }

      this.confirmLoading = true;

      fnc(params)
        .then((response) => {
          if (response.status == 200) {
            this.$message.success(`${this.confirmList[this.confirmIndex]}成功`);
            this.confirmReview = false;
            this.getList();
          }
          this.confirmLoading = false;
        })
        .catch((err) => {
          this.confirmLoading = false;
          // this.$message.error(err);
        });
    },
    initTime() {
      let startDate = "",
        endDate = "";

      const date = new Date();
      const year = date.getFullYear();
      const month =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1;
      const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      endDate = year + "-" + month + "-" + day;

      date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
      const year2 = date.getFullYear();
      const month2 =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1;
      const day2 = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      startDate = year2 + "-" + month2 + "-" + day2;

      this.queryParams.dateRange = [startDate, endDate];
    },
  },
};
</script>
<style lang="scss" scoped>
.charts-box {
  height: 350px;
  margin-top: 30px;
}
.erpPrice > span {
  color: #409eff;
}
.iconEdit {
  cursor: pointer;
}
.app-container {
  padding-bottom: 50px;
}
.input-box {
  text-align: left;
}
.disabled-text {
  em {
    color: #999;
  }
}
h3 {
  font-weight: bold;
  display: flex;
  align-items: center;
  margin-top: 36px;
  span {
    display: block;
    width: 2px;
    height: 14px;
    background: #f56c6c;
    margin-right: 6px;
  }
}
.sku-table {
  display: flex;
  justify-content: space-between;
  .total-table {
    display: flex;
    align-items: center;
    span {
      margin: 0 8px;
      white-space: nowrap;
      color: #f56c6c;
    }
  }
}
.goProcure {
  color: #1890ff;
  cursor: pointer;
  font-size: 12px;
}
.fixed-pagination {
  position: fixed;
}
.good-box {
  display: flex;
}
.table-overflow {
  width: 100%;
}
.table-overflow2 {
  width: 100%;
}
.color-r {
  color: #f56c6c;
}
.color-y {
  color: #fbc576;
}
</style>
<style lang="scss">
.warehouse-dialog {
  .el-upload {
    width: 100%;
  }
  .el-upload-dragger {
    width: 100%;
  }
}
.order-dialog {
  .el-tabs__content {
    height: 65vh;
    overflow-x: hidden;
    overflow-y: scroll;
    padding: 0 8px;
  }
  .el-dialog__body {
    padding: 0 16px 16px 16px;
  }
  .el-form-item__label {
    font-size: 12px;
  }
  .el-radio__label {
    font-size: 12px;
  }
  .el-table .el-table__cell > .cell {
    font-size: 12px;
  }
}
.ho-box {
  color: #1989fa;
}

.good-box {
  span {
    color: #666;
  }
}

.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  margin-left: 10px;
}
.link-ex {
  cursor: pointer;
  color: #409eff !important;
}
.abdialog {
  .el-dialog__body {
    max-height: 70vh;
    overflow-y: scroll;
  }
}
</style>
