<template>
  <div v-loading="pageLoading" class="app-container">
    <card-table :loading="loading" :modalData="contractLiftList" :searchParams="queryParams"
                :tableSearch="true" labelWidth="120px" @columnSearch="handleQuery" @pagination="getList"
                :max-height="$store.getters.tableMaxHeight"
                @selection-change="handleSelectionChange" @resetList="resetQuery" @sortChange="sortChange" show-no
                show-selection>
      <template #operations="{ selections }">
        <el-button v-hasPermi="['contract:export']" icon="el-icon-download" size="mini" plain
                   @click="handleExport">{{ $t('common.export') }}
        </el-button>
        <el-button icon="el-icon-plus" size="mini" type="primary"
                   @click="handleAdd">{{ $t('lift.informationInsert') }}
        </el-button>

        <el-button  icon="el-icon-plus" size="mini" type="primary"
                   @click="handleSn">{{ "序列号" }}
        </el-button>

        <el-button  icon="el-icon-plus" size="mini" type="primary"
                    @click="productionOrderNoConfirm">{{ "生产令号录入" }}
        </el-button>

      </template>
      <template #default="{ list }">
        <!--生产令号-->
        <Column :label="$t('lift.productionOrderNo')"  :searchParams="queryParams" :showSearch="true" fixed prop="productionOrderNo" v-if="checkPermi(['user:contract:lift:productionOrderNo'])" />
        <!--合同号-->
        <Column :label="$t('contract.contractNo')"  :searchParams="queryParams" :showSearch="true" fixed prop="contractNo" v-if="checkPermi(['user:contract:lift:contractNo'])" />
        <!--合同号-版本号-->
        <Column :label="$t('lift.contractNoVersionNo')"  :searchParams="queryParams" :showSearch="true" prop="contractNoVersionNo" v-if="checkPermi(['user:contract:lift:contractNoVersionNo'])" />
        <!-- 合同名 -->
        <Column :label="$t('lift.contractName')"  :searchParams="queryParams" :showSearch="true" prop="contractName" v-if="checkPermi(['user:contract:lift:contractName'])"/>
        <!-- 签单日期 -->
        <Column :label="$t('contract.signingDate')"  :searchParams="queryParams" :showSearch="true" prop="signingDate" v-if="checkPermi(['user:contract:lift:signingDate'])" search-type="dateRange"  width="250"/>
        <!--区域 -->
        <Column :label="$t('user.area')" prop="areaId" :searchParams="queryParams" :showSearch="true" searchType="select" :searchDict="areaList" :min-width="200" :selectMore="true" v-if="checkPermi(['user:contract:lift:areaId'])"/>
        <!--国家-->
        <Column :label="$t('project.countryId')" prop="countryId" :showSearch="true" searchType="select" :searchParams="queryParams" :searchDict="countryList" :min-width="200" :selectMore="true" v-if="checkPermi(['user:contract:lift:countryId'])"/>
        <!--城市-->
        <Column :label="$t('project.city')"  prop="city" show-search :searchParams="queryParams" v-if="checkPermi(['user:contract:lift:city'])"/>
        <!--业务员-->
        <Column :label="$t('contract.salesman')"  prop="salesmanName" width="250" show-search :searchParams="queryParams" v-if="checkPermi(['user:contract:lift:salesman'])">
          <template #default="{ row }">
            <span>{{ row.salesmanName }}</span>
          </template>
        </Column>
        <!--代理商-->
        <Column :label="$t('agent.agent')" prop="agentId" :showSearch="true" searchType="select" :searchParams="queryParams" :searchDict="agentList" :min-width="200" :selectMore="true" v-if="checkPermi(['user:contract:lift:agentId'])"/>
        <!--终端客户  v-hasRole="['system_manager', 'sales_director']" -->
        <Column :label="$t('contract.endCustomers')" prop="endCustomersName" show-search :searchParams="queryParams" v-if="checkPermi(['user:contract:lift:endCustomers'])"/>
        <!--贸易条款-->
        <Column :label="$t('contract.tradeTerms')" :searchDict="dict.type.contract_trade_terms" prop="tradeTerms" show-search v-if="checkPermi(['user:contract:lift:tradeTerms'])"
                :searchParams="queryParams"
                searchType="select" selectMore/>
        <!--销售模式-->
        <Column :label="$t('contract.salesModel')" :searchDict="dict.type.contract_sales_model" :showSearch="true" prop="salesModel" v-if="checkPermi(['user:contract:lift:salesModel'])"
                selectProp="origins" searchType="select" selectMore :searchParams="queryParams"/>
        <!--合同更改日期-->
        <Column :label="$t('lift.contractAmendmentDate')" :searchParams="queryParams" :showSearch="true" prop="contractAmendmentDate" v-if="checkPermi(['user:contract:lift:contractAmendmentDate'])"
                search-type="dateRange" width="250"/>
        <!--产品类别-->
        <Column :label="$t('lift.productCategory')" :searchParams="queryParams" :showSearch="true" prop="productCategory" v-if="checkPermi(['user:contract:lift:productCategory'])"
                 :searchDict="dict.type.product_category" searchType="select" selectMore sortable="custom"/>
        <!--梯型-->
        <Column :label="$t('lift.elevatorModel')" :searchParams="queryParams" :showSearch="true" prop="elevatorModel"  v-if="checkPermi(['user:contract:lift:elevatorModel'])" sortable="custom"/>
        <!--规格-->
        <Column :label="$t('lift.specification')" :searchParams="queryParams" :showSearch="true" prop="specification"  v-if="checkPermi(['user:contract:lift:specification'])"/>
        <!--数量-->
        <Column :label="$t('lift.count')" :searchParams="queryParams"  prop="count"  v-if="checkPermi(['user:contract:lift:count'])"/>
        <!--币种-->
        <Column :label="$t('contract.currencyId')" :searchParams="queryParams" :showSearch="true" prop="currencyId" searchType="select" v-if="checkPermi(['user:contract:lift:currencyId'])"  selectMore
                :searchDict="dict.type.currency_type"/>
        <!--单价-->
        <Column :label="$t('lift.unitPrice')" :searchParams="queryParams"  prop="unitPrice"  align="right" v-if="checkPermi(['user:contract:lift:unitPrice'])">
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.unitPrice)) }}</span>
          </template>
        </Column>
        <!--金额-->
        <Column :label="$t('lift.amountOfMoney')" :searchParams="queryParams"  prop="amountOfMoney"  align="right" v-if="checkPermi(['user:contract:lift:amountOfMoney'])">
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.amountOfMoney)) }}</span>
          </template>
        </Column>
        <!--报价折扣-->
        <Column :label="$t('lift.quotationDiscount')" :searchParams="queryParams"  prop="quotationDiscount" v-if="checkPermi(['user:contract:lift:quotationDiscount'])"/>
        <!--付款方式-->
        <Column :label="$t('contract.paymentMethod')" :searchParams="queryParams" :showSearch="true" prop="paymentMethod" searchType="select" v-if="checkPermi(['user:contract:lift:paymentMethod'])"  selectMore
          />      :searchDict="dict.type.contract_payment_method"
        <!--预计排产日期-->
        <Column :label="$t('lift.expectedProductionScheduleDate')" :searchParams="queryParams" :showSearch="true" v-if="checkPermi(['user:contract:lift:expectedProductionScheduleDate'])"
                sortable="custom" prop="expectedProductionScheduleDate" search-type="dateRange"  width="250"/>
        <!--希望排产日期-->
        <Column :label="$t('lift.hopeToScheduleProductionDate')" :searchParams="queryParams" :showSearch="true" prop="hopeToScheduleProductionDate" v-if="checkPermi(['user:contract:lift:hopeToScheduleProductionDate'])"
                sortable="custom" search-type="dateRange" width="250"/>
        <!--实际排产日期-->
        <Column :label="$t('lift.actualProductionScheduleDate')" :searchParams="queryParams" :showSearch="true" prop="actualProductionScheduleDate" v-if="checkPermi(['user:contract:lift:actualProductionScheduleDate'])"
                sortable="custom" search-type="dateRange" width="250"/>
        <!--排产日期-->
        <Column :label="$t('lift.productionScheduleDate')" :searchParams="queryParams" :showSearch="true" prop="productionScheduleDate" v-if="checkPermi(['user:contract:lift:productionScheduleDate'])"
                search-type="dateRange" sortable="custom"
                width="250"/>
        <!--项目取消暂停原因-->
        <Column :label="$t('lift.reasonForProjectCancellationAndSuspension')" :searchParams="queryParams" :showSearch="true" v-if="checkPermi(['user:contract:lift:reasonForProjectCancellationAndSuspension'])"
                prop="reasonForProjectCancellationAndSuspension" />
        <!--希望发货日-->
        <Column :label="$t('lift.hopeForDeliveryDate')" :searchParams="queryParams" :showSearch="true" prop="hopeForDeliveryDate" v-if="checkPermi(['user:contract:lift:hopeForDeliveryDate'])"
                search-type="dateRange" width="250" sortable="custom"/>
        <!--实际发货日-->
        <Column :label="$t('lift.actualDeliveryDate')" :searchParams="queryParams" :showSearch="true" prop="actualDeliveryDate" v-if="checkPermi(['user:contract:lift:actualDeliveryDate'])"
                search-type="dateRange"  width="250" sortable="custom"/>
        <!--港口-->
        <Column :label="$t('lift.port')" :searchParams="queryParams" :showSearch="true" prop="port"  v-if="checkPermi(['user:contract:lift:port'])"/>
        <!--生产订单状态-->
        <Column :label="$t('lift.productionOrderStatus')" :searchParams="queryParams" :showSearch="true" prop="productionOrderStatus" searchType="select" v-if="checkPermi(['user:contract:lift:productionOrderStatus'])"
                 selectMore   :searchDict="dict.type.production_order_status"/>
        <!--评审折扣-->
        <Column :label="$t('lift.reviewDiscount')" :searchParams="queryParams"  prop="reviewDiscount" v-if="checkPermi(['user:contract:lift:reviewDiscount'])"
                />
        <!--评审运费-->
        <Column :label="$t('lift.reviewShippingCosts')" :searchParams="queryParams" prop="reviewShippingCosts" align="right" v-if="checkPermi(['user:contract:lift:reviewShippingCosts'])"
                >
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.reviewShippingCosts)) }}</span>
          </template>
        </Column>
        <!--评审佣金-->
        <Column :label="$t('lift.reviewCommission')" :searchParams="queryParams"  prop="reviewCommission" align="right" v-if="checkPermi(['user:contract:lift:reviewCommission'])"
                >
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.reviewCommission)) }}</span>
          </template>
        </Column>
        <!--佣金付款日期-->
        <Column :label="$t('lift.commissionPaymentDate')" :searchParams="queryParams" :showSearch="true" prop="commissionPaymentDate" v-if="checkPermi(['user:contract:lift:commissionPaymentDate'])"
                search-type="dateRange" sortable="custom"
                width="250"/>
        <!--收款日期-->
        <Column :label="$t('lift.paymentDate')" :searchParams="queryParams" :showSearch="true" prop="paymentDate" v-if="checkPermi(['user:contract:lift:paymentDate'])" search-type="dateRange"  width="250" sortable="custom"/>
        <!--收款银行-->
        <Column :label="$t('lift.receivingBank')" :searchParams="queryParams" :showSearch="true" prop="receivingBank"  v-if="checkPermi(['user:contract:lift:receivingBank'])"/>
        <!--已收金额-->
        <Column :label="$t('lift.receivedAmount')" :searchParams="queryParams"  prop="receivedAmount"  align="right" v-if="checkPermi(['user:contract:lift:receivedAmount'])">
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.receivedAmount)) }}</span>
          </template>
        </Column>
        <!--收款比例-->
        <Column :label="$t('contract.paymentRatio')" :searchParams="queryParams" :showSearch="true" prop="paymentRatio"  align="right" v-if="checkPermi(['user:contract:lift:paymentRatio'])"/>
        <!--应收余额-->
        <Column :label="$t('lift.accountsReceivableBalance')" :searchParams="queryParams" prop="accountsReceivableBalance" v-if="checkPermi(['user:contract:lift:accountsReceivableBalance'])">
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.accountsReceivableBalance)) }}</span>
          </template>
        </Column>
        <!--计划调整日期-->
        <Column :label="$t('lift.planAdjustmentDate')" :searchParams="queryParams" :showSearch="true" prop="planAdjustmentDate" v-if="checkPermi(['user:contract:lift:planAdjustmentDate'])"
                search-type="dateRange"  width="250"/>
        <!--实际内陆运费-->
        <Column :label="$t('lift.actualInlandFreightCost')" :searchParams="queryParams"  prop="actualInlandFreightCost" align="right" v-if="checkPermi(['user:contract:lift:actualInlandFreightCost'])"
                >
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.actualInlandFreightCost)) }}</span>
          </template>
        </Column>
        <!--实际海运费-->
        <Column :label="$t('lift.actualOceanFreight')" :searchParams="queryParams"  prop="actualOceanFreight" align="right" v-if="checkPermi(['user:contract:lift:actualOceanFreight'])"
                >
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.actualOceanFreight)) }}</span>
          </template>
        </Column>
        <!--开票日期-->
        <Column :label="$t('lift.invoiceDate')" :searchParams="queryParams" :showSearch="true" prop="invoiceDate" v-if="checkPermi(['user:contract:lift:invoiceDate'])"
                search-type="dateRange" sortable="custom" width="250"/>
        <!--报关月份-->
        <Column :label="$t('lift.customsDeclarationMonth')" :searchParams="queryParams" :showSearch="true" prop="customsDeclarationMonth" v-if="checkPermi(['user:contract:lift:customsDeclarationMonth'])"
                sortable="custom" />
        <!--后续收取运费-->
        <Column :label="$t('lift.subsequentCollectionOfShippingFees')" :searchParams="queryParams"  align="right" v-if="checkPermi(['user:contract:lift:subsequentCollectionOfShippingFees'])"
                prop="subsequentCollectionOfShippingFees" >
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.subsequentCollectionOfShippingFees)) }}</span>
          </template>
        </Column>
        <!--收取日期-->
        <Column :label="$t('lift.collectionDate')" :searchParams="queryParams" :showSearch="true" prop="collectionDate" v-if="checkPermi(['user:contract:lift:collectionDate'])" search-type="dateRange"  width="250"/>

        <!--预计内陆运费-->
        <Column :label="$t('lift.planInlandFreightCost')" :searchParams="queryParams" align="right" v-if="checkPermi(['user:contract:lift:planInlandFreightCost'])"
                prop="planInlandFreightCost" >
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.planInlandFreightCost)) }}</span>
          </template>
        </Column>

        <!--预计海运费-->
        <Column :label="$t('lift.planOceanFreight')" :searchParams="queryParams"  align="right" v-if="checkPermi(['user:contract:lift:planOceanFreight'])" prop="planOceanFreight" >
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.planOceanFreight)) }}</span>
          </template>
        </Column>

        <!--项目状态-->
        <Column :label="$t('lift.projectStatus')" :searchParams="queryParams" :showSearch="true" prop="projectStatus" searchType="select" v-if="checkPermi(['user:contract:lift:projectStatus'])"
                :searchDict="dict.type.contract_project_status"/>
        <!--排产月美元汇率-->
        <Column :label="$t('lift.mUsdRate4ProductionScheduling')" :searchParams="queryParams" prop="rate4ProductionScheduling"  v-if="checkPermi(['user:contract:lift:mEuroRate4ProductionScheduling'])"/>
        <!--发货月美元汇率-->
        <Column :label="$t('lift.mUsdRate4Shipment')" :searchParams="queryParams"  prop="rate4Shipment"  v-if="checkPermi(['user:contract:lift:mUsdRate4Shipment'])"/>
        <!--签单月美元汇率-->
        <Column :label="$t('lift.mUsdRate4SigningContracts')" :searchParams="queryParams"  prop="rate4SigningContracts"  v-if="checkPermi(['user:contract:lift:mUsdRate4SigningContracts'])"/>
        <!--电梯号-->
        <Column :label="$t('lift.elevatorCode')" :searchParams="queryParams" :showSearch="true" prop="elevatorCode"  v-if="checkPermi(['user:contract:lift:elevatorCode'])"/>
        <!--来源-->
        <Column :label="$t('contract.origin')" :searchParams="queryParams" :showSearch="true" prop="origin" searchType="select" v-if="checkPermi(['user:contract:lift:origin'])"
                :searchDict="dict.type.contract_lift_origin"/>
        <!--设备类型-->
        <Column :label="$t('lift.elevatorType')" :searchParams="queryParams" :showSearch="true" prop="elevatorType" searchType="select" v-if="checkPermi(['user:contract:lift:elevatorType'])"
                :searchDict="dict.type.elevator_type"/>
        <!--报价编号-版本-->
        <Column :label="$t('lift.quotationNoVersion')" :searchParams="queryParams" :showSearch="true" prop="quotationNoVersion"  v-if="checkPermi(['user:contract:lift:quotationNoVersion'])"/>
        <!--项目名称-->
        <Column :label="$t('lift.projectName')" :searchParams="queryParams" :showSearch="true" prop="projectName"  v-if="checkPermi(['user:contract:lift:projectName'])"/>
<!--        <template #default="{ row }">-->
<!--          <span v-if="row.origin == 0">{{ getNickName(row.quoter) }}</span>-->
<!--          <span v-if="row.origin == 1">{{ row.quoter }}</span>-->
<!--        </template>-->

        <!--报价者-->
        <Column :label="$t('lift.quoter')" :searchParams="queryParams" :showSearch="true" prop="quoter"  v-if="checkPermi(['user:contract:lift:quoter'])">
          <template #default="{ row }">
            {{ row.origin === '0' ? row.quoterName : row.quoter }}
          </template>
        </Column>
        <!--附加费用-->
        <Column :label="$t('lift.additionalCost')" :searchParams="queryParams" prop="additionalCost"  v-if="checkPermi(['user:contract:lift:additionalCost'])">
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.additionalCost)) }}</span>
          </template>
        </Column>
        <!--其他费用-->
        <Column :label="$t('lift.otherFees')" :searchParams="queryParams"  prop="otherCost"  v-if="checkPermi(['user:contract:lift:otherCost'])">
          <template #default="{ row }">
            <span>{{ toDecimal2(numFormat(row.otherCost)) }}</span>
          </template>
        </Column>
        <!--备注-->
        <Column :label="$t('common.remark')" :searchParams="queryParams" :showSearch="true" prop="remark"  v-if="checkPermi(['user:contract:lift:remark'])"/>

        <Column :label="$t('common.operate')" :min-width="180" :searchParams="queryParams" :showSearch="true" fixed="right" searchType="operate"></Column>
      </template>
    </card-table>


    <!-- 电梯信息添加或修改对话框 -->
    <el-dialog :title="productionOrderNoTitle" :visible.sync="contractLiftEditOpen" :close-on-click-modal="false" width="80%">
      <div class="ml20">
        <el-table :data="contractLiftEditList"  v-loading="contractLiftEditLoading" border>
          <Column label="NO" type="index" width="50" ></Column>
          <!--生产令号-->
          <Column  :label="$t('lift.productionOrderNo')"  prop="productionOrderNo" v-if="checkPermi(['user:contract:lift:productionOrderNoEdit'])" width="200px"/>
          <!--合同号-->
          <Column  :label="$t('contract.contractNo')"  prop="contractNo" v-if="checkPermi(['user:contract:lift:contractNoEdit'])"  width="200px"/>
          <!--合同号-版本号-->
          <Column  :label="$t('lift.contractNoVersionNo')" prop="contractNoVersionNo" v-if="checkPermi(['user:contract:lift:contractNoVersionNoEdit'])"  width="200px"/>
          <!-- 合同名 -->
          <Column  :label="$t('lift.contractName')" prop="contractName" v-if="checkPermi(['user:contract:lift:contractNameEdit'])"  width="200px"/>
          <!-- 签单日期 -->
          <Column  :label="$t('contract.signingDate')" prop="signingDate" v-if="checkPermi(['user:contract:lift:signingDateEdit'])" width="250"></Column>
          <!--区域 -->
          <Column  :label="$t('user.area')" prop="areaId" searchType="select" :searchDict="areaList"  :min-width="200"  v-if="checkPermi(['user:contract:lift:areaIdEdit'])" />
          <!--国家-->
          <Column  :label="$t('project.countryId')" prop="countryId" searchType="select"  :searchDict="countryList" :min-width="200" :selectMore="true" v-if="checkPermi(['user:contract:lift:countryIdEdit'])"/>
          <!--城市-->
          <Column  :label="$t('project.city')"  prop="city"  v-if="checkPermi(['user:contract:lift:cityEdit'])"/>
          <!--业务员-->
          <Column  :label="$t('contract.salesman')"  prop="salesmanName" width="250" v-if="checkPermi(['user:contract:lift:salesmanEdit'])">
            <template #default="{ row }">
              <span>{{ row.salesmanName }}</span>
            </template>
          </Column >
          <!--代理商-->
          <Column  :label="$t('agent.agent')" prop="agentId" searchType="select"  :searchDict="agentList" :min-width="200" v-if="checkPermi(['user:contract:lift:agentIdEdit'])"/>
          <!--终端客户  v-hasRole="['system_manager', 'sales_director']" -->
          <Column  :label="$t('contract.endCustomers')" prop="endCustomersName"  v-if="checkPermi(['user:contract:lift:endCustomersEdit'])"/>
          <!--贸易条款-->
          <Column  :label="$t('contract.tradeTerms')" :searchDict="dict.type.contract_trade_terms" searchType="select"   prop="tradeTerms"  v-if="checkPermi(['user:contract:lift:tradeTermsEdit'])"/>
          <!--销售模式-->
          <Column  :label="$t('contract.salesModel')" :searchDict="dict.type.contract_sales_model" searchType="select"   prop="salesModel" v-if="checkPermi(['user:contract:lift:salesModelEdit'])" />
          <!--付款方式-->
          <Column  :label="$t('contract.paymentMethod')"  prop="paymentMethod" searchType="select" :searchDict="dict.type.contract_payment_method" v-if="checkPermi(['user:contract:lift:paymentMethodEdit'])" />
          <!--收款比例-->
          <Column  :label="$t('contract.paymentRatio')"  prop="paymentRatio" searchType="select" :searchDict="dict.type.contract_payment_ratio"  v-if="checkPermi(['user:contract:lift:paymentRatioEdit'])"/>
          <!--合同更改日期-->
          <Column  :label="$t('lift.contractAmendmentDate')"  prop="contractAmendmentDate" v-if="checkPermi(['user:contract:lift:contractAmendmentDateEdit'])" width="250"></Column>
          <!--产品类别-->
          <Column  :label="$t('lift.productCategory')"  prop="productCategory" :searchDict="dict.type.product_category" searchType="select" v-if="checkPermi(['user:contract:lift:productCategoryEdit'])" />

          <!--梯型-->
          <InputColumn  :label="$t('lift.elevatorModel')"  prop="elevatorModel" v-if="checkPermi(['user:contract:lift:elevatorModelEdit'])"/>
          <!--规格-->
          <InputColumn  :label="$t('lift.specification')"  prop="specification" v-if="checkPermi(['user:contract:lift:specificationEdit'])" width="200px"  :show-overflow-tooltip="true"/>
          <!--数量-->
          <Column  :label="$t('lift.count')"  prop="count" v-if="checkPermi(['user:contract:lift:countEdit'])"/>
          <!--币种-->
          <Column  :label="$t('contract.currencyId')"  prop="currencyId" searchType="select" :searchDict="dict.type.currency_type" v-if="checkPermi(['user:contract:lift:currencyIdEdit'])"/>
<!--          <InputDictColumn  :label="$t('contract.currencyId')"  prop="currencyId" :searchDict="dict.type.currency_type" v-if="checkPermi(['user:contract:lift:currencyIdEdit'])"/>-->
          <!--单价-->
          <Column  :label="$t('lift.unitPrice')"  prop="unitPrice"   align="right" v-if="checkPermi(['user:contract:lift:unitPriceEdit'])">
            <template v-slot="scope">
              <MoneyInput :inputValue="scope.row.unitPrice" :zeroLength="2" @change="item=>valueChanged(item,scope.row,'unitPrice')" ></MoneyInput>
            </template>
          </Column >
          <!--金额-->
          <Column  :label="$t('lift.amountOfMoney')"  prop="amountOfMoney"  align="right" v-if="checkPermi(['user:contract:lift:amountOfMoneyEdit'])">
            <template v-slot="scope">
              <MoneyInput :inputValue="scope.row.amountOfMoney" :zeroLength="2" @change="item=>valueChanged(item,scope.row,'amountOfMoney')" ></MoneyInput>
            </template>
          </Column >
          <!--报价折扣-->
          <InputNumberColumn  :label="$t('lift.quotationDiscount')"  prop="quotationDiscount" :step="0.0001"  :precision="4"  :min="0" :max="100" v-if="checkPermi(['user:contract:lift:quotationDiscountEdit'])"/>
          <!--预计排产日期-->
          <DatePickSelectColumn  :label="$t('lift.expectedProductionScheduleDate')"  v-if="checkPermi(['user:contract:lift:expectedProductionScheduleDateEdit'])" prop="expectedProductionScheduleDate"  width="250"></DatePickSelectColumn>
          <!--希望排产日期-->
          <DatePickSelectColumn  :label="$t('lift.hopeToScheduleProductionDate')"  prop="hopeToScheduleProductionDate" v-if="checkPermi(['user:contract:lift:hopeToScheduleProductionDateEdit'])" width="250"></DatePickSelectColumn>
          <!--实际排产日期-->
          <DatePickSelectColumn  :label="$t('lift.actualProductionScheduleDate')"  prop="actualProductionScheduleDate" v-if="checkPermi(['user:contract:lift:actualProductionScheduleDateEdit'])" width="250"></DatePickSelectColumn>
          <!--排产日期-->
          <DatePickSelectColumn  :label="$t('lift.productionScheduleDate')"  prop="productionScheduleDate" v-if="checkPermi(['user:contract:lift:productionScheduleDateEdit'])" width="250"></DatePickSelectColumn>
          <!--项目取消暂停原因-->
          <InputColumn  :label="$t('lift.reasonForProjectCancellationAndSuspension')"  v-if="checkPermi(['user:contract:lift:reasonForProjectCancellationAndSuspensionEdit'])" prop="reasonForProjectCancellationAndSuspension"   />
          <!--希望发货日-->
          <DatePickSelectColumn  :label="$t('lift.hopeForDeliveryDate')"  prop="hopeForDeliveryDate" v-if="checkPermi(['user:contract:lift:hopeForDeliveryDateEdit'])"width="250"></DatePickSelectColumn>
          <!--实际发货日-->
          <DatePickSelectColumn  :label="$t('lift.actualDeliveryDate')"  prop="actualDeliveryDate" v-if="checkPermi(['user:contract:lift:actualDeliveryDateEdit'])" width="250"></DatePickSelectColumn>
          <!--港口-->
          <InputColumn  :label="$t('lift.port')"  prop="port"  v-if="checkPermi(['user:contract:lift:portEdit'])"/>
          <!--生产订单状态-->
          <DictSelectColumn  :label="$t('lift.productionOrderStatus')"  prop="productionOrderStatus" searchType="select" :searchDict="dict.type.production_order_status" v-if="checkPermi(['user:contract:lift:productionOrderStatusEdit'])"/>
          <!--评审折扣-->
          <InputNumberColumn  :label="$t('lift.reviewDiscount')"  prop="reviewDiscount" v-if="checkPermi(['user:contract:lift:reviewDiscountEdit'])" :step="0.0001"  :precision="4"  :min="0" :max="100"/>
          <!--评审运费-->
          <Column  :label="$t('lift.reviewShippingCosts')"  prop="reviewShippingCosts" align="right" v-if="checkPermi(['user:contract:lift:reviewShippingCostsEdit'])">
            <template v-slot="scope">
              <MoneyInput :inputValue="scope.row.reviewShippingCosts" :zeroLength="2" @change="item=>valueChanged(item,scope.row,'reviewShippingCosts')" ></MoneyInput>
            </template>
          </Column >
          <!--评审佣金-->
          <Column :label="$t('lift.reviewCommission')"  prop="reviewCommission" align="right" v-if="checkPermi(['user:contract:lift:reviewCommissionEdit'])">
            <template v-slot="scope">
              <MoneyInput :inputValue="scope.row.reviewCommission" :zeroLength="2" @change="item=>valueChanged(item,scope.row,'reviewCommission')" ></MoneyInput>
            </template>
          </Column >

          <!--佣金付款日期-->
          <DatePickSelectColumn  :label="$t('lift.commissionPaymentDate')"  prop="commissionPaymentDate" v-if="checkPermi(['user:contract:lift:commissionPaymentDateEdit'])" width="250"></DatePickSelectColumn>
          <!--收款日期-->
          <DatePickSelectColumn  :label="$t('lift.paymentDate')"  prop="paymentDate" v-if="checkPermi(['user:contract:lift:paymentDateEdit'])"  width="250"></DatePickSelectColumn>
          <!--收款银行-->
          <InputColumn :label="$t('lift.receivingBank')"  prop="receivingBank"  v-if="checkPermi(['user:contract:lift:receivingBankEdit'])"></InputColumn>
          <!--已收金额-->
          <Column  :label="$t('lift.receivedAmount')"  prop="receivedAmount"  align="right" v-if="checkPermi(['user:contract:lift:receivedAmountEdit'])">
            <template v-slot="scope">
              <MoneyInput :inputValue="scope.row.receivedAmount" :zeroLength="2" @change="item=>valueChanged(item,scope.row,'receivedAmount')" ></MoneyInput>
            </template>
          </Column >
          <!--应收余额-->
          <Column  :label="$t('lift.accountsReceivableBalance')"  prop="accountsReceivableBalance" v-if="checkPermi(['user:contract:lift:accountsReceivableBalanceEdit'])">
            <template v-slot="scope">
              <MoneyInput :inputValue="scope.row.accountsReceivableBalance" :zeroLength="2" @change="item=>valueChanged(item,scope.row,'accountsReceivableBalance')" ></MoneyInput>
            </template>
          </Column >
          <!--计划调整日期-->
          <DatePickSelectColumn  :label="$t('lift.planAdjustmentDate')"  prop="planAdjustmentDate" v-if="checkPermi(['user:contract:lift:planAdjustmentDateEdit'])" width="250" sortable="custom"></DatePickSelectColumn>
          <!--实际内陆运费-->
          <Column  :label="$t('lift.actualInlandFreightCost')"  prop="actualInlandFreightCost" align="right" v-if="checkPermi(['user:contract:lift:actualInlandFreightCostEdit'])">
            <template v-slot="scope">
              <MoneyInput :inputValue="scope.row.actualInlandFreightCost" :zeroLength="2" @change="item=>valueChanged(item,scope.row,'actualInlandFreightCost')" ></MoneyInput>
            </template>
          </Column >
          <!--实际海运费-->
          <Column  :label="$t('lift.actualOceanFreight')"  prop="actualOceanFreight" align="right" v-if="checkPermi(['user:contract:lift:actualOceanFreightEdit'])">
            <template v-slot="scope">
              <MoneyInput :inputValue="scope.row.actualOceanFreight" :zeroLength="2" @change="item=>valueChanged(item,scope.row,'actualOceanFreight')" ></MoneyInput>
            </template>
          </Column >
          <!--开票日期-->
          <DatePickSelectColumn  :label="$t('lift.invoiceDate')"  prop="invoiceDate" v-if="checkPermi(['user:contract:lift:invoiceDateEdit'])" width="250"></DatePickSelectColumn>
          <!--报关月份-->
          <DictSelectColumn  :label="$t('lift.customsDeclarationMonth')"  prop="customsDeclarationMonth" :search-dict="months" v-if="checkPermi(['user:contract:lift:customsDeclarationMonthEdit'])"></DictSelectColumn>
          <!--后续收取运费-->
          <Column  :label="$t('lift.subsequentCollectionOfShippingFees')"  align="right" v-if="checkPermi(['user:contract:lift:subsequentCollectionOfShippingFeesEdit'])" prop="subsequentCollectionOfShippingFees"   >
            <template v-slot="scope">
              <MoneyInput :inputValue="scope.row.subsequentCollectionOfShippingFees" :zeroLength="2" @change="item=>valueChanged(item,scope.row,'subsequentCollectionOfShippingFees')" ></MoneyInput>
            </template>
          </Column >
          <!--收取日期-->
          <DatePickSelectColumn  :label="$t('lift.collectionDate')"  prop="collectionDate" v-if="checkPermi(['user:contract:lift:collectionDateEdit'])" width="250"></DatePickSelectColumn>
          <!--备注-->
          <Column  :label="$t('common.remark')" prop="remark"  v-if="checkPermi(['user:contract:lift:remarkEdit'])">
            <template slot-scope="scope">
              <el-tooltip effect="dark" :content="scope.row.remark" placement="top">
                <el-input v-model="scope.row.remark" maxlength="500" show-word-limit :placeholder="$t('common.pleaseInput') + $t('common.remark')"></el-input>
              </el-tooltip>
            </template>
          </Column>

        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="additionalCostSubmitForm" icon="el-icon-circle-check"  >{{ $t('common.confirm') }}</el-button>
        <el-button @click="contractLiftEditOpen = false" icon="el-icon-remove-outline">{{ $t('common.cancel') }}</el-button>
      </div>
    </el-dialog>
<!--    <el-dialog title="生产令号录入" :visible.sync="contractLiftSnOpen" :close-on-click-modal="false" width="80%">-->
<!--      <div class="ml20">-->
<!--        <el-table :data="contractLiftSnList"  v-loading="contractLiftSnLoading" border>-->

<!--        </el-table>-->
<!--      </div>-->
<!--    </el-dialog>-->
<!--    productionOrderNo-->
    <el-dialog title="生产序列号录入" :visible.sync="contractLiftSnOpen" :close-on-click-modal="false" width="50%">
      <div class="ml20">
        <card-table :loading="contractLiftSnLoading" :modalData="contractLiftSnList" :searchParams="contractLiftSnQueryParams"
                    :tableSearch="true" labelWidth="120px" @columnSearch="handleSnQuery" @pagination="getSnList" :max-height="$store.getters.tableMaxHeight"
                    @selection-change="handleSnSelectionChange" @resetList="resetSnQuery" @sortChange="sortSnChange" show-no >
          <template #operations="{ selections }">
            <span class="demonstration" style="padding-right: 20px">月份</span>
            <el-date-picker v-model="valueMonth" type="month" value-format="yyyy-MM-dd" :placeholder="$t('common.pleaseSelect') +'月份' "/>
            <span class="demonstration" style="padding-left: 20px;padding-right: 20px">序列号</span>
            <el-input v-model="valueInput" :placeholder="$t('common.pleaseInput') +'序列号' " clearable style="width: 200px " @input="validateInput"  />
            <el-button icon="el-icon-circle-check" size="small" type="primary" @click="handleSnAdd " style="margin-left: 20px">{{ $t('common.confirm') }}</el-button>
          </template>
          <template #default="{ list }">
            <!--月份-->
            <Column label="月份"  :searchParams="contractLiftSnQueryParams" prop="snEnterTime" search-type="dateRange"  date-type="monthrange" width="250" :showSearch="true" >
              <template #default="{ row }">
                {{ formatDate(row.snEnterTime) }}
              </template>
            </Column>
            <!-- 序列号 -->
            <Column label="序列号"  :searchParams="contractLiftSnQueryParams" :showSearch="true" prop="sn" />

            <Column :label="$t('common.operate')" :searchParams="contractLiftSnQueryParams" :min-width="180" :showSearch="true" fixed="right" searchType="operate"></Column>
          </template>
        </card-table>

      </div>
    </el-dialog>
  </div>
</template>

<script>


import tcAgentHistory from "@/views/user/tcAgentHistory/index.vue";
import Column from "@/components/element/table/Column.vue";
import {checkPermi, checkRole} from "@/utils/permission";
import {getCountryList} from "@/api/business/crm/follow";
import MoreBtn from "@/components/MoreBtn/index.vue";
import {addLiftBatch, listAllById, listLift, selectProductionOrderNo, updateOrderNoBo} from "@/api/contract/lift";
import {getAreaList} from "@/api/business/crm/account";
import {curAgent} from "@/api/business/crm/lead";
import {getAllOwnerList, getAuthRole} from "@/api/system/user";
import MoneyInput from "@/components/element/form/items/moneyInput.vue";
import DatePicker from "@/components/element/form/items/DatePicker.vue";
import DictColumn from "@/components/element/table/DictColumn.vue";
import InputDictColumn from "@/components/element/table/DictSelectColumn.vue";
import InputColumn from "@/components/element/table/InputColumn.vue";
import DatePickSelectColumn from "@/components/element/table/DatePickSelectColumn.vue";
import DictSelectColumn from "@/components/element/table/DictSelectColumn.vue";
import MoneyInputColumn from "@/components/element/table/MoneyInputColumn.vue";
import CardTable from "@/components/element/table/CardTable.vue";
import {addSn, listSn} from "@/api/contract/liftSn";
import InputNumberColumn from "@/components/element/table/InputNumberColumn.vue";
import InputNumber from "@/components/element/form/items/InputNumber.vue";
import {getAllNationNeedLanguageList} from "@/api/user/country";

export default {
  name: "Lift",
  components: {
    InputNumber,
    InputNumberColumn,
    CardTable,
    MoneyInputColumn,
    DictSelectColumn,
    DatePickSelectColumn, InputColumn, InputDictColumn, DictColumn, DatePicker, MoneyInput, MoreBtn, Column},
  dicts: ['contract_payment_ratio','production_order_status','agent_type', 'agent_level', 'currency_type', 'contract_approval_status', 'contract_sales_model', 'contract_payment_method', 'contract_trade_terms','product_category','elevator_type','contract_lift_origin','contract_project_status'],
  computed: {
    tcAgentHistory() {
      return tcAgentHistory
    },
    localLabelSuffix() {
      return localStorage.getItem('labelSuffix') || '';
    },

    showAreaColumn() {
      // VP 、总经理
      // const allowedRoles = ["sales_director", "manager"];
      // return allowedRoles.some(role => this.$store.getters.roles.includes(role));
      // 不可见的角色： 区总、销售经理、代理商经理、代理商销售、销售支持 暂不考虑多角色比如又是销售又是vp角色
      const invisibleRoles = ['area_sales_director', 'sales_manager', 'agent_manager', 'agent_sales', 'sales_support'];
      return !this.$store.getters.roles.some(role => invisibleRoles.includes(role));
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      pageLoading: false,
      targetLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 合同表格数据
      contractLiftList: [],
      contractLiftEditLoading:false,
      contractLiftEditList: [],

      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        approveStatus:'2',
        agentId: null,
        agentNo: null,
        agentName: null,
        areaId: null,
        countryId: null,
        city: null,
        agentType: null,
        hasContract: null,
        parentAgentId: null,
        parentSalerId: null,
        agentLevel: null,
        discount: null,
        head: null,
        phone: null,
        email: null,
        address: null,
        status: null,
        permissionChar: null,
        origin: null,
        firstCooperationYear: null,
        protocolStartDate: null,
        protocolEndDate: null,
        authorizedArea: null,
        language: this.$i18n.locale,
      },
      contractLiftSnQueryParams:{
        pageNum: 1,
        pageSize: 10,
      },
      //国家
      countryList: [],
      // 区域选项
      areaOptions: [],
      // 快速查询
      areaMap: new Map(),
      // 上级销售选项
      salesOptions: [],
      // 上级代理选项
      agentOptions: [],
      // 区域列表
      areaList: [],
      //代理商
      agentList:[],
      selectionList:[],
      productionOrderNoTitle:'生产信息录入',
      contractLiftEditOpen:false,
      productionOrderNoForm:{},
      productionOrderNoFormRules:{},
      contractLiftSnOpen:false,
      contractLiftSnList : [],
      contractLiftSnLoading: false,
      months: [
        { value: '01', label: '一月' },
        { value: '02', label: '二月' },
        { value: '03', label: '三月' },
        { value: '04', label: '四月' },
        { value: '05', label: '五月' },
        { value: '06', label: '六月' },
        { value: '07', label: '七月' },
        { value: '08', label: '八月' },
        { value: '09', label: '九月' },
        { value: '10', label: '十月' },
        { value: '11', label: '十一月' },
        { value: '12', label: '十二月' },
      ],
      valueMonth:null,
      valueInput:null,
    };
  },
  created() {
    this.queryParams.permissionChar = this.$store.state.user.permissionChar
    this.queryParams.language = this.$i18n.locale
    this.curAgent()
    this.getList();
    this.getAllOwnerList()
    this.getAreaList();
    this.getNationList()

  },
  methods: {
    formatDate(cellValue) {
      if (!cellValue) return '';
      const date = new Date(cellValue);
      return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
    },
    validateInput() {
      var regex = /\D/
      if(regex.test(this.valueInput)){
        this.valueInput = '1';
      }else{
        //含有特殊字符返回true, 没有特殊字符返回false
        const value = parseInt(this.valueInput, 10);
        if(value < 1){
          this.valueInput = '1'
        }
        else if (value > 9){
          this.valueInput = '9'
        }
        else if(isNaN(value)){
          this.valueInput = '';
        }
      }
    },
    getNickName(userId){
      const nickName = this.ownerList.find(item => item.userId === userId);
      return nickName ? nickName.nickName : '';
    },
    checkPermi,
    /** 查询客户所有人列表 */
    getAllOwnerList() {
      getAllOwnerList({onlySalesRole: false}).then(res => {
        this.ownerList = res.data;
      })
      // //将超级管理员的账号添加
      // getAuthRole(1).then(response => {
      //   this.ownerList.push(response.user)
      // })
    },
    //获取代理商
    async curAgent() {
      const response = await curAgent()
      response.data.forEach(item => {
        this.agentList.push({
          label: item['ownerAgentName' + this.localLabelSuffix],
          value: parseInt(item.ownerAgent)
        })
      })
      // 如果存在 ownerAgent =0，则添加总部选项
      this.agentList.unshift({value: 0, label: this.$t('agent.headquarters')})
    },
    //
    /** 查询代理商档案列表 */
    async getList() {
      this.loading = true;
      const {createTime, ...params} = this.queryParams;
      try {
        const response = await listLift(params);
        this.contractLiftList = response.rows;
        this.queryParams.total = response.total;
      } finally {
        this.loading = false;
      }
    },

    async getNationList() {
      const response = await getAllNationNeedLanguageList(this.$i18n.locale)
      response.data.forEach(item=>{
        this.countryList.push({
          label: item.countryName,
          value: parseInt(item.countryId)
        })
      })
    },
    //生产令号录入
    handleProductionOrderNoAdd(){

    },
    //电梯序列号履历打开
    handleSn(){
      this.valueInput = null
      this.valueMonth = null
      this.resetSnQuery()
      this.contractLiftSnOpen = true

    },
    /** 电梯系列号搜索按钮操作 */
    handleSnQuery(){
      this.contractLiftSnQueryParams.pageNum = 1
      this.getSnList()
    },
    /** 电梯系列号搜索按钮操作 */
    getSnList(){
      listSn({...this.contractLiftSnQueryParams}).then(res=>{
        this.contractLiftSnList = res.rows
        this.contractLiftSnQueryParams.total = res.total;
        // this.contractLiftSnList = res.
      })

    },
    handleSnSelectionChange(){

    },

    resetSnQuery(){
      this.$set(this.contractLiftSnQueryParams,'snEnterTime',null)
      this.$set(this.contractLiftSnQueryParams,'sn',null)
      this.getSnList()
    },

    sortSnChange({column, prop, order}){
      if (order === 'ascending') {
        this.contractLiftSnQueryParams.orderByColumn = prop;
        this.contractLiftSnQueryParams.isAsc = 'asc';
      } else if (order === 'descending') {
        this.contractLiftSnQueryParams.orderByColumn = prop;
        this.contractLiftSnQueryParams.isAsc = 'desc';
      } else {
        this.contractLiftSnQueryParams.orderByColumn = null;
        this.contractLiftSnQueryParams.isAsc = null;
      }
      this.getSnList();
    },
    async handleSnAdd() {
      if(this.valueMonth == null){
        this.$message.error("请选择月份")
        return
      }
      if(this.valueInput == null){
        this.$message.error("请输入序列号")
        return
      }
      //先查看数据库此序列号是否被占用（电梯表是否使用此序列号）
      const response = await selectProductionOrderNo(JSON.parse(JSON.stringify(this.valueMonth)))
      console.log(response)
      //如果没使用  则取人该月是否已经录入
      if(response && response.data === 0 ){
        //没录入  正常添加
        await addSn({sn:this.valueInput,snEnterTime:this.valueMonth}).then(res=>{
          if (res.code == 200) {
            this.$modal.msgSuccess("操作成功");
            this.contractLiftSnOpen = false
            this.getSnList()
          } else {
            this.$modal.msgError(res.msg);
          }
        })
      }else{
        this.$message.error("该月已导入序列号，并且该序列号已被使用，无法再次修改")
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 todo:待补充*/
    resetQuery() {
      this.$set(this.queryParams, 'contractNo', null)
      this.$set(this.queryParams, 'contractCustomer', null)
      this.$set(this.queryParams, 'versionNo', null)
      this.$set(this.queryParams, 'approvalStatus', null)
      this.$set(this.queryParams, 'productionOrderNo', null)
      this.$set(this.queryParams, 'contractNoVersionNo', null)
      this.$set(this.queryParams, 'contractName', null)
      this.$set(this.queryParams, 'signingDate', null)
      this.$set(this.queryParams, 'salesmanName', null)
      this.$set(this.queryParams, 'agent', null)
      this.$set(this.queryParams, 'endCustomersName', null)
      this.$set(this.queryParams, 'tradeTerms', null)
      this.$set(this.queryParams, 'salesModel', null)
      this.$set(this.queryParams, 'contractAmendmentDate', null)
      this.$set(this.queryParams, 'productCategory', null)
      this.$set(this.queryParams, 'elevatorModel', null)
      this.$set(this.queryParams, 'specification', null)
      this.$set(this.queryParams, 'count', null)
      this.$set(this.queryParams, 'currency', null)
      this.$set(this.queryParams, 'unitPrice', null)
      this.$set(this.queryParams, 'amountOfMoney', null)
      this.$set(this.queryParams, 'quotationDiscount', null)
      this.$set(this.queryParams, 'paymentMethod', null)
      this.$set(this.queryParams, 'expectedProductionScheduleDate', null)
      this.$set(this.queryParams, 'hopeToScheduleProductionDate', null)
      this.$set(this.queryParams, 'actualProductionScheduleDate', null)
      this.$set(this.queryParams, 'productionScheduleDate', null)
      this.$set(this.queryParams, 'reasonForProjectCancellationAndSuspension', null)
      this.$set(this.queryParams, 'hopeForDeliveryDate', null)
      this.$set(this.queryParams, 'actualDeliveryDate', null)
      this.$set(this.queryParams, 'port', null)
      this.$set(this.queryParams, 'productionOrderStatus', null)
      this.$set(this.queryParams, 'reviewDiscount', null)
      this.$set(this.queryParams, 'reviewShippingCosts', null)
      this.$set(this.queryParams, 'reviewCommission', null)
      this.$set(this.queryParams, 'commissionPaymentDate', null)
      this.$set(this.queryParams, 'paymentDate', null)
      this.$set(this.queryParams, 'receivingBank', null)
      this.$set(this.queryParams, 'receivedAmount', null)
      this.$set(this.queryParams, 'paymentRatio', null)
      this.$set(this.queryParams, 'accountsReceivableBalance', null)
      this.$set(this.queryParams, 'planAdjustmentDate', null)
      this.$set(this.queryParams, 'actualInlandFreightCost', null)
      this.$set(this.queryParams, 'actualOceanFreight', null)
      this.$set(this.queryParams, 'invoiceDate', null)
      this.$set(this.queryParams, 'customsDeclarationMonth', null)
      this.$set(this.queryParams, 'subsequentCollectionOfShippingFees ', null)
      this.$set(this.queryParams, 'collectionDate', null)
      this.$set(this.queryParams, 'remark', null)

      this.$set(this.queryParams, 'areaId', null)
      this.$set(this.queryParams, 'countryId', null)
      this.$set(this.queryParams, 'city', null)
      this.$set(this.queryParams, 'agentId', null)
      this.$set(this.queryParams, 'currencyId', null)
      this.$set(this.queryParams, 'subsequentCollectionOfShippingFees', null)

      this.$set(this.queryParams, 'quoter', null)
      this.$set(this.queryParams, 'projectName', null)
      this.$set(this.queryParams, 'quotationNoVersion', null)
      this.$set(this.queryParams, 'rate4ProductionScheduling', null)
      this.$set(this.queryParams, 'projectStatus', null)
      this.$set(this.queryParams, 'elevatorType', null)
      this.$set(this.queryParams, 'origin', null)
      this.$set(this.queryParams, 'rate4SigningContracts', null)
      this.$set(this.queryParams, 'rate4Shipment', null)
      this.$set(this.queryParams, 'elevatorCode', null)




      this.handleQuery();
    },
    valueChanged(value, rowAmount,column) {
      this.$nextTick(() => {
        this.$set(rowAmount,column,value)
        // this.$set(rowAmount,'additionalCost',this.sumPrice(rowAmount))
      })
    },


    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.selectionList = selection
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    /** 生产订单录入按钮操作 */
    async handleAdd() {
      if(this.ids && this.ids.length > 0){
        // if(this.selectionList)
        this.loading = true
        const response = await listAllById(this.ids);
        this.contractLiftEditList = response.rows;
        this.loading = false
        this.contractLiftEditOpen = true

      }
      else{
        //请选择数据！
        this.$message.error(this.$t('lift.pleaseSelectData'))
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/lift/export', {
        ...this.queryParams
      }, `lift_${new Date().getTime()}.xlsx`)
    },

    sortChange({column, prop, order}) {
      if (order === 'ascending') {
        this.queryParams.orderByColumn = prop;
        this.queryParams.isAsc = 'asc';
      } else if (order === 'descending') {
        this.queryParams.orderByColumn = prop;
        this.queryParams.isAsc = 'desc';
      } else {
        this.queryParams.orderByColumn = null;
        this.queryParams.isAsc = null;
      }
      this.getList();
    },
    getAgentName(areaId) {
      if (areaId !== null && areaId !== undefined && areaId >= 0) {
        const area = this.areaMap.get(areaId);
        if (area) {
          return area['areaName' + this.localLabelSuffix]
        }
      }
      return '-'
    },
    checkRole,

    getAreaList() {
      getAreaList().then(response => {
        if (response.data) {
          response.data.forEach(item => {
            this.areaList.push({
              label: item['second' + this.localLabelSuffix],
              value: parseInt(item.first)
            })
          })
        }
      })
    },
    productionOrderNoConfirm(){
      // 检查 selectionList 中是否有任何元素的 productionOrderNo 不为 null
      const hasNonNullProductionOrderNo = this.selectionList.some(item => item.productionOrderNo !== null);
      if (hasNonNullProductionOrderNo) {
        this.$message.error("存在生产令号已录入的数据，请重新选择！")
      }else{
        if(this.ids.length >  0 ){
          updateOrderNoBo({ids:this.ids}).then(res=>{
            if(res && res.code == 200){
              this.$message.success("生产令号录入成功")
              this.getList()
            }
          })
        }else{
          this.$message.error("请至少选择一条数据！")
        }
      }
    },
    //信息录入确认
    additionalCostSubmitForm(){
      addLiftBatch(this.contractLiftEditList).then(res=>{
        if(res && res.code == 200) {
          this.$message.success("生产信息录入成功")
          this.contractLiftEditOpen = false
          this.getList()
        }
      })
    },
    //信息录入取消
    additionalCostFormCancel(){
    },
    formatDict(value, dictData) {
      return dictData.find(dict => dict.value == value)?.label;
    },


  }
};
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
::v-deep .edit-dialog {
  .el-dialog__body {
    min-height: 50vh;
    max-height: 75vh;
    overflow: auto;
    padding: 30px 50px;
  }

  .el-dialog__footer {
    padding: 10px 50px 20px 50px;
  }

  .el-form-item--medium .el-form-item__content, .el-form-item--medium .el-form-item__label {
    line-height: 25px;
  }

  .el-form--label-top .el-form-item__label {
    padding: 0;
  }

  .el-form .el-row:last-child .el-form-item {
    margin-bottom: 0;
  }
  .vue-treeselect .vue-treeselect__control {
    padding: 0 10px;
  }
}
</style>
