add.vue 111 KB

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