storage.vue 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208
  1. <template>
  2. <div>
  3. <el-card shadow="never">
  4. <!-- <header-title title="基本信息"> </header-title> -->
  5. <div>基本信息</div>
  6. <el-form :model="formData" ref="formName" label-width="110px" :rules="rules">
  7. <el-row :gutter="20">
  8. <el-col :span="6">
  9. <el-form-item label="物品类型" prop="extInfo.assetType">
  10. <el-select style="width: 100%" disabled multiple v-model="formData.extInfo.assetType" placeholder="请选择">
  11. <el-option v-for="item in goodsLists" :key="item.id" :label="item.name" :value="item.id">
  12. </el-option>
  13. </el-select>
  14. </el-form-item>
  15. </el-col>
  16. <el-col :span="6">
  17. <el-form-item label="入库类型" prop="bizType">
  18. <el-select style="width: 100%" disabled filterable placeholder="请选择" v-model="formData.bizType" clearable>
  19. <el-option v-for="item in sceneState" :key="item.code" :value="item.code"
  20. :label="item.label"></el-option>
  21. </el-select> </el-form-item></el-col>
  22. <el-col :span="6">
  23. <el-form-item label="单据来源" prop="documentSource">
  24. <el-input placeholder="请选择" disabled v-model="formData.sourceBizNo"
  25. @click.native="openDocumentSourceDialog">
  26. </el-input>
  27. </el-form-item>
  28. </el-col>
  29. <!-- <el-col :span="6">
  30. <el-form-item label="权属部门" prop="deptName">
  31. <el-input
  32. placeholder="权属部门"
  33. disabled
  34. v-model="formData.extInfo.deptName"
  35. clearable
  36. />
  37. </el-form-item>
  38. </el-col> -->
  39. <el-col :span="6">
  40. <el-form-item label="入库时间">
  41. <el-date-picker v-model="formData.storageTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
  42. placeholder="选择日期时间">
  43. </el-date-picker></el-form-item></el-col>
  44. <el-col :span="6">
  45. <el-form-item label="入库登记人">
  46. <el-input placeholder="登记人" disabled v-model="formData.extInfo.createUserName"
  47. clearable /></el-form-item></el-col>
  48. <!-- <el-col :span="6" v-if="formData.bizType == 2">
  49. <el-form-item label="供应商" prop="supplierName">
  50. <el-input
  51. placeholder="请输入"
  52. clearable
  53. v-model="formData.extInfo.supplierName"
  54. />
  55. </el-form-item>
  56. </el-col> -->
  57. <!-- <el-col :span="6">
  58. <el-form-item label="送货人" prop="fromUser">
  59. <el-input placeholder="请输入" v-model="formData.fromUser" clearable /> </el-form-item></el-col>
  60. <el-col :span="6">
  61. <el-form-item label="送货人联系方式" prop="deliveryPhone">
  62. <el-input placeholder="请输入" v-model="formData.extInfo.deliveryPhone" clearable /></el-form-item></el-col> -->
  63. <el-col :span="6">
  64. <el-form-item label="备注" prop="remark">
  65. <el-input v-model="formData.remark" clearable type="textarea" placeholder="请详细说明" :rows="1"></el-input>
  66. </el-form-item>
  67. </el-col>
  68. </el-row>
  69. </el-form>
  70. <div class="inbound_details">
  71. <header-title title="产品信息">
  72. <el-button type="primary" @click="addProduct">添加</el-button>
  73. </header-title>
  74. <div class="form_table">
  75. <el-form ref="productListRef" :model="{ productList: productList }" :show-message="false">
  76. <el-button v-if="productList.length != 0" type="success" plain
  77. style="margin-bottom: 20px; float: right; margin-right: 20px" size="mini"
  78. @click="listSaveArrs">批量保存</el-button>
  79. <el-button v-if="productList.length != 0 && this.packingList.length == 0" type="success" plain
  80. style="margin-bottom: 20px; float: right; margin-right: 20px" size="mini"
  81. @click="handleWareHouse(productList, '', 'batch')">批量选择仓库</el-button>
  82. <el-table :header-cell-style="rowClass" :max-height="300" border ref="productListTable" :data="productList"
  83. tooltip-effect="dark">
  84. <el-table-column label="序号" type="index" width="50" align="center" fixed="left">
  85. </el-table-column>
  86. <el-table-column label="编码" prop="categoryCode" align="center" width="130" :show-overflow-tooltip="true"
  87. fixed="left"></el-table-column>
  88. <el-table-column label="名称" align="center" width="200" prop="categoryName" :show-overflow-tooltip="true"
  89. fixed="left"></el-table-column>
  90. <el-table-column label="牌号" align="center" width="100" prop="brandNum"
  91. :show-overflow-tooltip="true"></el-table-column>
  92. <el-table-column label="型号" align="center" width="100" prop="categoryModel"
  93. :show-overflow-tooltip="true"></el-table-column>
  94. <el-table-column label="规格" align="center" width="100" prop="specification"
  95. :show-overflow-tooltip="true"></el-table-column>
  96. <el-table-column v-for="(item, index) in newColumns" :label="item.label" :align="item.align"
  97. :prop="item.prop" :show-overflow-tooltip="item.showOverflowTooltip"></el-table-column>
  98. <el-table-column label="批次号" align="center" width="100" prop="batchNo">
  99. <template slot-scope="{ row, $index }">
  100. <template v-if="row.isSave">
  101. {{ row.batchNo }}
  102. </template>
  103. <el-form-item v-else :prop="`productList.${$index}.batchNo`" required>
  104. <el-input :ref="'batchNo' + $index" @keyup.native="
  105. moveFocus($event, $index, 'batchNo', '产品', row)
  106. " v-model.number="row.batchNo">
  107. </el-input>
  108. </el-form-item>
  109. </template>
  110. </el-table-column>
  111. <el-table-column label="数量" align="center" width="100" prop="packingQuantity">
  112. <template slot-scope="{ row, $index }">
  113. <template v-if="row.isSave">
  114. {{ row.packingQuantity }}
  115. </template>
  116. <el-form-item v-else :prop="`productList.${$index}.packingQuantity`" required>
  117. <el-input :ref="'packingQuantity' + $index" type="number" @keyup.native="
  118. moveFocus(
  119. $event,
  120. $index,
  121. 'packingQuantity',
  122. '产品',
  123. row
  124. )
  125. " v-model="row.packingQuantity" @input="computeNum(row, $index, true)">
  126. </el-input>
  127. </el-form-item>
  128. </template>
  129. </el-table-column>
  130. <el-table-column label="单位" align="center" prop="packingUnit" width="100">
  131. <template slot-scope="{ row, $index }">
  132. <template v-if="row.isSave">
  133. {{ row.packingUnit }}
  134. </template>
  135. <el-form-item v-else :prop="`productList.${$index}.packingUnit`" required>
  136. <el-select v-model="row.packingUnitId" placeholder="请选择" @change="computeNum(row, $index)">
  137. <el-option v-for="item in row.packingSpecificationOption" :label="`${item.conversionUnit}`"
  138. :value="item.id" :key="item.id">
  139. </el-option>
  140. </el-select>
  141. </el-form-item>
  142. </template>
  143. </el-table-column>
  144. <el-table-column label="包装规格" align="center" prop="packingSpecificationLabel" width="300"
  145. :show-overflow-tooltip="true">
  146. <template slot-scope="{ row, $index }">
  147. <el-tag v-for="item in row.packingSpecificationLabel">{{
  148. item
  149. }}</el-tag>
  150. </template>
  151. </el-table-column>
  152. <el-table-column label="允许拆包" prop="isUnpack">
  153. <template slot-scope="{ row, $index }">
  154. {{ row.isUnpack == 1 ? '是' : '否' }}
  155. </template>
  156. </el-table-column>
  157. <el-table-column label="计量数量" align="center" prop="measureQuantity"
  158. :show-overflow-tooltip="true"></el-table-column>
  159. <el-table-column label="计量单位" align="center" prop="measureUnit"
  160. :show-overflow-tooltip="true"></el-table-column>
  161. <el-table-column label="单重" align="center" prop="singleWeight" :show-overflow-tooltip="true" width="120">
  162. <template slot-scope="{ row, $index }">
  163. <template v-if="row.isSave">
  164. {{ row.singleWeight }}
  165. </template>
  166. <el-input-number v-else v-model="row.singleWeight" placeholder="请输入" :precision="2" :min="0"
  167. controls-position="right" @input="inputsingleWeight(row, $index)" :controls="false"
  168. style="width: 100%"></el-input-number>
  169. <template slot="append">
  170. {{ row.measureUnit }}
  171. </template>
  172. </template>
  173. </el-table-column>
  174. <el-table-column label="计价方式" align="center" prop="pricingWay" :show-overflow-tooltip="true" width="120">
  175. <template slot-scope="{ row, $index }">
  176. <span v-if="row.pricingWay == 1">数量</span>
  177. <span v-if="row.pricingWay == 2">重量</span>
  178. </template>
  179. </el-table-column>
  180. <el-table-column label="总重" align="center" prop="weight" width="120" :show-overflow-tooltip="true">
  181. <template slot-scope="{ row, $index }">
  182. <template v-if="row.isSave">
  183. {{ row.weight }}
  184. </template>
  185. <el-input v-else v-model="row.weight" placeholder="请输入" type="number"
  186. @input="inputWeight(row, $index)"></el-input>
  187. <template slot="append">
  188. {{ row.measureUnit }}
  189. </template>
  190. </template>
  191. </el-table-column>
  192. <el-table-column label="重量单位" align="center" prop="weightUnit" :show-overflow-tooltip="true">
  193. <template slot-scope="{ row, $index }">
  194. {{ row.weightUnit }}
  195. <template slot="append"> </template>
  196. </template>
  197. </el-table-column>
  198. <!-- <el-table-column label="单价" prop="unitPrice" width="200" align="center">
  199. <template slot-scope="{ row, $index }">
  200. <template v-if="row.isSave">
  201. <span>{{ row.unitPrice }}</span>
  202. <span v-if="row.unitPrice">/元</span>
  203. </template>
  204. <el-form-item v-else>
  205. <el-input type="number" :ref="'unitPrice' + $index" @keyup.native="
  206. moveFocus($event, $index, 'unitPrice', '产品', row)
  207. " v-model.number="row.unitPrice" placeholder="非必填" @input="
  208. (value) =>
  209. (row.unitPrice = value.replace(/[^0-9.]+/g, ''))
  210. ">
  211. <template slot="append">
  212. <span v-if="row.unitPrice">/元</span>
  213. </template>
  214. </el-input>
  215. </el-form-item>
  216. </template>
  217. </el-table-column> -->
  218. <!-- <el-table-column label="金额" align="center" prop="totalMoney" :show-overflow-tooltip="true">
  219. <template slot-scope="{ row, $index }">
  220. {{
  221. changeCount(
  222. calcSumTotal(row.measureQuantity, row.unitPrice, row)
  223. )
  224. }}
  225. </template>
  226. </el-table-column> -->
  227. <el-table-column label="供应商" align="center" prop="supplierId" width="200" :show-overflow-tooltip="true">
  228. <template slot-scope="{ row, $index }">
  229. <template v-if="row.isSave || row.supplierId">
  230. {{ row.supplierName }}
  231. </template>
  232. <el-select v-else @change="selectSupplier($event, row)" v-model="row.supplierId" placeholder="请选择"
  233. :clearable="true">
  234. <el-option v-for="item in row.supplierListOptions" :label="item.name" :value="item.id"
  235. :key="item.id">
  236. </el-option>
  237. </el-select>
  238. </template>
  239. </el-table-column>
  240. <el-table-column label="供应商代号" align="center" prop="supplierCode" width="120"
  241. :show-overflow-tooltip="true">
  242. <template slot-scope="{ row, $index }">
  243. {{ row.supplierCode }}
  244. </template>
  245. </el-table-column>
  246. <!-- <el-table-column v-else-if="bizType == 2" label="供应商代号" align="center" prop="supplierMark" width="120"
  247. :show-overflow-tooltip="true">
  248. <template slot-scope="{ row, $index }">
  249. {{ row.supplierMark }}
  250. </template>
  251. </el-table-column> -->
  252. <el-table-column v-if="bizType == 2" label="产地" align="center" prop="provenance "
  253. :show-overflow-tooltip="true" width="120">
  254. </el-table-column>
  255. <el-table-column label="仓库" align="center" prop="warehouseName" :show-overflow-tooltip="true" width="300">
  256. <template slot-scope="{ row, $index }">
  257. <el-form-item :prop="`productList.${$index}.warehouseId`" required>
  258. <div :class="row.warehouseName
  259. ? 'wareHouse_style'
  260. : 'wareHouse_style red_color'
  261. " @click="handleWareHouse(row, $index)">
  262. <span>
  263. {{
  264. row.warehouseName ? row.warehouseName : '请选择仓库'
  265. }}
  266. </span>
  267. </div>
  268. </el-form-item>
  269. </template>
  270. </el-table-column>
  271. <el-table-column label="采购原因" align="center" width="200" prop="purpose" :show-overflow-tooltip="true">
  272. <template slot-scope="{ row, $index }">
  273. <template v-if="row.isSave">
  274. {{ row.purpose }}
  275. </template>
  276. <el-input v-else :ref="'purpose' + $index" @keyup.native="
  277. moveFocus($event, $index, 'purpose', '产品', row)
  278. " v-model="row.purpose">
  279. </el-input>
  280. </template>
  281. </el-table-column>
  282. <el-table-column label="是否质检" align="center" width="80" prop="qualityControl"
  283. :show-overflow-tooltip="true" v-if="bizType != 1 && bizType != 6 && bizType != 9">
  284. <template slot-scope="{ row, $index }">
  285. {{ row.qualityControl == 1 ? '是' : row.qualityControl == 0 ? '否' : '' }}
  286. </template>
  287. </el-table-column>
  288. <el-table-column label="操作" width="200" fixed="right" align="center">
  289. <template slot="header" slot-scope="scope"> 操作 </template>
  290. <template slot-scope="{ row, $index }">
  291. <el-button type="text" v-show="!row.isSave" @click="listSave(row, $index)">保存</el-button>
  292. <el-button type="text" v-show="row.isSave" @click="listEdit(row, $index)">编辑</el-button>
  293. <el-button type="text" @click="listDel(row, $index)">删除</el-button>
  294. </template>
  295. </el-table-column>
  296. </el-table>
  297. </el-form>
  298. </div>
  299. </div>
  300. <div v-if="showPackingList.length > 0" class="inbound_details">
  301. <header-title :title="`包装明细`">
  302. <div class="switch_right">
  303. <el-button style="margin-left: 20px" type="text" @click="dateSetting">批量设置{{
  304. curDateType === 'productionDate' ? '生产日期' : '采购日期'
  305. }}</el-button>
  306. </div>
  307. </header-title>
  308. <el-table v-if="isWrapTable" ref="packingListTable" :data="showPackingList" tooltip-effect="dark"
  309. :key="formData.bizType" :header-cell-style="rowClass" style="width: 100%" border stripe :max-height="300"
  310. v-el-table-infinite-scroll="pickingHandleScroll" @selection-change="handleSelectionChange">
  311. <el-table-column type="selection" align="center" width="50">
  312. </el-table-column>
  313. <el-table-column label="序号" type="index" width="50" fixed="left">
  314. </el-table-column>
  315. <el-table-column label="编码" prop="categoryCode" width="130" :show-overflow-tooltip="true"
  316. fixed="left"></el-table-column>
  317. <el-table-column label="名称" prop="categoryName" width="150" :show-overflow-tooltip="true"
  318. fixed="left"></el-table-column>
  319. <el-table-column label="批次号" prop="batchNo" width="100"></el-table-column>
  320. <el-table-column :label="`包装编码`" prop="packageNo" width="200" :show-overflow-tooltip="true"></el-table-column>
  321. <el-table-column label="包装数量" prop="packingQuantity" width="80"></el-table-column>
  322. <el-table-column label="单位" prop="packingUnit"></el-table-column>
  323. <el-table-column label="计量数量" prop="measureQuantity" :show-overflow-tooltip="true"></el-table-column>
  324. <el-table-column label="计量单位" prop="measureUnit"></el-table-column>
  325. <!-- <el-table-column label="允许拆包" prop="isUnpack">
  326. <template slot-scope="{ row, $index }">
  327. {{ row.isUnpack ? '是' : '否' }}
  328. </template>
  329. </el-table-column> -->
  330. <el-table-column label="仓库" :show-overflow-tooltip="true" prop="warehouseName" width="200"></el-table-column>
  331. <el-table-column label="物料代号" prop="materielDesignation" width="130">
  332. <template slot-scope="{ row, $index }">
  333. <el-input v-if="!row.isPack" :ref="'packing_materielDesignation' + $index" @keyup.native="
  334. moveFocus(
  335. $event,
  336. $index,
  337. 'packing_materielDesignation',
  338. '包装',
  339. row
  340. )
  341. " v-model="row.materielDesignation"></el-input>
  342. <span v-else>{{ row.materielDesignation }}</span>
  343. </template>
  344. </el-table-column>
  345. <el-table-column label="客户代号" prop="clientCode" width="130">
  346. <template slot-scope="{ row, $index }">
  347. <el-input v-if="!row.isPack" :ref="'packing_clientCode' + $index" @keyup.native="
  348. moveFocus($event, $index, 'packing_clientCode', '包装', row)
  349. " v-model="row.clientCode"></el-input>
  350. <span v-else> {{ row.clientCode }}</span>
  351. </template>
  352. <!-- <template slot-scope="{ row, $index }" v-if="bizType == 2">
  353. <el-input v-if="!row.isPack" :ref="'packing_clientCode' + $index" @keyup.native="
  354. moveFocus($event, $index, 'packing_clientCode', '包装', row)
  355. " v-model="row.customerMark"></el-input>
  356. <span v-else> {{ row.customerMark }}</span>
  357. </template> -->
  358. </el-table-column>
  359. <el-table-column label="牌号" prop="brandNum" width="80">
  360. </el-table-column>
  361. <el-table-column label="发货条码" prop="barcodes" :show-overflow-tooltip="true"></el-table-column>
  362. <el-table-column label="供应商" align="center" prop="supplierName" width="120" :show-overflow-tooltip="true">
  363. </el-table-column>
  364. <el-table-column label="供应商代号" align="center" prop="supplierCode" width="120" :show-overflow-tooltip="true">
  365. <template slot-scope="{ row, $index }">
  366. {{ row.supplierCode }}
  367. </template>
  368. </el-table-column>
  369. <!-- <el-table-column v-else-if="bizType == 2" label="供应商代号" align="center" prop="supplierMark" width="120"
  370. :show-overflow-tooltip="true">
  371. <template slot-scope="{ row, $index }">
  372. {{ row.supplierMark }}
  373. </template>
  374. </el-table-column> -->
  375. <el-table-column label="序列号" prop="engrave" width="140">
  376. <template slot-scope="{ row, $index }">
  377. <span > {{ row.productSequence }}</span>
  378. </template>
  379. </el-table-column>
  380. <el-table-column label="刻码" prop="engrave" width="140">
  381. <template slot-scope="{ row, $index }">
  382. <el-input v-if="!row.isPack" :ref="'packing_engrave' + $index" @keyup.native="
  383. moveFocus($event, $index, 'packing_engrave', '包装', row)
  384. " v-model="row.engrave"></el-input>
  385. <span v-else>{{ row.engrave }}</span>
  386. </template>
  387. </el-table-column>
  388. <el-table-column label="重量" prop="weight" width="100">
  389. <template slot-scope="{ row, $index }">
  390. <el-input v-if="!row.isPack && row.measureUnit != row.weightUnit" :ref="'packing_weight' + $index"
  391. @keyup.native="
  392. moveFocus($event, $index, 'packing_weight', '包装', row)
  393. " v-model.number="row.weight" @input="weightInput($event, row, '包装')"></el-input>
  394. <span v-else>{{ row.weight }}</span>
  395. </template>
  396. </el-table-column>
  397. <el-table-column label="重量单位" prop="weightUnit">
  398. <template slot-scope="{ row }">
  399. {{ row.weightUnit }}
  400. </template>
  401. </el-table-column>
  402. <el-table-column label="序列号" prop="serialNumber">
  403. </el-table-column>
  404. <el-table-column label="质检结果" prop="result" width="120">
  405. <template slot-scope="{ row }">
  406. <el-select v-if="!row.isPack" @change="changeWrapStatus($event, row, '包装')" v-model="row.result"
  407. placeholder="请选择">
  408. <el-option v-for="item in qualityResultsOptions" :label="item.label" :value="item.value"
  409. :key="item.value">
  410. </el-option>
  411. </el-select>
  412. <span v-else>{{ qualityResults[row.result] }}</span>
  413. </template>
  414. </el-table-column>
  415. <el-table-column label="质检状态" prop="status" width="120">
  416. <template slot-scope="{ row }">
  417. <span>{{ qualityStatus[row.status] }}</span>
  418. </template>
  419. </el-table-column>
  420. <el-table-column label="是否质检" align="center" width="80" prop="qualityControl" :show-overflow-tooltip="true"
  421. v-if="bizType != 1 && bizType != 6 && bizType != 9">
  422. <template slot-scope="{ row, $index }">
  423. {{ row.qualityControl == 1 ? '是' : row.qualityControl == 0 ? '否' : '' }}
  424. </template>
  425. </el-table-column>
  426. <el-table-column label="生产日期" prop="" width="220">
  427. <template slot="header" slot-scope="scope">
  428. <el-select filterable v-model="curDateType">
  429. <el-option value="productionDate" label="生产日期"></el-option>
  430. <el-option value="purchaseDate" label="采购日期"></el-option>
  431. </el-select>
  432. </template>
  433. <template slot-scope="{ row }">
  434. <template v-if="formData.bizType == 5">
  435. {{ row[curDateType] }}
  436. </template>
  437. <el-date-picker v-else :disabled="row.isPack" size="small" v-model="row[curDateType]" type="datetime"
  438. value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期">
  439. </el-date-picker>
  440. </template>
  441. </el-table-column>
  442. <!-- <el-table-column label="操作" width="120" fixed="right">
  443. <template slot-scope="{ row, $index }">
  444. <el-button type="text" @click="wrapDelete(row, $index)">
  445. 删除
  446. </el-button>
  447. </template>
  448. </el-table-column> -->
  449. </el-table>
  450. </div>
  451. <div v-if="showMaterialList.length > 0" class="inbound_details">
  452. <!-- <header-title :title="`物料明细`"></header-title> -->
  453. <!-- <el-table ref="materialListTable" :data="showMaterialList" tooltip-effect="dark" :key="formData.bizType"
  454. :header-cell-style="rowClass" style="width: 100%" border stripe :max-height="300"
  455. v-el-table-infinite-scroll="materielHandleScroll">
  456. <el-table-column label="序号" type="index" width="50">
  457. </el-table-column>
  458. <el-table-column label="编码" prop="categoryCode" width="130" :show-overflow-tooltip="true"></el-table-column>
  459. <el-table-column label="名称" prop="categoryName" width="150" :show-overflow-tooltip="true"></el-table-column>
  460. <el-table-column label="批次号" prop="batchNo" width="70"></el-table-column>
  461. <el-table-column label="物料编码" prop="materialCode" width="200" :show-overflow-tooltip="true"></el-table-column>
  462. <el-table-column label="计量数量" prop="measureQuantity" width="90"
  463. :show-overflow-tooltip="true"></el-table-column>
  464. <el-table-column width="80" label="计量单位" prop="measureUnit"></el-table-column>
  465. <el-table-column label="物料代号" prop="materielDesignation" width="130">
  466. <template slot-scope="{ row, $index }">
  467. <el-input v-if="!row.isPack" :ref="'material_materielDesignation' + $index" @keyup.native="
  468. moveFocus(
  469. $event,
  470. $index,
  471. 'material_materielDesignation',
  472. '物料',
  473. row
  474. )
  475. " v-model="row.materielDesignation"></el-input>
  476. <span v-else>{{ row.materielDesignation }}</span>
  477. </template>
  478. </el-table-column>
  479. <el-table-column label="客户代号" prop="clientCode">
  480. <template slot-scope="{ row, $index }">
  481. <el-input v-if="!row.isPack" :ref="'material_clientCode' + $index" @keyup.native="
  482. moveFocus($event, $index, 'material_clientCode', '物料', row)
  483. " v-model="row.clientCode"></el-input>
  484. <span v-else>{{ row.clientCode }}</span>
  485. </template>
  486. </el-table-column>
  487. <el-table-column label="刻码" prop="engrave" width="140">
  488. <template slot-scope="{ row, $index }">
  489. <el-input v-if="!row.isPack" :ref="'material_engrave' + $index" @keyup.native="
  490. moveFocus($event, $index, 'material_engrave', '物料', row)
  491. " v-model="row.engrave"></el-input>
  492. <span v-else>{{ row.engrave }}</span>
  493. </template>
  494. </el-table-column>
  495. <el-table-column label="重量" prop="weight" width="100">
  496. <template slot-scope="{ row, $index }">
  497. <el-input v-if="!row.isPack && row.measureUnit != row.weightUnit" :ref="'material_weight' + $index"
  498. @keyup.native="
  499. moveFocus($event, $index, 'material_weight', '物料', row)
  500. " @input="weightInput($event, row, '物料')" v-model.number="row.weight"></el-input>
  501. <span v-else>{{ row.weight }}</span>
  502. </template>
  503. </el-table-column>
  504. <el-table-column label="重量单位" prop="weightUnit" width="100"></el-table-column>
  505. <el-table-column label="质检结果" prop="result" width="120">
  506. <template slot-scope="{ row }">
  507. <el-select v-if="!row.isPack" @change="changeWrapStatus($event, row, '物料')" v-model="row.result"
  508. placeholder="请选择">
  509. <el-option v-for="item in qualityResultsOptions" :label="item.label" :value="item.value"
  510. :key="item.value">
  511. </el-option>
  512. </el-select>
  513. <span v-else>{{ qualityResults[row.result] }}</span>
  514. </template>
  515. </el-table-column>
  516. <el-table-column label="质检状态" prop="status" width="120">
  517. <template slot-scope="{ row }">
  518. <span>{{ qualityStatus[row.status] }}</span>
  519. </template>
  520. </el-table-column>
  521. </el-table> -->
  522. </div>
  523. </el-card>
  524. <!-- 产品选择弹框 -->
  525. <selectType :visibleDialog.sync="visibleDialog" :title="title" :treeIds="formData.extInfo.assetType"
  526. :loadTree.sync="loadTree" @selectTableData="addGoods" />
  527. <!-- 仓库选择弹框 -->
  528. <WarehousingDialog ref="wareHouseDailogRef" @selection="wareHouseSelection"></WarehousingDialog>
  529. <!-- 生产日期、采购日期弹框 -->
  530. <el-dialog :visible.sync="dateVisible" title="选择日期" width="400px">
  531. <el-date-picker size="small" v-model="batchTime" type="datetime" style="width: 320px"
  532. value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期">
  533. </el-date-picker>
  534. <div style="text-align: right; margin-top: 20px">
  535. <el-button @click="dateVisible = false">取消</el-button>
  536. <el-button type="primary" @click="dateConfirm" :disabled="!batchTime">确认</el-button>
  537. </div>
  538. </el-dialog>
  539. </div>
  540. </template>
  541. <script>
  542. import elTableInfiniteScroll from 'el-table-infinite-scroll';
  543. import storageApi from '@/api/warehouseManagement/index.js';
  544. import warehouseDefinition from '@/api/warehouseManagement/warehouseDefinition.js';
  545. import WarehousingDialog from './components/WarehousingDialog.vue';
  546. import { getCode } from '@/api/codeManagement/index.js';
  547. import selectType from './components/selectType_new.vue';
  548. import {
  549. sceneState,
  550. qualityResultsOptions,
  551. qualityResults,
  552. qualityStatus
  553. } from '@/utils/dict/index';
  554. import { getTreeByGroup } from '@/api/classifyManage';
  555. import { deepClone } from '@/utils';
  556. import { getDetails } from '@/api/classifyManage/itemInformation';
  557. import { mapActions, mapGetters } from 'vuex';
  558. import BigNumber from 'bignumber.js';
  559. import { status } from 'nprogress';
  560. export default {
  561. components: {
  562. selectType,
  563. WarehousingDialog
  564. },
  565. // 虚拟列表滚动方法
  566. directives: {
  567. 'el-table-infinite-scroll': elTableInfiniteScroll
  568. },
  569. props: {
  570. form: { type: Object, default: () => { } },
  571. bizType: { type: Number, default: 1 },
  572. sourceBizNo: { type: String, default: '' },
  573. detailList: { type: Array, default: () => [] },
  574. saleProductList: { type: Array, default: () => [] },
  575. detailProductList: { type: Array, default: () => [] },
  576. isMoreProduct: { type: Boolean, default: false } //多产品包装明细
  577. },
  578. data() {
  579. return {
  580. newColumns: [], // 动态表头
  581. sceneState,
  582. saveLoading: false,
  583. dateVisible: false,
  584. loadTree: true,
  585. visibleDialog: false,
  586. title: '选择产品',
  587. goodsLists: [],
  588. formData: {
  589. bizType: '',
  590. storageTime: '',
  591. qualityControl: '',
  592. extInfo: {
  593. assetType: []
  594. }
  595. },
  596. rules: {
  597. 'extInfo.assetType': {
  598. required: true,
  599. message: '请选择物品类型',
  600. trigger: 'blur'
  601. },
  602. bizType: {
  603. required: true,
  604. message: '请选择入库场景',
  605. trigger: 'change'
  606. },
  607. storageTime: {
  608. required: true,
  609. message: '请选择入库时间',
  610. trigger: 'change'
  611. }
  612. },
  613. qualityResultsOptions, // 质检结果选项
  614. qualityStatus, // 质检状态 0未检 1已检
  615. qualityResults, // 质检结果 0无 1合格 2不合格
  616. productList: [], // 产品列表
  617. packingList: [], // 包装列表
  618. showPackingList: [], // 包装列表(虚拟列表)
  619. materialList: [], // 物料列表
  620. showMaterialList: [], // 物料列表(虚拟列表)
  621. curDateType: 'productionDate',
  622. packingListSelected: [], // 包装选择列表
  623. isWrapTable: true, // 解决表格不刷新问题(包装)
  624. currentPackingQuantity: '', // 当前包装数量
  625. batchTime: '', // 生产日期、采购日期
  626. pageSize: 20, // 物料和包装列表条数
  627. pickingPageNum: 1, // 包装虚拟分页页数
  628. materielPageNum: 1 // 物料虚拟分页页数
  629. };
  630. },
  631. computed: {
  632. ...mapGetters(['dict', 'getDict']),
  633. clientEnvironmentId() {
  634. return this.$store.state.user.info.clientEnvironmentId;
  635. }
  636. },
  637. watch: {
  638. packingList: {
  639. handler(newVal) {
  640. console.log(newVal);
  641. this.showPackingList = newVal.slice(
  642. 0,
  643. this.pageSize * (this.pickingPageNum > 0 ? this.pickingPageNum : 1)
  644. );
  645. this.showPackingList.forEach((obj) => {
  646. console.log(obj,'666666666');
  647. obj.workOrderId = this.detailProductList[0]?.workOrderId;
  648. obj.taskId = this.detailProductList[0]?.taskId;
  649. obj.outsourceBatchNo = this.detailProductList[0]?.batchNo;
  650. obj.outsourceCode = this.detailProductList[0]?.sourceCode;
  651. obj.taskId = this.detailList[0]?.taskId;
  652. obj.workOrderId = this.detailList[0]?.workOrderId;
  653. });
  654. this.pickingPageNum = Math.ceil(
  655. this.showPackingList.length / this.pageSize
  656. );
  657. },
  658. deep: true
  659. },
  660. materialList: {
  661. handler(newVal) {
  662. this.showMaterialList = newVal.slice(
  663. 0,
  664. this.pageSize *
  665. (this.materielPageNum > 0 ? this.materielPageNum : 1)
  666. );
  667. },
  668. deep: true
  669. },
  670. // detailList: {
  671. // handler(newVal) {
  672. // if (newVal.length) {
  673. // this.initFormData();
  674. // }
  675. // },
  676. // deep: true
  677. // },
  678. },
  679. async created() {
  680. await this.requestDict('不拆物料层规格');
  681. await this.getFieldModel();
  682. await this.getListItems();
  683. await this.initFormData();
  684. await this.getNowFormatDate();
  685. },
  686. methods: {
  687. ...mapActions('dict', ['requestDict']),
  688. changeCount(number) {
  689. return new BigNumber(number).toString();
  690. },
  691. selectSupplier(val, row) {
  692. row.supplierId = val;
  693. row.supplierName = row.supplierListOptions.filter(
  694. (item) => item.id == val
  695. )[0]?.name;
  696. row.supplierCode = row.supplierListOptions.filter(
  697. (item) => item.id == val
  698. )[0].serialNo;
  699. },
  700. inputsingleWeight(row, index) {
  701. row.weight = row.singleWeight * row.measureQuantity;
  702. },
  703. inputWeight(row, index) {
  704. row.singleWeight = row.measureQuantity
  705. ? row.weight / row.measureQuantity
  706. : 0;
  707. },
  708. // 计算最小单元数量
  709. async computeNum(row, index, isClear) {
  710. console.log('row, index', row, index);
  711. let data= row.packingSpecificationOption.find(item=>item.id==row.packingUnitId)
  712. row.packingUnit=data.conversionUnit
  713. // 清空仓库(包装数量输入)
  714. if (isClear) {
  715. if (row.packingQuantity < 0) {
  716. this.$set(this.productList[index], 'packingQuantity', 1);
  717. } else if (row.packingQuantity > 9999) {
  718. this.$set(this.productList[index], 'packingQuantity', 9999);
  719. }
  720. }
  721. //如果有包装数量和包装单位
  722. if (row.packingQuantity && row.packingUnit) {
  723. //获取仓库
  724. const res = await warehouseDefinition.list({
  725. // inventoryType: this.form.categoryLevelTopId
  726. });
  727. // 只有一个仓库自动显示出来
  728. if (res.length == 1) {
  729. let name = res[0]?.factoryName + '-' + res[0]?.name;
  730. console.log('仓库-----------------------------', res);
  731. this.$set(this.productList[index], 'warehouseId', res[0].id);
  732. this.$set(this.productList[index], 'warehouseName', name);
  733. let table1 = [];
  734. table1.push({
  735. measureQuantity: row.measureQuantity,
  736. packingQuantity: row.packingQuantity,
  737. warehouseName: name,
  738. warehouseId: res[0].id
  739. });
  740. this.wareHouseSelection(table1, index);
  741. } else {
  742. this.$set(this.productList[index], 'warehouseId', '');
  743. this.$set(this.productList[index], 'warehouseName', '');
  744. }
  745. // -----------------------------------------------------------------
  746. let startIndex = row.packingSpecificationOption.findIndex((ite) => {
  747. return (
  748. row.measuringUnit == ite.packingUnit &&
  749. ite.packingUnit != ite.conversionUnit
  750. );
  751. });
  752. let endIndex = row.packingSpecificationOption.findIndex(
  753. (ite) => data.id == ite.id
  754. );
  755. console.log(row, 'rowwwwwwwwwwwwww')
  756. let total = Number(row.packingQuantity);
  757. console.log(total, '111')
  758. if (row.packingUnit == row.measureUnit && row.measureUnit == '立方' && row.netWeight) {
  759. total = Number(row.packingQuantity) * row.netWeight;
  760. console.log(total, '单位是立方,计量单位也是立方,如果有单重,就计量数量x单重=总重')
  761. console.log(total, '2222')
  762. } else {
  763. console.log(total, 333)
  764. for (; 0 < endIndex; endIndex--) {
  765. total = this.$math.format(
  766. row.packingSpecificationOption[endIndex].packageCell * total,
  767. 14
  768. );
  769. }
  770. }
  771. console.log(total, '444456')
  772. //计量数量
  773. row.measureQuantity = this.changeCount(total);
  774. // 判断单位和计量单位是否为不拆物料层规格
  775. let packingBoolen = !!this.getDict('不拆物料层规格', row.packingUnit)
  776. .dictValue;
  777. let measureBoolen = !!this.getDict('不拆物料层规格', row.measureUnit)
  778. .dictValue;
  779. console.log(packingBoolen, 'packingBoolen')
  780. console.log(measureBoolen, 'measureBoolen')
  781. if (packingBoolen && measureBoolen && row.packingUnit != 'L') {
  782. row.weight = total;
  783. console.log(total, '6')
  784. }
  785. let weight = 0
  786. if(row.measureUnit==row.weightUnit){
  787. weight = row.measureQuantity
  788. }else if(row.singleWeight){
  789. weight = row.measureQuantity * Number(row.singleWeight);
  790. }
  791. this.$set(this.productList[index], 'weight', weight)
  792. }
  793. },
  794. // 获取动态表头
  795. getFieldModel() {
  796. storageApi.fieldModel({ fieldModel: 't_main_category' }).then((res) => {
  797. let newRes = res.map((m) => {
  798. return {
  799. prop: 'extField.' + m.prop,
  800. label: m.label,
  801. align: 'center',
  802. showOverflowTooltip: true
  803. };
  804. });
  805. this.newColumns = [...newRes];
  806. });
  807. },
  808. // 初始化信息
  809. async initFormData() {
  810. console.log(this.form, 'form')
  811. console.log(this.formData, 'formData')
  812. console.log(this.sourceBizNo, 'sourceBizNo')
  813. this.formData.type = 1;
  814. this.formData.bizType = this.bizType;
  815. if (this.sourceBizNo != null || this.sourceBizNo != '') {
  816. // this.formData.sourceBizNo = this.sourceBizNo;
  817. this.$set(this.formData, 'sourceBizNo', this.sourceBizNo);
  818. } else {
  819. this.$message.warning('未获取到单据来源!');
  820. }
  821. // 入库登记人
  822. this.formData.extInfo.createUserId = this.$store.state.user.info.userId;
  823. this.formData.extInfo.createUserName = this.$store.state.user.info.name;
  824. this.formData.extInfo.deliveryPhone = this.$store.state.user.info.phone;
  825. this.formData.createUserId = this.$store.state.user.info.userId;
  826. this.formData.extInfo.deptName = this.$store.state.user.info.deptName;
  827. // this.formData.extInfo.supplierName = this.form.supplierName;
  828. // this.formData.extInfo.supplierId = this.form.supplierId;
  829. console.log('saleProductList-------------------', this.saleProductList)
  830. if (this.saleProductList?.length > 0) {
  831. // 物品列表
  832. let codeList = this.saleProductList.map((item) => {
  833. return item.productCode;
  834. });
  835. storageApi.getListByNameOrModeType({ codeList }).then(async (res) => {
  836. if (res.length <= 0) {
  837. this.$message.warning('未获取到物品信息!');
  838. return;
  839. }
  840. console.log(res, 'res')
  841. // this.formData.extInfo.assetType = res.map((item) => item.categoryLevelPathIdParent)
  842. this.formData.extInfo.assetType = Array.from(new Set(res.map((item) => item.categoryLevelPathIdParent)));
  843. console.log(this.formData.extInfo.assetType, '类型类型')
  844. // 获取批次号
  845. const batchNo1 = await getCode('lot_number_code');
  846. // 获取供应商
  847. const supplierList = await storageApi.contactQueryByCategoryIdsAPI({
  848. categoryIds: res.map((item) => item.id)
  849. });
  850. // 获取包装规格
  851. let packingSpecification =
  852. await storageApi.getCategoryPackageDisposition({
  853. categoryIds: res.map((item) => item.id)
  854. });
  855. console.log(packingSpecification);
  856. this.packingSpecificationOption = res.map((item) => {
  857. return packingSpecification
  858. .filter((ite) => item.id == ite.categoryId)
  859. .sort((a, b) => a.sort - b.sort);
  860. });
  861. this.productList = res.map((item, index) => {
  862. let filtersItem = this.saleProductList.filter(
  863. (detailItem) => detailItem.productCode == item.code
  864. )[0];
  865. // 显示规格
  866. let packingSpecificationLabel = this.packingSpecificationOption[
  867. index
  868. ]
  869. .map((item) => {
  870. if (item.sort > 0) {
  871. return `${item.packageCell}${item.packageUnit}/${item.conversionUnit}`;
  872. }
  873. }).filter((item) => !!item);
  874. const newSpecificationOption = this.getNewSpecificationOption(this.packingSpecificationOption)
  875. console.log(newSpecificationOption, '啵啵啵啵啵啵啵啵啵啵啵啵2')
  876. let warehouseId = filtersItem.warehouseId;
  877. let warehouseName = filtersItem.warehouseName;
  878. let measureQuantity = filtersItem.totalCount || 0;
  879. let packingQuantity = filtersItem.totalCount || 0;
  880. let packingUnit = filtersItem.measuringUnit || '';
  881. let unitPrice = filtersItem.singlePrice || 0;
  882. let pricingWay = filtersItem.pricingWay || '';
  883. // 计价方式是重量
  884. let singleWeight =
  885. this.detailProductList[0]?.pricingWay == 2
  886. ? this.detailProductList[0]?.singleWeight
  887. : filtersItem.singleWeight || 0;
  888. let weight =
  889. this.detailProductList[0]?.pricingWay == 2
  890. ? this.detailProductList[0]?.singleWeight *
  891. filtersItem.measureQuantity
  892. : filtersItem.sendTotalWeight || 0;
  893. // 获取相同仓库
  894. let warehouseIds = [];
  895. let warehouseNames = [];
  896. for (let i = 0; i < filtersItem.totalCount; i++) {
  897. warehouseIds.push(filtersItem.warehouseId);
  898. warehouseNames.push(filtersItem.warehouseName);
  899. }
  900. let totalMoney = filtersItem.totalPrice || 0;
  901. console.log(filtersItem, 'filtersItemfiltersItemfiltersItemfiltersItemfiltersItem')
  902. let batchNo = ''
  903. if (filtersItem.batchNo) {
  904. batchNo = filtersItem.batchNo
  905. } else {
  906. batchNo = batchNo1
  907. }
  908. return {
  909. index: this.productList.length + index,
  910. categoryId: item.id, // 物品id
  911. categoryName: item.name, // 物品名称
  912. categoryCode: item.code, // 物品编码
  913. categoryModel: item.modelType, // 物品型号
  914. specification: item.specification, // 规格
  915. brandNum: item.brandNum, // 牌号
  916. batchNo: batchNo, // 批次号
  917. supplierListOptions: supplierList[item.id], // 供应商列表
  918. supplierId: this.form.supplierId, // 供应商id
  919. supplierCode: this.bizType == 2 ? filtersItem.supplierMark : item.supplierCode, // 供应商代号
  920. supplierName: this.form.supplierName, // 供应商名称
  921. approvalNumber: item.approvalNumber, // 批准文号
  922. packingSpecification: item.packingSpecification, // 包装规格
  923. packingSpecificationOption: newSpecificationOption[index], // 包装规格选项
  924. packingSpecificationLabel: packingSpecificationLabel, // 包装规格显示
  925. // minPackingQuantity: minPackingQuantity, // 最小包装单元数量
  926. packingQuantity: packingQuantity, // 包装数量
  927. packingUnit: packingUnit, // 单位
  928. measureQuantity: measureQuantity, // 计量数量
  929. measureUnit: item.measuringUnit, // 计量单位
  930. measureType: item.measureType, // 计量方式
  931. netWeight: item.netWeight > -1 ? item.netWeight : 0, // 净重
  932. singleWeight: singleWeight, // 单重重量
  933. weight: weight, // 总重量
  934. weightUnit: item.weightUnit, // 重量单位
  935. totalMoney: totalMoney, // 总价
  936. unitPrice: item.unitPrice || unitPrice, // 单价
  937. pricingWay: pricingWay, //计价方式
  938. purpose: '', // 用途
  939. isUnpack: item.isUnpack, // 是否允许拆包
  940. warehouseId, // 仓库id
  941. warehouseName, // 仓库名称
  942. warehouseIds,
  943. warehouseNames,
  944. qualityControl: filtersItem?.isComeCheck, // 是否需要质检
  945. };
  946. });
  947. console.log(this.productList, 'this.productListtttttttttttt')
  948. this.$nextTick(() => {
  949. this.batchSave();
  950. // this.listSaveArrs()
  951. });
  952. });
  953. }
  954. console.log('this.detailList-----------------', this.detailList)
  955. if (this.detailList?.length > 0) {
  956. if (
  957. this.form != null &&
  958. Object.keys(this.form).length > 0 &&
  959. this.form.categoryLevelTopId != ''
  960. ) {
  961. this.formData.extInfo.assetType = Array.from(
  962. new Set(this.form?.categoryLevelTopId?.split(','))
  963. );
  964. } else {
  965. this.$message.warning('未获取到物品类型!');
  966. }
  967. // 包装列表 this.detailList
  968. // 获取主数据物品详情
  969. // let { category } = await getDetails(this.form.categoryId);
  970. let codeList = this.detailList.map((item) => {
  971. return item.productCode || item.categoryCode;
  972. });
  973. storageApi.getListByNameOrModeType({ codeList }).then(async (res) => {
  974. console.log(res, 'detailList-res')
  975. // 获取批次号
  976. const batchNo = await getCode('lot_number_code');
  977. // 获取供应商
  978. const supplierList = await storageApi.contactQueryByCategoryIdsAPI({
  979. categoryIds: res.map((item) => item.id)
  980. });
  981. // 获取包装规格
  982. let packingSpecification =
  983. await storageApi.getCategoryPackageDisposition({
  984. categoryIds: res.map((item) => item.id)
  985. });
  986. this.packingSpecificationOption = res.map((item) => {
  987. return packingSpecification
  988. .filter((ite) => item.id == ite.categoryId)
  989. .sort((a, b) => a.sort - b.sort);
  990. });
  991. // 获取相同仓库
  992. let warehouseIds = [];
  993. let warehouseNames = [];
  994. for (let index = 0; index < this.form.totalCount; index++) {
  995. warehouseIds.push(this.form.warehouseId);
  996. warehouseNames.push(this.form.warehouseName);
  997. }
  998. if (this.isMoreProduct) {
  999. this.formData.extInfo.assetType = [];
  1000. res.map((item) => {
  1001. this.formData.extInfo.assetType.push(
  1002. item.categoryLevelPathIdParent
  1003. );
  1004. });
  1005. this.formData.extInfo.assetType = Array.from(
  1006. new Set(...this.formData.extInfo.assetType)
  1007. );
  1008. }
  1009. const newSpecificationOption = this.getNewSpecificationOption(this.packingSpecificationOption)
  1010. // 生成产品列表
  1011. this.productList = res.map((item, index) => {
  1012. // 显示规格
  1013. let packingSpecificationLabel = this.packingSpecificationOption[
  1014. index
  1015. ]
  1016. .map((item) => {
  1017. if (item.sort > 0) {
  1018. return `${item.packageCell}${item.packageUnit}/${item.conversionUnit}`;
  1019. }
  1020. })
  1021. .filter((item) => !!item);
  1022. // 换算重量
  1023. let weight = 0;
  1024. if (
  1025. this.form?.weightUnit?.toUpperCase() ==
  1026. item?.weightUnit.toUpperCase()
  1027. ) {
  1028. weight = this.form.totalWeight;
  1029. } else {
  1030. switch (item.weightUnit.toUpperCase()) {
  1031. case 'KG':
  1032. if (this.form.totalWeight > -1) {
  1033. weight = this.$math.format(
  1034. this.form.totalWeight / 1000,
  1035. 14
  1036. );
  1037. } else {
  1038. weight = 0;
  1039. }
  1040. break;
  1041. case 'G':
  1042. if (this.form.totalWeight > -1) {
  1043. weight = this.$math.format(
  1044. this.form.totalWeight * 1000,
  1045. 14
  1046. );
  1047. } else {
  1048. weight = 0;
  1049. }
  1050. break;
  1051. case 'L':
  1052. if (this.form.totalWeight > -1) {
  1053. weight = this.$math.format(
  1054. this.form.totalWeight * 1000,
  1055. 14
  1056. );
  1057. } else {
  1058. weight = 0;
  1059. }
  1060. break;
  1061. case 'l':
  1062. if (this.form.totalWeight > -1) {
  1063. weight = this.$math.format(
  1064. this.form.totalWeight * 1000,
  1065. 14
  1066. );
  1067. } else {
  1068. weight = 0;
  1069. }
  1070. break;
  1071. case 'ML':
  1072. if (this.form.totalWeight > -1) {
  1073. weight = this.$math.format(
  1074. this.form.totalWeight * 1000,
  1075. 14
  1076. );
  1077. } else {
  1078. weight = 0;
  1079. }
  1080. break;
  1081. case 'ml':
  1082. if (this.form.totalWeight > -1) {
  1083. weight = this.$math.format(
  1084. this.form.totalWeight * 1000,
  1085. 14
  1086. );
  1087. } else {
  1088. weight = 0;
  1089. }
  1090. break;
  1091. }
  1092. }
  1093. let packingUnit = item.packingUnit;
  1094. let singleWeight = item.singleWeight || 0; // 单重重量
  1095. return {
  1096. index: this.productList.length + index,
  1097. isSave: true,
  1098. categoryId: item.id, // 物品id
  1099. categoryName: item.name, // 物品名称
  1100. categoryCode: item.code, // 物品编码
  1101. categoryModel: item.modelType, // 物品型号
  1102. specification: item.specification, // 规格
  1103. brandNum: item.brandNum, // 牌号
  1104. batchNo: this.bizType==1?(item.batchNo||batchNo):batchNo, // 批次号
  1105. supplierListOptions: supplierList[item.id], // 供应商列表
  1106. supplierId: '', // 供应商id
  1107. supplierCode: item.supplierCode,
  1108. supplierName: item.supplierName, // 供应商名称
  1109. approvalNumber: item.approvalNumber, // 批准文号
  1110. packingSpecification: item.packingSpecification, // 包装规格
  1111. packingSpecificationOption: newSpecificationOption[index], // 包装规格选项
  1112. packingSpecificationLabel: packingSpecificationLabel, // 包装规格显示
  1113. // minPackingQuantity: 1, // 最小包装单元数量
  1114. packingQuantity: this.isMoreProduct
  1115. ? this.detailList.filter(
  1116. (val) => val.productCode == item.code
  1117. ).length
  1118. : this.detailList.length || this.form.detailList.length, // 包装数量
  1119. packingUnit: packingUnit, // 单位
  1120. measureQuantity: this.isMoreProduct
  1121. ? this.getMeasureQuantity(item.code)
  1122. : this.form.totalCount, // 计量数量
  1123. measureUnit: item.measuringUnit, // 计量单位
  1124. measureType: item.measureType, // 计量方式
  1125. netWeight: item.netWeight > -1 ? item.netWeight : 0, // 净重
  1126. weight: weight, // 重量
  1127. singleWeight: singleWeight,
  1128. weightUnit: item.weightUnit, // 重量单位
  1129. totalMoney: item.totalPrice, // 总价
  1130. unitPrice: item.unitPrice, // 单价
  1131. purpose: '', // 用途
  1132. isUnpack: item.isUnpack, // 是否允许拆包
  1133. warehouseId: this.isMoreProduct
  1134. ? this.detailList.find((val) => val.productCode == item.code)
  1135. ?.warehouseId
  1136. : this.form.warehouseId, // 仓库id
  1137. warehouseName: this.isMoreProduct
  1138. ? this.detailList.find((val) => val.productCode == item.code)
  1139. ?.warehouseName
  1140. : this.form.warehouseName, // 仓库名称
  1141. warehouseIds: this.isMoreProduct
  1142. ? this.detailList
  1143. .filter((val) => val.productCode == item.code)
  1144. .map((item) => item.warehouseId)
  1145. : warehouseIds,
  1146. warehouseNames: this.isMoreProduct
  1147. ? this.detailList
  1148. .filter((val) => val.productCode == item.code)
  1149. .map((item) => item.warehouseName)
  1150. : warehouseNames
  1151. };
  1152. });
  1153. let getAssetNumPr = this.isMoreProduct
  1154. ? this.detailList.map((val) => {
  1155. return {
  1156. assetCode: val.productCode,
  1157. batchNum: val.productBrand,
  1158. num: 1
  1159. };
  1160. })
  1161. : [
  1162. {
  1163. assetCode:
  1164. this.productList[0].categoryCode +
  1165. this.productList[0].index,
  1166. batchNum: this.productList[0].batchNo,
  1167. num: this.detailList.length
  1168. }
  1169. ];
  1170. console.log(this.productList, 'this.productList')
  1171. console.log(this.detailList, 'this.detailList')
  1172. // 生成包装编码
  1173. const { data } = await storageApi.getAssetNum(getAssetNumPr);
  1174. let packingCodeList = data;
  1175. // 生产包装
  1176. this.packingList = this.detailList.map((item, index) => {
  1177. console.log(item.packingUnit, 'itemitemitemitemitemitem2')
  1178. // 换算重量
  1179. let weight = 0;
  1180. if (
  1181. this.productList[0].weightUnit.toUpperCase() ==
  1182. item.weightUnit.toUpperCase()
  1183. ) {
  1184. weight = this.form.totalWeight;
  1185. } else {
  1186. switch (this.productList[0].weightUnit.toUpperCase()) {
  1187. case 'KG':
  1188. if (item.weightUnit > -1) {
  1189. weight = this.$math.format(item.weightUnit / 1000, 14);
  1190. } else {
  1191. weight = 0;
  1192. }
  1193. break;
  1194. case 'G':
  1195. if (item.weightUnit > -1) {
  1196. weight = this.$math.format(item.weightUnit * 1000, 14);
  1197. } else {
  1198. weight = 0;
  1199. }
  1200. break;
  1201. case 'L':
  1202. if (item.weightUnit > -1) {
  1203. weight = this.$math.format(item.weightUnit / 1000, 14);
  1204. } else {
  1205. weight = 0;
  1206. }
  1207. break;
  1208. case 'l':
  1209. if (item.weightUnit > -1) {
  1210. weight = this.$math.format(item.weightUnit / 1000, 14);
  1211. } else {
  1212. weight = 0;
  1213. }
  1214. break;
  1215. case 'ML':
  1216. if (item.weightUnit > -1) {
  1217. weight = this.$math.format(item.weightUnit / 1000, 14);
  1218. } else {
  1219. weight = 0;
  1220. }
  1221. break;
  1222. case 'ml':
  1223. if (item.weightUnit > -1) {
  1224. weight = this.$math.format(item.weightUnit / 1000, 14);
  1225. } else {
  1226. weight = 0;
  1227. }
  1228. break;
  1229. }
  1230. }
  1231. // 代入时间
  1232. let obj = this.getNowDate();
  1233. let productionDate = '';
  1234. let purchaseDate = '';
  1235. if (this.formData.bizType == '1') {
  1236. // 生产入库
  1237. productionDate = `${obj.year}-${obj.month}-${obj.strDate} ${obj.hour}:${obj.minute}:${obj.second}`;
  1238. this.curDateType = 'productionDate';
  1239. } else if (this.formData.bizType == '2') {
  1240. // 采购入库
  1241. const defaultTime = '00:00:00';
  1242. purchaseDate = `${this.form.receiveDate} ${defaultTime}`;
  1243. this.curDateType = 'purchaseDate';
  1244. }
  1245. let clientCode = ''
  1246. if (this.bizType == 2) {
  1247. clientCode = item.customerMark
  1248. } else if (this.bizType != 2) {
  1249. clientCode = item.clientCode || item.extInfo?.clientCode
  1250. }
  1251. return {
  1252. index: this.isMoreProduct
  1253. ? this.productList.find(
  1254. (val) => val.categoryCode == item.productCode
  1255. ).index +
  1256. '-' +
  1257. index
  1258. : this.productList[0].index + '-' + index, // 包装索引
  1259. warehouseId:
  1260. item.warehouseId || this.productList[0].warehouseIds[index], // 仓库id
  1261. warehouseName:
  1262. item.warehouseName ||
  1263. this.productList[0].warehouseNames[index], // 仓库名称
  1264. categoryName:
  1265. item.productName || this.productList[0].categoryName, // 产品名称
  1266. categoryCode:
  1267. item.productCode || this.productList[0].categoryCode, // 产品编码
  1268. categoryModel:
  1269. item.modelType || this.productList[0].categoryModel, // 物品型号
  1270. specification:
  1271. item.specification || this.productList[0].specification, // 规格
  1272. brandNum: item.productBrand || this.productList[0].brandNum, // 牌号
  1273. parentIndex: this.isMoreProduct
  1274. ? this.productList.find(
  1275. (val) => val.categoryCode == item.productCode
  1276. ).index
  1277. : this.productList[0].index, // 产品索引
  1278. batchNo: this.productList[0].batchNo, // 批次号
  1279. packageNo: item.packageNo || packingCodeList[index]?.onlyCode, // 包装编码
  1280. packingQuantity: 1, // 包装数量
  1281. packingUnit: item.packingUnit, // 单位
  1282. measureQuantity: item.quantity, // 计量数量
  1283. measureUnit: item.measuringUnit, // 计量单位
  1284. weight: item.packingWeight, // 重量
  1285. singleWeight: item.singleWeight,
  1286. pricingWay: item.pricingWay,
  1287. weightUnit: item.weightUnit || this.productList[0].weightUnit, // 重量单位
  1288. packingSpecificationOption: this.isMoreProduct
  1289. ? this.productList.find(
  1290. (val) => val.categoryCode == item.productCode
  1291. )?.packingSpecificationOption
  1292. : this.productList[0].packingSpecificationOption, // 包装规格
  1293. netWeight: this.productList[0].netWeight, // 净重
  1294. barcodes: item.barcodes || item.sendCode, // 发货条码
  1295. clientCode: clientCode, // 客户代号
  1296. materielDesignation:
  1297. item.materielDesignation || item.extInfo?.materielCode, // 物料代号
  1298. engrave: item.engrave || item.extInfo?.engrave, // 刻码
  1299. isUnpack: this.productList[0].isUnpack, // 是否允许拆包
  1300. productionDate: productionDate, // 生产日期
  1301. purchaseDate: purchaseDate, // 采购时间
  1302. result: 1, // 结果(1合格 2不合格)
  1303. status: 2,// 状态(0=未质检 1待检 2已检)
  1304. serialNumber: item.productSequence, // 产品序号
  1305. };
  1306. });
  1307. console.log(this.packingList, '包装明细列表')
  1308. });
  1309. }
  1310. },
  1311. //获取计量数量
  1312. getMeasureQuantity(code) {
  1313. let measureQuantity = 0;
  1314. this.detailList.forEach((item) => {
  1315. if (code == item.productCode) {
  1316. measureQuantity += item.quantity;
  1317. }
  1318. });
  1319. return measureQuantity;
  1320. },
  1321. //多产品明细获取批次号 ys
  1322. // getBatch(code) {
  1323. // let batch=''
  1324. // console.log(this.productList,'this.productList')
  1325. // this.productList.forEach((item) => {
  1326. // if (code == item.) {
  1327. // batch =item.batchNo
  1328. // }
  1329. // });
  1330. // return batch
  1331. // },
  1332. //多产品明细数据转换
  1333. async getDetailsVal(code, productBrand) {
  1334. const { data } = await storageApi.getAssetNum([
  1335. {
  1336. assetCode: code,
  1337. batchNum: 1,
  1338. num: 1
  1339. }
  1340. ]);
  1341. return data[0].onlyCode;
  1342. },
  1343. // 获取当前时间函数
  1344. getNowDate() {
  1345. let date = new Date(),
  1346. obj = {
  1347. year: date.getFullYear(), //获取当前月份(0-11,0代表1月)
  1348. month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
  1349. strDate: date.getDate(), // 获取当前日(1-31)
  1350. hour: date.getHours(), //获取当前小时(0 ~ 23)
  1351. minute: date.getMinutes(), //获取当前分钟(0 ~ 59)
  1352. second: date.getSeconds() //获取当前秒数(0 ~ 59)
  1353. };
  1354. Object.keys(obj).forEach((key) => {
  1355. if (obj[key] < 10) obj[key] = `0${obj[key]}`;
  1356. });
  1357. return obj;
  1358. },
  1359. // 赋值入库时间
  1360. getNowFormatDate() {
  1361. const obj = this.getNowDate();
  1362. const defaultTime = '00:00:00';
  1363. const currentTime = `${obj.hour}:${obj.minute}:${obj.second}`;
  1364. if (this.bizType === 2 || this.bizType === '2' || this.bizType === 6 || this.bizType === '6') {
  1365. this.formData.storageTime = this.form.receiveDate
  1366. ? `${this.form.receiveDate} ${defaultTime}`
  1367. : `${obj.year}-${obj.month}-${obj.strDate} ${currentTime}`;
  1368. } else {
  1369. this.formData.storageTime = `${obj.year}-${obj.month}-${obj.strDate} ${currentTime}`;
  1370. }
  1371. },
  1372. // 获取物品列表
  1373. async getListItems() {
  1374. const { data } = await getTreeByGroup({ type: 2 });
  1375. this.goodsLists = data;
  1376. },
  1377. // 打开单据来源弹窗
  1378. openDocumentSourceDialog() {
  1379. console.log('打开单据来源弹窗');
  1380. },
  1381. // 清除单据来源
  1382. clearDocumentSource() {
  1383. this.formData.sourceBizNo = '';
  1384. },
  1385. // 添加产品
  1386. addProduct() {
  1387. if (this.formData.extInfo.assetType.length <= 0) {
  1388. return this.$message.error('请选择物品类型');
  1389. }
  1390. if (!this.formData.bizType) {
  1391. return this.$message.error('请选择入库类型');
  1392. }
  1393. this.visibleDialog = true;
  1394. },
  1395. // 键盘移动
  1396. moveFocus(event, index, key, type, row) {
  1397. let keyfield = [];
  1398. let listLength = 0;
  1399. switch (type) {
  1400. case '产品':
  1401. listLength = this.productList.length;
  1402. keyfield = ['batchNo', 'packingQuantity', 'unitPrice', 'purpose'];
  1403. break;
  1404. case '包装':
  1405. listLength = this.showPackingList.length;
  1406. if (row.measureUnit != row.weightUnit) {
  1407. keyfield = [
  1408. 'packing_materielDesignation',
  1409. 'packing_clientCode',
  1410. 'packing_engrave',
  1411. 'packing_weight'
  1412. ];
  1413. } else {
  1414. keyfield = [
  1415. 'packing_materielDesignation',
  1416. 'packing_clientCode',
  1417. 'packing_engrave'
  1418. ];
  1419. }
  1420. break;
  1421. case '物料':
  1422. listLength = this.showMaterialList.length;
  1423. if (row.measureUnit != row.weightUnit) {
  1424. keyfield = [
  1425. 'material_materielDesignation',
  1426. 'material_clientCode',
  1427. 'material_engrave',
  1428. 'material_weight'
  1429. ];
  1430. } else {
  1431. keyfield = [
  1432. 'material_materielDesignation',
  1433. 'material_clientCode',
  1434. 'material_engrave'
  1435. ];
  1436. }
  1437. break;
  1438. }
  1439. if (event.keyCode === 13) {
  1440. // 回车
  1441. if (
  1442. index === listLength - 1 &&
  1443. key === keyfield[keyfield.length - 1]
  1444. ) {
  1445. // 最后一行最后一个
  1446. return;
  1447. }
  1448. this.$refs[key + index].blur();
  1449. if (key === keyfield[keyfield.length - 1]) {
  1450. // 当前行最后一个,跳转下一行第一个
  1451. if (this.$refs[keyfield[0] + (index + 1)].value == 0) {
  1452. this.$refs[keyfield[0] + (index + 1)].value = '';
  1453. }
  1454. this.$refs[keyfield[0] + (index + 1)].focus();
  1455. } else {
  1456. // 跳转下一个
  1457. const nextkeyindex = keyfield.findIndex((k) => k === key) + 1;
  1458. this.$nextTick(() => {
  1459. if (this.$refs[keyfield[nextkeyindex] + index].value == 0) {
  1460. this.$refs[keyfield[nextkeyindex] + index].value = '';
  1461. }
  1462. this.$refs[keyfield[nextkeyindex] + index].focus();
  1463. });
  1464. }
  1465. }
  1466. // 向上 =38
  1467. if (event.keyCode === 38) {
  1468. if (index === 0) {
  1469. // 第一行
  1470. return;
  1471. }
  1472. this.$refs[key + index].blur();
  1473. this.$nextTick(() => {
  1474. if (this.$refs[key + (index - 1)].value == 0) {
  1475. this.$refs[key + (index - 1)].value = '';
  1476. }
  1477. this.$refs[key + (index - 1)].focus();
  1478. });
  1479. }
  1480. // 下 = 40
  1481. if (event.keyCode === 40) {
  1482. if (index === listLength - 1) {
  1483. // 最后一行
  1484. return;
  1485. }
  1486. this.$refs[key + index].blur();
  1487. this.$nextTick(() => {
  1488. if (this.$refs[key + (index + 1)].value == 0) {
  1489. this.$refs[key + (index + 1)].value = '';
  1490. }
  1491. this.$refs[key + (index + 1)].focus();
  1492. });
  1493. }
  1494. // 左 = 37
  1495. if (event.keyCode === 37) {
  1496. console.log('向左');
  1497. if (index === 0 && key === keyfield[0]) {
  1498. // 第一行第一个
  1499. console.log('第一行第一个无法向左');
  1500. return;
  1501. }
  1502. this.$refs[key + index].blur();
  1503. if (key === keyfield[0]) {
  1504. if (
  1505. this.$refs[keyfield[keyfield.length - 1] + (index - 1)].value == 0
  1506. ) {
  1507. this.$refs[keyfield[keyfield.length - 1] + (index - 1)].value =
  1508. '';
  1509. }
  1510. // 当前行第一个,跳转上一行最后一个
  1511. this.$refs[keyfield[keyfield.length - 1] + (index - 1)].focus();
  1512. } else {
  1513. // 跳转上一个
  1514. const prevkeyindex = keyfield.findIndex((k) => k === key) - 1;
  1515. this.$nextTick(() => {
  1516. if (this.$refs[keyfield[prevkeyindex] + index].value == 0) {
  1517. this.$refs[keyfield[prevkeyindex] + index].value = '';
  1518. }
  1519. this.$refs[keyfield[prevkeyindex] + index].focus();
  1520. });
  1521. }
  1522. }
  1523. // 右 = 39
  1524. if (event.keyCode === 39) {
  1525. if (
  1526. index === listLength - 1 &&
  1527. key === keyfield[keyfield.length - 1]
  1528. ) {
  1529. // 最后一行最后一个
  1530. return;
  1531. }
  1532. this.$refs[key + index].blur();
  1533. if (key === keyfield[keyfield.length - 1]) {
  1534. // 当前行最后一个,跳转下一行第一个
  1535. if (this.$refs[keyfield[0] + (index + 1)].value == 0) {
  1536. this.$refs[keyfield[0] + (index + 1)].value = '';
  1537. }
  1538. this.$refs[keyfield[0] + (index + 1)].focus();
  1539. } else {
  1540. // 跳转下一个
  1541. const nextkeyindex = keyfield.findIndex((k) => k === key) + 1;
  1542. this.$nextTick(() => {
  1543. if (this.$refs[keyfield[nextkeyindex] + index].value == 0) {
  1544. this.$refs[keyfield[nextkeyindex] + index].value = '';
  1545. }
  1546. this.$refs[keyfield[nextkeyindex] + index].focus();
  1547. });
  1548. }
  1549. }
  1550. },
  1551. // 入库
  1552. getReturnStorage() {
  1553. if (this.productList.length <= 0) {
  1554. this.$message.error('请先添加产品信息');
  1555. return;
  1556. }
  1557. let boolen = this.productList.every((item) => item.isSave);
  1558. if (!boolen) {
  1559. this.$message.error('请先保存所有产品信息');
  1560. return;
  1561. }
  1562. // 处理包装数据
  1563. let _packingList = [];
  1564. _packingList = this.packingList.map((packingItem) => {
  1565. let _taskId = null;
  1566. let _workOrderId = null;
  1567. if ([1].includes(this.bizType)) {
  1568. _workOrderId = this.detailList[0]?.workOrderId;
  1569. _taskId = this.detailList[0]?.taskId;
  1570. } else {
  1571. _workOrderId = this.detailProductList[0]?.workOrderId;
  1572. _taskId = this.detailProductList[0]?.taskId;
  1573. }
  1574. return {
  1575. ...packingItem,
  1576. workOrderId: _workOrderId,
  1577. taskId: _taskId,
  1578. outsourceBatchNo: this.detailProductList[0]?.batchNo,
  1579. outsourceCode: this.detailProductList[0]?.sourceCode,
  1580. materialDetailList: this.materialList.filter(
  1581. (item) => item.parentIndex === packingItem.index
  1582. )
  1583. };
  1584. });
  1585. // 处理产品数据
  1586. this.productList = this.productList.map((productItem) => {
  1587. return {
  1588. ...productItem,
  1589. outInDetailRecordRequestList: _packingList.filter(
  1590. (item) => item.parentIndex === productItem.index
  1591. )
  1592. };
  1593. });
  1594. this.formData.outInDetailList = this.productList;
  1595. let obj = deepClone(this.formData);
  1596. // 处理物品类型assetType
  1597. obj.extInfo.assetType = obj.extInfo.assetType.join(',');
  1598. obj.extInfo.documentSource = this.formData.sourceBizNo;
  1599. obj.extInfo.deptName = this.formData.extInfo.deptName;
  1600. obj.extInfo.supplierName = this.form.supplierName;
  1601. obj.extInfo.deliveryPhone = this.formData.extInfo.deliveryPhone;
  1602. // 处理仓库id
  1603. let warehouseId = [];
  1604. let warehouseName = [];
  1605. let warehouseIds = this.productList
  1606. .map((item) => item.warehouseIds)
  1607. .flat();
  1608. let warehouseNames = this.productList
  1609. .map((item) => item.warehouseNames)
  1610. .flat();
  1611. warehouseIds.forEach((item, index) => {
  1612. if (!warehouseId.includes(item)) {
  1613. warehouseId.push(item);
  1614. warehouseName.push(warehouseNames[index]);
  1615. }
  1616. });
  1617. obj.warehouseIds = warehouseId;
  1618. obj.warehouseNames = warehouseName;
  1619. obj._packingList = _packingList;
  1620. // setTimeout(() => {
  1621. // resolve(obj);
  1622. // }, 1000);
  1623. console.log(obj, 'obj')
  1624. return obj;
  1625. },
  1626. pickingHandleScroll() {
  1627. if (this.showPackingList.length < this.packingList.length) {
  1628. if (this.packingList.length > this.pageSize) {
  1629. this.pickingPageNum += 1;
  1630. }
  1631. this.pickingFetchData();
  1632. }
  1633. },
  1634. pickingFetchData() {
  1635. const start = (this.pickingPageNum - 1) * this.pageSize;
  1636. const end = start + this.pageSize;
  1637. this.showPackingList = this.showPackingList.concat(
  1638. this.packingList.slice(start, end)
  1639. );
  1640. },
  1641. materielHandleScroll() {
  1642. if (this.showMaterialList.length < this.materialList.length) {
  1643. if (this.materialList.length > this.pageSize) {
  1644. this.materielPageNum += 1;
  1645. }
  1646. this.materielFetchData();
  1647. }
  1648. },
  1649. materielFetchData() {
  1650. const start = (this.materielPageNum - 1) * this.pageSize;
  1651. const end = start + this.pageSize;
  1652. this.showMaterialList = this.showMaterialList.concat(
  1653. this.materialList.slice(start, end)
  1654. );
  1655. },
  1656. // 日期选择
  1657. dateConfirm() {
  1658. this.packingListSelected.forEach((item) => {
  1659. this.$set(item, this.curDateType, this.batchTime);
  1660. });
  1661. this.batchTime = '';
  1662. this.dateVisible = false;
  1663. },
  1664. // 包装重量修改
  1665. packingWeightCahnge(value, row) {
  1666. // 修改物品重量
  1667. let filterPackingList = this.packingList.filter((item) => {
  1668. return item.parentIndex === row.parentIndex;
  1669. });
  1670. let productIndex = this.productList.findIndex((item) => {
  1671. return item.index === row.parentIndex;
  1672. });
  1673. let totalWeight = filterPackingList.reduce(
  1674. (accumulator, currentValue) => {
  1675. return this.$math.format(+accumulator + +currentValue.weight, 14);
  1676. },
  1677. 0
  1678. );
  1679. this.$set(this.productList[productIndex], 'weight', totalWeight);
  1680. this.$set(
  1681. this.productList[productIndex],
  1682. 'singleWeight',
  1683. totalWeight / this.productList[productIndex].measureQuantity
  1684. );
  1685. // 修改拆分物料
  1686. this.materialList.map((item, index) => {
  1687. if (item.parentIndex === row.index) {
  1688. this.$set(
  1689. this.materialList[index],
  1690. 'weight',
  1691. this.$math.format(value / row.measureQuantity, 14) >= 0
  1692. ? this.$math.format(value / row.measureQuantity, 14)
  1693. : 0
  1694. );
  1695. }
  1696. });
  1697. },
  1698. // 物料重量修改
  1699. materialWeightCahnge(row) {
  1700. // 修改包装重量
  1701. let filterMaterialList = this.materialList.filter((item) => {
  1702. return item.parentIndex === row.parentIndex;
  1703. });
  1704. let packingIndex = this.packingList.findIndex((item) => {
  1705. return item.index === row.parentIndex;
  1706. });
  1707. let totalMaterialWeight = filterMaterialList.reduce(
  1708. (accumulator, currentValue) => {
  1709. return this.$math.format(+accumulator + +currentValue.weight, 14);
  1710. },
  1711. 0
  1712. );
  1713. this.$set(
  1714. this.packingList[packingIndex],
  1715. 'weight',
  1716. totalMaterialWeight
  1717. );
  1718. // 修改物品重量
  1719. let filterPackingList = this.packingList.filter((item) => {
  1720. return (
  1721. item.parentIndex === this.packingList[packingIndex].parentIndex
  1722. );
  1723. });
  1724. let productIndex = this.productList.findIndex((item) => {
  1725. return item.index === this.packingList[packingIndex].parentIndex;
  1726. });
  1727. let totalWeight = filterPackingList.reduce(
  1728. (accumulator, currentValue) => {
  1729. return this.$math.format(+accumulator + +currentValue.weight, 14);
  1730. },
  1731. 0
  1732. );
  1733. this.$set(this.productList[productIndex], 'weight', totalWeight);
  1734. },
  1735. // 包装质检结果修改
  1736. packingResultCahnge(value, row) {
  1737. // 修改物料质检结果(0无 1合格 2不合格 3让步接收)
  1738. this.materialList.map((item, index) => {
  1739. if (item.parentIndex === row.index) {
  1740. this.$set(this.materialList[index], 'result', value);
  1741. this.$set(this.materialList[index], 'status', 2);
  1742. }
  1743. });
  1744. },
  1745. // 物料质量结果修改
  1746. materialResultCahnge(value, row) {
  1747. // 修改包装质检结果
  1748. let filterMaterialList = this.materialList.filter((item) => {
  1749. return item.parentIndex == row.parentIndex;
  1750. });
  1751. let packingIndex = this.packingList.findIndex((item) => {
  1752. return item.index == row.parentIndex;
  1753. });
  1754. let boolen = filterMaterialList.every((item) => {
  1755. return item.result == 1;
  1756. });
  1757. this.$set(this.packingList[packingIndex], 'result', boolen ? 1 : 2);
  1758. this.$set(this.packingList[packingIndex], 'status', 2);
  1759. },
  1760. // 重量限制
  1761. weightInput(value, row, type) {
  1762. const newValue = value.replace(/[^\d.]/g, ''); // 保留数字和小数点
  1763. const decimalCount = (newValue.match(/\./g) || []).length; // 计算小数点的个数
  1764. if (row.weight < 0) {
  1765. row.weight = 0;
  1766. } else if (row.weight > 9999) {
  1767. row.weight = 9999;
  1768. } else {
  1769. if (decimalCount > 1) {
  1770. // 如果小数点个数大于1,移除多余的小数点
  1771. const lastIndex = newValue.lastIndexOf('.');
  1772. row.weight =
  1773. newValue.slice(0, lastIndex) + newValue.slice(lastIndex + 1);
  1774. } else if (decimalCount === 1) {
  1775. // 如果小数点个数等于1,允许小数点的输入
  1776. row.weight = newValue;
  1777. } else {
  1778. row.weight = newValue === '' ? 0 : parseFloat(newValue); // 如果输入为空,则设为0
  1779. }
  1780. }
  1781. if (type === '包装') {
  1782. this.packingWeightCahnge(value, row);
  1783. } else {
  1784. this.materialWeightCahnge(row);
  1785. }
  1786. },
  1787. //计算金额
  1788. calcSumTotal(measureQuantity, unitPrice, row) {
  1789. //最小包装单元,包装数量,单价
  1790. if (this.bizType != 2) {
  1791. const total = {
  1792. measureQuantity: Number(measureQuantity > 0 ? measureQuantity : 0),
  1793. unitPrice: Number(unitPrice > 0 ? unitPrice : 0)
  1794. };
  1795. let number = Number(
  1796. this.$math.format(total.measureQuantity * total.unitPrice, 14)
  1797. );
  1798. row.totalMoney = number;
  1799. return number;
  1800. } else {
  1801. return row.totalMoney;
  1802. }
  1803. },
  1804. // 包装维度最小包装单元改变——>总重量
  1805. minPackingQuantityChange(row, value, index) {
  1806. if (row.measureUnit !== 'KG') {
  1807. if (value.replace(/^(0+)|[^\d]+/g, '') > 9999) {
  1808. this.$set(this.productList[index], 'minPackingQuantity', 9999);
  1809. } else {
  1810. this.$set(
  1811. this.productList[index],
  1812. 'minPackingQuantity',
  1813. value.replace(/^(0+)|[^\d]+/g, '')
  1814. );
  1815. }
  1816. } else {
  1817. if (value < 1) {
  1818. this.$set(this.productList[index], 'minPackingQuantity', 1);
  1819. } else if (value > 9999) {
  1820. this.$set(this.productList[index], 'minPackingQuantity', 9999);
  1821. }
  1822. }
  1823. if (row.packingQuantity >= 0 && value >= 0) {
  1824. this.packNum(row, row.packingQuantity, index);
  1825. }
  1826. },
  1827. // 包装数量过滤处理改变——>总重量
  1828. packNum(row, value, index) {
  1829. const total = {
  1830. minPackingQuantity: Number(
  1831. row.minPackingQuantity > 0
  1832. ? row.minPackingQuantity > 9999
  1833. ? 9999
  1834. : row.minPackingQuantity
  1835. : 0
  1836. ),
  1837. packingQuantity: Number(
  1838. row.packingQuantity > 0
  1839. ? row.packingQuantity > 9999
  1840. ? 9999
  1841. : row.packingQuantity
  1842. : 0
  1843. )
  1844. };
  1845. const totals = Number(
  1846. this.$math.format(
  1847. total.minPackingQuantity * total.packingQuantity,
  1848. 14
  1849. )
  1850. );
  1851. if (row.measureUnit == row.weightUnit) {
  1852. row.weight = Number(
  1853. this.$math.format(
  1854. total.minPackingQuantity *
  1855. 1 *
  1856. Number(total.packingQuantity).toFixed(2),
  1857. 14
  1858. )
  1859. );
  1860. } else {
  1861. row.weight = Number(
  1862. this.$math.format(
  1863. totals *
  1864. (row.netWeight > 0 ? Number(row.netWeight).toFixed(2) : 0),
  1865. 14
  1866. )
  1867. );
  1868. }
  1869. this.$set(this.productList[index], 'measureQuantity', totals);
  1870. // 清空仓库
  1871. this.$set(this.productList[index], 'warehouseId', '');
  1872. this.$set(this.productList[index], 'warehouseName', '');
  1873. if (value.replace(/^(0+)|[^\d]+/g, '') > 9999) {
  1874. this.$set(this.productList[index], 'packingQuantity', 9999);
  1875. } else {
  1876. this.$set(
  1877. this.productList[index],
  1878. 'packingQuantity',
  1879. value.replace(/^(0+)|[^\d]+/g, '')
  1880. );
  1881. }
  1882. // return (row.packingQuantity = value.replace(/^(0+)|[^\d]+/g, ''));
  1883. },
  1884. // 表格样式
  1885. rowClass({ row, column, rowIndex, columnIndex }) {
  1886. if (rowIndex === 1) {
  1887. return {
  1888. display: 'none',
  1889. background: '#EEEEEE'
  1890. };
  1891. }
  1892. return { background: '#0000' };
  1893. },
  1894. //过滤掉单位下拉框 相同的单位
  1895. getNewSpecificationOption(packingSpecificationOption) {
  1896. return packingSpecificationOption
  1897. return packingSpecificationOption.map(arr => {
  1898. return arr.reduce((acc, current) => {
  1899. const conversionUnit = current.conversionUnit;
  1900. if (!acc.some(item => item.conversionUnit === conversionUnit)) {
  1901. acc.push(current);
  1902. }
  1903. return acc;
  1904. }, []);
  1905. });
  1906. },
  1907. // 添加物品明细
  1908. async addGoods(data) {
  1909. // 获取批次号
  1910. const batchNo = await getCode('lot_number_code');
  1911. // 获取供应商
  1912. const supplierList = await storageApi.contactQueryByCategoryIdsAPI({
  1913. categoryIds: data.map((item) => item.id)
  1914. });
  1915. // 获取包装规格
  1916. let packingSpecification =
  1917. await storageApi.getCategoryPackageDisposition({
  1918. categoryIds: data.map((item) => item.id)
  1919. });
  1920. this.packingSpecificationOption = data.map((item) => {
  1921. return packingSpecification
  1922. .filter((ite) => item.id == ite.categoryId)
  1923. .sort((a, b) => a.sort - b.sort);
  1924. });
  1925. const newSpecificationOption = this.getNewSpecificationOption(this.packingSpecificationOption)
  1926. let productList = data.map((item, index) => {
  1927. // 显示规格
  1928. let packingSpecificationLabel = this.packingSpecificationOption[index]
  1929. .map((item) => {
  1930. if (item.sort > 0) {
  1931. return `${item.packageCell}${item.packageUnit}/${item.conversionUnit}`;
  1932. }
  1933. })
  1934. .filter((item) => !!item);
  1935. return {
  1936. index:
  1937. this.productList.length - 1 > -1
  1938. ? this.productList[this.productList.length - 1].index +
  1939. index +
  1940. 1
  1941. : this.productList.length + index,
  1942. categoryId: item.id, // 物品id
  1943. categoryName: item.name, // 物品名称
  1944. categoryCode: item.code, // 物品编码
  1945. categoryModel: item.modelType, // 物品型号
  1946. specification: item.specification, // 规格
  1947. brandNum: item.brandNum, // 牌号
  1948. batchNo: batchNo, // 批次号
  1949. supplierListOptions: supplierList[item.id], // 供应商列表
  1950. supplierId: '', // 供应商id
  1951. supplierCode: item.supplierCode, // 供应商代号
  1952. supplierName: item.supplierName, // 供应商名称
  1953. measureType: item.measureType, // 计量类型
  1954. approvalNumber: item.approvalNumber, // 批准文号
  1955. packingSpecification: item.packingSpecification, // 包装规格
  1956. packingSpecificationOption: newSpecificationOption[index], // 包装规格选项
  1957. packingSpecificationLabel: packingSpecificationLabel, // 包装规格显示
  1958. minPackingQuantity: '', // 最小包装单元数量
  1959. packingQuantity: '', // 包装数量
  1960. packingUnit: item.measuringUnit, // 单位
  1961. packingUnitId:newSpecificationOption[index].find(v=>v.conversionUnit==item.measuringUnit)?.id, // 单位
  1962. measureQuantity: 0, // 计量数量
  1963. measureUnit: item.measuringUnit, // 计量单位
  1964. netWeight: item.netWeight > -1 ? item.netWeight : 0, // 净重
  1965. weight: 0, // 重量
  1966. singleWeight: item.measuringUnit != 'KG' ? item.netWeight : 0, // 单重
  1967. pricingWay: item.pricingWay,
  1968. weightUnit: item.weightUnit, // 重量单位
  1969. totalMoney: item.totalPrice, // 总价
  1970. unitPrice: item.unitPrice, // 单价
  1971. purpose: '', // 用途
  1972. isUnpack: item.isUnpack // 是否允许拆包
  1973. };
  1974. });
  1975. this.productList = this.productList.concat(productList);
  1976. },
  1977. // 物品保存验证表单(批量)
  1978. validateForm() {
  1979. return new Promise(async (resolve, reject) => {
  1980. let list = this.productList.map(async (row, index) => {
  1981. let fileds = [
  1982. `productList.${index}.batchNo`,
  1983. `productList.${index}.packingQuantity`,
  1984. `productList.${index}.packingUnit`,
  1985. `productList.${index}.warehouseId`
  1986. ];
  1987. if (row.isSave) {
  1988. return Promise.resolve(true);
  1989. } else {
  1990. return await Promise.all(
  1991. fileds.map(
  1992. (item) =>
  1993. new Promise(async (res, rej) => {
  1994. this.$refs.productListRef.validateField(item, (err) => {
  1995. if (err) {
  1996. rej(err);
  1997. } else {
  1998. res(true);
  1999. }
  2000. });
  2001. })
  2002. )
  2003. );
  2004. }
  2005. });
  2006. Promise.all(list)
  2007. .then(() => {
  2008. console.log('保存成功!');
  2009. resolve();
  2010. })
  2011. .catch((err) => {
  2012. console.log('保存失败!');
  2013. this.$message.error('请填入必填项!');
  2014. reject(err);
  2015. });
  2016. });
  2017. },
  2018. // 产品批量保存
  2019. async listSaveArrs() {
  2020. this.validateForm()
  2021. .then(async () => {
  2022. // 批量获取包装编码并处理
  2023. let packingCodePrams = this.productList.map((row) => {
  2024. // 判断单位和计量单位是否为不拆物料层规格
  2025. let packingBoolen = !!this.getDict(
  2026. '不拆物料层规格',
  2027. row.packingUnit
  2028. ).dictValue;
  2029. let measureBoolen = !!this.getDict(
  2030. '不拆物料层规格',
  2031. row.measureUnit
  2032. ).dictValue;
  2033. let num = 0;
  2034. if (packingBoolen) {
  2035. let filterArr = row.packingSpecificationOption.filter(
  2036. (item) => {
  2037. return (
  2038. item.packageUnit == row.packingUnit &&
  2039. item.packageUnit != item.conversionUnit
  2040. );
  2041. }
  2042. );
  2043. num = Math.ceil(row.packingQuantity / filterArr[0].packageCell);
  2044. }
  2045. if (row.isSave) {
  2046. return {};
  2047. } else {
  2048. // 处理单位为KG类的情况
  2049. if (packingBoolen) {
  2050. return {
  2051. assetCode: row.categoryCode + row.index,
  2052. batchNum: row.batchNo,
  2053. num
  2054. };
  2055. } else {
  2056. if (row.isUnpack == 1) {
  2057. if (measureBoolen) {
  2058. // 处理单位不为KG类,计量单位为KG类的情况
  2059. let num = row.packingQuantity;
  2060. let splitIndex = row.packingSpecificationOption.findIndex(
  2061. (item) =>
  2062. item.conversionUnit == row.packingUnit &&
  2063. item.packageUnit != item.conversionUnit
  2064. );
  2065. for (; splitIndex > 1; splitIndex--) {
  2066. num = this.$math.format(
  2067. num *
  2068. row.packingSpecificationOption[splitIndex]
  2069. .packageCell,
  2070. 14
  2071. );
  2072. }
  2073. return {
  2074. assetCode: row.categoryCode + row.index,
  2075. batchNum: row.batchNo,
  2076. num
  2077. };
  2078. } else {
  2079. // 处理拆包到最小包装单元数量的情况
  2080. return {
  2081. assetCode: row.categoryCode + row.index,
  2082. batchNum: row.batchNo,
  2083. num: row.measureQuantity
  2084. };
  2085. }
  2086. } else {
  2087. return {
  2088. assetCode: row.categoryCode + row.index,
  2089. batchNum: row.batchNo,
  2090. num
  2091. };
  2092. }
  2093. }
  2094. }
  2095. });
  2096. let filterPackingCodePrams = packingCodePrams.filter(
  2097. (item) => item.assetCode
  2098. );
  2099. let { data } = await storageApi.getAssetNum(filterPackingCodePrams);
  2100. let packingCodeList = [];
  2101. packingCodePrams.forEach((item, index) => {
  2102. packingCodeList[index] = data.filter(
  2103. (ite) => ite.assetCode == item.assetCode
  2104. );
  2105. });
  2106. // 批量生成包装
  2107. this.productList.map((row, index) => {
  2108. if (!row.isSave) {
  2109. this.generateWrappers(row, index, packingCodeList[index]);
  2110. this.$set(this.productList[index], 'isSave', true);
  2111. }
  2112. });
  2113. // 加载虚拟列表数据(分页)
  2114. // this.pickingFetchData();
  2115. // this.materielFetchData();
  2116. })
  2117. .catch((err) => {
  2118. console.log(err);
  2119. });
  2120. },
  2121. // 物品保存验证表单(单独)
  2122. validateFormIndividually(index) {
  2123. return new Promise(async (resolve) => {
  2124. let fileds = [
  2125. `productList.${index}.batchNo`,
  2126. `productList.${index}.packingQuantity`,
  2127. `productList.${index}.packingUnit`,
  2128. `productList.${index}.warehouseId`
  2129. ];
  2130. Promise.all(
  2131. fileds.map(
  2132. (item) =>
  2133. new Promise(async (res, rej) => {
  2134. this.$refs.productListRef.validateField(item, (err) => {
  2135. if (err) {
  2136. rej(err);
  2137. } else {
  2138. res(true);
  2139. }
  2140. });
  2141. })
  2142. )
  2143. )
  2144. .then(() => {
  2145. resolve();
  2146. })
  2147. .catch(() => {
  2148. this.$message.error('请填入必填项!');
  2149. });
  2150. });
  2151. },
  2152. // 产品编辑
  2153. listEdit(row) {
  2154. this.$set(row, 'isSave', false);
  2155. // // 重新计算重量
  2156. // const totals = Number(
  2157. // this.$math.format(row.minPackingQuantity * row.packingQuantity, 14)
  2158. // );
  2159. // if (row.measureUnit == row.weightUnit) {
  2160. // row.weight = Number(
  2161. // this.$math.format(
  2162. // row.minPackingQuantity *
  2163. // 1 *
  2164. // Number(row.packingQuantity).toFixed(2),
  2165. // 14
  2166. // )
  2167. // );
  2168. // } else {
  2169. // row.weight = Number(
  2170. // this.$math.format(
  2171. // totals *
  2172. // (row.netWeight > 0 ? Number(row.netWeight).toFixed(2) : 0),
  2173. // 14
  2174. // )
  2175. // );
  2176. // }
  2177. this.deletePackingAndMaterial(row);
  2178. },
  2179. // 根据产品信息删除包装和物料
  2180. deletePackingAndMaterial(row) {
  2181. // 删除包装(去掉不相同的包装)
  2182. this.packingList = this.packingList.filter(
  2183. (item) => item.parentIndex !== row.index
  2184. );
  2185. this.showPackingList = this.showPackingList.filter(
  2186. (item) => item.parentIndex !== row.index
  2187. );
  2188. this.pickingPageNum = Math.ceil(
  2189. this.showPackingList.length / this.pageSize
  2190. );
  2191. // 删除物料(获取相同物料)
  2192. let packingIndexs = this.packingList.map((item) => item.index);
  2193. this.materialList = this.materialList.filter((item) =>
  2194. packingIndexs.includes(item.parentIndex)
  2195. );
  2196. this.showMaterialList = this.showMaterialList.filter((item) =>
  2197. packingIndexs.includes(item.parentIndex)
  2198. );
  2199. this.materielPageNum = Math.ceil(
  2200. this.showMaterialList.length / this.pageSize
  2201. );
  2202. },
  2203. async batchSave() {
  2204. try {
  2205. // 验证所有未保存的表单
  2206. await this.validateForm()
  2207. // 遍历所有产品进行保存
  2208. for (let i = 0; i < this.productList.length; i++) {
  2209. const row = this.productList[i]
  2210. if (!row.isSave) {
  2211. // 执行单个保存逻辑
  2212. await this.listSave(row, i)
  2213. }
  2214. }
  2215. } catch (error) {
  2216. this.$message.error('批量保存失败,请检查必填项')
  2217. }
  2218. },
  2219. listSave(row, index) {
  2220. console.log('row22222222', row);
  2221. this.validateFormIndividually(index).then(async () => {
  2222. // 判断单位和计量单位是否为不拆物料层规格
  2223. let packingBoolen = !!this.getDict('不拆物料层规格', row.packingUnit)
  2224. .dictValue;
  2225. let measureBoolen = !!this.getDict('不拆物料层规格', row.measureUnit)
  2226. .dictValue;
  2227. console.log('packingBoolen---------', packingBoolen);
  2228. console.log('measureBoolen---------', measureBoolen);
  2229. let packingNum = 0;
  2230. // 处理单位为KG类的情况
  2231. if (packingBoolen) {
  2232. if (!row.isUnpack && row.packingUnit == '立方') {
  2233. packingNum = 1;
  2234. } else {
  2235. let filterArr = row.packingSpecificationOption.filter((item) => {
  2236. return (
  2237. item.packageUnit == row.packingUnit &&
  2238. item.packageUnit != item.conversionUnit
  2239. );
  2240. });
  2241. packingNum = Math.ceil(
  2242. row.packingQuantity / filterArr[0].packageCell
  2243. );
  2244. }
  2245. }
  2246. // 处理单位不为KG类,计量单位为KG类的情况
  2247. let measureNum = row.packingQuantity;
  2248. let num = 0;
  2249. if (measureBoolen) {
  2250. let splitIndex = row.packingSpecificationOption.findIndex(
  2251. (item) =>
  2252. item.conversionUnit == row.packingUnit &&
  2253. item.packageUnit != item.conversionUnit
  2254. );
  2255. for (; splitIndex > 1; splitIndex--) {
  2256. measureNum = this.$math.format(
  2257. measureNum *
  2258. row.packingSpecificationOption[splitIndex].packageCell,
  2259. 14
  2260. );
  2261. }
  2262. } else {
  2263. if (row.packingSpecificationOption[1]?.packageCell) {
  2264. num = Math.ceil(
  2265. row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
  2266. );
  2267. } else {
  2268. num = row.packingQuantity;
  2269. }
  2270. }
  2271. console.log(packingNum, measureNum, num, '加油加油加油')
  2272. if (row.packingSpecificationLabel?.length < 1) {
  2273. this.$message.error('请到主数据维护包装组信息!')
  2274. return;
  2275. }
  2276. // 不拆包
  2277. if (!row.isUnpack) {
  2278. if (row.packingUnit != row.measureUnit) {
  2279. let pNum = row.packingQuantity;
  2280. const { data } = await storageApi.getAssetNum([
  2281. {
  2282. assetCode: row.categoryCode + row.index,
  2283. batchNum: row.batchNo,
  2284. num: pNum,
  2285. }
  2286. ]);
  2287. // this.generateWrappers(row, index, data)
  2288. } else {
  2289. let pNum = 0;
  2290. const { data } = await storageApi.getAssetNum([
  2291. {
  2292. assetCode: row.categoryCode + row.index,
  2293. batchNum: row.batchNo,
  2294. num: pNum,
  2295. }
  2296. ]);
  2297. }
  2298. } else {
  2299. //拆包
  2300. const { data } = await storageApi.getAssetNum([
  2301. {
  2302. assetCode: row.categoryCode + row.index,
  2303. batchNum: row.batchNo,
  2304. num: row.packingQuantity
  2305. }
  2306. ]);
  2307. this.generateWrappers(row, index, data);
  2308. }
  2309. this.$set(this.productList[index], 'isSave', true);
  2310. this.$set(this.productList[index], 'warehouseId', row.warehouseId);
  2311. this.$set(
  2312. this.productList[index],
  2313. 'warehouseName',
  2314. row.warehouseName
  2315. );
  2316. this.$set(this.productList[index], 'warehouseIds', row.warehouseId);
  2317. this.$set(
  2318. this.productList[index],
  2319. 'warehouseNames',
  2320. row.warehouseName
  2321. );
  2322. });
  2323. },
  2324. //入库明细删除
  2325. listDel(row, index) {
  2326. this.productList.splice(index, 1);
  2327. this.deletePackingAndMaterial(row);
  2328. },
  2329. // 打开仓库弹框
  2330. handleWareHouse(row, idx, type) {
  2331. console.log(row, '踩踩踩踩踩踩踩踩踩踩踩', this.form)
  2332. if (row.packingSpecificationLabel?.length < 1) {
  2333. this.$message.error('请到主数据维护包装组信息!')
  2334. return;
  2335. }
  2336. if (row.isSave) {
  2337. return false;
  2338. }
  2339. let packingBoolen = !!this.getDict('不拆物料层规格', row.packingUnit)
  2340. .dictValue;
  2341. let measureBoolen = !!this.getDict('不拆物料层规格', row.measureUnit)
  2342. .dictValue;
  2343. console.log(packingBoolen, 'packingBoolen')
  2344. console.log(measureBoolen, 'measureBoolen')
  2345. //行内选择仓库
  2346. if (idx > -1 && type != 'batch') {
  2347. if (row.packingQuantity > 0) {
  2348. //不拆
  2349. if (!row.isUnpack) {
  2350. //计量和包装单位相同
  2351. if (row.measureUnit == row.packingUnit) {
  2352. let pNum = 0;
  2353. let mNum = row.measureQuantity
  2354. this.$refs.wareHouseDailogRef.open(
  2355. pNum,
  2356. mNum,
  2357. idx,
  2358. row.warehouseId,
  2359. row.warehouseName + '',
  2360. // this.form.categoryLevelTopId
  2361. );
  2362. } else {
  2363. let pNum = row.packingQuantity;
  2364. let mNum = row.measureQuantity
  2365. this.$refs.wareHouseDailogRef.open(
  2366. pNum,
  2367. mNum,
  2368. idx,
  2369. row.warehouseId,
  2370. row.warehouseName + '',
  2371. // this.form.categoryLevelTopId
  2372. );
  2373. }
  2374. } else {
  2375. if (packingBoolen) {
  2376. console.log(packingBoolen, 'packingBoolen', row.packageUnit, row.isUnpack);
  2377. let filterArr = row.packingSpecificationOption.filter((item) => {
  2378. return (
  2379. item.packageUnit == row.packingUnit &&
  2380. item.packageUnit != item.conversionUnit
  2381. );
  2382. });
  2383. let num = Math.ceil(
  2384. row.packingQuantity / filterArr[0].packageCell
  2385. );
  2386. this.$refs.wareHouseDailogRef.open(
  2387. num,
  2388. row.measureQuantity,
  2389. idx,
  2390. row.warehouseId,
  2391. row.warehouseName + '',
  2392. // this.form.categoryLevelTopId
  2393. );
  2394. } else {
  2395. console.log(measureBoolen, 'measureBoolen');
  2396. let num = row.packingQuantity;
  2397. if (measureBoolen) {
  2398. let splitIndex = row.packingSpecificationOption.findIndex(
  2399. (item) =>
  2400. item.conversionUnit == row.packingUnit &&
  2401. item.packageUnit != item.conversionUnit
  2402. );
  2403. for (; splitIndex > 1; splitIndex--) {
  2404. num = this.$math.format(
  2405. num *
  2406. row.packingSpecificationOption[splitIndex].packageCell,
  2407. 14
  2408. );
  2409. }
  2410. this.$refs.wareHouseDailogRef.open(
  2411. num,
  2412. row.measureQuantity,
  2413. idx,
  2414. row.warehouseId,
  2415. row.warehouseName + '',
  2416. // this.form.categoryLevelTopId
  2417. );
  2418. } else {
  2419. if (row.measureType != 1 && row.measureUnit == row.packingUnit) {
  2420. let pNum = 0;
  2421. let mNum = row.measureQuantity
  2422. this.$refs.wareHouseDailogRef.open(
  2423. pNum,
  2424. mNum,
  2425. idx,
  2426. row.warehouseId,
  2427. row.warehouseName + '',
  2428. // this.form.categoryLevelTopId
  2429. );
  2430. } else {
  2431. if (row.packingSpecificationOption[1]?.packageCell) {
  2432. let num = Math.ceil(
  2433. row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
  2434. );
  2435. this.$refs.wareHouseDailogRef.open(
  2436. row.packingQuantity,
  2437. row.measureQuantity,
  2438. idx,
  2439. row.warehouseId,
  2440. row.warehouseName + '',
  2441. );
  2442. } else {
  2443. this.$refs.wareHouseDailogRef.open(
  2444. row.packingQuantity,
  2445. row.measureQuantity,
  2446. idx,
  2447. row.warehouseId,
  2448. row.warehouseName + ''
  2449. );
  2450. }
  2451. console.log(num, 'num')
  2452. }
  2453. }
  2454. }
  2455. }
  2456. } else {
  2457. this.$message.error('请先填写包装数量!');
  2458. }
  2459. } else {
  2460. //批量
  2461. console.log(row, `row`)
  2462. console.log(idx, `idx`)
  2463. console.log(type, 'type')
  2464. // 批量设置
  2465. if (row.some(item => !item.packingQuantity)) {
  2466. this.$message.error('请先填写所有行的包装数量!');
  2467. return;
  2468. }
  2469. for (let i = 0; i < row.length; i++) {
  2470. //测量单位等于包装单位
  2471. if (row[i].measureType != 1 && row[i].measureUnit === row[i].packingUnit) {
  2472. row[i].packingQuantity2 = 0;
  2473. console.log(row[i].packingQuantity2)
  2474. } else {
  2475. row[i].packingQuantity2 = Math.ceil(
  2476. row[i].measureQuantity / row[i].packingSpecificationOption[1]?.packageCell
  2477. );
  2478. console.log(row[i].packingQuantity2, '单位不一样')
  2479. }
  2480. }
  2481. console.log(row, 'rowrowrowrowrowrow我看看')
  2482. const pNum = row.reduce((sum, item) => {
  2483. if (item.packingQuantity2 !== undefined && item.packingQuantity2 !== null) {
  2484. return sum + Number(item.packingQuantity2);
  2485. }
  2486. return sum;
  2487. }, 0);
  2488. const mNum = row.reduce((sum, item) => {
  2489. if (item.measureQuantity !== undefined && item.measureQuantity !== null) {
  2490. return sum + Number(item.measureQuantity);
  2491. }
  2492. return sum;
  2493. }, 0);
  2494. console.log(pNum, 'pppp')
  2495. console.log(mNum, 'mmmmm')
  2496. this.$refs.wareHouseDailogRef.open(
  2497. pNum,
  2498. mNum,
  2499. // this.form.categoryLevelTopId
  2500. );
  2501. }
  2502. },
  2503. wareHouseSelection(argum, idx) {
  2504. console.log(argum, 'argumargumargumargumargumargum');
  2505. // 方便包装遍历获取仓库id和名称
  2506. let warehouseIds = [];
  2507. let warehouseNames = [];
  2508. argum.forEach((item) => {
  2509. console.log(item, 'itemitem')
  2510. for (let index = 0; index < item.packingQuantity; index++) {
  2511. warehouseIds.push(item.warehouseId);
  2512. warehouseNames.push(item.warehouseName);
  2513. }
  2514. });
  2515. console.log(idx, this.productList, 'idxidxidxidx')
  2516. if (idx > -1) {
  2517. this.$set(
  2518. this.productList[idx],
  2519. 'warehouseId',
  2520. argum.map((item) => item.warehouseId).join(',')
  2521. );
  2522. this.$set(
  2523. this.productList[idx],
  2524. 'warehouseName',
  2525. argum.map((item) => item.warehouseName).join(',')
  2526. );
  2527. this.$set(this.productList[idx], 'warehouseIds', warehouseIds);
  2528. this.$set(this.productList[idx], 'warehouseNames', warehouseNames);
  2529. console.log(this.productList, 'productList')
  2530. } else {
  2531. this.productList.map((item, index) => {
  2532. this.$set(
  2533. this.productList[index],
  2534. 'warehouseId',
  2535. argum.map((item) => item.warehouseId).join(',')
  2536. );
  2537. this.$set(
  2538. this.productList[index],
  2539. 'warehouseName',
  2540. argum.map((item) => item.warehouseName).join(',')
  2541. );
  2542. this.$set(this.productList[index], 'warehouseIds', warehouseIds);
  2543. this.$set(
  2544. this.productList[index],
  2545. 'warehouseNames',
  2546. warehouseNames
  2547. );
  2548. });
  2549. }
  2550. this.$forceUpdate();
  2551. },
  2552. // 生成包装
  2553. generateWrappers(row, productIndex, packingCodeList) {
  2554. console.log(packingCodeList, 'packingCodeList', row.measureType)
  2555. if (!row.measureType) return this.$message.warning('请到主数据维计量类型!')
  2556. // 判断是否拆包,如果是不拆包,计量单位=包装单位,则不生成包装层数据
  2557. if (!row.isUnpack && row.measureType != 1) {
  2558. // 计量单位=包装单位,则不生成包装层数据
  2559. if (row.measureUnit == row.packingUnit) {
  2560. // 直接生成物品层数据
  2561. this.productList[productIndex].measureQuantity = row.measureQuantity;
  2562. this.productList[productIndex].weight = row.weight;
  2563. return;
  2564. }
  2565. }
  2566. console.log('包装数据--------', row);
  2567. // console.log('包装规格----', row.packingSpecificationOption);
  2568. console.log('计量单位----', row.measureUnit);
  2569. let packingList = [];
  2570. let obj = this.getNowDate();
  2571. let productionDate = '';
  2572. let purchaseDate = '';
  2573. console.log(this.formData.bizType, 'bizTypebizTypebizTypebizTypebizTypebizTypebizTypebizTypebizTypebizTypebizType')
  2574. if (this.formData.bizType == '1') {
  2575. // 生产入库
  2576. productionDate = `${obj.year}-${obj.month}-${obj.strDate} ${obj.hour}:${obj.minute}:${obj.second}`;
  2577. this.curDateType = 'productionDate';
  2578. } else if (this.formData.bizType == '2') {
  2579. // 采购入库
  2580. const defaultTime = '00:00:00';
  2581. purchaseDate = `${this.form.receiveDate} ${defaultTime}`;
  2582. this.curDateType = 'purchaseDate';
  2583. }
  2584. // 判断单位和计量单位是否为不拆物料层规格
  2585. let packingBoolen = !!this.getDict('不拆物料层规格', row.packingUnit)
  2586. .dictValue;
  2587. let measureBoolen = !!this.getDict('不拆物料层规格', row.measureUnit)
  2588. .dictValue;
  2589. let num = row.packingQuantity;
  2590. let filterArr = [];
  2591. // 处理单位为KG类的情况
  2592. if (packingBoolen) {
  2593. console.log(packingBoolen, 'packingBoolenpackingBoolenpackingBoolenpackingBoolenpackingBoolenpackingBoolen')
  2594. if (!row.isUnpack && row.packingUnit == '立方') {
  2595. num = 1;
  2596. } else {
  2597. filterArr = row.packingSpecificationOption.filter((item) => {
  2598. return (
  2599. item.packageUnit == row.packingUnit &&
  2600. item.packageUnit != item.conversionUnit
  2601. );
  2602. });
  2603. num = Math.ceil(row.packingQuantity / filterArr[0]?.packageCell);
  2604. }
  2605. } else {
  2606. // if (row.isUnpack == 1) {
  2607. if (measureBoolen) {
  2608. // 处理单位不为KG类,计量单位为KG类的情况
  2609. let splitIndex = row.packingSpecificationOption.findIndex(
  2610. (item) =>
  2611. item.conversionUnit == row.packingUnit &&
  2612. item.packageUnit != item.conversionUnit
  2613. );
  2614. for (; splitIndex > 1; splitIndex--) {
  2615. num = this.$math.format(
  2616. num * row.packingSpecificationOption[splitIndex].packageCell,
  2617. 14
  2618. );
  2619. }
  2620. } else {
  2621. if (row.packingSpecificationOption[1]?.packageCell) {
  2622. num = Math.ceil(
  2623. row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
  2624. );
  2625. filterArr = row.packingSpecificationOption.filter((item) => {
  2626. return (
  2627. item.packageUnit == row.packingUnit &&
  2628. item.packageUnit != item.conversionUnit
  2629. );
  2630. });
  2631. }
  2632. }
  2633. }
  2634. console.log('num-----------', num);
  2635. if (!row.isUnpack) {
  2636. let packingUnit = !row.isUnpack ? row.packingUnit : row.packingSpecificationOption[1].conversionUnit;
  2637. let packingQuantity = row.packingQuantity / packingCodeList.length;
  2638. let measureUnit = row.measureUnit;
  2639. let measureQuantity = row.measureQuantity / row.packingQuantity;
  2640. let status = null;
  2641. //通过委外发货单编码判断是不是委外 委外收货 质检状态显示已质检
  2642. // if (this.form.outsourceSendCode != '') {
  2643. // status = 2;
  2644. // } else {
  2645. // // 0未检 1待检 2 已检
  2646. // if (row.qualityControl == 1) {
  2647. // status = 0;
  2648. // } else {
  2649. // status = 2;
  2650. // }
  2651. // }
  2652. if (row.qualityControl == 1) {
  2653. status = 0;
  2654. } else {
  2655. status = 2;
  2656. }
  2657. for (let index = 0; index < packingCodeList.length; index++) {
  2658. let item = {
  2659. index: row.index + '-' + index, // 包装索引
  2660. warehouseId: row.warehouseId, // 仓库id
  2661. warehouseName: row.warehouseName, // 仓库名称
  2662. categoryName: row.categoryName, // 产品名称
  2663. categoryCode: row.categoryCode, // 产品编码
  2664. categoryModel: row.categoryModel, // 物品型号
  2665. specification: row.specification, // 规格
  2666. supplierCode: row.supplierCode, // 供应商代号
  2667. supplierName: row.supplierName, // 供应商名称
  2668. brandNum: row.brandNum, // 牌号
  2669. parentIndex: row.index, // 产品索引
  2670. batchNo: row.batchNo, // 批次号
  2671. packageNo: packingCodeList[index]?.onlyCode, // 包装编码
  2672. packingQuantity: packingQuantity, // 包装数量
  2673. packingUnit: packingUnit,
  2674. measureQuantity: measureQuantity, // 计量数量
  2675. measureUnit: measureUnit, // 计量单位
  2676. weight: 0, // 重量
  2677. packingSpecificationOption: row.packingSpecificationOption, // 包装规格
  2678. weightUnit: row.weightUnit, // 重量单位
  2679. netWeight: row.netWeight, // 净重
  2680. barcodes: '', // 发货条码
  2681. clientCode: row.extInfo ? row.extInfo.clientCode : '', // 客户代号
  2682. materielDesignation: row.extInfo ? row.extInfo.materielCode : '', // 物料代号
  2683. engrave: '', // 刻码
  2684. isUnpack: row.isUnpack, // 是否允许拆包
  2685. productionDate: productionDate, // 生产日期
  2686. purchaseDate: purchaseDate, // 采购时间
  2687. result: 1, // 结果(1合格 2不合格)
  2688. qualityControl: row.qualityControl,
  2689. status: status // 状态(0=未质检 1待检 2已检)
  2690. };
  2691. let outBoolen = !!this.getDict('不拆物料层规格', item.measureUnit)
  2692. .dictValue;
  2693. if (outBoolen) {
  2694. // 计量单位为KG类,直接替换
  2695. item.weight = item.measureQuantity ? Number(item.measureQuantity) : 0;
  2696. } else {
  2697. console.log('计量单位为不为KG类======================');
  2698. // 计量单位为不为KG类,重新统计计算
  2699. let inBoolen = !!this.getDict(
  2700. '不拆物料层规格',
  2701. item.packingSpecificationOption[0].packageUnit
  2702. ).dictValue;
  2703. let startIndex = item.packingSpecificationOption.findIndex(
  2704. (ite) => {
  2705. return (
  2706. item.measureUnit == ite.packingUnit &&
  2707. ite.packingUnit != ite.conversionUnit
  2708. );
  2709. }
  2710. );
  2711. let endIndex = item.packingSpecificationOption.findIndex(
  2712. (ite) => item.packingUnit == ite.conversionUnit
  2713. );
  2714. if (measureBoolen) {
  2715. let total = item.packingQuantity ? Number(item.packingQuantity) : 0;
  2716. for (; startIndex < endIndex; endIndex--) {
  2717. total = this.$math.format(
  2718. item.packingSpecificationOption[endIndex].packageCell * total,
  2719. 14
  2720. );
  2721. }
  2722. if (inBoolen) {
  2723. // 第二层为KG类
  2724. item.weight = total ? Number(total) : 0;
  2725. } else {
  2726. // 第二层不为KG类
  2727. item.weight = this.$math.format(total * item.netWeight, 14);
  2728. }
  2729. } else if (!measureBoolen) {
  2730. if (inBoolen) {
  2731. // 第二层为KG类
  2732. item.weight = item.measureQuantity ? Number(item.measureQuantity) : 0;
  2733. } else {
  2734. // 第二层不为KG类
  2735. if (row.singleWeight && item.measureQuantity) {
  2736. item.weight = Number(item.measureQuantity) * Number(row.singleWeight);
  2737. } else {
  2738. item.weight = 0;
  2739. }
  2740. }
  2741. }
  2742. }
  2743. packingList.push(item);
  2744. console.log(
  2745. packingList,
  2746. 'packingList!!!!!!!!!!!!!!!!!!'
  2747. );
  2748. }
  2749. } else {
  2750. console.log('拆包处理', row);
  2751. for (let index = 0; index < packingCodeList.length; index++) {
  2752. let measureQuantity = 1;
  2753. let packingQuantity = 1;
  2754. let packingUnit = row.packingUnit;
  2755. // 处理单位为KG类,计算每桶KG值
  2756. if (packingBoolen) {
  2757. if (!row.isUnpack && row.packingUnit == '立方') {
  2758. let result = row.packingQuantity / row.packingSpecificationOption[1].packageCell;
  2759. packingQuantity = Math.ceil(result * 100) / 100;
  2760. console.log(packingQuantity, '包装数oppppp量')
  2761. measureQuantity = row.measureQuantity
  2762. console.log(measureQuantity, '计量数oppppp量')
  2763. packingUnit = row.packingUnit;
  2764. } else {
  2765. measureQuantity =
  2766. Number(row.packingQuantity) >
  2767. this.$math.format(filterArr[0].packageCell * (index + 1), 14)
  2768. ? filterArr[0].packageCell
  2769. : Number(row.packingQuantity) -
  2770. this.$math.format(filterArr[0].packageCell * index, 14);
  2771. console.log(measureQuantity, 'measureQuantity')
  2772. }
  2773. } else {
  2774. if (row.isUnpack == 1) {
  2775. console.log('1 拆--------', measureBoolen)
  2776. if (measureBoolen) {
  2777. // 处理单位不为KG类,计量单位为KG类的情况
  2778. let splitIndex = row.packingSpecificationOption.findIndex(
  2779. (item) =>
  2780. item.conversionUnit == row.packingUnit &&
  2781. item.packageUnit != item.conversionUnit
  2782. );
  2783. for (; splitIndex > 0; splitIndex--) {
  2784. measureQuantity = this.$math.format(
  2785. measureQuantity *
  2786. row.packingSpecificationOption[splitIndex].packageCell,
  2787. 14
  2788. );
  2789. }
  2790. } else {
  2791. measureQuantity = row.measureQuantity / row.packingQuantity;
  2792. }
  2793. } else {
  2794. console.log('4 拆--------')
  2795. if (row.packingQuantity) {
  2796. measureQuantity = row.measureQuantity / row.packingQuantity;
  2797. }
  2798. }
  2799. console.log(measureQuantity, 'measureQuantity')
  2800. }
  2801. let clientCode = ''
  2802. if (this.bizType == 2) {
  2803. clientCode = row?.customerMark
  2804. } else if (this.bizType != 2) {
  2805. clientCode = row.extInfo?.clientCode
  2806. }
  2807. console.log(filterArr[0], 'filterArr[0]')
  2808. let status = null;
  2809. //通过委外发货单编码判断是不是委外 委外收货 质检状态显示已质检
  2810. // if (this.form.outsourceSendCode != '') {
  2811. // status = 2;
  2812. // } else {
  2813. // // 0未检 1待检 2 已检
  2814. // if (row.qualityControl == 1) {
  2815. // status = 0;
  2816. // } else {
  2817. // status = 2;
  2818. // }
  2819. // }
  2820. if (row.qualityControl == 1) {
  2821. status = 0;
  2822. } else {
  2823. status = 2;
  2824. }
  2825. let item = {
  2826. index: row.index + '-' + index, // 包装索引
  2827. warehouseId: row.warehouseId, // 仓库id
  2828. warehouseName: row.warehouseName, // 仓库名称
  2829. categoryName: row.categoryName, // 产品名称
  2830. categoryCode: row.categoryCode, // 产品编码
  2831. categoryModel: row.categoryModel, // 物品型号
  2832. specification: row.specification, // 规格
  2833. supplierCode: row.supplierCode, // 供应商编码
  2834. supplierName: row.supplierName, // 供应商名称
  2835. brandNum: row.brandNum, // 牌号
  2836. parentIndex: row.index, // 产品索引
  2837. batchNo: row.batchNo, // 批次号
  2838. packageNo: packingCodeList[index]?.onlyCode, // 包装编码
  2839. packingQuantity: packingQuantity, // 包装数量
  2840. // packingUnit: row.isUnpack ? packingBoolen ? filterArr[0].conversionUnit : measureBoolen ? row.packingSpecificationOption[1]
  2841. // ? row.packingSpecificationOption[1].conversionUnit
  2842. // : row.packingSpecificationOption[0].conversionUnit
  2843. // : row.measureUnit
  2844. // : packingBoolen
  2845. // ? row.packingUnit === '立方' ? row.packingUnit : filterArr[0]?.conversionUnit
  2846. // : row.packingUnit,
  2847. // packingUnit: row.isUnpack ? packingBoolen ? filterArr[0].conversionUnit : measureBoolen ? row.packingSpecificationOption[2] ?
  2848. // row.packingSpecificationOption[2].conversionUnit : row.packingSpecificationOption[1].conversionUnit: row.measureUnit: packingBoolen ? filterArr[0].conversionUnit : row.packingUnit,
  2849. //!row.isUnpack && row.packingUnit
  2850. measureQuantity:measureQuantity, // 计量数量
  2851. measureUnit: row.isUnpack
  2852. ? measureBoolen
  2853. ? row.packingSpecificationOption[1]
  2854. ? row.packingSpecificationOption[1].packageUnit
  2855. : row.packingSpecificationOption[0].packageUnit
  2856. : row.measureUnit
  2857. : row.measureUnit, // 计量单位
  2858. weight: 0, // 重量
  2859. packingSpecificationOption: row.packingSpecificationOption, // 包装规格
  2860. weightUnit: row.weightUnit, // 重量单位
  2861. netWeight: row.netWeight, // 净重
  2862. barcodes: '', // 发货条码
  2863. clientCode: clientCode, // 客户代号
  2864. materielDesignation: row.extInfo ? row.extInfo.materielCode : '', // 物料代号
  2865. engrave: '', // 刻码
  2866. isUnpack: row.isUnpack, // 是否允许拆包
  2867. productionDate: productionDate, // 生产日期
  2868. purchaseDate: purchaseDate, // 采购时间
  2869. result: 1, // 结果(1合格 2不合格)
  2870. qualityControl: row.qualityControl,
  2871. status: status // 状态(0=未质检 1待检 2已检)
  2872. };
  2873. /**
  2874. * packingUnit: row.isUnpack ? packingBoolen ? filterArr[0].conversionUnit : measureBoolen ? row.packingSpecificationOption[2] ? row.packingSpecificationOption[2].conversionUnit
  2875. * : row.packingSpecificationOption[1].conversionUnit: row.measureUnit: packingBoolen ? filterArr[0].conversionUnit : row.packingUnit,
  2876. */
  2877. if (row.isUnpack) {
  2878. // 第二层条件: packingBoolen
  2879. if (packingBoolen) {
  2880. // 空值保护: 确保 filterArr[0] 存在
  2881. item.packingUnit = filterArr?.[0]?.conversionUnit;
  2882. } else {
  2883. // 第三层条件: measureBoolen
  2884. if (measureBoolen) {
  2885. // 处理 packingSpecificationOption 的索引
  2886. const option = row.packingSpecificationOption?.[1] || row.packingSpecificationOption?.[0];
  2887. item.packingUnit = option?.conversionUnit;
  2888. } else {
  2889. item.packingUnit =packingUnit
  2890. }
  2891. }
  2892. } else {
  2893. // 第二层条件: packingBoolen (isUnpack 为 false 时的分支)
  2894. if (packingBoolen) {
  2895. item.packingUnit = filterArr?.[0]?.conversionUnit;
  2896. } else {
  2897. item.packingUnit = row.packingUnit;
  2898. }
  2899. }
  2900. let outBoolen = !!this.getDict('不拆物料层规格', item.measureUnit)
  2901. .dictValue;
  2902. if (outBoolen) {
  2903. // 计量单位为KG类,直接替换
  2904. item.weight = item.measureQuantity ? Number(item.measureQuantity) : 0;
  2905. } else {
  2906. console.log('计量单位为不为KG类======================');
  2907. // 计量单位为不为KG类,重新统计计算
  2908. let inBoolen = !!this.getDict(
  2909. '不拆物料层规格',
  2910. item.packingSpecificationOption[0].packageUnit
  2911. ).dictValue;
  2912. let startIndex = item.packingSpecificationOption.findIndex(
  2913. (ite) => {
  2914. return (
  2915. item.measureUnit == ite.packingUnit &&
  2916. ite.packingUnit != ite.conversionUnit
  2917. );
  2918. }
  2919. );
  2920. let endIndex = item.packingSpecificationOption.findIndex(
  2921. (ite) => item.packingUnit == ite.conversionUnit
  2922. );
  2923. if (measureBoolen) {
  2924. let total = item.packingQuantity ? Number(item.packingQuantity) : 0;
  2925. for (; startIndex < endIndex; endIndex--) {
  2926. total = this.$math.format(
  2927. item.packingSpecificationOption[endIndex].packageCell * total,
  2928. 14
  2929. );
  2930. }
  2931. if (inBoolen) {
  2932. // 第二层为KG类
  2933. item.weight = total ? Number(total) : 0;
  2934. } else {
  2935. // 第二层不为KG类
  2936. item.weight = this.$math.format(total * item.netWeight, 14);
  2937. }
  2938. } else if (!measureBoolen) {
  2939. if (inBoolen) {
  2940. // 第二层为KG类
  2941. item.weight = item.measureQuantity ? Number(item.measureQuantity) : 0;
  2942. } else {
  2943. // 第二层不为KG类
  2944. if (row.singleWeight && item.measureQuantity) {
  2945. item.weight = Number(item.measureQuantity) * Number(row.singleWeight);
  2946. } else {
  2947. item.weight = 0;
  2948. }
  2949. }
  2950. }
  2951. }
  2952. packingList.push(item);
  2953. console.log(
  2954. packingList,
  2955. 'packingList!!!!!!!!!!!!!!!!!!拆'
  2956. );
  2957. }
  2958. }
  2959. // 单独点击保存并插入对应位置(包装)
  2960. if (productIndex == 0) {
  2961. this.packingList.splice(productIndex, 0, ...packingList);
  2962. } else {
  2963. let packingIndex = this.packingList.findLastIndex(
  2964. (item) =>
  2965. item.parentIndex == this.productList[productIndex - 1].index
  2966. );
  2967. this.packingList.splice(packingIndex + 1, 0, ...packingList);
  2968. }
  2969. const lastIndex = this.packingList.length - 1
  2970. let remainder = row.measureQuantity % row.packingSpecificationOption[1]?.packageCell
  2971. console.log(remainder, 'remainder')
  2972. if (remainder > 0) {
  2973. this.$set(this.packingList[lastIndex], 'measureQuantity', remainder)
  2974. }
  2975. // 单独点击保存并插入对应位置(物料)
  2976. // let materialList = packingList
  2977. // .map((item) => {
  2978. // if (item.isUnpack) {
  2979. // return this.generateMaterial(item);
  2980. // } else {
  2981. // return [];
  2982. // }
  2983. // })
  2984. // .flat();
  2985. // console.log(materialList);
  2986. // if (materialList.length > 0) {
  2987. // if (productIndex == 0) {
  2988. // this.materialList.splice(0, 0, ...materialList);
  2989. // } else {
  2990. // let preLastPackingIndex = this.packingList.findLastIndex((ite) => {
  2991. // return ite.parentIndex <= productIndex - 1 && ite.isUnpack;
  2992. // });
  2993. // let preLastMaterialIndex = this.materialList.findLastIndex(
  2994. // (ite) => {
  2995. // return (
  2996. // ite.parentIndex == this.packingList[preLastPackingIndex].index
  2997. // );
  2998. // }
  2999. // );
  3000. // this.materialList.splice(
  3001. // preLastMaterialIndex + 1,
  3002. // 0,
  3003. // ...materialList
  3004. // );
  3005. // }
  3006. // }
  3007. },
  3008. // 生成物料
  3009. generateMaterial(row) {
  3010. let materialList = [];
  3011. for (let index = 0; index < row.measureQuantity; index++) {
  3012. materialList.push({
  3013. materialCode: row.packageNo + index.toString().padStart(4, '0'), // 物料编码
  3014. index: row.index + '——' + index, // 包装索引
  3015. warehouseId: row.warehouseId, // 仓库id
  3016. warehouseName: row.warehouseName, // 仓库名称
  3017. categoryName: row.categoryName, // 产品名称
  3018. categoryCode: row.categoryCode, // 产品编码
  3019. parentIndex: row.index, // 产品索引
  3020. batchNo: row.batchNo, // 批次号
  3021. packageNo: row.packageNo, // 包装编码
  3022. measureQuantity: 1, // 计量数量
  3023. measureUnit: row.measureUnit, // 计量单位
  3024. weight: Number(
  3025. this.$math.format(row.weight / row.packingQuantity, 14)
  3026. ), // 重量
  3027. weightUnit: row.weightUnit, // 重量单位
  3028. barcodes: '', // 发货条码
  3029. clientCode: '', // 客户代号
  3030. materielDesignation: '', // 物料代号
  3031. engrave: '', // 刻码
  3032. result: 1, // 结果(1合格 2不合格 3让步接收)
  3033. status: 2 // 状态(0=未质检 1待检 2已检)
  3034. });
  3035. }
  3036. return materialList;
  3037. },
  3038. // 设置时间
  3039. dateSetting() {
  3040. if (!this.packingListSelected.length) {
  3041. return this.$message.error(`请选择${this.title}明细!`);
  3042. }
  3043. this.dateVisible = true;
  3044. },
  3045. // 选择包装列表
  3046. handleSelectionChange(val) {
  3047. this.packingListSelected = val;
  3048. },
  3049. // 选择质检结果改变质检状态
  3050. changeWrapStatus(resultValue, row, type) {
  3051. switch (resultValue) {
  3052. case 0:
  3053. // 清空质检状态
  3054. row.status = 0;
  3055. break;
  3056. default:
  3057. // 默认已检质检状态
  3058. row.status = 2;
  3059. break;
  3060. }
  3061. if (type === '包装') {
  3062. this.packingResultCahnge(resultValue, row);
  3063. } else {
  3064. this.materialResultCahnge(resultValue, row);
  3065. }
  3066. }
  3067. }
  3068. };
  3069. </script>
  3070. <style lang="scss" scoped>
  3071. .inbound_details {
  3072. margin-top: 10px;
  3073. .el-form-item {
  3074. margin-bottom: 0 !important;
  3075. }
  3076. }
  3077. .right_control {
  3078. display: flex;
  3079. >button {
  3080. margin-left: 20px;
  3081. }
  3082. }
  3083. .storage_btn {
  3084. margin-top: 20px;
  3085. display: flex;
  3086. align-content: center;
  3087. justify-content: center;
  3088. }
  3089. .el-date-editor.el-input,
  3090. .el-date-editor.el-input__inner {
  3091. width: 100% !important;
  3092. }
  3093. .red_color {
  3094. color: red;
  3095. }
  3096. .wareHouse_style {
  3097. text-overflow: ellipsis;
  3098. overflow: hidden;
  3099. word-break: break-all;
  3100. white-space: nowrap;
  3101. }
  3102. </style>