<!--批量加价-->
<template>
  <div class="app-container">
    <div class="page-title">
      <span>{{ $t("批量加价") }}</span>
      <!-- TODO 这里的批量申请费用需要跳转到和订单列表一致的批量订单费用申请页面 -->
      <el-button type="primary" style="margin-left: 5px" size="small" @click="batchOrderFeeApply(this.orderIds)">{{ $t("批量申请费用") }}</el-button>
    </div>
    <div>
      {{ $t("运费或全包加价") }}
      <!--货币-->
      <selector :disabled="approval" v-model="form.freightCurrencyId" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable class="w-100 ml-10" />
      <!--金额 :min="1"-->
      <el-input :disabled="approval" type="number" v-model="form.freightFee" @keyup.native="checkPositive(form, 'freightFee')" class="w-100 ml-10" />
      <!--单位-->
      <selector :disabled="approval" v-model="form.freightUnitId" :options="unitList" :label-field="$l('title')" value-field="id" defaultable class="w-100 ml-10" />
    </div>
    <div class="mt-10">
      {{ $t("清关费加价") }}
      <!--货币-->
      <selector :disabled="approval" v-model="form.clearanceCurrencyId" :options="currencyList" :label-field="$l('title')" value-field="id" defaultable class="w-100 ml-10" />
      <!--金额 :min="1"-->
      <el-input :disabled="approval" type="number" v-model="form.clearanceFee" @keyup.native="checkPositive(form, 'clearanceFee')" class="w-100 ml-10" />
      <!--单位-->
      <selector :disabled="approval" v-model="form.clearanceUnitId" :options="unitList" :label-field="$l('title')" value-field="id" defaultable class="w-100 ml-10" />
      <span>*{{ $t("若线路价格为全包价，输入清关费不生效") }}</span>
    </div>

    <el-card class="mt-20" v-if="shipmentObj">
      <el-descriptions :column="4" border>
        <el-descriptions-item :label="$t('自编号')">
          {{ shipmentObj.selfNo }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('运输方式')">
          <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="shipmentObj.transportType" />
        </el-descriptions-item>
        <!-- <el-descriptions-item :label="$t('出货渠道')">
          {{getShipChannelName(shipmentObj.shippingChannelId)}}
        </el-descriptions-item> -->
        <el-descriptions-item :label="$t('柜型')">
          {{ getCabinetLabel(shipmentObj.cabinetId) }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('状态')">
          {{ shipmentObj.shipmentStatusText }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('总计')">
          {{ getBoxSum(shipmentObj.boxStatistics) }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('始发地')">
          {{ getCityName(shipmentObj.startWarehouseId) }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('目的地')">
          {{ getCityName(shipmentObj.destWarehouseId) }}
        </el-descriptions-item>
        <el-descriptions-item label="SO NO">
          {{ shipmentObj.bookSeaInfo ? shipmentObj.bookSeaInfo.sono : "" }}
        </el-descriptions-item>
        <el-descriptions-item v-if="shipmentObj.transportType == 1 || shipmentObj.transportType == 2" :label="$t('装柜时间')">
          {{ shipmentObj.zgDate }}
        </el-descriptions-item>
        <el-descriptions-item v-else :label="$t('出仓时间')">
          {{ shipmentObj.ckDate }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('到港时间')">
          {{ shipmentObj.dgDate }}
        </el-descriptions-item>
        <el-descriptions-item :label="$t('清关时间')">
          {{ shipmentObj.qgDate }}
        </el-descriptions-item>
      </el-descriptions>
    </el-card>

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="140px" class="search-z mt-20">
      <el-form-item :label="$t('编号')" prop="orderNo">
        <el-input class="w-200" v-model.trim="noParam.value" :placeholder="$t('请输入订单号、唛头、提单号')" clearable @keyup.enter.native="handleQuery" @input="replaceSpace(noParam, 'value')">
          <template slot="prepend">
            <dict-selector :type="DICT_TYPE.ORDER_QUERY_NO_FIELD" defaultable v-model="noParam.key" />
          </template>
        </el-input>
      </el-form-item>
      <el-form-item :label="$t('发货人')" prop="consignorKey">
        <el-input v-model.trim="queryParams.consignorKey" :placeholder="$t('发货人')" clearable @keyup.enter.native="handleQuery" class="w-200" />
      </el-form-item>
      <el-form-item :label="$t('收货人')" prop="consigneeKey">
        <el-input v-model.trim="queryParams.consigneeKey" :placeholder="$t('收货人')" clearable @keyup.enter.native="handleQuery" class="w-200" />
      </el-form-item>
      <el-form-item :label="$t('控货状态')" prop="isCargoControl">
        <dict-selector v-model="queryParams.cargoControlStatusList" multiple :type="DICT_TYPE.CONTROL_GOODS_STATUS" clearable @change="handleQuery" class="w-200" />
      </el-form-item>
      <div>
        <el-form-item :label="$t('始发仓')" prop="startWarehouseIds">
          <el-select v-model="queryParams.startWarehouseIds" multiple :placeholder="$t('请选择始发仓')" clearable @change="handleQuery" class="w-200">
            <el-option v-for="item in exportWarehouseList" :label="item.titleZh" :value="item.id" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('目的国')" prop="destCountryId">
          <el-select v-model="destCountryId" multiple :label="destCountryId" :placeholder="$t('请选择目的国')" clearable @change="handleQuery" class="w-200">
            <el-option v-for="item in AddressProvince" :key="item.guojia" :label="item.guojiaName" :value="item.guojia"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('目的城市')" prop="objectiveId">
          <el-select v-model="objectiveId" multiple :placeholder="$t('请选择目的城市')" style="width: 200px" clearable @change="handleQuery" class="w-200">
            <el-option v-for="item in AddressCity" :key="item.shi" :label="item.shiName" :value="item.shi"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('目的仓')" prop="destWarehouseId">
          <el-select v-model="destWarehouseId" multiple :placeholder="$t('请选择目的仓')" style="width: 200px" clearable @change="handleQuery" class="w-200">
            <el-option v-for="item in AddressTown" :key="item.id" :label="item.titleZh" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </div>
      <el-form-item :label="$t('客户经理')">
        <user-selector manage v-model="queryParams.salesmanIds" multiple clearable @change="handleQuery" :prepend="{ id: 0, nickname: $t('未分配客户经理') }" class="w-200" />
      </el-form-item>
      <el-form-item :label="$t('运输方式')" prop="transportId" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.ECW_TRANSPORT_TYPE" v-model.number="queryParams.transportId" clearable @change="handleQuery" class="w-200" />
      </el-form-item>
      <el-form-item :label="$t('出货渠道')" prop="channelIds">
        <selector clearable :options="channelList" :label-field="$l('name')" value-field="channelId" v-model="queryParams.channelIds" multiple class="w-200"></selector>
      </el-form-item>
      <el-form-item :label="$t('商品') + ':'" v-show="showSearch">
        <el-input v-model.trim="prodParam.value" :placeholder="$t('请输入商品类型、品名或品牌')" clearable @keyup.enter.native="handleQuery" class="w-200">
          <template slot="prepend">
            <dict-selector :type="DICT_TYPE.ORDER_QUERY_PROD_FIELD" defaultable v-model="prodParam.key" />
          </template>
        </el-input>
      </el-form-item>

      <el-form-item :label="$t('订单状态')" prop="statusList" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.ORDER_STATUS" multiple v-model="queryParams.statusList" @keyup.enter.native="handleQuery" clearable @change="handleQuery" class="w-200" />
      </el-form-item>

      <el-form-item :label="$t('报关方式')" prop="customsTypes" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.ECW_CUSTOMS_TYPE" multiple v-model="queryParams.customsTypes" clearable @change="handleQuery" class="w-200" />
      </el-form-item>

      <el-form-item :label="$t('备案属性')" prop="productRecords" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.PRODUCT_RECORD_ATTRIBUTE" multiple v-model="queryParams.productRecords" clearable @change="handleQuery" class="w-200" />
      </el-form-item>
      <el-form-item :label="$t('外部仓')" prop="isExternalWarehouse" v-show="showSearch">
        <el-select v-model="queryParams.isExternalWarehouse" :placeholder="$t('请选择')" clearable @change="handleQuery" class="w-200">
          <el-option :label="$t('外部仓')" :value="1"></el-option>
          <el-option :label="$t('自有仓')" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('增值服务')" prop="types" v-show="showSearch">
        <el-select v-model="queryParams.types" :placeholder="$t('请选择')" clearable multiple @change="handleQuery" class="w-200">
          <el-option :label="$t('普通订单')" :value="0"></el-option>
          <el-option :label="$t('集运服务')" :value="1"></el-option>
          <el-option :label="$t('海外仓')" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('商品类型')" prop="goodsTypes" v-show="showSearch">
        <selector v-model="queryParams.goodsTypes" multiple :options="attrList" label-field="attrName" value-field="id" class="w-200"> </selector>
      </el-form-item>
      <el-form-item :label="$t('提货状态')" v-show="showSearch">
        <dict-selector :type="DICT_TYPE.PICK_STATE" multiple v-model="queryParams.pickStateList" clearable @change="handleQuery" class="w-200" />
      </el-form-item>
      <el-form-item :label="$t('放货率')" v-show="showSearch">
        <el-input type="number" v-model.trim="releaseRatio.value" :placeholder="$t('请输入数字')" clearable @keyup.enter.native="handleQuery" class="w-200">
          <template slot="prepend">
            <dict-selector :type="DICT_TYPE.RELEASE_RATIO_FIELD" defaultable v-model="releaseRatio.key" />
          </template>
        </el-input>
      </el-form-item>
      <el-form-item :label="$t('提货率')" v-show="showSearch">
        <el-input type="number" v-model.trim="pickRatio.value" :placeholder="$t('请输入数字')" clearable @keyup.enter.native="handleQuery" class="w-200">
          <template slot="prepend">
            <dict-selector :type="DICT_TYPE.PICK_RATIO_FIELD" defaultable v-model="pickRatio.key" />
          </template>
        </el-input>
      </el-form-item>
      <el-form-item :label="$t('特需')" prop="packageTypeArr" v-show="showSearch">
        <el-select v-model="queryParams.packageTypeArr" multiple :placeholder="$t('请选择')" clearable class="w-200">
          <template v-for="item in getDictDatas(DICT_TYPE.ORDER_SPECIAL_NEEDS)">
            <el-option :label="$l(item, 'label')" :value="item.value"></el-option>
          </template>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('订单限制修改收货人')" prop="isLimitUpdateConsignee">
        <el-select v-model="queryParams.isLimitUpdateConsignee" :placeholder="$t('请选择')" clearable @change="handleQuery" class="w-200">
          <el-option :label="$t('是')" :value="1"></el-option>
          <el-option :label="$t('否')" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('特价')" prop="specialPriceType">
        <el-select v-model="queryParams.specialPriceType" :placeholder="$t('请选择')" clearable @change="handleQuery" class="w-200">
          <el-option :label="$t('是')" :value="1"></el-option>
          <el-option :label="$t('否')" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <div class="flex pb-20">
        <dict-selector :type="DICT_TYPE.ECW_BEGINTIME_TYPE_ENDTIME" v-model="dateFilterType" defaultable class="w-200 mr-5" />
        <el-date-picker v-model="dateFilter" type="datetimerange" range-separator="-" :start-placeholder="$t('开始日期')" :end-placeholder="$t('结束日期')" value-format="yyyy-MM-dd HH:mm:ss" @change="handleQuery"> </el-date-picker>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery" :loading="loading" class="ml-10">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t("重置") }}</el-button>
      </div>
    </el-form>

    <div class="flex-c-c">
      <div class="fills"></div>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      <div style="margin-left: 30px">
        <el-button type="primary" @click="listOpen" v-if="!isExpand">{{ $t("展开明细") }}</el-button>
        <el-button type="default" @click="listOpen" v-else>{{ $t("收起明细") }}</el-button>
      </div>
    </div>
    <el-table v-loading="loading" ref="orderTable" border :data="list || []" @selection-change="handleSelectionChange" class="mt-10">
      <el-table-column type="selection" width="50"></el-table-column>
      <el-table-column align="center" :label="$t('序号')" width="50" prop="tidanNum" />
      <el-table-column prop="orderNo" :label="$t('订单号')" align="center" width="150">
        <template slot-scope="{ row }">
          <router-link :to="'/order/detail?orderId=' + row.orderId"> {{ row.orderNo }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('发货人')" width="100" align="center">
        <template slot-scope="{ row }">
          <router-link :to="'/customer/query/' + row.consignorCustomerId"> {{ row.consignorCustomerNumber }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('收货人')" width="100" align="center">
        <template slot-scope="{ row }">
          <router-link :to="'/customer/query/' + row.consigneeCustomerId">{{ row.consigneeCustomerNumber }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('始发仓/渠道-目的仓')" align="center">
        <template v-slot="scope"> {{ scope.row.destAdjustToStartWarehouseName }}-{{ scope.row.destAdjustToDestWarehouseName }} </template>
      </el-table-column>
      <el-table-column :label="$t('额外费用')" align="center">
        <template v-slot="scope"></template>
      </el-table-column>
      <el-table-column :label="$t('加价单价')" align="center">
        <template v-slot="scope"></template>
      </el-table-column>
      <el-table-column prop="salesmanName" :label="$t('客户经理')" align="center"></el-table-column>
      <el-table-column prop="firstInTime" :label="$t('首次入仓时间')" align="center" width="150"></el-table-column>
      <el-table-column prop="lastInTime" :label="$t('最后入仓时间')" align="center" width="150"></el-table-column>
      <el-table-column prop="createTime" :label="$t('创建时间')" align="center" width="150"></el-table-column>
      <el-table-column :label="$t('特价')" align="center">
        <template v-slot="scope">{{ scope.row.specialPriceType ? "是" : "否" }}</template>
      </el-table-column>
      <el-table-column type="expand" :label="$t('更多')">
        <template v-slot="scope">
          <batchMarkupComList :list="scope.row.orderItemBackVOList" :transportId="scope.row.transportId" :prodTypeList="prodTypeList" :attrList="attrList" :unitMap="unitMap" :currencyMap="currencyMap" />
        </template>
      </el-table-column>
    </el-table>

    <el-card class="mt-20">
      <work-flow xmlkey="shipment_batch_add_price" v-model="form.copyUserId" :disabled="approval"></work-flow>
    </el-card>

    <div class="mt-20" v-if="shipmentObj">
      <template v-if="approval">
        <el-button type="primary" @click="$router.push('/bpm/process-instance/detail?id=' + shipmentObj.batchAddPriceApprovalInfo.bpmProcessId)">{{ $t("加价申请审核中") }}</el-button>
        <el-button type="default" @click="cancelAproval">{{ $t("取消审核") }}</el-button>
      </template>
      <template v-else>
        <el-button type="primary" @click="submit">{{ $t("提交审核") }}</el-button>
      </template>
      <el-button type="default" @click="$store.dispatch('tagsView/delCurrentView')">{{ $t("返回") }}</el-button>
    </div>
  </div>
</template>

<script>
import { getCurrencyList } from "@/api/ecw/currency"
import { getUnitList } from "@/api/ecw/unit"
import selector from "@/components/Selector"
import { getChannelList } from "@/api/ecw/channel"
import { getCabinetPage } from "@/api/ecw/cabinet"
import { getWarehouseList } from "@/api/ecw/warehouse"
import { getSupplierPage } from "@/api/ecw/supplier"
import { approvalCancel, boxGoodsDetail, createApproval, getBatchOrderList, loadSecGoodsList } from "@/api/ecw/boxSea"
import { getAbnormalList, getbox, getLogList } from "@/api/ecw/box"
import { getTotlContent } from "@/views/ecw/box/shippingSea/utils"
import WorkFlow from "@/components/WorkFlow"
import Template from "@/views/cms/template/index.vue"
import batchMarkupComList from "./batchMarkupComList"
import { getRegionList } from "@/api/ecw/order"

import { getProductAttrList } from "@/api/ecw/productAttr"
import { getProductTypeList } from "@/api/ecw/productType"

import UserSelector from "@/components/UserSelector"

export default {
  name: "batchMarkup",
  components: { Template, selector, WorkFlow, batchMarkupComList, UserSelector },
  data() {
    return {
      unitList: [],
      currencyList: [],
      form: {
        copyUserId: [],
        freightUnitId: 6,
        clearanceUnitId: 6
      },
      // 表格多选
      multipleSelection: [],
      // 选择的id
      ids: [],
      attrList: [],
      channelList: [],
      cabinetList: [],
      sectionList: [],
      warehouseList: [],
      // allSupplier:[]
      shipmentObj: null,
      shipmentId: null,
      list: [],
      isExpand: false,
      dateFilterType: "", //日期筛选类别
      dateFilter: [], //筛选日期
      showSearch: false,
      queryParams: {
        specialPriceType: null,
        packageTypeArr: [],
        channelId: null,
        channelIds: null,
        customsTypes: null,
        productRecords: null,
        goodsTypes: null
      },
      // 编号搜索条件
      noParam: {
        key: "numberKey",
        value: ""
      },
      // 商品搜索条件
      prodParam: {
        key: "prodKey",
        value: ""
      },
      // 放货率
      releaseRatio: {
        key: "geReleaseRatio",
        value: ""
      },
      AddressProvince: [],
      AddressCity: [],
      AddressTown: [],
      destCountryId: null,
      objectiveId: null,
      destWarehouseId: null,
      pickRatio: {
        key: "gePickRatio",
        value: ""
      },
      loading: false
    }
  },
  computed: {
    currencyMap() {
      let map = {}
      this.currencyList.forEach((item) => {
        map[item.id] = this.$l(item, "title")
      })
      return map
    },
    unitMap() {
      let map = {}
      this.unitList.forEach((item) => {
        map[item.id] = this.$l(item, "title")
      })
      return map
    },
    /* 渠道 */
    getShipChannelName() {
      return (shippingChannelId) => {
        let item = this.channelList.find((item) => item.channelId == shippingChannelId)
        if (!item) return ""
        return this.$l(item, "name")
      }
    },
    /* 获取柜型 */
    getCabinetLabel() {
      return (cabinetId) => {
        return this.cabinetList.find((item) => item.id == cabinetId)?.name
      }
    },
    /* 总计 */
    getBoxSum() {
      return (boxStatistics) => {
        if (boxStatistics) {
          return this.$t("{num}箱 {volume}m³ {weight}kg", {
            num: boxStatistics.num ?? 0,
            volume: boxStatistics.volume ?? 0,
            weight: boxStatistics.weight ?? 0
          })
        }
        return 0
      }
    },
    /* 获取仓库 */
    getCityName() {
      return (id) => {
        if (!this.warehouseList || !this.warehouseList.length) return ""
        let warehouse = this.warehouseList.find((item) => item.id == id)
        return warehouse ? this.$l(warehouse, "title") : this.$t("无")
      }
    },
    getDocStatus() {
      return (list = []) => {
        // 获取类型
        let customsTypes = list.map((item) => item.customsType)
        // 去重
        return Array.from(new Set(customsTypes))
      }
    },
    // 是否审核中
    approval() {
      return this.shipmentObj?.batchAddPriceApprovalInfo?.approvalStatus === 1
    },
    exportWarehouseList() {
      return this.warehouseList.filter((item) => item.tradeType == 2 || item.tradeType == 3)
    },
    combinedQueryParams() {
      let timeParams = {}
      if (this.dateFilterType && this.dateFilter) {
        timeParams["begin" + this.dateFilterType] = this.dateFilter[0]
        timeParams["end" + this.dateFilterType] = this.dateFilter[1]
      }
      let queryParams = { ...this.queryParams }
      if (this.noParam.value) {
        queryParams[this.noParam.key] = this.noParam.value
      }
      //目的国
      if (this.destCountryId != null && this.destCountryId != "") {
        queryParams.destCountryIds = this.destCountryId
      }
      //目的城市
      if (this.objectiveId != null && this.objectiveId != "") {
        queryParams.objectiveIds = this.objectiveId
      }
      //目的仓
      if (this.destWarehouseId != null && this.destWarehouseId != "") {
        queryParams.destWarehouseIds = this.destWarehouseId
      }
      // 提货率
      if (this.pickRatio.value) {
        queryParams[this.pickRatio.key] = this.pickRatio.value
      }
      // 放货率
      if (this.releaseRatio.value) {
        queryParams[this.releaseRatio.key] = this.releaseRatio.value
      }
      if (this.prodParam.value) {
        queryParams[this.prodParam.key] = this.prodParam.value
      }
      if (queryParams.statusList?.length) {
        queryParams.statusString = queryParams.statusList.join(",")
        delete queryParams.statusList
      }
      return Object.assign({}, timeParams, queryParams)
    }
  },

  async created() {
    getUnitList().then((res) => (this.unitList = res.data))
    getCurrencyList().then((res) => (this.currencyList = res.data))
    getProductAttrList().then((response) => {
      this.attrList = response.data
    })
    getProductTypeList().then((response) => {
      this.prodTypeList = response.data
    })

    this.shipmentId = this.$route.query.shipmentId
    if (!this.shipmentId) {
      return this.$message.error("请求参数错误")
    }
    await this.getBoxDetail()
    await this.initData()
  },
  watch: {
    destCountryId: {
      //监听当前地区值的变化，于与上方地区值进行了双向绑定
      deep: true, //深度监听
      handler() {
        //每当值省份值改变时其下地区值进行清空
        this.AddressCity = []
        this.AddressTown = []
        this.objectiveId = ""
        this.destWarehouseId = ""
        this.findByprovinceCode()
        if (this.destCountryId == "") {
          this.getAddressCity()
          this.getAddressTown()
        } else if (this.destCountryId != "" && this.objectiveId == "" && this.destWarehouseId == "") {
          this.getAddressTown()
        }
      }
    },
    objectiveId: {
      deep: true, //深度监听
      handler() {
        this.AddressTown = []
        this.destWarehouseId = ""
        this.findBycityCode()

        if (this.objectiveId != "" && this.destCountryId != "" && this.destWarehouseId == "") {
          //获取当前城市值id，获取该城市下区域
        } else if (this.destCountryId == "" && this.objectiveId == "" && this.destWarehouseId == "") {
          this.getAddressTown()
        } else if (this.destCountryId != "" && this.objectiveId == "" && this.destWarehouseId == "") {
          this.findByprovinceCode()
          this.getAddressTown()
        }
      }
    },
    destWarehouseId: {
      deep: true, //深度监听
      handler() {
        if (this.objectiveId != "" && this.destCountryId != "" && this.destWarehouseId == "") {
          //获取当前城市值id，获取该城市下区域
          this.findBycityCode()
        } else if (this.destCountryId != "" && this.objectiveId == "" && this.destWarehouseId == "") {
          this.getAddressTown()
        }
      }
    }
  },
  methods: {
    listOpen() {
      this.isExpand = !this.isExpand
      this.$nextTick(() => {
        let $table = this.$refs.orderTable
        this.list.map((item) => {
          $table.toggleRowExpansion(item, this.isExpand)
        })
      })
    },
    // 检查正数
    checkPositive(object, field) {
      // object[field] = parseFloat(object[field])
      // object[field] = isNaN(object[field]) ? '' : object[field].toString()
    },
    // 表格多选
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.ids = selection.map((item) => item.orderId)
    },
    // 初始化字典数据
    async initData() {
      // 查询渠道
      getChannelList().then((res) => (this.channelList = res.data))
      // 查询柜型
      getCabinetPage(null).then((response) => (this.cabinetList = response.data.list))
      // 仓库
      getWarehouseList().then((r) => {
        this.warehouseList = r.data
      })
      this.getAddressProvince()
      this.getAddressCity()
      this.getAddressTown()
      this.getList()
    },
    getAddressProvince() {
      /*getListTree({ treeType: 1 }).then((response) => {
        this.countryList = response.data;
      })*/
      getRegionList(1, 1).then(({ data }) => {
        this.AddressProvince = data
      })
    },
    getAddressCity() {
      getRegionList(4, 4).then(({ data }) => {
        this.AddressCity = data
      })
    },
    getAddressTown() {
      getRegionList(5, 5).then(({ data }) => {
        this.AddressTown = data
      })
    },
    findByprovinceCode() {
      if (this.destCountryId != null && this.destCountryId != "") {
        //获取当前省份值id，获取该省份下城市 destCountryId provinceCode
        getRegionList(2, this.destCountryId).then(({ data }) => {
          this.AddressCity = data
        })
      }
    },
    findBycityCode() {
      if (this.objectiveId != null && this.objectiveId != "") {
        //获取当前城市值id，获取该城市下区域
        getRegionList(3, this.objectiveId).then(({ data }) => {
          this.AddressTown = data
        })
      }
    },
    // 自动去除空格
    replaceSpace(obj, field) {
      obj[field] = obj[field].replace(/\s+/g, "")
    },
    // 出货信息
    getBoxDetail() {
      getbox(this.shipmentId).then((res) => {
        const { data } = res
        this.shipmentObj = data ?? {}
        // 如果是审核中则表单给默认值
        if (this.shipmentObj.batchAddPriceApprovalInfo && this.approval) {
          let details = JSON.parse(this.shipmentObj.batchAddPriceApprovalInfo.details)
          this.$set(this, "form", details)
        }
      })
    },
    getList() {
      this.loading = true
      // 执行查询
      const query = { ...this.combinedQueryParams }
      if (query.packageTypeArr && query.packageTypeArr.length) {
        query.packageType = query.packageTypeArr.join(",")
      }
      getBatchOrderList({
        shipmentId: this.shipmentId,
        ...query
      }).then((res) => {
        this.list = res.data
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$nextTick(this.getList)
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.queryParams = {
        page: 1,
        rows: 10,
        packageTypeArr: [],
        channelId: null,
        channelIds: null,
        customsTypes: null,
        productRecords: null,
        goodsTypes: null
      }
      this.destCountryId = null
      this.destWarehouseId = null
      this.objectiveId = null
      this.pickRatio.value = ""
      this.noParam.value = ""
      this.prodParam.value = ""
      this.dateFilter = []
      this.handleQuery()
    },
    // 提交审核
    submit() {
      if (!this.form.freightFee && !this.form.clearanceFee) {
        return this.$message.error(this.$t("运费和清关费不能同时为空"))
      }
      if (!this.ids.length) {
        return this.$message.error(this.$t("最少选择一个订单"))
      }
      let form = { ...this.form, orderIds: this.ids }
      let data = {
        approvalType: 18, // 批量加价
        copyUserId: this.form.copyUserId,
        details: JSON.stringify(form),
        shipmentId: this.shipmentId
      }
      createApproval(data).then(() => {
        this.$message.success(this.$t("提交成功"))
        this.$store.dispatch("tagsView/delCurrentView")
      })
    },
    // 取消审核
    cancelAproval() {
      this.$prompt(this.$t("请输入取消原因"), this.$t("取消审核"), {
        inputPattern: /\S/,
        inputErrorMessage: this.$t("请输入取消原因")
      })
        .then(({ value }) => {
          console.log("cancelApproval", value)
          return approvalCancel({
            applyReason: value,
            id: this.shipmentObj.batchAddPriceApprovalInfo.id,
            shipmentId: this.shipmentId
          })
        })
        .then((res) => {
          this.$message.success("已取消审核")
          this.getBoxDetail()
        })
    }
  }
}
</script>

<style scoped>
.document-status .document ~ .document:before {
  content: "，";
}
</style>
