add.vue 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820
  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. // console.log(row.packingQuantity,'row.packingQuantity')
  2027. // return
  2028. //拆包
  2029. const { data } = await storageApi.getAssetNum([
  2030. {
  2031. assetCode: row.categoryCode + row.index,
  2032. batchNum: row.batchNo,
  2033. num: Math.ceil(pNum),
  2034. }
  2035. ]);
  2036. this.generateWrappers(row, index, data);
  2037. }
  2038. this.$set(this.productList[index], 'isSave', true);
  2039. this.$set(this.productList[index], 'warehouseId', row.warehouseId);
  2040. this.$set(this.productList[index], 'warehouseName', row.warehouseName);
  2041. this.$set(this.productList[index], 'warehouseIds', [row.warehouseId]);
  2042. this.$set(this.productList[index], 'warehouseNames', [row.warehouseName]);
  2043. resolve()
  2044. } catch (error) {
  2045. reject(error)
  2046. }
  2047. })
  2048. },
  2049. // 生成包装
  2050. generateWrappers(row, productIndex, packingCodeList) {
  2051. console.log(packingCodeList, 'packingCodeListROW', row.measureType)
  2052. //计量类型不是数量
  2053. if (!row.isUnpack && row.measureType != 1) {
  2054. // 计量单位=包装单位,则不生成包装层数据
  2055. if (row.measureUnit == row.packingUnit) {
  2056. // 直接生成物品层数据
  2057. this.productList[productIndex].measureQuantity = row.measureQuantity;
  2058. this.productList[productIndex].weight = row.weight;
  2059. return;
  2060. }
  2061. }
  2062. console.log('包装数据--------', row);
  2063. // console.log('包装规格----', row.packingSpecificationOption);
  2064. console.log('计量单位----', row.measureUnit);
  2065. let packingList = [];
  2066. let obj = this.getNowDate();
  2067. let productionDate = '';
  2068. let purchaseDate = '';
  2069. if (this.formData.bizType == '1') {
  2070. // 生产入库
  2071. productionDate = `${obj.year}-${obj.month}-${obj.strDate} ${obj.hour}:${obj.minute}:${obj.second}`;
  2072. this.curDateType = 'productionDate';
  2073. } else if (this.formData.bizType == '2') {
  2074. // 采购入库
  2075. purchaseDate = `${obj.year}-${obj.month}-${obj.strDate} ${obj.hour}:${obj.minute}:${obj.second}`;
  2076. this.curDateType = 'purchaseDate';
  2077. }
  2078. // 判断单位和计量单位是否为不拆物料层规格
  2079. let packingBoolen = !!this.getDict('不拆物料层规格', row.packingUnit)
  2080. .dictValue;
  2081. let measureBoolen = !!this.getDict('不拆物料层规格', row.measureUnit)
  2082. .dictValue;
  2083. let num = row.packingQuantity;
  2084. let filterArr = [];
  2085. // 处理单位为KG类的情况
  2086. if (packingBoolen) {
  2087. console.log(packingBoolen, 'packingBoolenpackingBoolenpackingBoolenpackingBoolenpackingBoolenpackingBoolen')
  2088. if (!row.isUnpack && row.packingUnit == '立方') {
  2089. num = 1;
  2090. } else {
  2091. filterArr = row.packingSpecificationOption.filter((item) => {
  2092. return (
  2093. item.packageUnit == row.packingUnit &&
  2094. item.packageUnit != item.conversionUnit
  2095. );
  2096. });
  2097. num = Math.ceil(row.packingQuantity / filterArr[0]?.packageCell);
  2098. }
  2099. } else {
  2100. if (measureBoolen) {
  2101. // 处理单位不为KG类,计量单位为KG类的情况
  2102. let splitIndex = row.packingSpecificationOption.findIndex(
  2103. (item) =>
  2104. item.conversionUnit == row.packingUnit &&
  2105. item.packageUnit != item.conversionUnit
  2106. );
  2107. for (; splitIndex > 1; splitIndex--) {
  2108. num = this.$math.format(
  2109. num * row.packingSpecificationOption[splitIndex].packageCell,
  2110. 14
  2111. );
  2112. }
  2113. } else {
  2114. if (row.packingSpecificationOption[1]?.packageCell) {
  2115. num = Math.ceil(
  2116. row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
  2117. );
  2118. filterArr = row.packingSpecificationOption.filter((item) => {
  2119. return (
  2120. item.packageUnit == row.packingUnit &&
  2121. item.packageUnit != item.conversionUnit
  2122. );
  2123. });
  2124. }
  2125. }
  2126. }
  2127. console.log('num-----------', num);
  2128. if (!row.isUnpack) {
  2129. console.log(row.packingSpecificationOption[1])
  2130. // let packingUnit = !row.isUnpack ? row.packingUnit : row.packingSpecificationOption[1].conversionUnit;
  2131. // let packingQuantity = row.packingQuantity / packingCodeList.length;
  2132. let packingUnit = row.packingSpecificationOption[1]?.conversionUnit;
  2133. let startIndex = row.packingSpecificationOption.findIndex((ite) => {
  2134. return (
  2135. row.measuringUnit == ite.packingUnit &&
  2136. ite.packingUnit != ite.conversionUnit
  2137. );
  2138. });
  2139. let endIndex = row.packingSpecificationOption.findIndex(
  2140. (ite) => row.packingUnit == ite.conversionUnit
  2141. );
  2142. let total = Number(row.packingQuantity);
  2143. for (; startIndex < endIndex; endIndex--) {
  2144. total = this.$math.format(
  2145. row.packingSpecificationOption[endIndex].packageCell * total,
  2146. 14
  2147. );
  2148. }
  2149. console.log('total-----------', total)
  2150. let packingQuantity = row.measureQuantity / total;
  2151. let measureUnit = row.measureUnit;
  2152. let measureQuantity = row.measureQuantity / packingCodeList.length;
  2153. for (let index = 0; index < packingCodeList.length; index++) {
  2154. let item = {
  2155. index: row.index + '-' + index, // 包装索引
  2156. warehouseId: row.warehouseId, // 仓库id
  2157. warehouseName: row.warehouseName, // 仓库名称
  2158. categoryName: row.categoryName, // 产品名称
  2159. categoryCode: row.categoryCode, // 产品编码
  2160. categoryModel: row.categoryModel, // 物品型号
  2161. specification: row.specification, // 规格
  2162. supplierCode: row.supplierCode, // 供应商编码
  2163. brandNum: row.brandNum, // 牌号
  2164. parentIndex: row.index, // 产品索引
  2165. batchNo: row.batchNo, // 批次号
  2166. packageNo: packingCodeList[index]?.onlyCode, // 包装编码
  2167. packingQuantity: packingQuantity, // 包装数量
  2168. packingUnit: packingUnit,//包装单位
  2169. measureQuantity: measureQuantity, // 计量数量
  2170. measureUnit: measureUnit, // 计量单位
  2171. weight: 0, // 重量
  2172. packingSpecificationOption: row.packingSpecificationOption, // 包装规格
  2173. weightUnit: row.weightUnit, // 重量单位
  2174. netWeight: row.netWeight, // 净重
  2175. barcodes: '', // 发货条码
  2176. clientCode: row.extInfo ? row.extInfo.clientCode : '', // 客户代号
  2177. materielDesignation: row.extInfo ? row.extInfo.materielCode : '', // 物料代号
  2178. supplierName: row.supplierName, // 供应商名称
  2179. supplierCode: row.supplierCode, // 供应商代号
  2180. engrave: '', // 刻码
  2181. isUnpack: row.isUnpack, // 是否允许拆包
  2182. productionDate: productionDate, // 生产日期
  2183. purchaseDate: purchaseDate, // 采购时间
  2184. result: 1, // 结果(1合格 2不合格)
  2185. status: 2 // 状态(0=未质检 1待检 2已检)
  2186. };
  2187. let outBoolen = !!this.getDict('不拆物料层规格', item.measureUnit)
  2188. .dictValue;
  2189. if (outBoolen) {
  2190. // 计量单位为KG类,直接替换
  2191. item.weight = item.measureQuantity ? Number(item.measureQuantity) : 0;
  2192. } else {
  2193. console.log('计量单位为不为KG类======================');
  2194. // 计量单位为不为KG类,重新统计计算
  2195. let inBoolen = !!this.getDict(
  2196. '不拆物料层规格',
  2197. item.packingSpecificationOption[0].packageUnit
  2198. ).dictValue;
  2199. let startIndex = item.packingSpecificationOption.findIndex(
  2200. (ite) => {
  2201. return (
  2202. item.measureUnit == ite.packingUnit &&
  2203. ite.packingUnit != ite.conversionUnit
  2204. );
  2205. }
  2206. );
  2207. let endIndex = item.packingSpecificationOption.findIndex(
  2208. (ite) => item.packingUnit == ite.conversionUnit
  2209. );
  2210. if (measureBoolen) {
  2211. let total = item.packingQuantity ? Number(item.packingQuantity) : 0;
  2212. for (; startIndex < endIndex; endIndex--) {
  2213. total = this.$math.format(
  2214. item.packingSpecificationOption[endIndex].packageCell * total,
  2215. 14
  2216. );
  2217. }
  2218. if (inBoolen) {
  2219. // 第二层为KG类
  2220. item.weight = total ? Number(total) : 0;
  2221. } else {
  2222. // 第二层不为KG类
  2223. item.weight = this.$math.format(total * item.netWeight, 14);
  2224. }
  2225. } else if (!measureBoolen) {
  2226. if (inBoolen) {
  2227. // 第二层为KG类
  2228. item.weight = item.measureQuantity ? Number(item.measureQuantity) : 0;
  2229. } else {
  2230. // 第二层不为KG类
  2231. if (row.singleWeight && item.measureQuantity) {
  2232. item.weight = Number(item.measureQuantity) * Number(row.singleWeight);
  2233. } else {
  2234. item.weight = 0;
  2235. }
  2236. }
  2237. }
  2238. }
  2239. packingList.push(item);
  2240. }
  2241. } else {
  2242. console.log('拆包处理', row);
  2243. for (let index = 0; index < num; index++) {
  2244. let measureQuantity = 1;
  2245. let packingQuantity = 1;
  2246. let packingUnit = row.packingUnit;
  2247. // 处理单位为KG类,计算每桶KG值
  2248. if (packingBoolen) {
  2249. if (!row.isUnpack && row.packingUnit == '立方') {
  2250. let result = row.packingQuantity / row.packingSpecificationOption[1].packageCell;
  2251. packingQuantity = Math.ceil(result * 100) / 100;
  2252. console.log(packingQuantity, '包装数oppppp量')
  2253. measureQuantity = row.measureQuantity
  2254. console.log(measureQuantity, '计量数oppppp量')
  2255. packingUnit = row.packingUnit;
  2256. } else {
  2257. measureQuantity =
  2258. Number(row.packingQuantity) >
  2259. this.$math.format(filterArr[0].packageCell * (index + 1), 14)
  2260. ? filterArr[0].packageCell
  2261. : Number(row.packingQuantity) -
  2262. this.$math.format(filterArr[0].packageCell * index, 14);
  2263. }
  2264. } else {
  2265. if (row.isUnpack == 1) {
  2266. console.log('1 拆--------', measureBoolen)
  2267. if (measureBoolen) {
  2268. // 处理单位不为KG类,计量单位为KG类的情况
  2269. let splitIndex = row.packingSpecificationOption.findIndex(
  2270. (item) =>
  2271. item.conversionUnit == row.packingUnit &&
  2272. item.packageUnit != item.conversionUnit
  2273. );
  2274. for (; splitIndex > 0; splitIndex--) {
  2275. measureQuantity = this.$math.format(
  2276. measureQuantity *
  2277. row.packingSpecificationOption[splitIndex].packageCell,
  2278. 14
  2279. );
  2280. }
  2281. console.log('2 拆--------', measureQuantity)
  2282. } else {
  2283. measureQuantity = row.packingSpecificationOption[1]?.packageCell;
  2284. console.log('3 拆--------', measureQuantity)
  2285. }
  2286. } else {
  2287. console.log('4 拆--------')
  2288. if (row.packingQuantity) {
  2289. measureQuantity = row.measureQuantity / row.packingQuantity;
  2290. }
  2291. }
  2292. console.log(measureQuantity, 'measureQuantity')
  2293. }
  2294. console.log(filterArr[0], 'filterArr[0]')
  2295. let item = {
  2296. index: row.index + '-' + index, // 包装索引
  2297. warehouseId: row.warehouseId, // 仓库id
  2298. warehouseName: row.warehouseName, // 仓库名称
  2299. categoryName: row.categoryName, // 产品名称
  2300. categoryCode: row.categoryCode, // 产品编码
  2301. categoryModel: row.categoryModel, // 物品型号
  2302. specification: row.specification, // 规格
  2303. supplierCode: row.supplierCode, // 供应商编码
  2304. brandNum: row.brandNum, // 牌号
  2305. parentIndex: row.index, // 产品索引
  2306. batchNo: row.batchNo, // 批次号
  2307. packageNo: packingCodeList[index]?.onlyCode, // 包装编码
  2308. packingQuantity: packingQuantity, // 包装数量
  2309. measureQuantity: row.isUnpack
  2310. ? packingBoolen
  2311. ? measureQuantity
  2312. : measureBoolen
  2313. ? row.packingSpecificationOption[1]
  2314. ? row.packingSpecificationOption[1].packageCell
  2315. : row.packingSpecificationOption[0].packageCell
  2316. : measureQuantity
  2317. : measureQuantity, // 计量数量
  2318. measureUnit: row.isUnpack
  2319. ? measureBoolen
  2320. ? row.packingSpecificationOption[1]
  2321. ? row.packingSpecificationOption[1].packageUnit
  2322. : row.packingSpecificationOption[0].packageUnit
  2323. : row.measureUnit
  2324. : row.measureUnit, // 计量单位
  2325. weight: 0, // 重量
  2326. packingSpecificationOption: row.packingSpecificationOption, // 包装规格
  2327. weightUnit: row.weightUnit, // 重量单位
  2328. netWeight: row.netWeight, // 净重
  2329. barcodes: '', // 发货条码
  2330. clientCode: row.extInfo ? row.extInfo.clientCode : '', // 客户代号
  2331. materielDesignation: row.extInfo ? row.extInfo.materielCode : '', // 物料代号
  2332. supplierName: row.supplierName, // 供应商名称
  2333. supplierCode: row.supplierCode, // 供应商代号
  2334. engrave: '', // 刻码
  2335. isUnpack: row.isUnpack, // 是否允许拆包
  2336. productionDate: productionDate, // 生产日期
  2337. purchaseDate: purchaseDate, // 采购时间
  2338. result: 1, // 结果(1合格 2不合格)
  2339. status: 2 // 状态(0=未质检 1待检 2已检)
  2340. };
  2341. if (row.isUnpack) {
  2342. // 第二层条件: packingBoolen
  2343. if (packingBoolen) {
  2344. // 空值保护: 确保 filterArr[0] 存在
  2345. item.packingUnit = filterArr?.[0]?.conversionUnit;
  2346. } else {
  2347. // 第三层条件: measureBoolen
  2348. if (measureBoolen) {
  2349. // 处理 packingSpecificationOption 的索引
  2350. const option = row.packingSpecificationOption?.[1] || row.packingSpecificationOption?.[0];
  2351. item.packingUnit = option?.conversionUnit;
  2352. } else {
  2353. item.packingUnit = row.packingSpecificationOption?.[1].conversionUnit;
  2354. }
  2355. }
  2356. } else {
  2357. // 第二层条件: packingBoolen (isUnpack 为 false 时的分支)
  2358. if (packingBoolen) {
  2359. item.packingUnit = filterArr?.[0]?.conversionUnit;
  2360. } else {
  2361. item.packingUnit = row.packingUnit;
  2362. }
  2363. }
  2364. let outBoolen = !!this.getDict('不拆物料层规格', item.measureUnit)
  2365. .dictValue;
  2366. if (outBoolen) {
  2367. // 计量单位为KG类,直接替换
  2368. item.weight = item.measureQuantity ? Number(item.measureQuantity) : 0;
  2369. } else {
  2370. console.log('计量单位为不为KG类======================');
  2371. // 计量单位为不为KG类,重新统计计算
  2372. let inBoolen = !!this.getDict(
  2373. '不拆物料层规格',
  2374. item.packingSpecificationOption[0].packageUnit
  2375. ).dictValue;
  2376. let startIndex = item.packingSpecificationOption.findIndex(
  2377. (ite) => {
  2378. return (
  2379. item.measureUnit == ite.packingUnit &&
  2380. ite.packingUnit != ite.conversionUnit
  2381. );
  2382. }
  2383. );
  2384. let endIndex = item.packingSpecificationOption.findIndex(
  2385. (ite) => item.packingUnit == ite.conversionUnit
  2386. );
  2387. if (measureBoolen) {
  2388. let total = item.packingQuantity ? Number(item.packingQuantity) : 0;
  2389. for (; startIndex < endIndex; endIndex--) {
  2390. total = this.$math.format(
  2391. item.packingSpecificationOption[endIndex].packageCell * total,
  2392. 14
  2393. );
  2394. }
  2395. if (inBoolen) {
  2396. // 第二层为KG类
  2397. item.weight = total ? Number(total) : 0;
  2398. } else {
  2399. // 第二层不为KG类
  2400. item.weight = this.$math.format(total * item.netWeight, 14);
  2401. }
  2402. } else if (!measureBoolen) {
  2403. if (inBoolen) {
  2404. // 第二层为KG类
  2405. item.weight = item.measureQuantity ? Number(item.measureQuantity) : 0;
  2406. } else {
  2407. // 第二层不为KG类
  2408. if (row.singleWeight && item.measureQuantity) {
  2409. item.weight = Number(item.measureQuantity) * Number(row.singleWeight);
  2410. } else {
  2411. item.weight = 0;
  2412. }
  2413. }
  2414. }
  2415. }
  2416. packingList.push(item);
  2417. }
  2418. const existingIndex = this.packingList.findIndex(p =>
  2419. p.parentIndex === row.index
  2420. );
  2421. if (existingIndex > -1) {
  2422. this.packingList.splice(existingIndex, 1); // 移除旧数据
  2423. }
  2424. }
  2425. console.log(productIndex, 'productIndex')
  2426. // 单独点击保存并插入对应位置(包装)
  2427. if (productIndex == 0) {
  2428. this.packingList.splice(productIndex, 0, ...packingList);
  2429. } else {
  2430. let packingIndex = this.packingList.findLastIndex(
  2431. (item) =>
  2432. item.parentIndex == this.productList[productIndex - 1].index
  2433. );
  2434. this.packingList.splice(packingIndex + 1, 0, ...packingList);
  2435. }
  2436. const lastIndex = this.packingList.length - 1
  2437. let remainder = row.measureQuantity % row.packingSpecificationOption[1]?.packageCell
  2438. console.log(remainder, 'remainder')
  2439. if (remainder > 0) {
  2440. this.$set(this.packingList[lastIndex], 'measureQuantity', remainder)
  2441. }
  2442. },
  2443. //入库明细删除
  2444. listDel(row, index) {
  2445. this.productList.splice(index, 1);
  2446. this.deletePackingAndMaterial(row);
  2447. },
  2448. // 打开仓库弹框
  2449. handleWareHouse(row, idx, type) {
  2450. console.log(row, 'row')
  2451. console.log(idx, 'idx')
  2452. console.log(type, 'type')
  2453. if (row.packingSpecificationLabel?.length < 1) {
  2454. this.$message.error('请到主数据维护包装组信息!')
  2455. return;
  2456. }
  2457. if (row.isSave) {
  2458. return false;
  2459. }
  2460. //单个
  2461. if (idx > -1 && type != 'batch') {
  2462. if (row.packingQuantity > 0) {
  2463. if (!row.isUnpack) {
  2464. console.log('不拆')
  2465. //计量和包装单位相同
  2466. if (row.measureUnit == row.packingUnit) {
  2467. let pNum = 0;
  2468. let mNum = row.measureQuantity
  2469. this.$refs.wareHouseDailogRef.open(
  2470. pNum,
  2471. mNum,
  2472. idx,
  2473. row.warehouseId,
  2474. row.warehouseName + '',
  2475. row.categoryLevelPathIdParent
  2476. );
  2477. } else {
  2478. if (row.packingSpecificationOption[1]?.packageCell) {
  2479. // let num = Math.ceil(
  2480. // row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
  2481. // );
  2482. let num = row.packingQuantity;
  2483. let splitIndex = row.packingSpecificationOption.findIndex(
  2484. (item) =>
  2485. item.conversionUnit == row.packingUnit &&
  2486. item.packageUnit != item.conversionUnit
  2487. );
  2488. for (; splitIndex > 1; splitIndex--) {
  2489. num = this.$math.format(
  2490. num *
  2491. row.packingSpecificationOption[splitIndex].packageCell,
  2492. 14
  2493. );
  2494. }
  2495. this.$refs.wareHouseDailogRef.open(
  2496. num,
  2497. row.measureQuantity,
  2498. idx,
  2499. row.warehouseId,
  2500. row.warehouseName + '',
  2501. row.categoryLevelPathIdParent);
  2502. } else {
  2503. this.$refs.wareHouseDailogRef.open(
  2504. num,
  2505. row.measureQuantity,
  2506. idx,
  2507. row.warehouseId,
  2508. row.warehouseName + '',
  2509. row.categoryLevelPathIdParent);
  2510. }
  2511. }
  2512. } else {
  2513. console.log('拆')
  2514. // let filterArr = row.packingSpecificationOption.filter((item) => {
  2515. // return (
  2516. // item.packageUnit == row.packingUnit &&
  2517. // item.packageUnit != item.conversionUnit
  2518. // );
  2519. // });
  2520. let num = Math.ceil(
  2521. row.measureQuantity / row.packingSpecificationOption[1]?.packageCell
  2522. );
  2523. console.log(num, 'num')
  2524. this.$refs.wareHouseDailogRef.open(
  2525. num,
  2526. row.measureQuantity,
  2527. idx,
  2528. row.warehouseId,
  2529. row.warehouseName + '',
  2530. row.categoryLevelPathIdParent
  2531. );
  2532. }
  2533. } else {
  2534. this.$message.error('请先填写包装数量!');
  2535. }
  2536. } else {
  2537. //批量
  2538. console.log(row, `row`)
  2539. console.log(idx, `idx`)
  2540. console.log(type, 'type')
  2541. // 验证所有选中行是否填写了包装数量
  2542. if (row.some(item => !item.packingQuantity)) {
  2543. this.$message.error('请先填写所有行的包装数量!');
  2544. return;
  2545. }
  2546. // 计算总需求数量
  2547. let totalPacking = row.reduce((sum, item) => {
  2548. return sum + Number(this.calculateRequiredWarehouseNum(item));
  2549. }, 0);
  2550. const mNum = row.reduce((sum, item) => {
  2551. if (item.measureQuantity !== undefined && item.measureQuantity !== null) {
  2552. return sum + Number(item.measureQuantity);
  2553. }
  2554. return sum;
  2555. }, 0);
  2556. // 打开仓库选择弹窗
  2557. this.$refs.wareHouseDailogRef.open(
  2558. totalPacking,
  2559. mNum
  2560. );
  2561. }
  2562. },
  2563. calculateRequiredWarehouseNum(row) {
  2564. if (!row.isUnpack && row.measureUnit !== row.packingUnit) {
  2565. let splitIndex = row.packingSpecificationOption.findIndex(
  2566. item => item.conversionUnit === row.packingUnit
  2567. );
  2568. let num = row.packingQuantity;
  2569. for (; splitIndex > 1; splitIndex--) {
  2570. num = Math.ceil(num * row.packingSpecificationOption[splitIndex].packageCell);
  2571. }
  2572. return num;
  2573. }
  2574. console.log(row.packingQuantity, 'row.calculateRequiredWarehouseNum')
  2575. return row.packingQuantity;
  2576. },
  2577. wareHouseSelection(argum, idx) {
  2578. console.log(argum, 'argumargumargumargumargumargum', idx);
  2579. // 方便包装遍历获取仓库id和名称
  2580. let warehouseIds = [];
  2581. let warehouseNames = [];
  2582. argum.forEach((item) => {
  2583. console.log(item, 'itemitem')
  2584. for (let index = 0; index < item.packingQuantity; index++) {
  2585. warehouseIds.push(item.warehouseId);
  2586. warehouseNames.push(item.warehouseName);
  2587. }
  2588. });
  2589. console.log(idx, 'idxidxidxidx', this.productList, 'this.productList')
  2590. if (idx > -1) {
  2591. this.$set(
  2592. this.productList[idx],
  2593. 'warehouseId',
  2594. argum.map((item) => item.warehouseId).join(',')
  2595. );
  2596. this.$set(
  2597. this.productList[idx],
  2598. 'warehouseName',
  2599. argum.map((item) => item.warehouseName).join(',')
  2600. );
  2601. this.$set(this.productList[idx], 'warehouseIds', warehouseIds);
  2602. this.$set(this.productList[idx], 'warehouseNames', warehouseNames);
  2603. console.log(this.productList, 'productList')
  2604. } else {
  2605. this.productList.map((item, index) => {
  2606. this.$set(
  2607. this.productList[index],
  2608. 'warehouseId',
  2609. argum.map((item) => item.warehouseId).join(',')
  2610. );
  2611. this.$set(
  2612. this.productList[index],
  2613. 'warehouseName',
  2614. argum.map((item) => item.warehouseName).join(',')
  2615. );
  2616. this.$set(this.productList[index], 'warehouseIds', warehouseIds);
  2617. this.$set(
  2618. this.productList[index],
  2619. 'warehouseNames',
  2620. warehouseNames
  2621. );
  2622. });
  2623. }
  2624. this.$forceUpdate();
  2625. },
  2626. // 生成物料
  2627. generateMaterial(row) {
  2628. let materialList = [];
  2629. for (let index = 0; index < row.measureQuantity; index++) {
  2630. materialList.push({
  2631. materialCode: row.packageNo + index.toString().padStart(4, '0'), // 物料编码
  2632. index: row.index + '——' + index, // 包装索引
  2633. warehouseId: row.warehouseId, // 仓库id
  2634. warehouseName: row.warehouseName, // 仓库名称
  2635. categoryName: row.categoryName, // 产品名称
  2636. categoryCode: row.categoryCode, // 产品编码
  2637. parentIndex: row.index, // 产品索引
  2638. batchNo: row.batchNo, // 批次号
  2639. packageNo: row.packageNo, // 包装编码
  2640. measureQuantity: 1, // 计量数量
  2641. measureUnit: row.measureUnit, // 计量单位
  2642. weight: Number(
  2643. this.$math.format(row.weight / row.packingQuantity, 14)
  2644. ), // 重量
  2645. weightUnit: row.weightUnit, // 重量单位
  2646. barcodes: '', // 发货条码
  2647. clientCode: '', // 客户代号
  2648. materielDesignation: '', // 物料代号
  2649. engrave: '', // 刻码
  2650. result: 1, // 结果(1合格 2不合格)
  2651. status: 2 // 状态(0=未质检 1待检 2已检)
  2652. });
  2653. }
  2654. return materialList;
  2655. },
  2656. // 设置时间
  2657. dateSetting() {
  2658. if (!this.packingListSelected.length) {
  2659. return this.$message.error(`请选择${this.title}明细!`);
  2660. }
  2661. this.dateVisible = true;
  2662. },
  2663. // 选择包装列表
  2664. handleSelectionChange(val) {
  2665. this.packingListSelected = val;
  2666. },
  2667. // 选择质检结果改变质检状态
  2668. changeWrapStatus(resultValue, row, type) {
  2669. console.log(resultValue);
  2670. switch (resultValue) {
  2671. case 0:
  2672. // 清空质检状态
  2673. row.status = 0;
  2674. break;
  2675. default:
  2676. // 默认已检质检状态
  2677. row.status = 2;
  2678. break;
  2679. }
  2680. if (type === '包装') {
  2681. this.packingResultCahnge(resultValue, row);
  2682. } else {
  2683. this.materialResultCahnge(resultValue, row);
  2684. }
  2685. }
  2686. }
  2687. };
  2688. </script>
  2689. <style lang="scss" scoped>
  2690. .inbound_details {
  2691. margin-top: 10px;
  2692. .el-form-item {
  2693. margin-bottom: 0 !important;
  2694. }
  2695. }
  2696. .el-form-item {
  2697. margin-bottom: 5px;
  2698. }
  2699. .right_control {
  2700. display: flex;
  2701. >button {
  2702. margin-left: 5px;
  2703. }
  2704. }
  2705. .storage_btn {
  2706. margin-top: 20px;
  2707. display: flex;
  2708. align-content: center;
  2709. justify-content: center;
  2710. }
  2711. .el-date-editor.el-input,
  2712. .el-date-editor.el-input__inner {
  2713. width: 100% !important;
  2714. }
  2715. .red_color {
  2716. color: red;
  2717. }
  2718. .wareHouse_style {
  2719. text-overflow: ellipsis;
  2720. overflow: hidden;
  2721. word-break: break-all;
  2722. white-space: nowrap;
  2723. }
  2724. </style>