add.vue 127 KB

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