| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688 |
- <template>
- <el-form ref="form" :model="form" :rules="rules">
- <div v-table-scroll-sync class="table-container">
- <ele-pro-table
- ref="table"
- :needPage="false"
- :columns="columns"
- :datasource="form.datasource"
- class="time-form"
- :class="{ 'time-form-busy': tableBusy }"
- :selection.sync="selection"
- @columns-change="handleColumnChange"
- @header-dragend="handleHeaderDragend"
- :cache-key="cacheKeyUrl"
- height="350"
- full-height="calc(100vh - 76px)"
- :show-summary="true"
- :summary-method="getSummaries"
- >
- <!-- 表头工具栏 -->
- <template v-slot:toolbar>
- <div class="headbox">
- <div>
- <el-button
- v-if="isShowAdd && needProduce != 4"
- size="small"
- type="primary"
- icon="el-icon-plus"
- class="ele-btn-icon"
- @click="handlAdd"
- >
- 新增
- </el-button>
- <el-button
- size="small"
- type="primary"
- icon="el-icon-plus"
- class="ele-btn-icon"
- @click="handParent()"
- v-if="isShowAdd && needProduce == 4"
- >
- 新增
- </el-button>
- <el-button
- size="small"
- type="danger"
- icon="el-icon-delete"
- class="ele-btn-icon"
- :disabled="!selection.length"
- @click="batchRemove"
- >
- 批量删除
- </el-button>
- <!-- 批量设置发货数量:仅开发环境提供 -->
- <setAllCountPrice
- :disabled="tableBusy || !selection.length || sourceType == 4"
- :show-price="false"
- count-title="发货数量"
- button-text="批量设置发货数量"
- @success="setAllSendCountChange"
- />
- </div>
- </div>
- </template>
- <template v-slot:technicalDrawings="{ row, $index }">
- <el-form-item :prop="'datasource.' + $index + '.technicalDrawings'">
- <fileMain
- v-model="row.technicalDrawings"
- type="view"
- lazy-render
- defer-modal
- ></fileMain>
- </el-form-item>
- </template>
- <template v-slot:remark="{ row, $index }">
- <el-form-item :prop="'datasource.' + $index + '.remark'">
- <el-input
- clearable
- v-model="row.remark"
- type="textarea"
- placeholder="请输入"
- />
- </el-form-item>
- </template>
- <template v-slot:packagingStrength="scope">
- <el-form-item>
- <DictSelection
- dict-name="包装强度"
- @change="keyChange(scope.$index, scope.row, 'packagingStrength')"
- v-model="scope.row.extField.packagingStrength"
- :isOne="scope.$index === 0"
- ></DictSelection>
- </el-form-item>
- </template>
- <template v-slot:packagingDensity="scope">
- <el-form-item>
- <DictSelection
- dict-name="包装密度"
- @change="keyChange(scope.$index, scope.row, 'packagingDensity')"
- v-model="scope.row.extField.packagingDensity"
- :isOne="scope.$index === 0"
- ></DictSelection>
- </el-form-item>
- </template>
- <template v-slot:batchStockId="scope">
- <el-form-item :prop="'datasource.' + scope.$index + '.batchStockId'" :rules="[
- {
- required: scope.row.isLockSaleOrder == 1,
- message: '请选择批次号',
- trigger: 'blur'
- }
- ]">
- <!-- <el-input v-model="scope.row.batchNo"></el-input> -->
- <el-select
- v-model="scope.row.batchStockId"
- clearable
- placeholder="请选择"
- :disabled="isSaleOrderLockReadonly(scope.row)"
- :loading="lookupLoading(scope.row, 'batch')"
- @visible-change="
- (visible) => visible && loadBatchOptions(scope.row)
- "
- @change="batchNoChange(scope.$index, scope.row)"
- >
- <el-option
- v-for="item in batchOptions(scope.row)"
- :key="item.id"
- :label="item.id == 999 ? `${item.batchNo}(无匹配可发库存)` : item.batchNo"
- :value="item.id"
- :disabled="item.id == 999"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </template>
- <!-- 生产编号 可编辑 -->
- <template v-slot:productionCodes="{ row }">
- <el-form-item>
- <el-input v-model="row.productionCodes"></el-input>
- </el-form-item>
- </template>
- <template v-slot:blockCount="scope">
- <el-form-item
- :prop="'datasource.' + scope.$index + '.blockCount'"
- :rules="[{ required: true, message: '请输入', trigger: 'blur' }]"
- >
- <el-input
- v-model="scope.row.blockCount"
- @input="
- (val) => tableHandleKeyUp(scope.row, scope.$index, 'blockCount')
- "
- ></el-input>
- </el-form-item>
- </template>
- <template v-slot:receiveTotalWeight="scope">
- <el-form-item
- :prop="'datasource.' + scope.$index + '.receiveTotalWeight'"
- >
- <el-input
- type="number"
- v-model="scope.row.receiveTotalWeight"
- @input="changeSendTotalWeight(scope.row, scope.$index)"
- style="width: calc(100% - 70px); margin-right: 10px"
- >
- <template slot="append">
- {{ scope.row.weightUnit }}
- </template>
- </el-input>
- <el-button
- size="small"
- type="primary"
- v-if="entrustedCode"
- @click.native="
- (e) => handleInnerBound(e, scope.row, scope.$index)
- "
- >选择
- </el-button>
- </el-form-item>
- </template>
- <!-- 编码:该产品存在替代料时给出“替”标识 -->
- <template v-slot:productCode="{ row }">
- <div class="replace-code-cell">
- <span class="code-text" :title="row.productCode">{{
- row.productCode
- }}</span>
- <el-tooltip v-if="isRowReplaced(row)" placement="top" effect="dark">
- <el-tag type="warning" size="mini" effect="dark">替</el-tag>
- <div slot="content" class="replace-tip">
- 该产品存在替代料,详见“替代料”页签,发货时以替代料为准
- </div>
- </el-tooltip>
- </div>
- </template>
- <template v-slot:orderNo="scope">
- <el-form-item
- :prop="'datasource.' + scope.$index + '.orderNo'"
- :rules="[
- {
- required: false,
- message: '请选择订单编号',
- trigger: 'blur'
- }
- ]"
- >
- <el-select
- v-if="needProduce == 4 && orderNoList.length > 1"
- v-model="scope.row.orderNo"
- placeholder="请选择"
- >
- <el-option
- v-for="item in orderNoList"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- >
- </el-option>
- </el-select>
- <span v-else>{{ scope.row.orderNo }}</span>
- </el-form-item>
- </template>
- <template v-slot:sendTotalWeight="scope">
- <el-form-item
- :prop="'datasource.' + scope.$index + '.sendTotalWeight'"
- >
- <el-input
- type="number"
- v-model="scope.row.sendTotalWeight"
- style="width: 100%"
- @input="changeCount(scope.row, scope.$index, true, 'totalWeight')"
- >
- <template slot="append">
- {{ scope.row.weightUnit }}
- </template>
- </el-input>
- </el-form-item>
- </template>
- <template v-slot:increaseTotalWeight="scope">
- <el-form-item
- :prop="'datasource.' + scope.$index + '.increaseTotalWeight'"
- >
- <el-input
- type="number"
- v-model="scope.row.increaseTotalWeight"
- style="width: 100%"
- disabled
- >
- <template slot="append">
- {{ scope.row.weightUnit }}
- </template>
- </el-input>
- </el-form-item>
- </template>
- <template v-slot:warehouseId="scope">
- <el-form-item
- :prop="'datasource.' + scope.$index + '.warehouseId'"
- :rules="[
- {
- required: isWarehouseId == 1 || scope.row.isLockSaleOrder == 1,
- message: '请选择仓库',
- trigger: 'blur'
- }
- ]"
- >
- <el-select
- v-model="scope.row.warehouseId"
- clearable
- :disabled="isSaleOrderLockReadonly(scope.row)"
- placeholder="请选择"
- :loading="lookupLoading(scope.row, 'warehouse')"
- @visible-change="
- (visible) => visible && loadWarehouseOptions(scope.row)
- "
- @change="warehouseChange(scope.$index, scope.row, true)"
- >
- <el-option
- v-for="(item, optIndex) in warehouseOptions(scope.row)"
- :key="`${item.warehouseId}_${optIndex}`"
- :label="item.warehouseName"
- :value="item.warehouseId"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </template>
- <template v-slot:availableCountBase="{ row }">
- <span>{{
- row.availableCountBase === undefined ||
- row.availableCountBase === null
- ? 0
- : row.availableCountBase
- }}</span>
- </template>
- <template v-slot:singlePrice="scope">
- <el-form-item
- style="margin-bottom: 20px"
- :prop="'datasource.' + scope.$index + '.singlePrice'"
- :rules="{
- required: true,
- message: '请输入正确的单价',
- trigger: 'change'
- }"
- >
- <el-input
- v-model="scope.row.singlePrice"
- placeholder="请输入"
- @input="changeCount(scope.row, scope.$index)"
- type="number"
- >
- <template slot="append">元</template>
- </el-input>
- </el-form-item>
- </template>
- <template v-slot:singleWeight="scope">
- <el-form-item
- style="margin-bottom: 20px"
- :rules="{
- required: false,
- trigger: 'change'
- }"
- :prop="'datasource.' + scope.$index + '.singleWeight'"
- >
- <el-input
- v-model="scope.row.singleWeight"
- type="number"
- placeholder="请输入"
- :disabled="needProduce == 4"
- @input="changeCount(scope.row, scope.$index)"
- >
- <template slot="append">
- {{ scope.row.weightUnit }}
- </template>
- </el-input>
- </el-form-item>
- </template>
- <template v-slot:headerWarehouseNum="{ column }">
- <span class="is-required">{{ column.label }}</span>
- </template>
- <template v-slot:headerWarehouseId="{ column }">
- <span :class="isWarehouseId == 1 ? 'is-required' : ''">{{
- column.label
- }}</span>
- </template>
- <template v-slot:headerTotalCount="{ column }">
- <span class="is-required">{{ column.label }}</span>
- </template>
- <template v-slot:headerReceiveTotalWeight="{ column }">
- <span :class="{ 'is-required': entrustedCode && pricingWay == 2 }">{{
- column.label
- }}</span>
- </template>
- <template v-slot:saleCount="scope">
- <el-form-item
- style="margin-bottom: 20px"
- :prop="'datasource.' + scope.$index + '.saleCount'"
- :rules="[
- {
- required: true,
- message: '请输入数量',
- trigger: 'change'
- },
- {
- validator: (rule, value, callback) => {
- if (value === undefined || value === null || value === '') {
- callback('请输入数量');
- } else if (parseFloat(value) <= 0) {
- callback('数量必须大于0');
- } else {
- callback();
- }
- },
- trigger: 'blur'
- }
- ]"
- >
- <el-input
- v-model="scope.row.saleCount"
- placeholder="请输入"
- type="number"
- :min="0"
- :disabled="sourceType == 4"
- @input="changeCount(scope.row, scope.$index, false)"
- >
- <template slot="append">
- <el-select
- v-model="scope.row.saleUnitId"
- style="width: 80px"
- @change="changeCount(scope.row, scope.$index)"
- :disabled="clientEnvironmentId == 4 || sourceType == 4"
- >
- <el-option
- :label="item.conversionUnit"
- :value="item.id"
- v-for="(item, index) in scope.row.packageDispositionList"
- :key="index"
- ></el-option>
- </el-select>
- </template>
- </el-input>
- </el-form-item>
- </template>
- <template v-slot:cuttingLength="{ row, $index }">
- <el-form-item :prop="'datasource.' + $index + '.cuttingLength'">
- <el-input v-model="row.cuttingLength" placeholder="请输入">
- </el-input>
- </el-form-item>
- </template>
- <!-- <template v-slot:saleUnit="scope">
- <el-form-item
- style="margin-bottom: 20px"
- :prop="'datasource.' + scope.$index + '.saleUnitId'"
- >
- <el-select
- v-model="scope.row.saleUnitId"
- style="width: 100%"
- @change="changeCount(scope.row, scope.$index)"
- :disabled="clientEnvironmentId == 4"
- >
- <el-option
- :label="item.conversionUnit"
- :value="item.id"
- @click.native="packingChange(item, scope.$index)"
- v-for="(item, index) in scope.row.packageDispositionList"
- :key="index"
- ></el-option>
- </el-select>
- </el-form-item>
- </template> -->
- <template v-slot:modelKey="scope">
- <el-form-item :prop="'datasource.' + scope.$index + '.' + 'modelKey'">
- <DictSelection
- dictName="物品机型"
- clearable
- v-model="scope.row.modelKey"
- :isOne="scope.$index === 0"
- filterable
- allow-create
- default-first-option
- >
- </DictSelection>
- </el-form-item>
- </template>
- <template v-slot:colorKey="scope">
- <el-form-item :prop="'datasource.' + scope.$index + '.' + 'colorKey'">
- <DictSelection
- dictName="物品颜色"
- clearable
- v-model="scope.row.colorKey"
- :isOne="scope.$index === 0"
- filterable
- allow-create
- default-first-option
- >
- </DictSelection>
- </el-form-item>
- </template>
- <!-- 操作列 -->
- <template v-slot:action="scope">
- <el-popconfirm
- class="ele-action"
- title="确定要删除吗?"
- @confirm="remove(scope.$index)"
- >
- <template v-slot:reference>
- <el-link type="danger" :underline="false" icon="el-icon-delete">
- 删除
- </el-link>
- </template>
- </el-popconfirm>
- <el-link
- type="primary"
- :underline="false"
- icon="el-icon-edit"
- @click="selectStockLedgerDialogOpen(scope.row)"
- >
- 替代料
- </el-link>
- </template>
- </ele-pro-table>
- <!-- 遮罩放在表格之后,保证盖在内容上方;v-if 直接绑定 tableLoading,全部批次渲染完成后才卸载 -->
- <div v-if="tableLoading" class="table-loading-mask">
- <i class="el-icon-loading"></i>
- <span class="table-loading-text">
- {{
- batchLoading
- ? `正在加载 ${loadedCount}/${batchTotal}`
- : '正在加载,请稍候'
- }}
- </span>
- </div>
- </div>
- <productListNew
- ref="productListRef"
- @changeParent="changeParent"
- ></productListNew>
- <!--入库详情-->
- <innertboundDetailsDialog
- v-if="innerboundDetailsDialogFlag"
- ref="innerboundDetailsDialogRef"
- :innerboundDetailsDialogFlag.sync="innerboundDetailsDialogFlag"
- @saveDate="saveInnerDate"
- ></innertboundDetailsDialog>
- <!-- 库存台账 -->
- <stock-ledger-dialog
- v-if="stockLedgerDialogFlag"
- :stock-ledger-dialog-flag.sync="stockLedgerDialogFlag"
- ref="stockLedgerDialogRef"
- @getStockLedger="getStockLedger"
- ></stock-ledger-dialog>
- <selectStockLedgerDialog
- ref="selectStockLedgerDialogRef"
- @changeParent="replaceTable"
- ></selectStockLedgerDialog>
- <BIZproductList
- ref="BIZproductListRef"
- classType="1"
- :isGetInventoryTotal="true"
- @changeParent="changeParentBiz"
- :typeIds="typeIds"
- :isFirstRefreshTable="true"
- ></BIZproductList>
- </el-form>
- </template>
- <script>
- import { numberReg } from 'ele-admin';
- import dictMixins from '@/mixins/dictMixins';
- import productListNew from './product-listNew.vue';
- import {
- getWarehouseOutStockInfo,
- getIdWarehouseList
- } from '@/api/saleManage/saleorder';
- import { copyObj } from '@/utils/util';
- import innertboundDetailsDialog from '@/BIZComponents/innerboundDetailsDialog.vue';
- import stockLedgerDialog from './stockLedger/stockLedgerDialog.vue';
- import getDynamicsColumns from '@/mixins/getDynamicsColumns';
- import selectStockLedgerDialog from '@/BIZComponents/selectStockLedger/selectStockLedgerDialog.vue'; //库存台账
- import BIZproductList from '@/BIZComponents/product-list.vue';
- import setAllCountPrice from '@/BIZComponents/setAllCountPrice.vue'; //批量设置发货数量
- import { IS_DEV } from '@/config/setting'; //是否开发环境
- import tabMixins from '@/mixins/tableColumnsMixin';
- import { levelList, pricingWayList, lbjtList } from '@/enum/dict.js';
- import { changeCount, formatPrice } from '@/BIZComponents/setProduct.js';
- import { parameterGetByCode } from '@/api/main/index.js';
- import { getSummaries } from '@/utils/util.js';
- import { getBatchList, getWarehouseOutStockBatchAPI } from '@/api/wms';
- /**
- * ==========================================================================
- * 辅助数据请求调度器
- * 一次选中上百个物品时,仓库列表 / 批次列表会按行发起上百个请求,
- * 打满浏览器连接池,页面长时间无响应。这里统一做三件事:
- * 1. 同键合并:相同查询条件的并发请求复用同一个 Promise,只打一次
- * 2. 短时缓存:仓库 / 批次列表在 TTL 内直接复用上一次结果
- * 3. 并发限流:全局最多 LOOKUP_MAX_CONCURRENCY 个请求同时在飞
- * ==========================================================================
- */
- const LOOKUP_CACHE_TTL = 30 * 1000; // 仓库 / 批次列表缓存时长
- const LOOKUP_MAX_CONCURRENCY = 6; // 同时在飞的请求上限
- const lookupCache = new Map(); // key -> { expire, data }
- const lookupPending = new Map(); // key -> Promise(同键合并)
- const lookupQueue = []; // 等待队列
- let lookupActive = 0; // 当前在飞的请求数
- function pumpLookupQueue() {
- while (lookupActive < LOOKUP_MAX_CONCURRENCY && lookupQueue.length) {
- const task = lookupQueue.shift();
- lookupActive++;
- Promise.resolve()
- .then(task.factory)
- .then(
- (data) => {
- lookupActive--;
- task.resolve(data);
- pumpLookupQueue();
- },
- (error) => {
- lookupActive--;
- task.reject(error);
- pumpLookupQueue();
- }
- );
- }
- }
- /**
- * 走调度器的请求:命中缓存直接返回;相同 key 的并发请求合并成一次
- * @param {string} key 查询键
- * @param {Function} factory 真正发起请求的工厂函数
- * @param {number} ttl 缓存时长,0 表示不缓存(只做同键合并 + 限流)
- */
- function scheduleLookup(key, factory, ttl = LOOKUP_CACHE_TTL) {
- if (ttl) {
- const cached = lookupCache.get(key);
- if (cached) {
- if (cached.expire > Date.now()) {
- return Promise.resolve(cached.data);
- }
- lookupCache.delete(key);
- }
- }
- const pending = lookupPending.get(key);
- if (pending) {
- return pending;
- }
- const promise = new Promise((resolve, reject) => {
- lookupQueue.push({ factory, resolve, reject });
- pumpLookupQueue();
- });
- lookupPending.set(key, promise);
- promise.then(
- (data) => {
- lookupPending.delete(key);
- if (ttl) {
- lookupCache.set(key, { expire: Date.now() + ttl, data });
- }
- },
- () => {
- lookupPending.delete(key);
- }
- );
- return promise;
- }
- export default {
- mixins: [dictMixins, getDynamicsColumns, tabMixins],
- props: {
- orderId: String,
- orderIds: String,
- orderNos: String,
- needProduce: [String, Number],
- entrustedCode: String,
- pricingWay: [String, Number],
- isShowAdd: {
- type: Boolean,
- default: true
- },
- typeIds: {
- type: Array,
- default: () => []
- },
- oldProductList: {
- type: Array,
- default: () => []
- },
- sourceType: {
- type: [String, Number],
- default: ''
- },
- isTotalCount: {
- default: 0
- },
- isReturnGoodsCreate: {
- type: Boolean,
- default: false
- },
- // 替代料关联的原产品 id 集合,用于标记“已替代”的原产品
- replaceRelationIds: {
- type: Array,
- default: () => []
- }
- },
- components: {
- // fileMain,
- innertboundDetailsDialog,
- productListNew,
- stockLedgerDialog,
- selectStockLedgerDialog,
- BIZproductList,
- setAllCountPrice
- },
- data() {
- const defaultForm = {
- key: null,
- endTime: '',
- isFirst: 0,
- name: '',
- startTime: '',
- workHour: '',
- technicalDrawings: []
- // warehouseCode:"",
- // warehouseId:'',
- // warehouseName:'',
- };
- return {
- cacheKeyUrl: 'eos-saleManage-invoice-inventoryTable-2026102201',
- current: {},
- childrenColumns: [
- {
- width: 45,
- type: 'selection',
- columnKey: 'selection',
- align: 'center'
- },
- {
- width: 45,
- type: 'index',
- columnKey: 'index',
- align: 'center',
- fixed: 'left'
- },
- {
- minWidth: 100,
- prop: 'code',
- label: '编码',
- align: 'center'
- },
- {
- minWidth: 140,
- prop: 'barcodes',
- label: '发货条码',
- align: 'center'
- },
- {
- minWidth: 100,
- prop: 'engrave',
- label: '刻码',
- align: 'center'
- }
- ],
- selection: [],
- discountTotalPrice: 0.0,
- allPrice: 0.0,
- curIndex: null,
- innerboundDetailsDialogFlag: false,
- stockLedgerDialogFlag: false,
- numberReg,
- defaultForm,
- warehouseList: [],
- dynamicsColumns: [],
- isWarehouseId: 0,
- blockCountColumn: {},
- form: {
- datasource: []
- },
- batchLookupPending: 0,
- // 仓库 / 批次列表的懒加载状态:key = 行唯一标识 + 类型。
- // 独立于行对象存放,行对象会整体提交给后端,不能塞内部标记。
- lookupState: {},
- // 回填令牌:新的回填开始时丢弃上一次未完成的回填,避免乱序追加
- loadToken: 0,
- // 一次追加的行数较多时按批渲染,避免一次性入表长时间阻塞主线程
- appendBatchSize: 20,
- // 自绘 loading 遮罩状态:ele-pro-table 内置 loading 会在每次 reload 时被重置
- tableLoading: false,
- batchLoading: false,
- loadedCount: 0,
- batchTotal: 0,
- rules: {},
- columnsVersion: 1
- };
- },
- created() {
- // 行唯一标识(弱引用,不参与响应式,也不会写入行对象)
- this._rowUidMap = new WeakMap();
- this._rowUidSeq = 0;
- this.requestDict('产地');
- this.requestDict('生产类型');
- parameterGetByCode({
- code: 'eom_saleManage_invoice_warehouseId'
- }).then((res) => {
- if (res.value) {
- this.isWarehouseId = res.value;
- }
- });
- },
- computed: {
- canHandl() {
- return this.form.datasource.length;
- },
- // 批量回填期间禁止会改动数据源的操作
- tableBusy() {
- return this.tableLoading || this.batchLoading;
- },
- // 已被替代的原产品 id 集合(转成字符串便于与行上的 id/tempId 比较)
- replaceRelationKeySet() {
- return new Set(
- this.replaceRelationIds
- .filter((v) => v !== undefined && v !== null && v !== '')
- .map((v) => String(v))
- );
- },
- clientEnvironmentId() {
- return this.$store.state.user.info.clientEnvironmentId;
- },
- orderNoList() {
- const temp = this.orderNos?.split(',') || [];
- return temp.map((item) => {
- return {
- label: item,
- value: item
- };
- });
- },
- columns() {
- let columnsVersion = this.columnsVersion;
- return this.applyColumnWidth([
- {
- width: 45,
- type: 'selection',
- columnKey: 'selection',
- align: 'center',
- fixed: 'left'
- },
- {
- width: 60,
- type: 'index',
- columnKey: 'index',
- align: 'center',
- fixed: 'left'
- },
- {
- minWidth: 200,
- prop: 'orderNo',
- label: '订单编码',
- align: 'center',
- slot: 'orderNo',
- fixed: 'left'
- },
- {
- width: 200,
- prop: 'productName',
- label: '名称',
- slot: 'productName',
- align: 'center'
- },
- {
- width: 150,
- prop: 'productCode',
- label: '编码',
- slot: 'productCode',
- align: 'center'
- },
- {
- width: 200,
- prop: 'productCategoryName',
- label: '类型',
- slot: 'productCategoryName',
- align: 'center'
- },
- {
- width: 140,
- prop: 'pricingWay',
- label: '计价方式',
- align: 'center',
- fixed: 'left',
- formatter: (row, column) => {
- return pricingWayList.find((item) => item.id == row.pricingWay)
- ?.name;
- }
- },
- {
- width: 160,
- prop: 'batchStockId',
- label: '批次号',
- slot: 'batchStockId',
- align: 'center'
- },
- {
- minWidth: 180,
- prop: 'systemBatchNo',
- label: '系统内部批次号',
- align: 'center',
- formatter: (row) => row.systemBatchNo || '-'
- },
- {
- width: 160,
- prop: 'productBrand',
- label: '牌号',
- slot: 'productBrand',
- align: 'center'
- },
- {
- width: 120,
- prop: 'modelType',
- label: '型号',
- slot: 'modelType',
- align: 'center'
- },
- {
- width: 120,
- prop: 'specification',
- label: '规格',
- slot: 'specification',
- align: 'center'
- },
- {
- width: 160,
- prop: 'modelKey',
- label: '机型',
- slot: 'modelKey',
- align: 'center'
- },
- {
- width: 160,
- prop: 'colorKey',
- label: '颜色',
- slot: 'colorKey',
- align: 'center'
- },
- {
- minWidth: 160,
- prop: 'productionCodes',
- label: '生产编号',
- align: 'center',
- slot: 'productionCodes'
- },
- {
- minWidth: 280,
- prop: 'productionRequirements',
- label: '生产要求',
- align: 'center'
- },
- {
- minWidth: 120,
- prop: 'goodsLevel',
- label: '物品级别',
- formatter: (_row, _column, cellValue) => {
- return levelList.find((item) => item.value == _row.goodsLevel)
- ?.label;
- },
- align: 'center'
- },
- {
- width: 120,
- prop: 'customerMark',
- label: '客户代号',
- slot: 'customerMark',
- align: 'center'
- },
- {
- width: 200,
- prop: 'warehouseId',
- label: '仓库名称',
- slot: 'warehouseId',
- headerSlot: 'headerWarehouseId',
- align: 'center'
- },
- {
- width: 100,
- prop: 'stockCountBase',
- label: '库存数量',
- align: 'center'
- },
- {
- width: 100,
- prop: 'availableCountBase',
- label: '可用数量',
- slot: 'availableCountBase',
- align: 'center'
- },
- // {
- // width: 100,
- // prop: 'stockLedger',
- // label: '发货明细',
- // slot: 'stockLedger',
- // align: 'center'
- // },
- {
- width: 250,
- prop: 'saleCount',
- label: '发货数量',
- slot: 'saleCount',
- headerSlot: 'headerTotalCount',
- align: 'center'
- },
- {
- width: 150,
- prop: 'pendingShipmentQuantity',
- label: '待发数量',
- align: 'center'
- },
- {
- width: 100,
- prop: 'notSendTotalCount',
- label: '未出库数量',
- align: 'center',
- formatter: (row, column) => {
- // if (row.notSendTotalCount) {
- return row.notSendTotalCount;
- // }
- }
- },
- {
- width: 100,
- prop: 'notGenerateSendCount',
- label: '未发数量',
- align: 'center',
- formatter: (row, column) => {
- // if (row.notGenerateSendCount) {
- return row.notGenerateSendCount;
- // }
- }
- },
- {
- width: 120,
- prop: 'totalCount',
- label: '计量数量',
- formatter: (row, column) => {
- // if (row.totalCount) {
- return row.totalCount + ' ' + row.measuringUnit;
- // }
- },
- align: 'center'
- },
- {
- width: 120,
- prop: 'orderTotalCount',
- label: '订单数量',
- formatter: (row, column) => {
- if (row.orderTotalCount) {
- return row.orderTotalCount + ' ' + row.measuringUnit;
- }
- },
- align: 'center'
- },
- {
- width: 120,
- prop: 'packingSpecification',
- align: 'center',
- label: '包装规格',
- showOverflowTooltip: true
- },
- // {
- // width: 80,
- // prop: 'measuringUnit',
- // label: '计量单位',
- // slot: 'measuringUnit',
- // align: 'center'
- // },
- this.clientEnvironmentId == 4
- ? {
- width: 150,
- prop: 'blockCount',
- label: '发货块数',
- slot: 'blockCount',
- align: 'center'
- }
- : { width: 1 },
- {
- width: 200,
- prop: 'singleWeight',
- slot: 'singleWeight',
- label: '单重',
- align: 'center'
- },
- {
- width: 250,
- prop: 'receiveTotalWeight',
- label: '收货总重',
- slot: 'receiveTotalWeight',
- align: 'center',
- headerSlot: 'headerReceiveTotalWeight'
- },
- {
- width: 220,
- prop: 'sendTotalWeight',
- label: '发货总重',
- slot: 'sendTotalWeight',
- align: 'center'
- },
- {
- width: 220,
- prop: 'increaseTotalWeight',
- label: '增重重量',
- slot: 'increaseTotalWeight',
- align: 'center'
- },
- {
- width: 180,
- prop: 'singlePrice',
- label: '单价',
- slot: 'singlePrice',
- align: 'center'
- },
- {
- width: 160,
- prop: 'taxRate',
- label: '税率',
- formatter: (_row, _column, cellValue) => {
- return _row.taxRate ? _row.taxRate + '%' : '';
- },
- align: 'center'
- },
- {
- width: 180,
- prop: 'notaxSinglePrice',
- label: '不含税单价',
- align: 'center'
- },
- {
- width: 160,
- prop: 'discountSinglePrice',
- label: '折后单价',
- slot: 'discountSinglePrice',
- align: 'center'
- },
- {
- width: 120,
- prop: 'totalPrice',
- label: '合计',
- slot: 'totalPrice',
- align: 'center'
- },
- {
- width: 160,
- prop: 'notaxTotalPrice',
- label: '含税合计',
- align: 'center'
- },
- {
- width: 120,
- prop: 'discountTotalPrice',
- label: '折后合计',
- slot: 'discountTotalPrice',
- align: 'center'
- },
- {
- minWidth: 280,
- prop: 'cuttingLength',
- label: '裁线米段',
- align: 'center',
- slot: 'cuttingLength'
- },
- {
- width: 120,
- prop: 'imgCode',
- align: 'center',
- label: '图号/件号',
- showOverflowTooltip: true
- },
- {
- width: 120,
- prop: 'produceType',
- align: 'center',
- label: '属性类型',
- formatter: (row, column) => {
- if (row.produceType) {
- return row.produceType
- .map((item) => {
- return lbjtList[item];
- })
- .toString();
- }
- },
- showOverflowTooltip: true
- },
- {
- width: 200,
- prop: 'guaranteePeriod',
- label: '有效期',
- slot: 'guaranteePeriod',
- formatter: (_row, _column, cellValue) => {
- let val = '';
- if (_row.guaranteePeriod) {
- val += _row.guaranteePeriod;
- }
- if (_row.guaranteePeriodUnitName) {
- val += _row.guaranteePeriodUnitName;
- }
- return val;
- },
- align: 'center'
- },
- {
- width: 200,
- prop: 'guaranteePeriodDeadline',
- label: '有效期截止日期',
- slot: 'guaranteePeriodDeadline',
- align: 'center'
- },
- {
- prop: 'provenance',
- label: '产地',
- slot: 'provenance',
- align: 'center',
- // show:this.contractBookType==2,
- minWidth: 200,
- showOverflowTooltip: true,
- formatter: (row, column) => {
- return row.provenance && row.provenance.length
- ? row.provenance
- .map((item) => this.getDictValue('产地', item))
- .join(',')
- : '';
- }
- },
- {
- width: 130,
- prop: 'technicalAnswerName',
- label: '技术答疑人',
- slot: 'technicalAnswerName',
- align: 'center'
- },
- {
- width: 220,
- prop: 'technicalParams',
- label: '技术参数',
- slot: 'technicalParams',
- align: 'center'
- },
- {
- width: 240,
- prop: 'technicalDrawings',
- label: '技术图纸',
- slot: 'technicalDrawings',
- align: 'center'
- },
- {
- width: 220,
- prop: 'remark',
- label: '备注',
- slot: 'remark',
- align: 'center'
- },
- // 动态扩展字段默认排在最后(操作列固定在右侧,需留在最后)
- ...this.dynamicsColumns,
- {
- columnKey: 'action',
- label: '操作',
- width: 200,
- align: 'center',
- resizable: false,
- slot: 'action',
- fixed: 'right',
- showOverflowTooltip: true
- }
- ]);
- }
- },
- mounted() {
- // this.clientEnvironmentId =
- },
- methods: {
- formatPrice,
- isSaleOrderLockReadonly(row) {
- if (row.hasSendRejectedOrWithdrawn == 1) {
- return false;
- }
- const orderType = row.needProduce ?? this.needProduce;
- return orderType == 0 || (orderType == 1 && row.isLockSaleOrder == 1);
- },
- dedupeBatchNoList(list) {
- const seen = new Set();
- return (list || []).filter((item) => {
- if (seen.has(item.id)) {
- return false;
- }
- seen.add(item.id);
- return true;
- });
- },
- getSummaries(param) {
- return getSummaries(
- param,
- ['saleCount', 'blockCount', 'totalCount'],
- ' '
- );
- },
- //发货明细选择
- stockLedgerSelect(row, index) {
- this.curIndex = index;
- this.stockLedgerDialogFlag = true;
- this.$nextTick(() => {
- this.$refs.stockLedgerDialogRef.init(row.sendProductDetail, row);
- });
- },
- packingChange(item, index) {
- this.$set(this.form.datasource[index], 'saleUnit', item.conversionUnit);
- },
- //获取
- getStockLedger(sendProductDetail) {
- if (!this.form.datasource[this.curIndex].sendProductDetail)
- this.form.datasource[this.curIndex].sendProductDetail = [];
- let row = this.form.datasource[this.curIndex];
- row.sendProductDetail.push(...sendProductDetail);
- this.form.datasource[this.curIndex] = row;
- this.$refs['childrenTable' + this.curIndex].reload();
- this.$refs.table.reload();
- },
- //删除发货明细
- stockLedgerRemove(PIndex) {
- let row = this.form.datasource[PIndex];
- this.selection.forEach((item) => {
- let index = row.sendProductDetail.findIndex((i) => i.id == item.id);
- row.sendProductDetail.splice(index, 1);
- });
- this.form.datasource[PIndex] = row;
- this.$refs['childrenTable' + PIndex].reload();
- this.$refs.table.reload();
- this.selection = [];
- },
- // 将接口返回的库存数量和可用数量同步到当前物品清单行。
- setWarehouseOutStock(index, stockInfo) {
- const stockCountBase = stockInfo?.stockCountBase || 0;
- const availableCountBase = stockInfo?.availableCountBase || 0;
- this.$set(
- this.form.datasource[index],
- 'stockCountBase',
- stockCountBase
- );
- this.$set(
- this.form.datasource[index],
- 'availableCountBase',
- availableCountBase
- );
- // 保留原字段,兼容已有发货数量校验和提交逻辑。
- this.$set(
- this.form.datasource[index],
- 'warehouseNum',
- availableCountBase
- );
- },
- async refreshWarehouseOutStock(index, row) {
- if (!row.warehouseId) {
- this.setWarehouseOutStock(index, {});
- return;
- }
- const query = {
- warehouseId: row.warehouseId,
- code: row.productCode,
- batchNo: row.batchNo,
- systemBatchNo: row.systemBatchNo,
- colorKey: row.colorKey,
- modelType: row.modelType
- };
- const stockInfo = await scheduleLookup(
- `stock:${this.stockLookupKey(row)}`,
- () => getWarehouseOutStockInfo(query),
- 0
- );
- if (this.form.datasource[index] === row &&
- row.warehouseId == query.warehouseId &&
- row.batchNo == query.batchNo &&
- row.systemBatchNo == query.systemBatchNo &&
- row.colorKey == query.colorKey &&
- row.modelType == query.modelType) {
- this.setWarehouseOutStock(index, stockInfo);
- }
- },
- async warehouseChange(index, row, isReset = false) {
- console.log('warehouseChange', index, row.warehouseId, isReset);
- const warehouseId = row.warehouseId;
- const colorKey = row.colorKey;
- const modelType = row.modelType;
- // 仓库列表改成懒加载后,列表可能还没加载出来,这里做兜底查找
- const data = (row.warehouseList || []).find(
- (item) => item.warehouseId == row.warehouseId
- );
- console.log('warehouseChange', data);
- this.$set(
- this.form.datasource[index],
- 'warehouseName',
- data?.warehouseName || row.warehouseName || ''
- );
- this.$set(
- this.form.datasource[index],
- 'warehouseCode',
- data?.warehouseCode || row.warehouseCode || 0
- );
- if (isReset) {
- this.$set(row, 'batchStockId', '');
- this.$set(row, 'batchNo', '');
- this.$set(row, 'systemBatchNo', '');
- }
- const batchStockId = row.batchStockId;
- // 换仓后原仓库的批次失效,先清空再拉新仓库的批次
- const batchKey = this.lookupStateKey(row, 'batch');
- this.$set(row, 'batchNoList', []);
- this.$set(this.lookupState, batchKey, 'loading');
- let tempBatchNoList = [];
- let batchFailed = false;
- try {
- tempBatchNoList = await this.fetchBatchList({
- warehouseId: data?.warehouseId || '',
- categoryCode: row.productCode,
- colorKey: row.colorKey,
- modelType: row.modelType
- });
- } catch (e) {
- batchFailed = true;
- }
- this.$set(
- this.lookupState,
- batchKey,
- batchFailed ? 'error' : 'loaded'
- );
- if (this.form.datasource[index] !== row || row.warehouseId != warehouseId ||
- row.colorKey != colorKey || row.modelType != modelType ||
- row.batchStockId != batchStockId) return;
- this.$set(
- this.form.datasource[index],
- 'batchNoList',
- (tempBatchNoList || []).slice()
- );
- await this.refreshWarehouseOutStock(index, this.form.datasource[index]);
- },
- //批次号选择
- async batchNoChange(index, row) {
- if (!row.batchStockId) {
- this.$set(this.form.datasource[index], 'batchStockId', '');
- this.$set(this.form.datasource[index], 'batchNo', '');
- this.$set(this.form.datasource[index], 'systemBatchNo', '');
- // 仓库列表改成懒加载后,这里不再预取仓库列表
- // this.$set(this.form.datasource[index], 'warehouseNum', '');
- await this.refreshWarehouseOutStock(
- index,
- this.form.datasource[index]
- );
- return;
- }
- const data = (row.batchNoList || []).find(
- (item) => item.id == row.batchStockId
- );
- if (!data) {
- // 批次列表还没加载出来时(占位项),保留已有批次号,不做覆盖
- await this.refreshWarehouseOutStock(
- index,
- this.form.datasource[index]
- );
- return;
- }
- this.$set(this.form.datasource[index], 'batchNo', data.batchNo);
- this.$set(
- this.form.datasource[index],
- 'systemBatchNo',
- data.systemBatchNo
- );
- await this.refreshWarehouseOutStock(index, this.form.datasource[index]);
- },
- //改变数量
- changeCount(row, index, isBlockCount = true, weightType) {
- if (weightType == 'totalWeight') {
- this.$set(
- this.form.datasource[index],
- 'totalWeight',
- this.form.datasource[index].sendTotalWeight
- );
- }
- this.$set(
- this.form.datasource,
- index,
- changeCount(
- row,
- {
- countKey: 'saleCount',
- unitKey: 'saleUnit',
- unitIdKey: 'saleUnitId'
- },
- false,
- weightType
- )
- );
- this.$set(
- this.form.datasource[index],
- 'sendTotalWeight',
- this.form.datasource[index].totalWeight
- );
- this.changeSendTotalWeight(row, index);
- // 只重算当前行的不含税单价,避免每次输入都遍历整张表
- this.getNotaxSinglePrice(index);
- if (this.clientEnvironmentId == 4 && !isBlockCount) {
- this.tableHandleKeyUp(row, index, 'sum');
- }
- },
- //修改发货总重
- changeSendTotalWeight(row, index) {
- this.curIndex = index;
- this.setIcreaseTotalWeight(row);
- },
- keyChange(index, row, key) {
- // 字典值已由 v-model 写回 extField,这里把该字段补成响应式属性:
- // 初始没有该键时 v-model 写入的是普通属性,视图不会随下一次选择更新
- if (row.extField) {
- const value = row.extField[key];
- if (Object.prototype.hasOwnProperty.call(row.extField, key)) {
- delete row.extField[key];
- }
- this.$set(row.extField, key, value);
- }
- },
- //设置增重总重
- setIcreaseTotalWeight(row) {
- let receiveTotalWeight = Number(
- this.form.datasource[this.curIndex]?.receiveTotalWeight
- );
- let sendTotalWeight = Number(
- this.form.datasource[this.curIndex]?.sendTotalWeight
- );
- if (sendTotalWeight) {
- let increaseTotalWeight = sendTotalWeight - receiveTotalWeight;
- this.$set(
- this.form.datasource[this.curIndex],
- 'increaseTotalWeight',
- increaseTotalWeight.toFixed(4)
- );
- if (row.pricingWay == 3) {
- this.$set(
- this.form.datasource[this.curIndex],
- 'totalPrice',
- (increaseTotalWeight * row.singlePrice).toFixed(2)
- );
- }
- }
- this.$refs.table.reload();
- this.$forceUpdate();
- },
- //计算不含税单价:只重算指定行,不传时退化为全量重算
- getNotaxSinglePrice(index) {
- const calc = (item, i) => {
- if (item.singlePrice && item.taxRate) {
- this.$set(
- this.form.datasource[i],
- 'notaxSinglePrice',
- formatPrice(item.singlePrice / (1 + item.taxRate / 100))
- );
- } else {
- this.$set(this.form.datasource[i], 'notaxSinglePrice', '');
- }
- };
- if (index === undefined || index === null) {
- this.form.datasource.forEach((item, i) => calc(item, i));
- return;
- }
- const item = this.form.datasource[index];
- if (item) {
- calc(item, index);
- }
- },
- //入库单详情
- handleInnerBound(e, rows, index) {
- this.curIndex = index;
- this.innerboundDetailsDialogFlag = true;
- this.$nextTick(() => {
- let row = {
- code: this.entrustedCode
- };
- this.$refs.innerboundDetailsDialogRef.init(row);
- });
- },
- //选择入库单信息
- saveInnerDate(data = []) {
- let totalWeight = data.reduce((num, row) => {
- num += Number(row.weight);
- return num;
- }, 0);
- this.$set(
- this.form.datasource[this.curIndex],
- 'receiveTotalWeight',
- totalWeight
- );
- console.log(totalWeight, 'totalWeight');
- this.setIcreaseTotalWeight(this.form.datasource[this.curIndex]);
- },
- // getWeightPrice() {
- // let increaseTotalWeight =
- // this.form.datasource[this.curIndex].increaseTotalWeight;
- // let singlePrice = this.form.datasource[this.curIndex].singlePrice;
- // let discountSinglePrice =
- // this.form.datasource[this.curIndex].discountSinglePrice;
- // this.$set(
- // this.form.datasource[this.curIndex],
- // 'totalPrice',
- // (Number(increaseTotalWeight) * Number(singlePrice)).toFixed(2)
- // );
- // this.$set(
- // this.form.datasource[this.curIndex],
- // 'discountTotalPrice',
- // (Number(discountSinglePrice) * Number(increaseTotalWeight)).toFixed(2)
- // );
- // },
- // 表格:模数、数量(方)、块数输入框 输入事件
- tableHandleKeyUp(row, index, name) {
- if (row.specification) {
- let modelArr = row.specification.split('*');
- let modelLong = modelArr[0]; // model规格长度
- let modeWide = modelArr[1]; // model规格宽度
- let modeHight = modelArr[2].substr(0, modelArr[2].indexOf('cm')); // model规格高度
- modeHight = Number(modeHight);
- if (name === 'sum') {
- // row.blockCount = Math.floor(
- // row.totalCount / ((modelLong * modeWide * modeHight) / 1000000)
- // );
- this.$set(
- this.form.datasource[index],
- 'blockCount',
- Math.floor(
- row.totalCount / ((modelLong * modeWide * modeHight) / 1000000)
- )
- );
- } else if (name === 'blockCount') {
- row.totalCount =
- (Number(row.blockCount) * modelLong * modeWide * modeHight) /
- 1000000;
- row.saleCount = row.totalCount;
- this.changeCount(row, index, true);
- }
- }
- },
- //选择产品回调(订单来源物品)
- async changeParent(obj) {
- if (!obj || !obj.length) return;
- // 先在普通对象上组装行,不直接改动选品弹窗里的原始数据
- const rows = obj.map((item) => {
- const row = copyObj(item);
- row.orderTotalCount = row.totalCount;
- // 清空选入行ID前保留订单来源,避免换成同一批次后误合并额度。
- row.orderProductId = row.orderProductId || row.id;
- row.id = '';
- return row;
- });
- await this.appendOrderRows(rows);
- },
- //选择产品回调(不定向订单:从产品库选物品)
- async changeParentBiz(obj = [], idx) {
- if (!obj || !obj.length) return;
- const startIndex = this.form.datasource.length;
- const supplierMark = this.form.datasource[0]?.supplierMark;
- const rows = obj.map((item, index) =>
- this.buildBizProductRow(item, startIndex + index + 1, supplierMark)
- );
- if (idx === undefined || idx === null || idx === -1) {
- await this.appendBizRows(rows);
- return;
- }
- // 编辑已有行:整行替换(保留原行的 key / tempId,替代料关联不能断)
- await this.fillBizLookups(rows);
- const oldRow = this.form.datasource[idx];
- if (oldRow) {
- rows[0].key = oldRow.key;
- rows[0].tempId = oldRow.tempId;
- }
- this.$set(this.form.datasource, idx, rows[0]);
- },
- replaceTable(list) {
- console.log('list~~~~', list);
- list.forEach((item) => {
- item['relationId'] = this.current.id || this.current.tempId;
- });
- this.$emit('replaceTableChange', list);
- },
- // 该产品是否已被替代料替代(新增时按 tempId,回显时按产品 id)
- isRowReplaced(row) {
- const keys = this.replaceRelationKeySet;
- if (!keys.size) {
- return false;
- }
- if (row.id !== undefined && row.id !== null && row.id !== '') {
- return keys.has(String(row.id));
- }
- return (
- row.tempId !== undefined &&
- row.tempId !== null &&
- row.tempId !== '' &&
- keys.has(String(row.tempId))
- );
- },
- // validateTotalCount(row) {
- // return (rule, value, callback) => {
- // if (isNaN(value) || Number(value) <= 0) {
- // this.$message.error('请输入大于0的数');
- // callback(false);
- // } else else {
- // callback();
- // }
- // };
- // },
- // 返回列表数据
- getTableValue() {
- let comitDatasource = this.form.datasource;
- if (comitDatasource.length === 0) return [];
- comitDatasource.forEach((v) => {
- // 清空批次时同步清理批次库存 ID,避免更新接口残留旧批次。
- if (!v.batchNo) {
- v.batchNo = '';
- v.systemBatchNo = '';
- v.batchStockId = '';
- }
- v.totalCount = Number(v.totalCount);
- v.technicalDrawings = Array.isArray(v.technicalDrawings)
- ? v.technicalDrawings
- : [];
- v.customerReqFiles = Array.isArray(v.customerReqFiles)
- ? v.customerReqFiles
- : [];
- v.industryArtFiles = v.industryArtFiles || [];
- v.otherFiles = v.otherFiles || [];
- });
- return comitDatasource;
- },
- getPrice() {
- return [this.allPrice];
- },
- //修改回显
- // mode='edit' 表示回显的是"已经保存过的发货单":只原样显示用户保存的数据,
- // 不替用户选仓库 / 配批次(否则会在回显时凭空写入用户没选过的值)。
- putTableValue(data, isInit, mode) {
- if (isInit) {
- this.form.datasource = [];
- }
- if (data && data.length) {
- this.setValue(data, mode);
- }
- },
- // 回显:先组装好所有行,再批量取数、分批入表
- setValue(data, mode) {
- const rows = data.map((item) => this.buildOrderRow(item));
- if (mode === 'edit') {
- return this.appendEditRows(rows);
- }
- return this.appendOrderRows(rows);
- },
- // ==================== 大批量回显(性能相关) ====================
- /**
- * 订单来源物品组装成一行(普通对象,暂不进响应式数组,赋值零成本)
- */
- buildOrderRow(item) {
- const row = copyObj(item);
- row.receiveTotalWeight = row.receiveTotalWeight || 0;
- if (row.weightUnit == row.measuringUnit) {
- row.sendTotalWeight = row.sendTotalWeight || row.totalCount;
- } else {
- row.sendTotalWeight =
- row.sendTotalWeight || Number(row.totalWeight) || 0;
- }
- if (this.outsourceSendCode) {
- row.increaseTotalWeight =
- Number(row.receiveTotalWeight) - Number(row.sendTotalWeight);
- } else {
- row.increaseTotalWeight =
- row.increaseTotalWeight || row.receiveTotalWeight || 0;
- }
- return row;
- },
- /**
- * 不定向订单:从产品库选中的物品组装成一行(普通对象)
- */
- buildBizProductRow(item, key, supplierMark) {
- const row = JSON.parse(JSON.stringify(this.defaultForm));
- row.key = key;
- row.tempId = key;
- row.productId = item.id;
- row.categoryName = item.name;
- row.productCategoryId = item.categoryLevelId;
- row.productBrand = item.brandNum;
- row.productCategoryName = item.categoryLevelPath;
- row.productCode = item.code;
- row.productName = item.name;
- row.modelType = item.modelType;
- row.availableCountBase = item.availableCountBase;
- row.measuringUnit = item.measuringUnit;
- row.specification = item.specification;
- row.weightUnit = item.weightUnit;
- row.imgCode = item.imgCode;
- row.produceType = item.componentAttribute;
- row.approvalNumber = item.extField?.approvalNumber;
- row.extField = copyObj(item.extField || {});
- row.singleWeight = item.netWeight;
- row.pricingWay = item.pricingWay || 1;
- row.singlePrice = 0;
- row.discountSinglePrice = 0;
- row.goodsLevel = item.goodsLevel;
- row.orderNo = this.orderNoList[0]?.value || '';
- if (item.modelKey) {
- row.modelKey = item.modelKey;
- }
- if (item.colorKey) {
- row.colorKey = item.colorKey;
- }
- row.receiveTotalWeight = 0;
- row.sendTotalWeight = 0;
- row.increaseTotalWeight = 0;
- row.packageDispositionList = item.packageDispositionList;
- if (item.packageDispositionList?.length) {
- row.saleUnitId = item.packageDispositionList[0].id;
- row.saleUnit = item.packageDispositionList[0].conversionUnit;
- }
- row.packingSpecification = item.extField?.packingSpecification;
- row.supplierMark = supplierMark;
- // 提交给 EOM 的产地必须是编码数组,不能是库存台账里的展示字符串
- row.provenance =
- item.purchaseOrigins?.length > 0
- ? item.purchaseOrigins.map((val) => val + '')
- : [];
- return row;
- },
- /**
- * 批量回填入口:先把 loading 遮罩画出来,再取辅助数据,最后分批入表。
- * 取数期间用 batchLookupPending 挡住保存,避免提交到半成品数据。
- */
- async runBatchAppend(rows, prepareFn) {
- const token = ++this.loadToken;
- const startIndex = this.form.datasource.length;
- this.batchLookupPending++;
- this.startTableLoading();
- try {
- await this.nextFrame();
- const prepared = await prepareFn(rows, startIndex);
- if (token !== this.loadToken) return;
- await this.appendRowsInBatches(prepared, startIndex, token);
- } catch (error) {
- console.error('物品清单批量回显失败', error);
- this.$message.error('物品清单加载失败,请重试');
- } finally {
- this.batchLookupPending--;
- if (token === this.loadToken) {
- this.endTableLoading();
- }
- }
- },
- // 订单来源物品:批量补齐仓库/批次/可发库存后入表
- appendOrderRows(rows) {
- return this.runBatchAppend(rows, (list, startIndex) =>
- this.prepareOrderRows(list, startIndex)
- );
- },
- // 编辑回显:仓库 / 批次列表全部懒加载,库存用一次批量接口刷新
- appendEditRows(rows) {
- return this.runBatchAppend(rows, (list, startIndex) =>
- this.prepareEditRows(list, startIndex)
- );
- },
- // 不定向订单:仓库 / 批次列表改为懒加载,入表时不再预取
- appendBizRows(rows) {
- return this.runBatchAppend(rows, async (list) => {
- await this.fillBizLookups(list);
- return list;
- });
- },
- /**
- * 分批追加:一次选中上百个物品时一次性塞进表格会让主线程长时间阻塞,
- * 这里按 appendBatchSize 分批写入,每批之间让出一帧,
- * 浏览器可以正常绘制 loading 遮罩和已经渲染出来的行。
- */
- appendRowsInBatches(
- rows,
- startIndex = this.form.datasource.length,
- token
- ) {
- return new Promise((resolve) => {
- if (!rows.length) {
- resolve();
- return;
- }
- const batchSize = Math.max(1, this.appendBatchSize || 20);
- const total = rows.length;
- this.batchLoading = true;
- this.loadedCount = 0;
- this.batchTotal = total;
- let done = 0;
- const step = () => {
- // 已被新的回填取代时直接放弃,避免旧数据插到新数据前面
- if (token !== undefined && token !== this.loadToken) {
- this.batchLoading = false;
- resolve();
- return;
- }
- const batch = rows.slice(done, done + batchSize);
- if (batch.length) {
- this.form.datasource = this.form.datasource.concat(batch);
- done += batch.length;
- this.loadedCount = done;
- }
- if (done < total) {
- requestAnimationFrame(step);
- return;
- }
- this.batchLoading = false;
- resolve();
- };
- requestAnimationFrame(step);
- });
- },
- // 让出一帧,保证 loading 遮罩先绘制出来再执行会阻塞主线程的计算
- nextFrame() {
- return new Promise((resolve) => {
- this.$nextTick(() => {
- requestAnimationFrame(() => resolve());
- });
- });
- },
- startTableLoading() {
- this._loadingStart = Date.now();
- this.tableLoading = true;
- },
- // 保证遮罩最短展示时间,避免一闪而过
- endTableLoading(minDuration = 200) {
- const start = this._loadingStart || Date.now();
- const rest = minDuration - (Date.now() - start);
- if (rest > 0) {
- setTimeout(() => {
- this.tableLoading = false;
- }, rest);
- } else {
- this.tableLoading = false;
- }
- },
- /**
- * 订单来源物品的辅助数据回填:
- * 仓库 / 批次列表改成"按需懒加载"——只有业务判断真正依赖的行才立即查询,
- * 其余行等用户展开下拉时再查;库存数量统一走一次批量接口。
- * 这样一次回显上百个物品时,请求数从"上百个"降到"个位数 + 按需查询"。
- */
- async prepareOrderRows(rows, startIndex) {
- // 1. 仓库列表:只有"还没定仓库"的行需要立即查询(要自动选中第一个仓库);
- // 已有仓库的行改为懒加载,避免一百个物品打出一百个仓库列表请求
- const autoPickRows = rows.filter((row) => !row.warehouseId);
- const warehouseMap = await this.loadWarehouseListMap(autoPickRows);
- rows.forEach((row) => {
- if (row.warehouseId) {
- this.$set(row, 'warehouseList', []);
- return;
- }
- const list = (warehouseMap.get(String(row.productId)) || []).slice();
- this.$set(row, 'warehouseList', list);
- if (list.length) {
- const first = list[0];
- row.warehouseId = first.warehouseId;
- row.warehouseName = first.warehouseName || '';
- row.warehouseCode = first.warehouseCode || 0;
- }
- });
- // 2. 批次列表:只有"指定了批次号"的行需要立即查询(要按批次明细匹配),
- // 其余行改为懒加载
- const needBatchRows = rows.filter((row) => row.batchNo);
- const batchMap = await this.loadBatchListMap(needBatchRows);
- const stockRows = [];
- let lookupFailed = false;
- rows.forEach((row) => {
- if (!row.batchNo) {
- this.$set(row, 'batchNoList', []);
- if (row.warehouseId) {
- stockRows.push(row);
- }
- return;
- }
- const list = batchMap.get(this.batchLookupKey(row));
- if (list === null) {
- // 批次查询失败:按无匹配批次处理
- lookupFailed = true;
- row.batchStockId = 999;
- this.$set(row, 'batchNoList', [{ id: 999, batchNo: row.batchNo }]);
- row.warehouseNum = '';
- row.stockCountBase = '';
- row.availableCountBase = '';
- return;
- }
- // 优先按批次明细ID匹配,无ID时按系统批次和业务批次兼容匹配
- const matched = (list || []).filter(
- (item) =>
- item.categoryId == row.productId &&
- item.warehouseId == row.warehouseId &&
- (item.colorKey || '') == (row.colorKey || '') &&
- item.batchNo == row.batchNo &&
- (!row.systemBatchNo || item.systemBatchNo == row.systemBatchNo) &&
- (!row.batchStockId || item.id == row.batchStockId)
- );
- if (matched.length == 1) {
- row.batchStockId = matched[0].id;
- row.systemBatchNo = matched[0].systemBatchNo || '';
- this.$set(row, 'batchNoList', (list || []).slice());
- stockRows.push(row);
- } else {
- // 批次不存在:列表里补一条"无匹配可发库存"
- this.$set(
- row,
- 'batchNoList',
- this.dedupeBatchNoList(
- (list || []).concat([
- {
- batchNo: row.batchNo,
- systemBatchNo: row.systemBatchNo,
- id: 999,
- measureQuantity: 0
- }
- ])
- )
- );
- row.batchStockId = 999;
- row.warehouseNum = '';
- row.stockCountBase = '';
- row.availableCountBase = '';
- }
- });
- // 3. 库存数量(一次批量接口查完)
- const stockMap = await this.loadStockInfoMap(stockRows);
- stockRows.forEach((row) => {
- const stockInfo = stockMap.get(this.stockLookupKey(row));
- if (!stockInfo) return;
- row.stockCountBase = stockInfo.stockCountBase || 0;
- row.availableCountBase = stockInfo.availableCountBase || 0;
- row.warehouseNum = row.availableCountBase;
- });
- if (lookupFailed) {
- this.$message.error('批次库存查询失败,请重新打开后重试');
- }
- // 4. 统一分配 key / tempId(替代料关联用,必须在清单内唯一)
- rows.forEach((row, index) => {
- row.key = startIndex + index + 1;
- row.tempId = row.id || startIndex + index;
- });
- return rows;
- },
- /**
- * 编辑回显的行数据准备:
- * 编辑只是把用户已经保存的数据原样显示出来,不应该再替用户"选仓库"或"配批次",
- * 所以这里不做任何写入型预取——仓库 / 批次列表全部懒加载(展开下拉时才查),
- * 库存数量统一走一次批量接口刷新(只针对已选仓库的行)。
- * 否则一百行的发货单一打开就会打出上百个 getBatchWarehouseList 请求。
- */
- async prepareEditRows(rows, startIndex) {
- // 1. 仓库 / 批次列表:清空,等用户展开下拉时再按需查询
- rows.forEach((row) => {
- this.$set(row, 'warehouseList', []);
- this.$set(row, 'batchNoList', []);
- });
- // 2. 库存数量:一次批量接口查完(没有仓库的行查不到库存,保持空)
- const stockRows = rows.filter((row) => !!row.warehouseId);
- const stockMap = await this.loadStockInfoMap(stockRows);
- stockRows.forEach((row) => {
- const stockInfo = stockMap.get(this.stockLookupKey(row));
- if (!stockInfo) return;
- row.stockCountBase = stockInfo.stockCountBase || 0;
- row.availableCountBase = stockInfo.availableCountBase || 0;
- row.warehouseNum = row.availableCountBase;
- });
- // 3. 统一分配 key / tempId(替代料关联用,必须在清单内唯一)
- rows.forEach((row, index) => {
- row.key = startIndex + index + 1;
- row.tempId = row.id || startIndex + index;
- });
- return rows;
- },
- // 不定向订单:仓库 / 批次列表只用于下拉展示,没有任何业务判断依赖,
- // 改成懒加载(展开下拉时才查询),一次选上百个物品不再打出上百个请求
- async fillBizLookups(rows) {
- rows.forEach((row) => {
- this.$set(row, 'warehouseList', []);
- this.$set(row, 'batchNoList', []);
- });
- },
- // 查询键:同一批新增行里仓库/批次/库存的查询条件可能完全相同,按键去重后只查一次
- lookupKey(...parts) {
- return JSON.stringify(
- parts.map((item) => {
- if (item === undefined) return 'u';
- if (item === null) return 'n';
- return 's' + String(item);
- })
- );
- },
- // 批次查询键:仓库 + 物品编码 + 颜色 + 型号
- batchLookupKey(row) {
- return this.lookupKey(
- row.warehouseId,
- row.productCode,
- row.colorKey,
- row.modelType
- );
- },
- // 库存查询键:仓库 + 物品编码 + 批次 + 系统批次 + 颜色 + 型号
- stockLookupKey(row) {
- return this.lookupKey(
- row.warehouseId,
- row.productCode,
- row.batchNo,
- row.systemBatchNo,
- row.colorKey,
- row.modelType
- );
- },
- // 批量查询产品对应的仓库列表(按物品去重)
- async loadWarehouseListMap(rows) {
- const map = new Map();
- const ids = [
- ...new Set(
- rows
- .map((row) => row.productId)
- .filter((id) => id !== undefined && id !== null && id !== '')
- )
- ];
- await Promise.all(
- ids.map(async (productId) => {
- try {
- map.set(String(productId), await this.fetchWarehouseList(productId));
- } catch (e) {
- map.set(String(productId), []);
- }
- })
- );
- return map;
- },
- // 批量查询批次列表(按 仓库+物品+颜色+型号 去重)
- async loadBatchListMap(rows) {
- const map = new Map();
- const paramsMap = new Map();
- rows.forEach((row) => {
- const key = this.batchLookupKey(row);
- if (paramsMap.has(key)) return;
- paramsMap.set(key, {
- warehouseId: row.warehouseId,
- categoryCode: row.productCode,
- colorKey: row.colorKey,
- modelType: row.modelType
- });
- });
- await Promise.all(
- [...paramsMap.entries()].map(async ([key, params]) => {
- try {
- map.set(key, await this.fetchBatchList(params));
- } catch (e) {
- // null 表示查询失败,调用方按无匹配批次处理
- map.set(key, null);
- }
- })
- );
- return map;
- },
- /**
- * 批量查询库存数量:一次 POST 批量接口替代 N 次单条 GET。
- * 后端返回顺序与请求顺序一一对应,条数不一致时回退逐条查询。
- */
- async loadStockInfoMap(rows) {
- const map = new Map();
- const paramsMap = new Map();
- rows.forEach((row) => {
- if (!row.warehouseId) return;
- const key = this.stockLookupKey(row);
- if (paramsMap.has(key)) return;
- paramsMap.set(key, {
- warehouseId: row.warehouseId,
- code: row.productCode,
- batchNo: row.batchNo,
- systemBatchNo: row.systemBatchNo,
- colorKey: row.colorKey,
- modelType: row.modelType
- });
- });
- const entries = [...paramsMap.entries()];
- if (!entries.length) {
- return map;
- }
- const requests = entries.map(([, params]) => params);
- try {
- const list = await getWarehouseOutStockBatchAPI(requests);
- if (Array.isArray(list) && list.length === requests.length) {
- entries.forEach(([key], index) => {
- const item = list[index] || {};
- map.set(key, {
- stockCountBase: Number(item.stockCountBase || 0),
- availableCountBase: Number(item.availableCountBase || 0)
- });
- });
- return map;
- }
- console.warn(
- '[发货单] 批量库存返回条数与请求不一致,回退逐条查询',
- list?.length,
- requests.length
- );
- } catch (e) {
- console.warn('[发货单] 批量库存查询失败,回退逐条查询', e);
- }
- // 回退:逐条查询(走调度器限流,不会一次性打满连接池)
- await Promise.all(
- entries.map(async ([key, params]) => {
- try {
- map.set(
- key,
- await scheduleLookup(
- `stock:${key}`,
- () => getWarehouseOutStockInfo(params),
- 0
- )
- );
- } catch (e) {
- map.set(key, null);
- }
- })
- );
- return map;
- },
- // ==================== 仓库 / 批次列表懒加载 ====================
- // 行唯一标识:懒加载状态存组件上,不写进行对象(行对象会整体提交给后端)
- rowUid(row) {
- if (!this._rowUidMap) {
- this._rowUidMap = new WeakMap();
- this._rowUidSeq = 0;
- }
- let uid = this._rowUidMap.get(row);
- if (!uid) {
- this._rowUidSeq += 1;
- uid = `r${this._rowUidSeq}`;
- this._rowUidMap.set(row, uid);
- }
- return uid;
- },
- lookupStateKey(row, type) {
- return `${this.rowUid(row)}__${type}`;
- },
- lookupLoading(row, type) {
- return this.lookupState[this.lookupStateKey(row, type)] === 'loading';
- },
- // 仓库下拉选项:未加载时用已选仓库占位,保证仓库名能回显
- warehouseOptions(row) {
- const list = row.warehouseList;
- if (Array.isArray(list) && list.length) {
- return list;
- }
- if (row.warehouseId) {
- return [
- {
- warehouseId: row.warehouseId,
- warehouseName: row.warehouseName || row.warehouseId
- }
- ];
- }
- return [];
- },
- // 批次下拉选项:未加载时用已选批次占位
- batchOptions(row) {
- const list = row.batchNoList;
- if (Array.isArray(list) && list.length) {
- return list;
- }
- if (row.batchStockId) {
- return [{ id: row.batchStockId, batchNo: row.batchNo || '' }];
- }
- return [];
- },
- // 展开仓库下拉时才加载该行的仓库列表
- async loadWarehouseOptions(row) {
- const key = this.lookupStateKey(row, 'warehouse');
- const state = this.lookupState[key];
- if (state === 'loading' || state === 'loaded') {
- return;
- }
- this.$set(this.lookupState, key, 'loading');
- try {
- const list = await this.fetchWarehouseList(row.productId);
- const options = (list || []).slice();
- // 当前仓库不在列表里时补一条,保证已选仓库仍可回显
- if (
- row.warehouseId &&
- !options.some((item) => item.warehouseId == row.warehouseId)
- ) {
- options.push({
- warehouseId: row.warehouseId,
- warehouseName: row.warehouseName || row.warehouseId
- });
- }
- this.$set(row, 'warehouseList', options);
- this.$set(this.lookupState, key, 'loaded');
- } catch (e) {
- this.$set(this.lookupState, key, 'error');
- this.$message.error('仓库列表加载失败,请重试');
- }
- },
- // 展开批次下拉时才加载该行的批次列表
- async loadBatchOptions(row) {
- const key = this.lookupStateKey(row, 'batch');
- const state = this.lookupState[key];
- if (state === 'loading' || state === 'loaded') {
- return;
- }
- if (!row.warehouseId) {
- this.$message.warning('请先选择仓库');
- return;
- }
- this.$set(this.lookupState, key, 'loading');
- try {
- const list = await this.fetchBatchList({
- warehouseId: row.warehouseId,
- categoryCode: row.productCode,
- colorKey: row.colorKey,
- modelType: row.modelType
- });
- const options = (list || []).slice();
- // 已选批次不在最新列表里时补一条,保证回显的批次号仍然能显示出来
- if (
- row.batchStockId &&
- !options.some((item) => item.id == row.batchStockId)
- ) {
- options.unshift({
- id: row.batchStockId,
- batchNo: row.batchNo || ''
- });
- }
- this.$set(row, 'batchNoList', options);
- this.$set(this.lookupState, key, 'loaded');
- } catch (e) {
- this.$set(this.lookupState, key, 'error');
- this.$message.error('批次列表加载失败,请重试');
- }
- },
- // 仓库列表请求(走同键合并 + 缓存 + 限流)
- fetchWarehouseList(productId) {
- return scheduleLookup(`warehouse:${productId}`, async () => {
- const list = await getIdWarehouseList({ categoryId: productId });
- return Array.isArray(list) ? list : [];
- });
- },
- // 批次列表请求(走同键合并 + 缓存 + 限流)
- fetchBatchList(params) {
- const key = `batch:${params.warehouseId || ''}|${
- params.categoryCode || ''
- }|${params.colorKey || ''}|${params.modelType || ''}`;
- return scheduleLookup(key, async () => {
- const res = await getBatchList({ ...params, size: -1 });
- return this.dedupeBatchNoList(res?.list);
- });
- },
- remove(i) {
- this.form.datasource.splice(i, 1);
- this.setSort();
- },
- // 批量删除选中的物品
- batchRemove() {
- if (!this.selection.length) {
- return this.$message.warning('请先勾选要删除的数据');
- }
- this.$confirm(
- `确定要删除选中的 ${this.selection.length} 条物品吗?`,
- '提示',
- { type: 'warning' }
- )
- .then(() => {
- const rows = this.selection;
- this.form.datasource = this.form.datasource.filter(
- (row) => !rows.includes(row)
- );
- this.selection = [];
- if (this.$refs.table && this.$refs.table.clearSelection) {
- this.$refs.table.clearSelection();
- }
- this.setSort();
- this.$message.success('删除成功');
- })
- .catch(() => {});
- },
- // 批量设置发货数量:只作用于勾选的行,仅开发环境可用
- setAllSendCountChange({ count }) {
- if (!IS_DEV) return;
- if (this.tableBusy) {
- return this.$message.warning('物品清单加载中,请稍后再试');
- }
- if (count === undefined || count === null || count === '') {
- return this.$message.warning('请输入发货数量');
- }
- const indexS = this.getSelectedIndexes();
- if (!indexS.length) {
- return this.$message.warning('请先勾选需要设置的行');
- }
- const countObj = {
- countKey: 'saleCount',
- unitKey: 'saleUnit',
- unitIdKey: 'saleUnitId'
- };
- // changeCount 会返回新对象,这里只把算出来的字段写回原行对象,
- // 保持行引用不变,否则勾选状态(selection 存的是行引用)会与表格失联
- const calcFields = [
- 'totalCount',
- 'totalWeight',
- 'singleWeight',
- 'saleUnit',
- 'discountSinglePrice',
- 'totalPrice',
- 'discountTotalPrice'
- ];
- const exceedItems = [];
- indexS.forEach((i) => {
- const row = this.form.datasource[i];
- if (!row) return;
- this.$set(row, 'saleCount', count);
- const next = changeCount(row, countObj, false);
- calcFields.forEach((key) => {
- if (next[key] !== undefined) {
- this.$set(row, key, next[key]);
- }
- });
- // 发货总重 / 增重总重:与单行 changeCount 逻辑保持一致
- this.$set(row, 'sendTotalWeight', row.totalWeight);
- const receiveTotalWeight = Number(row.receiveTotalWeight) || 0;
- const sendTotalWeight = Number(row.sendTotalWeight) || 0;
- if (sendTotalWeight) {
- const increaseTotalWeight = sendTotalWeight - receiveTotalWeight;
- this.$set(row, 'increaseTotalWeight', increaseTotalWeight.toFixed(4));
- if (row.pricingWay == 3) {
- this.$set(
- row,
- 'totalPrice',
- (increaseTotalWeight * row.singlePrice).toFixed(2)
- );
- }
- }
- // 不含税单价
- this.getNotaxSinglePrice(i);
- // 客户环境 4:按模数换算发货块数
- if (this.clientEnvironmentId == 4) {
- this.tableHandleKeyUp(row, i, 'sum');
- }
- // 超过订单剩余数量的行先提示,提交时仍会被拦截
- const remainingCount = Number(row.notGenerateSendCount) || 0;
- if (remainingCount && Number(row.totalCount) > remainingCount) {
- exceedItems.push(row.productCode || row.productName);
- }
- });
- this.$message.success(`已设置 ${indexS.length} 行的发货数量`);
- if (exceedItems.length) {
- this.$message.warning(
- `${exceedItems.join('、')} 的发货数量大于订单剩余数量,请提交前调整`
- );
- }
- // datasource 变化会触发表格 reload,reload 会清空勾选,
- // 这里把本次设置的行重新勾上,方便连续设置不同的数量
- this.$nextTick(() => {
- const table = this.$refs.table;
- if (!table || !table.toggleRowSelection) return;
- indexS.forEach((i) => {
- const row = this.form.datasource[i];
- if (row) {
- table.toggleRowSelection(row, true);
- }
- });
- });
- },
- // 勾选行在数据源中的下标:按 row-key 匹配,不依赖 key 与下标一一对应
- getSelectedIndexes() {
- const keys = new Set(this.selection.map((item) => item.key));
- const indexS = [];
- this.form.datasource.forEach((row, index) => {
- if (keys.has(row.key)) {
- indexS.push(index);
- }
- });
- return indexS;
- },
- // 重新排序
- setSort() {
- this.form.datasource.forEach((n, index) => {
- n.key = index + 1;
- });
- },
- //选择产品
- handParent() {
- console.log('this.type~~~~111', this.orderId);
- if (!this.orderId && !this.orderIds)
- return this.$message.error('请先选择订单');
- this.$refs.BIZproductListRef.open('', -1);
- },
- // 添加
- handlAdd() {
- console.log('this.type~~~~222', this.orderId);
- if (!this.orderId && !this.orderIds)
- return this.$message.error('请先选择订单');
- this.$refs.productListRef.open(this.oldProductList);
- },
- //库存台账
- selectStockLedgerDialogOpen(row) {
- this.current = row;
- this.$refs.selectStockLedgerDialogRef.open();
- },
- validateForm(callback) {
- if (this.batchLookupPending) {
- this.$message.warning('批次库存查询中,请稍后重试');
- callback(false);
- return;
- }
- //开始表单校验
- this.$refs.form.validate((valid, obj) => {
- if (this.form.datasource.some((item) => item.batchStockId == 999)) {
- this.$message.warning('订单批次无匹配的可发库存,请核对仓库、批次和颜色');
- callback(false);
- return;
- }
- // 同一订单产品可能拆成多条发货明细,删除明细后只按当前有效行汇总校验。
- const groups = this.form.datasource.reduce((result, item) => {
- const key = item.orderProductId
- ? `order:${item.orderProductId}`
- : `product:${item.productCode}|${item.batchNo || ''}|${item.colorKey || ''}|${item.modelType || ''}`;
- const group = result[key] || { totalCount: 0, remainingCount: Number(item.notGenerateSendCount) || 0, productCode: item.productCode };
- group.totalCount += Number(item.totalCount) || 0;
- group.remainingCount = Math.max(group.remainingCount, Number(item.notGenerateSendCount) || 0);
- result[key] = group;
- return result;
- }, {});
- const exceededItems = Object.values(groups).filter(
- (item) => item.totalCount > item.remainingCount
- );
- // 退货单退货不校验数量,实物赔偿无法计算
- if (
- exceededItems.length > 0 &&
- this.sourceType != 3 &&
- this.needProduce != 4
- ) {
- // 提取产品名称,生成详细提示消息
- const productNames = exceededItems
- .map((item) => item.productCode)
- .join('、');
- this.$message.warning(`${productNames} 的发货数量大于订单剩余数量`);
- callback(false);
- return;
- }
- if (obj) {
- let messages = Object.keys(obj).map((key) => obj[key][0]);
- if (messages.length > 0) {
- this.$message.warning(messages[0].message);
- }
- }
- callback(valid);
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- ::v-deep .el-table .warning-row {
- background: #d9ecff;
- }
- .headbox {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- .amount {
- font-size: 14px;
- font-weight: bold;
- padding-right: 30px;
- }
- }
- .replace-code-cell {
- display: flex;
- flex-direction: column;
- align-items: center;
- line-height: 1.5;
- }
- .code-text {
- max-width: 100%;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .time-form .el-form-item {
- margin-bottom: 0 !important;
- }
- /* 遮罩层:批量回显期间盖在表格上方,避免用户看到半成品数据 */
- .table-container {
- position: relative;
- }
- .table-loading-mask {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 10;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- background-color: rgba(255, 255, 255, 0.75);
- }
- .table-loading-mask .el-icon-loading {
- font-size: 30px;
- color: #409eff;
- }
- .table-loading-text {
- margin-top: 10px;
- font-size: 13px;
- color: #909399;
- }
- /* 批量追加期间禁止单元格交互:只关掉 .cell 的指针事件,
- 滚轮事件仍会落在滚动容器上,所以表格照常可以滚动 */
- ::v-deep .time-form-busy .el-table__body-wrapper .cell,
- ::v-deep .time-form-busy .el-table__fixed-body-wrapper .cell {
- pointer-events: none;
- }
- ::v-deep .period {
- display: flex;
- .borderleftnone {
- .el-input--medium .el-input__inner {
- border-top-right-radius: 0;
- border-bottom-right-radius: 0;
- }
- }
- .borderrightnone {
- .el-input--medium .el-input__inner {
- border-top-left-radius: 0;
- border-bottom-left-radius: 0;
- }
- }
- }
- ::v-deep .time-form tbody > tr:hover > td {
- background-color: transparent !important;
- }
- // ::v-deep .time-form .el-table tr {
- // background-color: #ffffff;
- // }
- .pricebox {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- font-weight: bold;
- }
- </style>
|