addNew.vue 110 KB

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