new-edit.vue 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080
  1. <!-- 用户编辑弹窗 -->
  2. <template>
  3. <ele-modal
  4. :title="title"
  5. :visible.sync="visible"
  6. :before-close="handleClose"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. width="80%"
  11. :maxable="true"
  12. >
  13. <header-title title="基本信息"></header-title>
  14. <base-info
  15. ref="baseInfoRefs"
  16. v-if="baseForm"
  17. :form="baseForm"
  18. :btnType="btnType"
  19. :isChangeNumber="isChangeNumber"
  20. :isChangeType="isChangeType"
  21. @resetTable="resetTable"
  22. @changeModel="changeModel"
  23. @getList="getList"
  24. @table2="table2"
  25. @changeType="changeType"
  26. @changeSource="changeSource"
  27. @getInspectionStandards="getInspectionStandards"
  28. :packingLists="packingList"
  29. @getCategoryInfo="getCategoryInfo"
  30. @changeProductNumberModel="changeProductNumberModel"
  31. @changesStokledgerNumberModal="changesStokledgerNumberModal"
  32. @getQualityTemplate="getQualityTemplate"
  33. ></base-info>
  34. <header-title title="样品信息"></header-title>
  35. <el-form label-width="110px">
  36. <el-row>
  37. <el-col :span="6">
  38. <el-form-item label="样品合格数:">
  39. <el-input
  40. type="number"
  41. :min="0"
  42. disabled
  43. v-model="baseForm.sampleQualifiedNumber"
  44. placeholder=""
  45. ></el-input>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="6">
  49. <el-form-item label="样品不合格数:">
  50. <el-input
  51. type="number"
  52. :min="0"
  53. disabled
  54. v-model="baseForm.sampleNoQualifiedNumber"
  55. placeholder=""
  56. ></el-input>
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="6">
  60. <el-form-item label="样品合格率:">
  61. <el-input v-model="baseForm.sampleQualificationRate" disabled />
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="6">
  65. <el-form-item label="样品不合格率:">
  66. <el-input v-model="baseForm.sampleNoQualificationRate" disabled />
  67. </el-form-item>
  68. </el-col>
  69. </el-row>
  70. <el-row>
  71. <el-col :span="6">
  72. <el-form-item label="样品类型:">
  73. <el-input disabled :value="sampletypeVal(baseForm.conditionType)" />
  74. </el-form-item>
  75. </el-col>
  76. <el-col :span="6">
  77. <el-form-item label="样品数量:">
  78. <el-input
  79. type="number"
  80. disabled
  81. v-model="baseForm.sampleQuantity"
  82. />
  83. </el-form-item>
  84. </el-col>
  85. <el-col :span="6">
  86. <el-form-item label="样品重量:">
  87. <el-input type="number" disabled v-model="baseForm.sampleWeight" />
  88. </el-form-item>
  89. </el-col>
  90. </el-row>
  91. </el-form>
  92. <el-row>
  93. <header-title title="质检内容"></header-title>
  94. <el-tabs v-model="activeName" @tab-click="handleClick">
  95. <el-tab-pane label="来源清单" name="1">
  96. <!-- <ele-pro-table
  97. ref="table12"
  98. :columns="tableColumns"
  99. :datasource="datasource"
  100. :needPage="
  101. btnType == 'add' ||
  102. (btnType == 'edit' && !isFormNumber && !isOrder)
  103. ? false
  104. : true
  105. "
  106. @selection-change="handleSelectionChange"
  107. > -->
  108. <!-- :datasource="sourceList" -->
  109. <!-- :datasource="
  110. btnType == 'add' ||
  111. (btnType == 'edit' && (!isPackingList || !isSampleList))
  112. ? sourceList
  113. : datasource
  114. " -->
  115. <!-- 来料列表表格 -->
  116. <ele-pro-table
  117. ref="table12"
  118. :columns="tableColumns"
  119. :datasource="sourceList"
  120. :needPage="false"
  121. @selection-change="handleSelectionChange"
  122. height="500"
  123. >
  124. <template
  125. v-slot:toolbar
  126. v-if="this.baseForm.qualityMode == 2 && btnType != 'detail'"
  127. >
  128. <el-dropdown trigger="click" @command="handleSampleNumber">
  129. <el-link type="primary" icon="el-icon-plus">取样</el-link>
  130. <el-dropdown-menu slot="dropdown">
  131. <el-dropdown-item command="1">取整样</el-dropdown-item>
  132. <el-dropdown-item command="2">取小样</el-dropdown-item>
  133. </el-dropdown-menu>
  134. </el-dropdown>
  135. </template>
  136. <template v-slot:toolkit v-if="this.baseForm.qualityMode == 2">
  137. <el-row>
  138. <el-form
  139. ref="ruleForm"
  140. :model="formData"
  141. label-width="60px"
  142. size="mini"
  143. :rules="rules"
  144. class="flex"
  145. :show-message="false"
  146. >
  147. <el-col :span="6" v-if="conditionType == 2">
  148. <el-form-item
  149. prop="number"
  150. label-width="0"
  151. style="margin-bottom: 0"
  152. >
  153. <el-input
  154. v-model="formData.number"
  155. placeholder="请输入"
  156. size="mini"
  157. ></el-input>
  158. </el-form-item>
  159. </el-col>
  160. <el-col :span="6" v-if="conditionType == 2">
  161. <el-form-item
  162. prop="sampleUnit"
  163. label-width="0"
  164. style="margin: 0"
  165. >
  166. <DictSelection
  167. dictName="计量单位"
  168. clearable
  169. v-model="formData.sampleUnit"
  170. size="mini"
  171. @change="changeSamUnit"
  172. ></DictSelection>
  173. </el-form-item>
  174. </el-col>
  175. <el-col :span="8" v-if="conditionType == 2">
  176. <el-form-item prop="portion" label="数量" style="margin: 0">
  177. <el-input
  178. v-model="formData.portion"
  179. placeholder="请输入"
  180. size="mini"
  181. clearable
  182. ></el-input>
  183. </el-form-item>
  184. </el-col>
  185. <el-col :span="10" v-if="conditionType == 1">
  186. <el-form-item prop="portion" label="数量" style="margin: 0">
  187. <el-input
  188. v-model="formData.portion"
  189. placeholder="请输入"
  190. size="mini"
  191. clearable
  192. ></el-input>
  193. </el-form-item>
  194. </el-col>
  195. <el-col :span="10" v-if="conditionType == 1">
  196. <el-form-item
  197. prop="packingUnit"
  198. label="单位"
  199. style="margin: 0"
  200. >
  201. <el-select
  202. v-model="formData.packingUnit"
  203. placeholder="请选择"
  204. >
  205. <el-option
  206. v-for="item in packingSpecificationOption"
  207. :key="item.id"
  208. :label="item.conversionUnit"
  209. :value="item.id"
  210. >
  211. </el-option>
  212. </el-select>
  213. </el-form-item>
  214. </el-col>
  215. <el-col
  216. :span="4"
  217. style="text-align: right"
  218. v-if="conditionType == 1"
  219. >
  220. <el-button
  221. type="primary"
  222. size="mini"
  223. @click="handleExtractFull"
  224. style="margin-right: 12px"
  225. >确认</el-button
  226. >
  227. </el-col>
  228. <el-col
  229. :span="4"
  230. style="text-align: right"
  231. v-if="conditionType == 2"
  232. >
  233. <el-button
  234. type="primary"
  235. size="mini"
  236. @click="handleExtractFull"
  237. style="margin-right: 12px"
  238. >确认</el-button
  239. >
  240. </el-col>
  241. </el-form>
  242. </el-row>
  243. </template>
  244. </ele-pro-table>
  245. </el-tab-pane>
  246. <el-tab-pane label="样品清单" name="2">
  247. <el-table
  248. v-show="activeName === '2'"
  249. v-if="sampleList.length > 0"
  250. ref="showSampleListTable"
  251. :data="paginatedSampleList"
  252. tooltip-effect="dark"
  253. height="500"
  254. border
  255. row-key="sampleCode"
  256. >
  257. <el-table-column
  258. label="序号"
  259. type="index"
  260. width="50"
  261. align="center"
  262. ></el-table-column>
  263. <template v-for="column in tableColumns2">
  264. <el-table-column
  265. :key="column.prop"
  266. :label="column.label"
  267. :prop="column.prop"
  268. :show-overflow-tooltip="true"
  269. :width="column.width"
  270. :align="column.align"
  271. ></el-table-column>
  272. </template>
  273. </el-table>
  274. <!-- <el-pagination
  275. v-show="activeName === '2' && sampleList.length > 0"
  276. @size-change="handleSampleSizeChange"
  277. @current-change="handleSampleCurrentChange"
  278. :current-page="samplePagination.currentPage"
  279. :page-sizes="[10, 20, 50, 100]"
  280. :page-size="samplePagination.pageSize"
  281. layout="total, sizes, prev, pager, next, jumper"
  282. :total="samplePagination.total"
  283. style="margin-top: 10px"
  284. ></el-pagination> -->
  285. </el-tab-pane>
  286. <el-tab-pane label="质检方案" name="3">
  287. <el-button
  288. @click="addInspectionTemplate(baseForm.type)"
  289. type="primary"
  290. style="margin-top: 5px"
  291. >选择质检方案</el-button
  292. >
  293. <el-table
  294. v-show="activeName === '3'"
  295. v-if="schemeList.length > 0"
  296. ref="showSchemeListTable"
  297. :data="paginatedSchemeList"
  298. tooltip-effect="dark"
  299. height="500"
  300. border
  301. row-key="id"
  302. >
  303. <el-table-column
  304. label="序号"
  305. type="index"
  306. width="50"
  307. align="center"
  308. ></el-table-column>
  309. <el-table-column
  310. label="质检方案编码"
  311. prop="qualitySchemeTemplateCode"
  312. align="center"
  313. width="170"
  314. ></el-table-column>
  315. <el-table-column
  316. label="质检方案名称"
  317. prop="qualitySchemeTemplateName"
  318. align="center"
  319. width="170"
  320. ></el-table-column>
  321. <el-table-column
  322. label="质检类型"
  323. prop="categoryLevelClassName"
  324. align="center"
  325. width="170"
  326. ></el-table-column>
  327. <el-table-column
  328. label="质检项编码"
  329. prop="inspectionCode"
  330. align="center"
  331. width="170"
  332. ></el-table-column>
  333. <el-table-column
  334. label="质检项名称"
  335. prop="inspectionName"
  336. align="center"
  337. width="150"
  338. ></el-table-column>
  339. <el-table-column
  340. label="工艺参数"
  341. prop="defaultValue"
  342. align="center"
  343. >
  344. <template slot-scope="scope">
  345. <div style="display: flex; flex-direction: row">
  346. <DictSelection
  347. v-if="btnType != 'detail'"
  348. style="width: 85px"
  349. clearable
  350. dictName="数学字符"
  351. v-model="scope.row.symbol"
  352. ></DictSelection>
  353. <el-input
  354. :disabled="btnType == 'detail'"
  355. v-model="scope.row.defaultValue"
  356. placeholder="请输入内容"
  357. style="width: 120px"
  358. ></el-input>
  359. <DictSelection
  360. v-if="btnType != 'detail'"
  361. dictName="工艺参数单位"
  362. clearable
  363. filterable
  364. v-model="scope.row.unitName"
  365. style="width: 100px"
  366. >
  367. </DictSelection>
  368. </div>
  369. </template>
  370. </el-table-column>
  371. <el-table-column fixed="right" label="操作" width="80">
  372. <template slot-scope="scope">
  373. <el-popconfirm
  374. class="ele-action"
  375. title="确定要删除当前方案吗?"
  376. @confirm="handDel(scope.$index)"
  377. >
  378. <template v-slot:reference>
  379. <el-link
  380. type="danger"
  381. :underline="false"
  382. icon="el-icon-delete"
  383. >
  384. 删除
  385. </el-link>
  386. </template>
  387. </el-popconfirm>
  388. </template>
  389. </el-table-column>
  390. </el-table>
  391. <!-- <el-pagination
  392. v-show="activeName === '3' && schemeList.length > 0"
  393. @size-change="handleSchemeSizeChange"
  394. @current-change="handleSchemeCurrentChange"
  395. :current-page="schemePagination.currentPage"
  396. :page-sizes="[10, 20, 50, 100]"
  397. :page-size="schemePagination.pageSize"
  398. layout="total, sizes, prev, pager, next, jumper"
  399. :total="schemePagination.total"
  400. style="margin-top: 10px"
  401. ></el-pagination> -->
  402. </el-tab-pane>
  403. </el-tabs>
  404. </el-row>
  405. <template v-slot:footer>
  406. <el-button @click="handleClose">取消</el-button>
  407. <el-button
  408. v-if="btnType != 'detail' && btnType != 'issued'"
  409. type="primary"
  410. :loading="loading"
  411. @click="handleSave"
  412. >保存</el-button
  413. >
  414. <el-button
  415. v-if="btnType != 'detail'"
  416. type="primary"
  417. :loading="loading"
  418. @click="handleIssued"
  419. >下发</el-button
  420. >
  421. <!-- 选择质检方案 -->
  422. <inspectionTemplateDialog
  423. v-if="baseForm"
  424. :type="baseForm.type"
  425. ref="inspectionTemplateRef"
  426. @choose="inspectionTemplateSuccess"
  427. ></inspectionTemplateDialog>
  428. </template>
  429. </ele-modal>
  430. </template>
  431. <script>
  432. // import baseInfo from './baseInfo.vue';
  433. import baseInfo from './new-baseInfo.vue';
  434. // 质检方案的弹窗
  435. import inspectionTemplateDialog from '@/views/inspectionTemplate/components/inspectionTemplateDialog.vue';
  436. import { getCode, getCodeList } from '@/api/login';
  437. import { save, update, planIssued } from '@/api/inspectionPlan';
  438. import {
  439. getQualityTemplateList,
  440. getTemplateListByPlanId,
  441. getSampleListByPlanId,
  442. getInventoryListByPlanId,
  443. outInRecordsPage,
  444. getBatchInfoData,
  445. getProductOrder,
  446. getProductSteup
  447. } from '@/api/inspectionPlan/index.js';
  448. import { getQualityTemplateByIds } from '@/api/inspectionTemplate';
  449. export default {
  450. components: {
  451. baseInfo,
  452. inspectionTemplateDialog
  453. },
  454. data() {
  455. const defaultForm = function () {
  456. return {
  457. id: '',
  458. code: '',
  459. name: '',
  460. type: '',
  461. qualityMode: '',
  462. inspectionStandards: '',
  463. autoOrder: '',
  464. groupId: '',
  465. groupName: '',
  466. executeId: '',
  467. executeName: '',
  468. planStartTime: '',
  469. planEndTime: '',
  470. standard: '',
  471. planSource: '',
  472. planSourceCode: '',
  473. productName: '',
  474. productCode: '',
  475. batchNo: '',
  476. specification: '',
  477. modelType: '',
  478. brandNo: '',
  479. productNumber: '',
  480. qualifiedNumber: '',
  481. unqualifiedNumber: '',
  482. qualificationRate: '',
  483. totalWeight: '',
  484. sampleNumber: null,
  485. sampleMeasureUnit: '',
  486. sampleProportion: '',
  487. supplierMark: '',
  488. remark: '',
  489. accessory: [],
  490. conditionType: 1
  491. };
  492. };
  493. return {
  494. defaultForm,
  495. // 表单数据
  496. baseForm: { ...defaultForm() },
  497. tableColumns2: [
  498. {
  499. label: '样品编码',
  500. prop: 'sampleCode',
  501. width: '150',
  502. align: 'center'
  503. },
  504. {
  505. label: '编码',
  506. prop: 'categoryCode',
  507. width: '150',
  508. align: 'center'
  509. },
  510. {
  511. label: '名称',
  512. prop: 'categoryName',
  513. width: '150',
  514. align: 'center'
  515. },
  516. { label: '批次号', prop: 'batchNo', align: 'center', width: 120 },
  517. { label: '发货条码', prop: 'barcodes', align: 'center' },
  518. { label: '包装编码', prop: 'packageNo', align: 'center' },
  519. { label: '包装数量', prop: 'packingQuantity', align: 'center' },
  520. { label: '包装单位', prop: 'packingUnit', align: 'center' },
  521. { label: '计量数量', prop: 'measureQuantity', align: 'center' },
  522. { label: '计量单位', prop: 'measureUnit', align: 'center' },
  523. { label: '物料代号', prop: 'materielDesignation', align: 'center' },
  524. { label: '客户代号', prop: 'clientCode', align: 'center' },
  525. { label: '刻码', prop: 'engrave', align: 'center' },
  526. // { prop: 'specification', label: '规格', align: 'center', width: 100, showOverflowTooltip: true },
  527. // { prop: 'brandNum', label: '牌号', align: 'center', width: 100, showOverflowTooltip: true },
  528. // { prop: 'modelType', label: '型号', align: 'center', width: 100, showOverflowTooltip: true },
  529. { label: '重量', prop: 'weight', align: 'center' },
  530. { label: '重量单位', prop: 'weightUnit', align: 'center' },
  531. { label: '仓库', prop: 'warehouseName', align: 'center' },
  532. { label: '货区', prop: 'areaName', align: 'center' },
  533. { label: '货架', prop: 'goodsShelfName', align: 'center' },
  534. { label: '货位', prop: 'goodsAllocationName', align: 'center' },
  535. { label: '生产日期', prop: 'productionDate', align: 'center' },
  536. { label: '采购日期', prop: 'purchaseDate', align: 'center' }
  537. ],
  538. packingList: [],
  539. sourceList: [],
  540. sourcePagination: {
  541. currentPage: 1,
  542. pageSize: 10,
  543. total: 0
  544. },
  545. sampleList: [],
  546. samplePagination: {
  547. currentPage: 1,
  548. pageSize: 10,
  549. total: 0
  550. },
  551. schemeList: [],
  552. schemePagination: {
  553. currentPage: 1,
  554. pageSize: 10,
  555. total: 0
  556. },
  557. // 表单验证规则
  558. visible: false,
  559. btnType: null,
  560. title: null,
  561. loading: false,
  562. listPage: [],
  563. activeName: '1',
  564. selectedList: [],
  565. isCheck: false, // 是否拆包 false 不拆包 true 拆包
  566. rowIds: '',
  567. formData: {
  568. number: 1,
  569. sampleUnit: '',
  570. portion: null,
  571. packingUnit: ''
  572. },
  573. rules: {
  574. number: [
  575. {
  576. required: true,
  577. message: '请输入',
  578. trigger: 'blur'
  579. }
  580. ],
  581. sampleUnit: [
  582. {
  583. required: true,
  584. message: '请选择样品单位',
  585. trigger: 'change'
  586. }
  587. ],
  588. portion: [
  589. {
  590. required: true,
  591. message: '请输入',
  592. trigger: 'blur'
  593. }
  594. ],
  595. packingUnit: [
  596. {
  597. required: true,
  598. message: '请选择',
  599. trigger: 'change'
  600. }
  601. ]
  602. },
  603. isScheme: true,
  604. isOrder: true,
  605. isConsumable: '', //0 单件 1批量
  606. netWeight: '', // 净重
  607. conditionType: null,
  608. isFormNumber: true,
  609. sampleListCode: '',
  610. productItem: {}, //产品信息
  611. isUpdateData: true,
  612. isChangeNumber: true,
  613. isChangeType: true,
  614. isOnce: true,
  615. dimensionType: '',
  616. isSampleList: true,
  617. isPackingList: true,
  618. isSchemeList: true,
  619. newSampleList: [],
  620. kkconditionType: '',
  621. packingSpecificationOption: [] // 包装规格下拉
  622. };
  623. },
  624. watch: {
  625. // 样品清单
  626. sampleList: {
  627. handler: async function (newVal) {
  628. // 计算重量跟数量
  629. this.calculate(newVal);
  630. if (newVal && newVal.length > 0 && !newVal[0].sampleCode) {
  631. let count = newVal ? newVal.length : 0;
  632. const codeList = await this.batchCodes(count);
  633. console.log(codeList, 'codeList 0000');
  634. console.log(newVal, 'newVal');
  635. newVal.map(async (el, index) => {
  636. if (!el.sampleCode) {
  637. this.$set(el, 'sampleCode', codeList[index]);
  638. // el.sampleCode = codeList[index];
  639. }
  640. });
  641. }
  642. },
  643. deep: true,
  644. immediate: true
  645. }
  646. },
  647. computed: {
  648. tableColumns() {
  649. let arr = [
  650. // (this.btnType !== 'issued' || this.baseForm.qualityMode === 2)
  651. // ? {
  652. // columnKey: 'selection',
  653. // type: 'selection',
  654. // width: 45,
  655. // align: 'center'
  656. // }
  657. // : null,
  658. {
  659. columnKey: 'selection',
  660. type: 'selection',
  661. width: 45,
  662. align: 'center'
  663. },
  664. {
  665. columnKey: 'index',
  666. label: '序号',
  667. type: 'index',
  668. width: 55,
  669. align: 'center',
  670. fixed: 'left'
  671. },
  672. {
  673. label: '编码',
  674. prop: 'categoryCode',
  675. width: 150,
  676. align: 'center',
  677. showOverflowTooltip: true
  678. },
  679. {
  680. label: '名称',
  681. prop: 'categoryName',
  682. width: '150',
  683. align: 'center',
  684. width: 120,
  685. showOverflowTooltip: true
  686. },
  687. { label: '批次号', prop: 'batchNo', align: 'center', width: 120 },
  688. { label: '发货条码', prop: 'barcodes', align: 'center' },
  689. {
  690. label: '包装编码',
  691. prop: 'packageNo',
  692. align: 'center',
  693. width: 120,
  694. showOverflowTooltip: true
  695. },
  696. { label: '包装数量', prop: 'packingQuantity', align: 'center' },
  697. { label: '包装单位', prop: 'packingUnit', align: 'center' },
  698. { label: '计量数量', prop: 'measureQuantity', align: 'center' },
  699. { label: '计量单位', prop: 'measureUnit', align: 'center' },
  700. { label: '物料代号', prop: 'materielDesignation', align: 'center' },
  701. { label: '客户代号', prop: 'clientCode', align: 'center' },
  702. {
  703. label: '供应商名称',
  704. prop: 'supplierName',
  705. align: 'center',
  706. width: 120,
  707. showOverflowTooltip: true
  708. },
  709. {
  710. label: '供应商代号',
  711. prop: 'supplierCode',
  712. align: 'center',
  713. width: '120',
  714. showOverflowTooltip: true
  715. },
  716. { label: '刻码', prop: 'engrave', align: 'center' },
  717. { label: '重量', prop: 'weight', align: 'center' },
  718. { label: '重量单位', prop: 'weightUnit', align: 'center' },
  719. {
  720. label: '仓库',
  721. prop: 'warehouseName',
  722. align: 'center',
  723. width: 120,
  724. showOverflowTooltip: true
  725. },
  726. { label: '货区', prop: 'areaName', align: 'center' },
  727. { label: '货架', prop: 'goodsShelfName', align: 'center' },
  728. { label: '货位', prop: 'goodsAllocationName', align: 'center' },
  729. {
  730. label: '生产日期',
  731. prop: 'productionDate',
  732. align: 'center',
  733. width: 120,
  734. showOverflowTooltip: true
  735. },
  736. {
  737. label: '采购日期',
  738. prop: 'purchaseDate',
  739. align: 'center',
  740. width: 120,
  741. showOverflowTooltip: true
  742. }
  743. ];
  744. return arr;
  745. },
  746. sampletypeVal() {
  747. return (row) => {
  748. if (row == 1) {
  749. return '整样';
  750. }
  751. return '小样';
  752. };
  753. },
  754. //分页后的来源列表
  755. paginatedSourceList() {
  756. console.log('分页', this.sourceList);
  757. // const { currentPage, pageSize } = this.sourcePagination;
  758. // const start = (currentPage - 1) * pageSize;
  759. // const end = start + pageSize;
  760. // return this.sourceList.slice(start, end);
  761. return this.sourceList;
  762. },
  763. // 分页后的样品列表
  764. paginatedSampleList() {
  765. return this.sampleList;
  766. // if (this.rowIds && this.isSampleList) {
  767. // console.log(this.sampleList, 'sampleList');
  768. // return this.sampleList;
  769. // }
  770. // const { currentPage, pageSize } = this.samplePagination;
  771. // const start = (currentPage - 1) * pageSize;
  772. // const end = start + pageSize;
  773. // return this.sampleList.slice(start, end);
  774. },
  775. // 分页后的质检方案列表
  776. paginatedSchemeList() {
  777. // if (this.rowIds && this.isScheme) {
  778. // console.log(this.schemeList, 'test');
  779. // return this.schemeList;
  780. // }
  781. // const { currentPage, pageSize } = this.schemePagination;
  782. // const start = (currentPage - 1) * pageSize;
  783. // const end = start + pageSize;
  784. // return this.schemeList.slice(start, end);
  785. return this.schemeList;
  786. }
  787. },
  788. created() {},
  789. methods: {
  790. //
  791. calculate(list) {
  792. // if (list.length == 0) {
  793. // this.baseForm.sampleQuantity = 0;
  794. // this.baseForm.sampleWeight = 0;
  795. // }
  796. let sampleQuantity = 0; // 样品数量
  797. let sampleWeight = 0; // 样品重量
  798. // // let sampleQualifiedNumber = 0; // 样品合格数
  799. // let sampleNoQualifiedNumber = 0; // 样品不合格数
  800. list.forEach((el) => {
  801. sampleQuantity += el.measureQuantity - 0;
  802. sampleWeight += el.weight - 0;
  803. // if (el.qualityResults != 2) {
  804. // sampleQualifiedNumber += el.measureQuantity - 0;
  805. // } else {
  806. // sampleNoQualifiedNumber += el.measureQuantity - 0;
  807. // }
  808. });
  809. this.$set(this.baseForm, 'sampleQuantity', sampleQuantity); // 样品数量
  810. this.$set(this.baseForm, 'sampleWeight', sampleWeight); // 样品重量
  811. // // 计算合格率和不合格率(百分比形式)
  812. // let sampleQualificationRate = ''; // 合格率
  813. // let sampleNoQualificationRate = ''; // 不合格率
  814. // if (sampleQualifiedNumber) {
  815. // sampleQualificationRate =
  816. // ((sampleQualifiedNumber / sampleQuantity) * 100).toFixed(2) || '';
  817. // sampleNoQualificationRate =
  818. // ((sampleNoQualifiedNumber / sampleQuantity) * 100).toFixed(2) || '';
  819. // }
  820. // if (sampleQualificationRate || sampleQualificationRate == '0.00') {
  821. // sampleQualificationRate = sampleQualificationRate + '%';
  822. // }
  823. // if (sampleNoQualificationRate || sampleNoQualificationRate == '0.00') {
  824. // sampleNoQualificationRate = sampleNoQualificationRate + '%';
  825. // }
  826. // let resultsTotal = this.baseForm.productNumber - sampleQuantity;
  827. // if (sampleQuantity == sampleQualifiedNumber) {
  828. // this.$set(this.baseForm, 'qualifiedNumber', resultsTotal);
  829. // this.$set(this.baseForm, 'unqualifiedNumber', 0);
  830. // this.$set(this.baseForm, 'qualificationRate', '100%');
  831. // // this.$set(this.baseForm, 'noQualificationRate', '0');
  832. // this.$set(this.baseForm, 'qualityResults', 1);
  833. // } else {
  834. // this.$set(this.baseForm, 'unqualifiedNumber', resultsTotal);
  835. // this.$set(this.baseForm, 'qualifiedNumber', 0);
  836. // this.$set(this.baseForm, 'qualificationRate', '0');
  837. // // this.$set(this.form, 'noQualificationRate', '100%');
  838. // this.$set(this.baseForm, 'qualityResults', 2);
  839. // }
  840. // // this.$set(this.form, 'resultsTotal', resultsTotal);
  841. // this.$set(
  842. // this.baseForm,
  843. // 'sampleQualificationRate', // 样品合格率
  844. // sampleQualificationRate
  845. // );
  846. // this.$set(
  847. // this.baseForm,
  848. // 'sampleNoQualificationRate', // 样品不合格率
  849. // sampleNoQualificationRate
  850. // );
  851. // this.$set(
  852. // this.baseForm,
  853. // 'sampleNoQualifiedNumber', // 样品不合格数
  854. // sampleNoQualifiedNumber
  855. // );
  856. // this.$set(
  857. // this.baseForm,
  858. // 'sampleQualifiedNumber',
  859. // sampleQualifiedNumber
  860. // ); // 样品合格数
  861. },
  862. //成品检验类型,计划来源主数据,修改数量生成来源清单
  863. changeProductNumberModel(num) {
  864. // if (
  865. // this.btnType == 'add' ||
  866. // (this.btnType == 'edit' && !this.isUpdateData)
  867. // ) {
  868. // this.$refs.table12.setData([]);
  869. // this.isOrder = false;
  870. // let nums = Number(num);
  871. // let p = this.productItem;
  872. // let list = [];
  873. // if (this.isConsumable == 0) {
  874. // for (let i = 0; i < nums; i++) {
  875. // let obj = {
  876. // id: p.id,
  877. // batchNo: p.batchNo,
  878. // categoryCode: p.code, //编码
  879. // categoryName: p.name, //名称
  880. // measureQuantity: 1,
  881. // measureUnit: p.measuringUnit, //计量单位
  882. // weightUnit: p.weightUnit, //重量单位
  883. // weight: p.netWeight //重量
  884. // };
  885. // list.push(obj);
  886. // }
  887. // } else if (this.isConsumable == 1) {
  888. // let obj = {
  889. // id: p.id,
  890. // batchNo: p.batchNo,
  891. // categoryCode: p.code, //编码
  892. // categoryName: p.name, //名称
  893. // measureQuantity: nums, //计量数量
  894. // measureUnit: p.measuringUnit, //计量单位
  895. // weightUnit: p.weightUnit, //重量单位
  896. // weight: p.netWeight * nums //重量
  897. // };
  898. // list.push(obj);
  899. // }
  900. // this.$refs.table12.setData(list);
  901. // // *** 如果检验方式是全量的话 还需要同步样品清单数据
  902. // if (
  903. // this.baseForm.qualityMode == 1 &&
  904. // this.baseForm.inspectionStandards
  905. // ) {
  906. // this.isFormNumber = false;
  907. // this.handleSampleList();
  908. // }
  909. // console.log(this.baseForm, 'form --');
  910. // }
  911. console.log('数据33333');
  912. // this.$refs.table12.setData([]);
  913. this.sourceList = [];
  914. this.packingList = [];
  915. this.isOrder = false;
  916. let nums = Number(num);
  917. let p = this.productItem;
  918. let list = [];
  919. if (this.isConsumable == 0) {
  920. for (let i = 0; i < nums; i++) {
  921. let obj = {
  922. id: p.id,
  923. batchNo: p.batchNo,
  924. categoryCode: p.code, //编码
  925. categoryName: p.name, //名称
  926. measureQuantity: 1,
  927. measureUnit: p.measuringUnit, //计量单位
  928. weightUnit: p.weightUnit, //重量单位
  929. weight: p.netWeight //重量
  930. };
  931. list.push(obj);
  932. }
  933. } else if (this.isConsumable == 1) {
  934. let obj = {
  935. id: p.id,
  936. batchNo: p.batchNo,
  937. categoryCode: p.code, //编码
  938. categoryName: p.name, //名称
  939. measureQuantity: nums, //计量数量
  940. measureUnit: p.measuringUnit, //计量单位
  941. weightUnit: p.weightUnit, //重量单位
  942. weight: p.netWeight * nums //重量
  943. };
  944. list.push(obj);
  945. }
  946. console.log('数据22222');
  947. console.log(this.isOrder);
  948. // this.$refs.table12.setData(list);
  949. this.sourceList = list;
  950. this.packingList = list;
  951. // *** 如果检验方式是全量的话 还需要同步样品清单数据
  952. if (
  953. this.baseForm.qualityMode == 1 &&
  954. this.baseForm.inspectionStandards
  955. ) {
  956. this.isFormNumber = false;
  957. console.log('+++++++++2');
  958. this.handleSampleList();
  959. }
  960. console.log(this.baseForm, 'form --');
  961. },
  962. //成品类型检验类型,计划来源库存台账, 生成来源清单
  963. async changesStokledgerNumberModal(val, dimension, type) {
  964. val.map((el) => (el.sourceId = el.id));
  965. console.log(val, dimension, '获取成品检验订单数据', type);
  966. // this.$refs.table12.setData([]);
  967. val = this.proceSources(val);
  968. console.log(val, 'valvalvalvalvalvalval');
  969. this.sourceList = [];
  970. this.packingList = [];
  971. if (dimension) this.dimensionType = dimension;
  972. if (dimension == 3) {
  973. // this.$refs.table12.setData(val);
  974. this.sourceList = val;
  975. this.packingList = val;
  976. this.calculateWeightAndQuantity(val);
  977. if (this.baseForm.qualityMode == '1' || type) {
  978. this.handleUnpackCase(val);
  979. } else if (this.baseForm.qualityMode == '2' || type) {
  980. this.sampleList = [];
  981. }
  982. return;
  983. }
  984. console.log('其他', 'dimension');
  985. let item = val[0];
  986. let num = Number(item.outboundNum);
  987. let list = [];
  988. // let weight = (item.weight / item.measureQuantity).toFixed(2);
  989. let weight = (
  990. (item.weight / item.measureQuantity) *
  991. item.outboundNum
  992. ).toFixed(2);
  993. list.push({
  994. ...item,
  995. id: 1,
  996. packingQuantity: null,
  997. measureQuantity: item.outboundNum,
  998. weight
  999. });
  1000. // for (let i = 0; i < num; i++) {
  1001. // list.push({
  1002. // ...item,
  1003. // id: i + 1,
  1004. // packingQuantity: null,
  1005. // measureQuantity: 1,
  1006. // weight
  1007. // });
  1008. // }
  1009. // list.push({
  1010. // ...item
  1011. // });
  1012. console.log(list, 'for循环成品检验订单数据');
  1013. // this.$refs.table12.setData(list);
  1014. this.sourceList = list;
  1015. this.packingList = list;
  1016. if (this.baseForm.qualityMode == '1' || type) {
  1017. this.handleUnpackCase(list);
  1018. } else if (this.baseForm.qualityMode == '2' || type) {
  1019. this.sampleList = [];
  1020. }
  1021. },
  1022. // changesStokledgerNumberModal(val, dimension) {
  1023. // console.log(val, dimension, '获取成品检验订单数据');
  1024. // this.$refs.table12.setData([]);
  1025. // if (dimension) this.dimensionType = dimension;
  1026. // if (dimension == 3) return this.$refs.table12.setData(val);
  1027. // let item = val[0];
  1028. // let num = Number(item.outboundNum);
  1029. // let list = [];
  1030. // let weight = (item.weight / item.measureQuantity).toFixed(2);
  1031. // for (let i = 0; i < num; i++) {
  1032. // list.push({
  1033. // ...item,
  1034. // id: i + 1,
  1035. // packingQuantity: null,
  1036. // measureQuantity: 1,
  1037. // weight
  1038. // });
  1039. // }
  1040. // console.log(list, 'for循环成品检验订单数据');
  1041. // this.$refs.table12.setData(list);
  1042. // if (this.baseForm.qualityMode == '1') {
  1043. // this.handleUnpackCase(list);
  1044. // } else if (this.baseForm.qualityMode == '2') {
  1045. // this.sampleList = [];
  1046. // }
  1047. // },
  1048. //获取基本信息中计量方式
  1049. getInspectionStandards(data) {
  1050. console.log(data, 'data');
  1051. this.baseForm.inspectionStandards = data;
  1052. if (this.baseForm.type == '3' && this.baseForm.planSource == '6') {
  1053. // this.isOrder = false;
  1054. this.handleSampleList();
  1055. }
  1056. if (this.btnType == 'edit' && !this.isOnce) {
  1057. this.isOrder = false;
  1058. this.handleSampleList();
  1059. }
  1060. this.isOnce = false;
  1061. },
  1062. async datasource({ page, limit, where }) {
  1063. // console.log(this.btnType);
  1064. // console.log(this.isScheme, this.isOrder);
  1065. // const res = await getInventoryListByPlanId({
  1066. // ...where,
  1067. // pageNum: page,
  1068. // size: limit
  1069. // });
  1070. // console.log(res.list);
  1071. // this.packingList = res.list;
  1072. // return res;
  1073. return await getInventoryListByPlanId({
  1074. ...where,
  1075. pageNum: page,
  1076. size: limit
  1077. });
  1078. },
  1079. // 切换质检内容
  1080. handleClick(tab) {
  1081. this.activeName = tab.name;
  1082. },
  1083. async open(type, row) {
  1084. this.kkconditionType = row?.conditionType;
  1085. this.visible = true;
  1086. this.activeName = '1';
  1087. this.btnType = type;
  1088. this.title =
  1089. type == 'add'
  1090. ? '新增'
  1091. : type == 'edit'
  1092. ? '编辑'
  1093. : type == 'issued'
  1094. ? '下发'
  1095. : '详情';
  1096. if (this.btnType === 'add') {
  1097. const code = await getCode('qms_plan_code');
  1098. this.baseForm.code = code;
  1099. this.rowIds = '';
  1100. return;
  1101. } else {
  1102. await this.handleEditOrDetail(row);
  1103. }
  1104. },
  1105. addInspectionTemplate(type) {
  1106. this.$refs.inspectionTemplateRef.open(type);
  1107. },
  1108. async inspectionTemplateSuccess(select) {
  1109. let data = await getQualityTemplateByIds({
  1110. templateIds: select.map((item) => item.id)
  1111. });
  1112. console.log('---------------------------');
  1113. this.isScheme = false;
  1114. this.schemeList.push(...data);
  1115. const strings = this.schemeList.map((item) => JSON.stringify(item));
  1116. const removeDupList = [...new Set(strings)];
  1117. const result = removeDupList.map((item) => JSON.parse(item));
  1118. this.schemeList = result;
  1119. this.schemePagination.total = this.schemeList.length;
  1120. },
  1121. async handleEditOrDetail(row) {
  1122. console.log('row====', row);
  1123. row.accessory = row.accessory || [];
  1124. this.baseForm = {
  1125. ...JSON.parse(JSON.stringify(row)),
  1126. groupId: row.groupId,
  1127. qualityMode: row.qualityMode
  1128. };
  1129. this.$nextTick(() => {
  1130. if (this.$refs.baseInfoRefs) {
  1131. // 获取人员
  1132. if (this.baseForm.groupId) {
  1133. this.$refs.baseInfoRefs.getUserList({
  1134. groupId: this.baseForm.groupId
  1135. });
  1136. }
  1137. //根据类型获取计划来源
  1138. if (this.baseForm.type) {
  1139. this.$refs.baseInfoRefs.typeChange(this.baseForm.type, '1111');
  1140. }
  1141. if (this.baseForm.productId) {
  1142. this.$refs.baseInfoRefs.getProductDetails(
  1143. this.baseForm.productId
  1144. );
  1145. }
  1146. }
  1147. });
  1148. // 如果是编辑或者详情,则查询物料清单、质检方案和样品列表
  1149. if (row.id) {
  1150. this.rowIds = row.id;
  1151. this.isScheme = true;
  1152. this.schemePagination.currentPage = 1;
  1153. this.schemePagination.pageSize = 10;
  1154. this.schemePagination.total = 0;
  1155. this.samplePagination.pageSize = 10;
  1156. this.samplePagination.currentPage = 1;
  1157. this.samplePagination.total = 0;
  1158. this.isFormNumber = true;
  1159. this.isOrder = true;
  1160. console.log('edit true');
  1161. if (row.isUnpack === 1) {
  1162. this.isCheck = true;
  1163. } else {
  1164. this.isCheck = false;
  1165. }
  1166. await this.getSourceList(row.id);
  1167. //操作行点击时查询清单
  1168. // await this.getInventoryList();
  1169. await this.reload({ planId: row.id });
  1170. //操作行点击时查询样品
  1171. await this.getSampleList(row.id);
  1172. //操作行点击时查询质检
  1173. await this.getTemplateList(row.id);
  1174. }
  1175. },
  1176. reload(where) {
  1177. this.$nextTick(() => {
  1178. if (this.$refs.table12 && this.$refs.table12.reload)
  1179. this.$refs.table12.reload({ page: 1, where: where });
  1180. });
  1181. },
  1182. async getSourceList(id) {
  1183. const listData = await getInventoryListByPlanId({
  1184. planId: id,
  1185. pageNum: 1,
  1186. size: -1
  1187. });
  1188. if (listData.list.length == 0) {
  1189. this.sourceList = [];
  1190. return;
  1191. }
  1192. // let o = listData.list[0];
  1193. // let listArr = [];
  1194. // console.log(listData,'listData 会执行吗1234')
  1195. // if (o.measureUnit) {
  1196. // listArr.push({
  1197. // packageCellTotal: 1,
  1198. // conversionUnit: o.measureUnit,
  1199. // id: '111'
  1200. // });
  1201. // }
  1202. // if (o.packingUnit) {
  1203. // listArr.push({
  1204. // packageCellTotal: o.measureQuantity - 0,
  1205. // conversionUnit: o.packingUnit,
  1206. // id: '222'
  1207. // });
  1208. // }
  1209. // listData.list.map((el) => {
  1210. // el.weightProportion = el.weight
  1211. // ? (el.weight / el.measureQuantity).toFixed(4)
  1212. // : 0;
  1213. // el.weightProportion = el.weightProportion - 0;
  1214. // });
  1215. listData.list = this.proceSources(listData.list);
  1216. // this.packingSpecificationOption = listArr;
  1217. this.sourceList = listData.list;
  1218. },
  1219. // 处理来源清单数据
  1220. proceSources(arr) {
  1221. console.log('方法调用没 443');
  1222. let list = arr;
  1223. let o = list[0];
  1224. let listArr = [];
  1225. if (o.measureUnit) {
  1226. listArr.push({
  1227. packageCellTotal: 1,
  1228. conversionUnit: o.measureUnit,
  1229. id: '111'
  1230. });
  1231. }
  1232. if (o.packingUnit) {
  1233. listArr.push({
  1234. packageCellTotal: o.measureQuantity - 0,
  1235. conversionUnit: o.packingUnit,
  1236. id: '222'
  1237. });
  1238. }
  1239. list.map((el) => {
  1240. el.weightProportion = el.weight
  1241. ? (el.weight / el.measureQuantity).toFixed(4)
  1242. : 0;
  1243. el.weightProportion = el.weightProportion - 0;
  1244. });
  1245. this.packingSpecificationOption = listArr;
  1246. return list;
  1247. },
  1248. async getSampleList(id) {
  1249. // console.log('执行?')
  1250. // let res = await getSampleListByPlanId({
  1251. // planId: id,
  1252. // pageNum: this.samplePagination.currentPage,
  1253. // size: this.samplePagination.pageSize
  1254. // });
  1255. // this.sampleList = res?.list || [];
  1256. // this.samplePagination.total = res.count;
  1257. let newRes = await getSampleListByPlanId({
  1258. planId: id,
  1259. pageNum: 1,
  1260. size: -1
  1261. });
  1262. this.sampleList = newRes?.list || [];
  1263. this.newSampleList = newRes?.list || [];
  1264. },
  1265. async getTemplateList(id) {
  1266. let res = await getTemplateListByPlanId({
  1267. planId: id,
  1268. pageNum: this.schemePagination.currentPage,
  1269. // size: this.schemePagination.pageSize,
  1270. size: 100000
  1271. });
  1272. this.schemeList = res?.list || [];
  1273. this.schemePagination.total = res.count;
  1274. },
  1275. async getList(
  1276. receiveNo,
  1277. productCode,
  1278. productCategoryId,
  1279. productCategoryName,
  1280. categoryid,
  1281. batchNo,
  1282. supplierName,
  1283. supplierMark
  1284. ) {
  1285. //通过来源和产品 获取来料清单
  1286. await this.getGoodsList(
  1287. receiveNo,
  1288. productCode,
  1289. null,
  1290. productCategoryId,
  1291. productCategoryName,
  1292. categoryid,
  1293. batchNo,
  1294. supplierName,
  1295. supplierMark
  1296. );
  1297. //通过来源和产品 获取质检方案
  1298. await this.getQualityTemplate(productCode);
  1299. },
  1300. async getGoodsList(
  1301. receiveNo,
  1302. productCode,
  1303. ids,
  1304. productCategoryId,
  1305. productCategoryName,
  1306. categoryid,
  1307. batchNo,
  1308. supplierName,
  1309. supplierMark
  1310. ) {
  1311. // this.$refs.table12.setData([]);
  1312. this.sourceList = [];
  1313. this.packingList = [];
  1314. let res;
  1315. const res1 = await outInRecordsPage({
  1316. sourceBizNo: receiveNo,
  1317. categoryCode: productCode,
  1318. categoryId: categoryid,
  1319. qualityQlanId: ids,
  1320. size: -1
  1321. });
  1322. console.log(res1, 'res1');
  1323. if (res1.list.length > 0) {
  1324. console.log(res1.list[0].status, 'status=2 不赋值');
  1325. if (res1.list[0].status != 2) {
  1326. res = res1.list;
  1327. this.isCheck = true;
  1328. console.log('this.isCheck=true', this.isCheck);
  1329. } else {
  1330. res = [];
  1331. this.$message.error('此数据已质检,无需再次质检!');
  1332. return;
  1333. }
  1334. } else {
  1335. let resData = await getBatchInfoData({
  1336. sourceBizNo: receiveNo,
  1337. categoryCode: productCode,
  1338. batchNo: batchNo
  1339. });
  1340. console.log(resData, 'resData');
  1341. if (resData) {
  1342. if (resData.qualityControl != 2) {
  1343. this.isCheck = false;
  1344. res = [resData];
  1345. } else {
  1346. res = [];
  1347. this.$message.error('此数据已质检,无需再次质检!');
  1348. return;
  1349. }
  1350. }
  1351. }
  1352. console.log(res, '来料清单');
  1353. if (res.length > 0) {
  1354. let _arr1 = res.map((m) => {
  1355. m.sourceId = m.id;
  1356. m.productCategoryId = productCategoryId;
  1357. m.productCategoryName = productCategoryName;
  1358. delete m.id;
  1359. return { ...m };
  1360. });
  1361. this.packingList = _arr1;
  1362. // this.$refs.table12.setData(_arr1); //赋值
  1363. this.sourceList = _arr1;
  1364. this.packingList = _arr1;
  1365. // const _arr2 = this.$refs.table12.getData();
  1366. // if (_arr2.length > 1) {
  1367. // this.baseForm.productNumber = _arr2.length;
  1368. // } else {
  1369. // this.baseForm.productNumber = _arr2[0].measureQuantity;
  1370. // }
  1371. this.baseForm.totalWeight = this.sourceList.reduce((acc, pre) => {
  1372. return pre.weight ? acc + Number(pre.weight) : acc;
  1373. }, 0);
  1374. if (this.sourceList.length > 1) {
  1375. this.baseForm.productNumber = this.sourceList.reduce((acc, pre) => {
  1376. return pre.measureQuantity
  1377. ? acc + Number(pre.measureQuantity)
  1378. : acc;
  1379. }, 0);
  1380. } else {
  1381. this.baseForm.productNumber = this.sourceList[0].measureQuantity;
  1382. }
  1383. //处理样品清单
  1384. console.log('处理来源清单数据');
  1385. // await this.handleSampleList();
  1386. _arr1 = this.proceSources(_arr1);
  1387. await this.updatePackingList(_arr1);
  1388. } else {
  1389. console.log('来料清单数据为空');
  1390. // this.$refs.table12.setData([]);
  1391. this.sourceList = val;
  1392. this.packingList = [];
  1393. }
  1394. },
  1395. async handleSampleList() {
  1396. // let packingList = this.$refs.table12.getData();
  1397. if (this.baseForm.type == '1' && this.btnType != 'detail') {
  1398. if (this.baseForm.inspectionStandards == '2') {
  1399. console.log(13131313213);
  1400. this.sampleList = [];
  1401. let list = [];
  1402. if (this.baseForm.productNumber) {
  1403. let p = this.productItem;
  1404. console.log(p);
  1405. let obj = {
  1406. id: p.id,
  1407. batchNo: p.batchNo,
  1408. categoryCode: p.code, //编码
  1409. categoryName: p.name, //名称
  1410. measureQuantity: this.baseForm.productNumber, //计量数量
  1411. measureUnit: p.measuringUnit, //计量单位
  1412. weightUnit: p.weightUnit, //重量单位
  1413. weight: p.netWeight * this.baseForm.productNumber //重量
  1414. };
  1415. list.push(obj);
  1416. }
  1417. if (list.length > 0 && list[0].categoryCode) {
  1418. // this.$refs.table12.setData(list);
  1419. this.sourceList = list;
  1420. this.packingList = list;
  1421. let packList = this.$refs.table12.getData();
  1422. this.getFullInspectionWeight(packList);
  1423. }
  1424. // this.$refs.table12.setData(list);
  1425. // let packList = this.$refs.table12.getData();
  1426. // console.log(list);
  1427. // console.log(1654646);
  1428. // this.getFullInspectionWeight(packList);
  1429. // this.getFullInspectionWeight(list);
  1430. } else {
  1431. if (this.$refs.table12) {
  1432. let packingList = this.$refs.table12.getData();
  1433. if (
  1434. Math.ceil(Number(this.baseForm.productNumber || 0)) ===
  1435. packingList.length
  1436. ) {
  1437. console.log(
  1438. '--->',
  1439. Math.ceil(Number(this.baseForm.productNumber || 0))
  1440. );
  1441. console.log('--->', packingList.length);
  1442. await this.handleUnpackCase(packingList);
  1443. return;
  1444. } else {
  1445. this.getFullInspectionWeight(packingList);
  1446. }
  1447. }
  1448. // let packingList = this.$refs.table12.getData();
  1449. // if (
  1450. // Math.ceil(Number(this.baseForm.productNumber || 0)) ===
  1451. // packingList.length
  1452. // ) {
  1453. // await this.handleUnpackCase(packingList);
  1454. // return;
  1455. // } else {
  1456. // this.getFullInspectionWeight(packingList);
  1457. // }
  1458. }
  1459. }
  1460. //全检时 计量时
  1461. else if (
  1462. this.baseForm.qualityMode == 1 &&
  1463. this.baseForm.inspectionStandards == 1 &&
  1464. this.btnType != 'detail'
  1465. ) {
  1466. this.sampleList = [];
  1467. console.log(this.baseForm, '---isUnpack---');
  1468. if (this.baseForm.productNumber) {
  1469. console.log('数据777777');
  1470. if (this.$refs.table12) {
  1471. // this.$refs.table12.setData([]);
  1472. this.sourceList = [];
  1473. this.packingList = [];
  1474. let nums = Number(this.baseForm.productNumber);
  1475. let p = this.productItem;
  1476. let list = [];
  1477. for (let i = 0; i < nums; i++) {
  1478. let obj = {
  1479. id: p.id,
  1480. batchNo: p.batchNo,
  1481. categoryCode: p.code, //编码
  1482. categoryName: p.name, //名称
  1483. measureQuantity: 1,
  1484. measureUnit: p.measuringUnit, //计量单位
  1485. weightUnit: p.weightUnit, //重量单位
  1486. weight: p.netWeight //重量
  1487. };
  1488. list.push(obj);
  1489. }
  1490. console.log('数据666666');
  1491. // this.$refs.table12.setData(list);
  1492. this.sourceList = list;
  1493. this.packingList = list;
  1494. let packList = this.$refs.table12.getData();
  1495. await this.handleUnpackCase(packList);
  1496. return;
  1497. }
  1498. // this.$refs.table12.setData([]);
  1499. // let nums = Number(this.baseForm.productNumber);
  1500. // let p = this.productItem;
  1501. // let list = [];
  1502. // for (let i = 0; i < nums; i++) {
  1503. // let obj = {
  1504. // id: p.id,
  1505. // batchNo: p.batchNo,
  1506. // categoryCode: p.code, //编码
  1507. // categoryName: p.name, //名称
  1508. // measureQuantity: 1,
  1509. // measureUnit: p.measuringUnit, //计量单位
  1510. // weightUnit: p.weightUnit, //重量单位
  1511. // weight: p.netWeight //重量
  1512. // };
  1513. // list.push(obj);
  1514. // }
  1515. // console.log('数据666666');
  1516. // this.$refs.table12.setData(list);
  1517. // let packList = this.$refs.table12.getData();
  1518. // await this.handleUnpackCase(packList);
  1519. // return;
  1520. }
  1521. // if (this.rowIds) {
  1522. // const res = await getInventoryListByPlanId({
  1523. // planId: this.rowIds,
  1524. // pageNum: 1,
  1525. // size: 5000
  1526. // });
  1527. // // console.log(res.list);
  1528. // if (res.list.length > 0) {
  1529. // await this.handleUnpackCase(res.list);
  1530. // }
  1531. // } else {
  1532. // await this.handleUnpackCase(packingList);
  1533. // }
  1534. // if (this.baseForm.isUnpack != null && this.baseForm.isUnpack != undefined && this.baseForm.isUnpack != '') {
  1535. // //拆包
  1536. // if (this.baseForm.isUnpack == 1) {
  1537. // await this.handleUnpackCase(packingList);
  1538. // } else if (this.baseForm.isUnpack == 0) {
  1539. // await this.updatePackingList(packingList);
  1540. // }
  1541. // } else {
  1542. // console.log(this.isCheck, 'this.isCheck')
  1543. // if (!this.isCheck) {
  1544. // await this.handleUnpackCase(packingList);
  1545. // } else {
  1546. // await this.updatePackingList(packingList);
  1547. // }
  1548. // }
  1549. //全检 计重时
  1550. } else if (
  1551. this.baseForm.qualityMode == 1 &&
  1552. this.baseForm.inspectionStandards == 2 &&
  1553. this.btnType != 'detail'
  1554. // (this.btnType != 'detail' || this.btnType != 'edit')
  1555. // this.btnType == 'add'
  1556. ) {
  1557. this.sampleList = [];
  1558. let list = [];
  1559. if (this.baseForm.productNumber) {
  1560. let p = this.productItem;
  1561. let obj = {
  1562. id: p.id,
  1563. batchNo: p.batchNo,
  1564. categoryCode: p.code, //编码
  1565. categoryName: p.name, //名称
  1566. measureQuantity: this.baseForm.productNumber, //计量数量
  1567. measureUnit: p.measuringUnit, //计量单位
  1568. weightUnit: p.weightUnit, //重量单位
  1569. weight: p.netWeight * this.baseForm.productNumber //重量
  1570. };
  1571. list.push(obj);
  1572. }
  1573. console.log('数据55555');
  1574. console.log(list);
  1575. if (list.length > 0 && list[0].categoryCode) {
  1576. // this.$refs.table12.setData(list);
  1577. this.sourceList = list;
  1578. this.packingList = list;
  1579. let packList = this.$refs.table12.getData();
  1580. this.getFullInspectionWeight(packList);
  1581. }
  1582. // this.$refs.table12.setData(list);
  1583. // let packList = this.$refs.table12.getData();
  1584. // this.getFullInspectionWeight(packList);
  1585. // this.getFullInspectionWeight(packList);
  1586. } else {
  1587. console.log('进来了这里');
  1588. this.sampleList = [];
  1589. }
  1590. },
  1591. //全检 计重时生成样品清单
  1592. async getFullInspectionWeight(packingList) {
  1593. this.updatePackingList(packingList);
  1594. },
  1595. //拆包处理样品清单数据
  1596. async handleUnpackCase(packingList) {
  1597. if (this.baseForm.type == '3') {
  1598. this.getFullInspectionWeight(packingList);
  1599. } else {
  1600. const num = Number(this.baseForm.productNumber || 0);
  1601. console.log('num:' + num);
  1602. if (num) {
  1603. await this.getUnpackSamList(packingList, num);
  1604. }
  1605. }
  1606. },
  1607. //获取样品编码
  1608. async getSampleCode() {
  1609. return await getCode('sample_code');
  1610. },
  1611. // 创建计量数量为1的样品清单函数,用于计数类型的
  1612. async createSampleList(list) {
  1613. if (this.baseForm.qualityMode != null) {
  1614. const ProductSampleList = [];
  1615. console.log(list, 'list');
  1616. for (const oldItem of list) {
  1617. const count = oldItem.measureQuantity;
  1618. const newMeasureQuantity = oldItem.measureQuantity / count;
  1619. const newWeight = parseFloat((oldItem.weight / count).toFixed(2));
  1620. console.log(typeof oldItem.qualitySampleTemplateList, 'ssssss');
  1621. // 遍历新数组设置 qualityResults 默认值
  1622. this.schemeList.forEach((item) => {
  1623. if (typeof item === 'object' && item !== null) {
  1624. item.qualityResults = 1; // 设置默认值
  1625. }
  1626. delete item.id;
  1627. });
  1628. console.log(oldItem, 'oldItem');
  1629. console.log(count, newMeasureQuantity, newWeight);
  1630. delete oldItem.id;
  1631. if (
  1632. oldItem.qualitySampleTemplateList == undefined ||
  1633. oldItem.qualitySampleTemplateList == null ||
  1634. oldItem.qualitySampleTemplateList.length == 0
  1635. ) {
  1636. oldItem.qualitySampleTemplateList = JSON.parse(
  1637. JSON.stringify(this.schemeList)
  1638. );
  1639. for (let i = 0; i < count; i++) {
  1640. ProductSampleList.push({
  1641. ...oldItem,
  1642. measureQuantity: newMeasureQuantity,
  1643. weight: newWeight,
  1644. sampleCode: await this.getSampleCode(),
  1645. qualitySampleTemplateList: JSON.parse(
  1646. JSON.stringify(this.schemeList)
  1647. )
  1648. });
  1649. }
  1650. console.log(ProductSampleList, 'ProductSampleList');
  1651. this.sampleList = ProductSampleList;
  1652. const pNum = ProductSampleList.reduce((sum, item) => {
  1653. return sum + Number(item.weight || 0);
  1654. }, 0);
  1655. this.baseForm.totalWeight = parseFloat(pNum.toFixed(2));
  1656. } else {
  1657. for (let i = 0; i < count; i++) {
  1658. ProductSampleList.push({
  1659. ...oldItem,
  1660. measureQuantity: newMeasureQuantity,
  1661. weight: newWeight,
  1662. sampleCode: await this.getSampleCode(),
  1663. qualitySampleTemplateList: JSON.parse(
  1664. JSON.stringify(oldItem.qualitySampleTemplateList)
  1665. )
  1666. });
  1667. }
  1668. console.log(ProductSampleList, 'ProductSampleList');
  1669. this.sampleList = ProductSampleList;
  1670. const pNum = ProductSampleList.reduce((sum, item) => {
  1671. return sum + Number(item.weight || 0);
  1672. }, 0);
  1673. this.baseForm.totalWeight = parseFloat(pNum.toFixed(2));
  1674. }
  1675. }
  1676. }
  1677. },
  1678. // 批量生成编码 4444444 getCodeList
  1679. async batchCodes(count) {
  1680. if (count <= 0) return;
  1681. let params = { count };
  1682. const res = await getCodeList('sample_code', params);
  1683. return res;
  1684. },
  1685. //更新样品清单数据
  1686. async updatePackingList(list) {
  1687. console.log('进来了没有 pppppp');
  1688. // 计量类型1是数量,2是重量
  1689. // if (this.baseForm.inspectionStandards == 1) {
  1690. // this.createSampleList(list);
  1691. // return;
  1692. // }
  1693. let count = list ? list.length : 0;
  1694. const codeList = await this.batchCodes(count);
  1695. if (this.baseForm.inspectionStandards == 2) {
  1696. for (let i = 0; i < list.length; i++) {
  1697. // list[i].sampleCode = await this.getSampleCode();
  1698. list[i].sampleCode = codeList[i];
  1699. }
  1700. // this.updatePackingList(list, this.form.total);
  1701. // this.handleWeightFullSample(this.form.total);
  1702. }
  1703. console.log(this.baseForm.inspectionStandards);
  1704. console.log(list, 'list +++++++++++ 00000000000');
  1705. this.sampleList = list;
  1706. this.baseForm.sampleNumber = list.length;
  1707. this.samplePagination.currentPage = 1;
  1708. this.samplePagination.total = list.length;
  1709. // const sampleProportion = this
  1710. // this.samplePagination.total = this.sampleList.length;
  1711. },
  1712. async getUnpackSamList(list, num) {
  1713. console.log(list, num);
  1714. let data = [];
  1715. list.forEach((oldItem, index) => {
  1716. const newMeasureQuantity =
  1717. oldItem.measureQuantity / this.baseForm.productNumber;
  1718. const newWeight = parseFloat(
  1719. (oldItem.weight / this.baseForm.productNumber).toFixed(2)
  1720. );
  1721. // 将 measureQuantity 转换为数字
  1722. const measureQuantity = Number(oldItem.measureQuantity);
  1723. // 判断是否有小数部分
  1724. const hasDecimal = measureQuantity % 1 !== 0;
  1725. let roundedQuantity;
  1726. if (hasDecimal) {
  1727. // 有小数部分,向上取整
  1728. roundedQuantity = Math.ceil(measureQuantity);
  1729. } else {
  1730. roundedQuantity = measureQuantity;
  1731. }
  1732. delete oldItem.id;
  1733. for (let i = 0; i < roundedQuantity; i++) {
  1734. data.push({
  1735. ...oldItem,
  1736. // measureQuantity: 1,
  1737. weight: this.netWeight || 0
  1738. // weight:
  1739. // num - index >= 1
  1740. // ? this.netWeight
  1741. // : ((num * 100000 - index * 100000) / 100000) * this.netWeight
  1742. });
  1743. }
  1744. });
  1745. console.log(data, '样品数据-条数', num);
  1746. await this.updatePackingList(data);
  1747. },
  1748. async getQualityTemplate(productCode, ids) {
  1749. await getQualityTemplateList({
  1750. type: this.baseForm.type,
  1751. productCode: productCode,
  1752. qualityQlanId: ids
  1753. }).then((res) => {
  1754. if (Object.keys(res).length === 0) {
  1755. return;
  1756. }
  1757. this.baseForm.sampleProportion = res.checkProportion;
  1758. // this.baseForm.inspectionStandards = res?.inspectionStandards;
  1759. let combinedList = [];
  1760. for (let i = 0; i < res.qualityTemplateVOList.length; i++) {
  1761. res.qualityTemplateVOList[i].inspectionItemVOList =
  1762. res.qualityTemplateVOList[i]?.inspectionItemVOList.map((item) => {
  1763. item.templateId = res.qualityTemplateVOList[i]?.id;
  1764. item.qualitySchemeTemplateCode =
  1765. res.qualityTemplateVOList[i]?.qualitySchemeTemplateCode;
  1766. item.qualitySchemeTemplateName =
  1767. res.qualityTemplateVOList[i]?.qualitySchemeTemplateName;
  1768. delete item.id;
  1769. return {
  1770. ...item
  1771. };
  1772. });
  1773. combinedList = combinedList.concat(
  1774. res.qualityTemplateVOList[i].inspectionItemVOList
  1775. );
  1776. console.log(combinedList, '质检方案');
  1777. this.schemeList = combinedList;
  1778. this.schemePagination.currentPage = 1;
  1779. this.schemePagination.total = this.schemeList.length;
  1780. }
  1781. });
  1782. },
  1783. //来料列表表格选择事件
  1784. handleSelectionChange(selection) {
  1785. console.log(selection, '勾选');
  1786. this.selectedList = selection;
  1787. //如果取小样
  1788. if (this.conditionType == 2) {
  1789. if (this.isCheck) {
  1790. this.formData.portion = selection.length;
  1791. this.baseForm.sampleNumber = selection.length;
  1792. } else {
  1793. this.baseForm.sampleNumber = this.formData.portion;
  1794. }
  1795. const data1 = this.$refs.table12.getData();
  1796. this.$set(this.formData, 'sampleUnit', data1[0]?.measureUnit);
  1797. this.$set(this.baseForm, 'sampleMeasureUnit', data1[0]?.measureUnit);
  1798. } else if (this.conditionType == 1) {
  1799. this.baseForm.sampleNumber = this.formData.portion;
  1800. this.formData.number = 0;
  1801. }
  1802. },
  1803. //取样方式选择
  1804. async handleSampleNumber(val) {
  1805. console.log(val, 'val');
  1806. this.conditionType = val;
  1807. //清空样品清单列表
  1808. this.sampleList = [];
  1809. // const dataS = this.$refs.table12.getData();
  1810. //取整样
  1811. // if (val == 1) {
  1812. // if (this.selectedList.length == 0) {
  1813. // this.$message.warning('请先选择样品!');
  1814. // } else {
  1815. // if (this.isCheck) {
  1816. // for (let i = 0; i < this.selectedList.length; i++) {
  1817. // for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
  1818. // // this.selectedList[i].sampleCode = await this.getSampleCode();
  1819. // this.sampleList.push({
  1820. // ...this.selectedList[i],
  1821. // sampleCode: await this.getSampleCode(),
  1822. // measureQuantity: 1,
  1823. // weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
  1824. // });
  1825. // }
  1826. // }
  1827. // } else {
  1828. // for (let i = 0; i < this.selectedList.length; i++) {
  1829. // let forNum = 0;
  1830. // if (this.formData.portion != null && this.formData.portion != '') {
  1831. // forNum = this.formData.portion;
  1832. // } else {
  1833. // forNum = this.selectedList[i].measureQuantity;
  1834. // }
  1835. // for (let j = 0; j < forNum; j++) {
  1836. // // this.selectedList[i].sampleCode = await this.getSampleCode();
  1837. // this.sampleList.push({
  1838. // ...this.selectedList[i],
  1839. // sampleCode: await this.getSampleCode(),
  1840. // measureQuantity: 1,
  1841. // weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
  1842. // });
  1843. // }
  1844. // }
  1845. // }
  1846. // this.formData.portion = this.sampleList.length;
  1847. // this.activeName = '2';
  1848. // this.$message.success('取样成功!');
  1849. // }
  1850. // } else if (val == 2) {
  1851. // this.formData.sampleUnit = dataS[0].measureUnit;
  1852. // this.$refs.table12.clearSelection();
  1853. // //小样
  1854. // if (this.selectedList.length == 0) {
  1855. // this.$message.warning('请先选择样品!');
  1856. // } else {
  1857. // if (this.formData.number == null || this.formData.sampleUnit == '') {
  1858. // this.$message.warning('请先选择取样的数量和单位!');
  1859. // }
  1860. // }
  1861. // }
  1862. },
  1863. handleInputNumber(val) {
  1864. let packingList = this.$refs.table12.getData();
  1865. const maxValue =
  1866. packingList.length > 1
  1867. ? packingList.length
  1868. : packingList[0].measureQuantity;
  1869. if (val > maxValue) {
  1870. this.$message.warning('数量不能大于计量数量!');
  1871. this.formData.number = maxValue;
  1872. return;
  1873. }
  1874. },
  1875. // 整样输入框事件
  1876. handleInput(val) {
  1877. if (val == 0 || val == '' || val == null) {
  1878. this.$refs.table12.clearSelection();
  1879. return;
  1880. }
  1881. let packingList = this.$refs.table12.getData();
  1882. if (!packingList || packingList.length === 0) {
  1883. return;
  1884. }
  1885. // 计算 packingList 中 measureQuantity 字段的总和
  1886. const measureQuantitySum = packingList.reduce((sum, item) => {
  1887. const quantity = Number(item.measureQuantity) || 0;
  1888. return sum + quantity;
  1889. }, 0);
  1890. const portion = Number(this.formData.portion);
  1891. // 清空当前选中
  1892. this.$refs.table12.clearSelection();
  1893. if (this.conditionType == 2) {
  1894. // 取小样
  1895. // 确保 portion 不超过数据列表长度
  1896. const safePortion = Math.min(portion, packingList.length);
  1897. if (this.isCheck) {
  1898. // 是否拆包 false 不拆包
  1899. if (portion > packingList.length) {
  1900. this.$message.warning('取样数量不能大于来源清单数量!');
  1901. this.formData.portion = packingList.length;
  1902. }
  1903. } else {
  1904. const maxQuantity = Number(packingList[0].measureQuantity);
  1905. if (portion > maxQuantity) {
  1906. this.$message.warning('取样数量不能大于计量数量!');
  1907. this.formData.portion = maxQuantity;
  1908. }
  1909. }
  1910. // 选中前 safePortion 行
  1911. packingList.slice(0, safePortion).forEach((row) => {
  1912. this.$refs.table12.toggleRowSelection(row, true);
  1913. });
  1914. } else if (this.conditionType == 1) {
  1915. // 确保 portion 不超过数据列表长度
  1916. const safePortion = Math.min(portion, measureQuantitySum);
  1917. if (portion > measureQuantitySum) {
  1918. this.$message.warning('取样数量不能大于计量数量!');
  1919. this.formData.portion = measureQuantitySum;
  1920. }
  1921. // 选中前 safePortion 行
  1922. packingList.slice(0, safePortion).forEach((row) => {
  1923. this.$refs.table12.toggleRowSelection(row, true);
  1924. });
  1925. }
  1926. },
  1927. // 选中物品后触发了这个事件
  1928. async getCategoryInfo(val) {
  1929. console.log(this.baseForm.type, this.baseForm.planSource);
  1930. // this.baseForm.isUnpack = val.categoryWms.isUnpack;
  1931. console.log(val, '产品信息');
  1932. if (this.baseForm.type == 2 && this.baseForm.planSource == '4') {
  1933. if (val.category.id) {
  1934. const res1 = await getProductSteup(val.category.id);
  1935. const index = res1.findIndex(
  1936. (item) => item.taskId == val.category.taskId
  1937. );
  1938. if (index) {
  1939. const res2 = await getProductOrder({
  1940. taskId: res1[index - 1].taskId,
  1941. workOrderId: val.category.id
  1942. });
  1943. if (res2[0].semiProductList.length > 1) {
  1944. this.baseForm.productNumber = res2[0].semiProductList.length;
  1945. } else {
  1946. this.baseForm.productNumber =
  1947. res2[0].semiProductList.measureQuantity;
  1948. }
  1949. }
  1950. this.isConsumable = val.category.isConsumable;
  1951. this.netWeight = val.category.netWeight;
  1952. this.productItem = val.category;
  1953. console.log('+++++++++');
  1954. this.handleSampleList();
  1955. return;
  1956. }
  1957. }
  1958. this.isConsumable = val.category.isConsumable;
  1959. this.netWeight = val.category.netWeight;
  1960. this.productItem = val.category; //产品信息
  1961. },
  1962. changeSamUnit(val) {
  1963. console.log(val);
  1964. this.$refs.baseInfoRefs.getsampleMeasureUnit(val);
  1965. },
  1966. calculateWeightAndQuantity(list) {
  1967. console.log(list);
  1968. this.baseForm.totalWeight = list.reduce((acc, pre) => {
  1969. return pre.weight ? acc + Number(pre.weight) : acc;
  1970. }, 0);
  1971. this.baseForm.productNumber = list.reduce((acc, pre) => {
  1972. return pre.measureQuantity ? acc + Number(pre.measureQuantity) : acc;
  1973. }, 0);
  1974. },
  1975. //整样确认按钮-样品列表右上角确认按钮
  1976. // handleExtractFull() {
  1977. // this.$refs.ruleForm.validate((valid) => {
  1978. // if (valid) {
  1979. // if (!this.selectedList || this.selectedList.length == 0) {
  1980. // this.$message.warning('请先选择样品!');
  1981. // return;
  1982. // }
  1983. // this.sampleList = []
  1984. // //取样条数
  1985. // let safePortion = Number(this.formData.portion);
  1986. // //计量数量
  1987. // let measureQ = this.formData.number || 1;
  1988. // //计量单位
  1989. // let unit = this.formData.sampleUnit;
  1990. // //抽检计量整样小样或者抽检计重小样
  1991. // if ((this.baseForm.inspectionStandards === 1) || (this.baseForm.inspectionStandards === 2 && this.conditionType == 2)) {
  1992. // if (this.conditionType == 2) {
  1993. // if (measureQ <= 0) {
  1994. // this.$message.info('取样计量数量必须大于0');
  1995. // return
  1996. // }
  1997. // }
  1998. // // 计算总计量数量
  1999. // const totalQuantity = this.selectedList.reduce((sum, item) => sum + item['measureQuantity'], 0);
  2000. // // 验证取样总量不超过总计量数量,只有计量单位相同才进行验证
  2001. // if (this.selectedList[0].measureUnit == unit || this.conditionType == 1) {
  2002. // if (measureQ * safePortion > totalQuantity) {
  2003. // this.$message.info('取样计量数量不能大于总计量数量');
  2004. // return
  2005. // }
  2006. // // 验证每条数据的计量数量都大于等于取样计量数量
  2007. // for (const item of this.selectedList) {
  2008. // if (item['measureQuantity'] < measureQ) {
  2009. // this.$message.info(`条目计量数量小于取样计量数量`);
  2010. // return
  2011. // }
  2012. // }
  2013. // }
  2014. // if (unit === 'KG') {
  2015. // let totalMaxPossible = 0;
  2016. // this.selectedList.map(item => {
  2017. // const maxPossible = item['measureQuantity'] / measureQ;
  2018. // totalMaxPossible += maxPossible;});
  2019. // if (totalMaxPossible < safePortion) {
  2020. // this.formData.portion = totalMaxPossible;
  2021. // return this.$message.info(`最大取样条数为${totalMaxPossible}`);
  2022. // }
  2023. // // 计算总重量
  2024. // let totalWeight = this.selectedList.reduce((sum, item) => sum + item['weight'], 0);
  2025. // let weightUnit = this.selectedList[0].weightUnit;
  2026. // if (weightUnit === 'G') {
  2027. // totalWeight = totalWeight / 1000
  2028. // }
  2029. // if (measureQ * safePortion > totalWeight) {
  2030. // this.$message.info('取样计量重量不能大于总计量重量');
  2031. // return
  2032. // }
  2033. // for (const item of this.selectedList) {
  2034. // let weight = weightUnit === 'G' ? item.weight / 1000 : item.weight
  2035. // if (weight < measureQ) {
  2036. // this.$message.info(`勾选条目重量小于取样重量`);
  2037. // return
  2038. // }
  2039. // }
  2040. // }
  2041. // this.getNewFullSampleList(Math.ceil(safePortion), measureQ, unit);
  2042. // //抽检计重整样
  2043. // } else if (this.baseForm.inspectionStandards === 2 && this.conditionType == 1) {
  2044. // for (const item of this.selectedList) {
  2045. // if (item['measureQuantity'] < safePortion) {
  2046. // this.$message.info(`所选的条目计量数量小于取样计量数量`);
  2047. // return
  2048. // }
  2049. // }
  2050. // let list = [];
  2051. // for (let i = 0; i < this.selectedList.length; i++) {
  2052. // list.push({
  2053. // ...this.selectedList[i],
  2054. // measureQuantity: safePortion, //作为计量数量
  2055. // });
  2056. // }
  2057. // this.updatePackingList(list);
  2058. // }
  2059. // this.activeName = '2'
  2060. // }
  2061. // });
  2062. // },
  2063. //从来源数组取样到目标数组
  2064. async getNewFullSampleList(
  2065. sampleCount,
  2066. sampleQuantity,
  2067. sampleUnit,
  2068. specifications
  2069. ) {
  2070. console.log(
  2071. '从来源数组取样到目标数组',
  2072. sampleCount,
  2073. sampleQuantity,
  2074. sampleUnit
  2075. );
  2076. const sourceArray = this.selectedList;
  2077. // 检查单位是否匹配
  2078. const isUnitMismatch =
  2079. sourceArray.length > 0 && sourceArray[0].measureUnit !== sampleUnit;
  2080. // 创建副本并计算初始可取样数量
  2081. const items = sourceArray.map((item) => ({
  2082. ...item,
  2083. remainingQuantity: isUnitMismatch
  2084. ? Infinity
  2085. : item['measureQuantity'], // 剩余可取样数量
  2086. maxPossible: item['measureQuantity'] / sampleQuantity // 最大取样次数
  2087. }));
  2088. console.log(items, 'items items items');
  2089. console.log(sampleQuantity, 'sampleQuantity sampleQuantity [[[]]]');
  2090. const result = [];
  2091. let remainingCount = sampleCount;
  2092. console.log(remainingCount, 'remainingCount ========');
  2093. let count = Math.ceil(remainingCount);
  2094. const codeList = await this.batchCodes(count);
  2095. let codeIdx = 0;
  2096. // 尽可能均匀地从各条目取样
  2097. while (remainingCount > 0) {
  2098. // 按剩余可取样比例排序
  2099. items.sort(
  2100. (a, b) =>
  2101. b.remainingQuantity / b['measureQuantity'] -
  2102. a.remainingQuantity / a['measureQuantity']
  2103. );
  2104. let distributed = false;
  2105. for (const item of items) {
  2106. console.log(
  2107. remainingCount,
  2108. 'remainingCount remainingCount remainingCount'
  2109. );
  2110. let values = remainingCount > 1 ? 1 : remainingCount;
  2111. // sampleQuantity = remainingCount > 1 ? 1 : remainingCount;
  2112. // console.log(sampleQuantity, 'sampleQuantity ----');
  2113. if (
  2114. (!isUnitMismatch && remainingCount > 0) ||
  2115. (item.remainingQuantity >= sampleQuantity && remainingCount > 0)
  2116. ) {
  2117. // 添加到结果数组
  2118. this.samplePagination.total = 0;
  2119. // let sampleCode = await this.getSampleCode();
  2120. let sampleCode = codeList[codeIdx];
  2121. if (
  2122. this.conditionType == 1 &&
  2123. this.baseForm.inspectionStandards == 1
  2124. ) {
  2125. console.log('进来1');
  2126. result.push({
  2127. ...item,
  2128. // measureQuantity: values,
  2129. measureQuantity: 1,
  2130. sampleCode
  2131. });
  2132. } else if (
  2133. this.conditionType == 2 &&
  2134. (this.baseForm.inspectionStandards == 1 ||
  2135. this.baseForm.inspectionStandards == 2)
  2136. ) {
  2137. console.log('进来2');
  2138. let weight = (item.weight / item.maxPossible).toFixed(2);
  2139. result.push({
  2140. ...item,
  2141. measureQuantity: sampleQuantity,
  2142. measureUnit: sampleUnit,
  2143. sampleCode,
  2144. weight
  2145. });
  2146. }
  2147. // 更新剩余数量
  2148. if (!isUnitMismatch) {
  2149. item.remainingQuantity -= sampleQuantity;
  2150. }
  2151. remainingCount = (remainingCount - 1).toFixed(2);
  2152. codeIdx++;
  2153. distributed = true;
  2154. }
  2155. }
  2156. // 如果没有分配任何取样
  2157. if (!distributed) {
  2158. break;
  2159. }
  2160. }
  2161. console.log('样品清单', this.sampleList);
  2162. console.log('样品清单List', result);
  2163. // 判断是不是取整样
  2164. if (
  2165. this.baseForm.conditionType == 1 &&
  2166. specifications &&
  2167. specifications.id
  2168. ) {
  2169. result.map((el) => {
  2170. el.measureQuantity =
  2171. el.measureQuantity * specifications.packageCellTotal;
  2172. el.weight = this.formatNumber(
  2173. el.measureQuantity,
  2174. el.weightProportion
  2175. );
  2176. });
  2177. }
  2178. this.sampleList = result;
  2179. this.samplePagination.total = result.length;
  2180. this.baseForm.sampleNumber = this.sampleList.length; // 更新样品数量
  2181. this.changeSamUnit(sampleUnit);
  2182. },
  2183. // 小数点数据判断
  2184. formatNumber(a, b, maxDecimals = 4) {
  2185. if (a == 0 || b == 0 || !a || !b) {
  2186. return 0;
  2187. }
  2188. // 计算乘积
  2189. const product = a * b;
  2190. // 转换为固定小数位数,然后转换为数字以去除末尾零
  2191. const rounded = Number(product.toFixed(maxDecimals));
  2192. // 转换为字符串检查是否需要显示小数部分
  2193. const str = rounded.toString();
  2194. // 如果包含小数点
  2195. if (str.indexOf('.') !== -1) {
  2196. // 移除末尾的零和小数点(如果后面没有数字了)
  2197. return str.replace(/\.?0+$/, '');
  2198. }
  2199. return str;
  2200. },
  2201. //抽样确认按钮事件-样品列表右上角确认按钮
  2202. handleSampleSubmit() {
  2203. this.$refs.ruleForm.validate((valid) => {
  2204. if (valid) {
  2205. this.sampleList = [];
  2206. this.baseForm.sampleMeasureUnit = this.formData.sampleUnit;
  2207. let measureQ = this.formData.number;
  2208. let unit = this.formData.sampleUnit;
  2209. let nums = Number(this.formData.portion);
  2210. console.log(measureQ, unit, nums, 'measureQ, unit, nums');
  2211. this.getNewFullSampleList(nums, measureQ, unit);
  2212. // if (this.conditionType == 1) {
  2213. // this.sampleList = this.selectedList
  2214. // } else {
  2215. // let measureQ = this.formData.number;
  2216. // let unit = this.formData.sampleUnit;
  2217. // let nums = Number(this.formData.portion);
  2218. //
  2219. // console.log(measureQ, unit, nums, 'measureQ, unit, nums')
  2220. // this.getNewSampleList(measureQ, unit, nums)
  2221. // }
  2222. this.activeName = '2';
  2223. }
  2224. });
  2225. },
  2226. //更新计量数量、单位后重新生成样品列表数据
  2227. // async getNewSampleList(measureQ, unit, nums) {
  2228. // this.sampleList = [];
  2229. // if (!this.selectedList || this.selectedList.length == 0) {
  2230. // this.$message.warning('请先选择样品!');
  2231. // return;
  2232. // }
  2233. // if (!this.isCheck) {
  2234. // let measureQuantity = 1;
  2235. // if (this.conditionType == 2) {
  2236. // measureQuantity = this.formData.number;
  2237. // }
  2238. // for (let i = 0; i < nums; i++) {
  2239. // this.sampleList.push({
  2240. // ...this.selectedList[0],
  2241. // sampleCode: await this.getSampleCode(),
  2242. // measureQuantity: measureQuantity,
  2243. // measureUnit: unit,
  2244. // weight: this.netWeight || 0
  2245. // });
  2246. // }
  2247. // } else {
  2248. // if (this.conditionType == 1) {
  2249. // measureQ = 1;
  2250. // }
  2251. // for (let i = 0; i < this.selectedList.length; i++) {
  2252. // this.sampleList.push({
  2253. // ...this.selectedList[i],
  2254. // sampleCode: await this.getSampleCode(),
  2255. // measureQuantity: measureQ,
  2256. // measureUnit: unit,
  2257. // weight: this.netWeight || 0
  2258. // });
  2259. // }
  2260. // }
  2261. // },
  2262. //监听类型变化
  2263. resetTable() {
  2264. this.$nextTick(() => {
  2265. this.table1();
  2266. this.table2();
  2267. });
  2268. },
  2269. table1() {
  2270. this.$refs.table12.setData([]);
  2271. this.sourceList = [];
  2272. this.packingList = [];
  2273. this.schemeList = [];
  2274. },
  2275. table2() {
  2276. this.$nextTick(() => {
  2277. // if (this.btnType == 'edit' && !this.isOnce) {
  2278. // this.isOrder = false;
  2279. this.sampleList = [];
  2280. // }
  2281. });
  2282. },
  2283. resetForm() {
  2284. this.baseForm = { ...this.defaultForm() };
  2285. },
  2286. handleClose() {
  2287. this.$nextTick(() => {
  2288. // 关闭后,销毁所有的表单数据
  2289. this.resetForm();
  2290. this.resetTable();
  2291. this.isScheme = true;
  2292. this.isOrder = true;
  2293. this.packingList = [];
  2294. this.sampleList = [];
  2295. this.samplePagination = {
  2296. currentPage: 1,
  2297. pageSize: 10,
  2298. total: 0
  2299. };
  2300. (this.schemeList = []),
  2301. (this.schemePagination = {
  2302. currentPage: 1,
  2303. pageSize: 10,
  2304. total: 0
  2305. });
  2306. // 表单验证规则
  2307. this.visible = false;
  2308. this.btnType = null;
  2309. this.title = null;
  2310. this.loading = false;
  2311. this.listPage = [];
  2312. this.activeName = '1';
  2313. this.selectedList = [];
  2314. this.isCheck = false; // 是否拆包 false 不拆包 true 拆包
  2315. this.rowIds = '';
  2316. (this.formData = {
  2317. number: 1,
  2318. sampleUnit: '',
  2319. portion: null
  2320. }),
  2321. (this.rules = {
  2322. number: [
  2323. {
  2324. required: true,
  2325. message: '请输入',
  2326. trigger: 'blur'
  2327. }
  2328. ],
  2329. sampleUnit: [
  2330. {
  2331. required: true,
  2332. message: '请选择样品单位',
  2333. trigger: 'change'
  2334. }
  2335. ],
  2336. portion: [
  2337. {
  2338. required: true,
  2339. message: '请输入',
  2340. trigger: 'blur'
  2341. }
  2342. ]
  2343. });
  2344. this.isConsumable = ''; //0 单件 1批量
  2345. this.netWeight = ''; // 净重
  2346. this.conditionType = null;
  2347. this.isFormNumber = true;
  2348. this.sampleListCode = '';
  2349. this.productItem = {}; //产品信息
  2350. this.$refs['baseInfoRefs'] &&
  2351. this.$refs['baseInfoRefs'].$refs.form1.resetFields();
  2352. this.visible = false;
  2353. this.baseForm.groupId = '';
  2354. this.baseForm.qualityMode = '';
  2355. this.baseForm = { ...this.defaultForm() };
  2356. this.isChangeNumber = true;
  2357. this.isChangeType = true;
  2358. this.isOnce = true;
  2359. this.dimensionType = '';
  2360. this.isPackingList = true;
  2361. this.isSampleList = true;
  2362. });
  2363. },
  2364. /* 保存编辑 */
  2365. handleSave() {
  2366. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  2367. if (!valid) {
  2368. return false;
  2369. }
  2370. this.loading = true;
  2371. if (this.baseForm.isUnpack == null || this.baseForm.isUnpack == '') {
  2372. this.baseForm.isUnpack = this.isCheck ? 1 : 2;
  2373. }
  2374. this.baseForm.conditionType =
  2375. this.conditionType ?? this.kkconditionType;
  2376. // isSampleList: true,
  2377. // isPackingList: true,
  2378. console.log(this.isSampleList);
  2379. console.log(this.isPackingList);
  2380. console.log(this.$refs.table12.getData());
  2381. const qualityListData =
  2382. this.btnType == 'add'
  2383. ? this.sourceList
  2384. : this.btnType == 'edit' && this.isPackingList
  2385. ? []
  2386. : this.sourceList;
  2387. const sampleListData =
  2388. this.btnType == 'add'
  2389. ? this.sampleList
  2390. : this.btnType == 'edit' && this.isSampleList
  2391. ? this.newSampleList
  2392. : this.sampleList;
  2393. // let params = {
  2394. // ...this.baseForm,
  2395. // qualityInventoryList: this.$refs.table12.getData(),
  2396. // sampleList: this.sampleList,
  2397. // planTemplateList: this.schemeList
  2398. // };
  2399. let params = {
  2400. ...this.baseForm,
  2401. qualityInventoryList: qualityListData,
  2402. sampleList: sampleListData,
  2403. planTemplateList: this.schemeList
  2404. };
  2405. console.log(params, 'params');
  2406. if (this.btnType == 'issued' && this.schemeList.length < 1) {
  2407. this.$message.warning('质检方案不能为空!');
  2408. this.loading = false;
  2409. return;
  2410. }
  2411. let URL =
  2412. this.btnType == 'add' ? save : this.btnType == 'edit' ? update : '';
  2413. console.log(params, 'params');
  2414. URL(params)
  2415. .then((msg) => {
  2416. this.loading = false;
  2417. this.$message.success(msg);
  2418. this.handleClose();
  2419. this.$emit('done');
  2420. })
  2421. .catch((e) => {
  2422. this.loading = false;
  2423. });
  2424. });
  2425. },
  2426. handleIssued() {
  2427. if (this.sampleList.length == 0) {
  2428. this.$message.warning('样品清单为空!先进行修改操作再下发!');
  2429. return;
  2430. }
  2431. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  2432. if (!valid) {
  2433. return false;
  2434. }
  2435. this.loading = true;
  2436. if (this.baseForm.isUnpack == null || this.baseForm.isUnpack == '') {
  2437. this.baseForm.isUnpack = this.isCheck ? 1 : 2;
  2438. }
  2439. this.baseForm.conditionType =
  2440. this.conditionType ?? this.kkconditionType;
  2441. // let params = {
  2442. // ...this.baseForm,
  2443. // qualityInventoryList: this.$refs.table12.getData(),
  2444. // sampleList: this.sampleList,
  2445. // planTemplateList: this.schemeList
  2446. // };
  2447. // const qualityListData =
  2448. // this.btnType == 'add'
  2449. // ? this.sourceList
  2450. // : this.btnType == 'edit' && this.isPackingList
  2451. // ? []
  2452. // : this.sourceList;
  2453. console.log(this.newSampleList, 'newSampleList');
  2454. const qualityListData = this.sourceList;
  2455. const sampleListData =
  2456. this.btnType == 'add'
  2457. ? this.sampleList
  2458. : this.btnType == 'issued' && this.isSampleList
  2459. ? this.newSampleList
  2460. : this.sampleList;
  2461. // let params = {
  2462. // ...this.baseForm,
  2463. // qualityInventoryList: this.$refs.table12.getData(),
  2464. // sampleList: this.sampleList,
  2465. // planTemplateList: this.schemeList
  2466. // };
  2467. let params = {
  2468. ...this.baseForm,
  2469. qualityInventoryList: qualityListData,
  2470. sampleList: sampleListData,
  2471. planTemplateList: this.schemeList
  2472. };
  2473. console.log(params, 'params');
  2474. if (this.btnType == 'issued' && this.schemeList.length < 1) {
  2475. this.$message.warning('质检方案不能为空!');
  2476. this.loading = false;
  2477. return;
  2478. }
  2479. planIssued(params)
  2480. .then((msg) => {
  2481. this.loading = false;
  2482. this.$message.success(msg);
  2483. this.handleClose();
  2484. this.$emit('done');
  2485. })
  2486. .catch((e) => {
  2487. this.loading = false;
  2488. });
  2489. });
  2490. },
  2491. // 样品列表分页方法
  2492. async handleSampleSizeChange(val) {
  2493. this.samplePagination.pageSize = val;
  2494. this.samplePagination.currentPage = 1;
  2495. if (this.rowIds && this.isOrder) {
  2496. await this.getSampleList(this.rowIds);
  2497. }
  2498. //操作行点击时查询样品
  2499. },
  2500. async handleSampleCurrentChange(val) {
  2501. this.samplePagination.currentPage = val;
  2502. if (this.rowIds && this.isSampleList) {
  2503. await this.getSampleList(this.rowIds);
  2504. }
  2505. },
  2506. // 质检方案分页方法
  2507. async handleSchemeSizeChange(val) {
  2508. this.schemePagination.pageSize = val;
  2509. this.schemePagination.currentPage = 1;
  2510. //操作行点击时查询质检
  2511. if (this.rowIds && this.isScheme) {
  2512. await this.getTemplateList(this.rowIds);
  2513. }
  2514. },
  2515. async handleSchemeCurrentChange(val) {
  2516. this.schemePagination.currentPage = val;
  2517. //操作行点击时查询质检
  2518. if (this.rowIds && this.isScheme) {
  2519. await this.getTemplateList(this.rowIds);
  2520. }
  2521. },
  2522. //检验方式改变时,重新获取样品列表
  2523. changeModel(val) {
  2524. console.log('更改检验方式');
  2525. this.baseForm.qualityMode = val;
  2526. this.isSampleList = false;
  2527. if (this.btnType != 'issued') {
  2528. this.baseForm.sampleNumber = '';
  2529. }
  2530. console.log(this.baseForm, 'this.baseForm 0000000000000');
  2531. if (this.baseForm.type == '3') {
  2532. console.log(this.sourceList, this.dimensionType, '更改检验方式223');
  2533. if (
  2534. this.sourceList &&
  2535. this.dimensionType &&
  2536. this.baseForm.qualityMode == '1'
  2537. ) {
  2538. // const listData = this.$refs.table12.getData();
  2539. console.log(this.sourceList, '成品检验订单数据');
  2540. this.changesStokledgerNumberModal(
  2541. this.sourceList,
  2542. this.dimensionType,
  2543. 'type'
  2544. );
  2545. return;
  2546. } else if (
  2547. this.sourceList &&
  2548. this.dimensionType &&
  2549. this.baseForm.qualityMode == '2'
  2550. ) {
  2551. this.sampleList = [];
  2552. } else {
  2553. if (
  2554. this.baseForm.qualityMode == '1' &&
  2555. this.sourceList.length > 1
  2556. ) {
  2557. this.changesStokledgerNumberModal(this.sourceList, '3', 'type');
  2558. } else if (
  2559. this.baseForm.qualityMode == '2' &&
  2560. this.sourceList.length > 1
  2561. ) {
  2562. this.sampleList = [];
  2563. } else if (
  2564. this.baseForm.qualityMode == '1' &&
  2565. this.sourceList.length > 0
  2566. ) {
  2567. this.changesStokledgerNumberModal(
  2568. this.sourceList,
  2569. this.dimensionType,
  2570. 'type'
  2571. );
  2572. } else {
  2573. this.sampleList = [];
  2574. }
  2575. }
  2576. // if (this.$refs.table12 && this.dimensionType) {
  2577. // const listData = this.$refs.table12.getData();
  2578. // console.log(listData, '成品检验订单数据');
  2579. // this.changesStokledgerNumberModal(
  2580. // listData,
  2581. // this.dimensionType,
  2582. // 'type'
  2583. // );
  2584. // // if (this.dimensionType == 3) {
  2585. // // if (this.baseForm.qualityMode == '1') {
  2586. // // this.handleUnpackCase(val);
  2587. // // } else if (this.baseForm.qualityMode == '2') {
  2588. // // this.sampleList = [];
  2589. // // }
  2590. // // } else {
  2591. // // if (this.baseForm.qualityMode == '1') {
  2592. // // this.handleUnpackCase(listData);
  2593. // // } else if (this.baseForm.qualityMode == '2') {
  2594. // // this.sampleList = [];
  2595. // // }
  2596. // // }
  2597. // }
  2598. return;
  2599. }
  2600. // 全检
  2601. if (this.baseForm.qualityMode == 1) {
  2602. // console.log('+++++++++1');
  2603. // this.handleSampleList();
  2604. this.updatePackingList(this.sourceList);
  2605. } else {
  2606. this.sampleList = [];
  2607. }
  2608. },
  2609. changeType() {
  2610. this.isPackingList = false;
  2611. },
  2612. changeSource() {
  2613. this.isSampleList = false;
  2614. },
  2615. //确定按钮
  2616. handleExtractFull() {
  2617. this.$refs.ruleForm.validate(async (valid) => {
  2618. if (!valid || !this.validateSelection()) return;
  2619. this.isSampleList = false;
  2620. this.baseForm.sampleMeasureUnit = this.formData.sampleUnit;
  2621. this.sampleList = [];
  2622. const sampleCount = Number(this.formData.portion);
  2623. console.log(sampleCount, 'sampleCount sampleCount == p');
  2624. console.log(this.formData, 'this.formData 000');
  2625. const measureQ = this.formData.number || 1;
  2626. const unit = this.formData.sampleUnit;
  2627. let specifications = this.packingSpecificationOption.find(
  2628. (el) => el.id == this.formData.packingUnit
  2629. );
  2630. // console.log(this.conditionType, this.baseForm.inspectionStandards);
  2631. // console.log(this.isStandard1OrWeightSample())
  2632. // console.log(this.isWeightStandardFullSample())
  2633. try {
  2634. if (this.isStandard1OrWeightSample()) {
  2635. // 新增校验 数量 取整样 ***
  2636. console.log(this.baseForm.conditionType, '33333333333');
  2637. if (this.conditionType == 1) {
  2638. let isFlag = this.validateSampleQuantity(
  2639. sampleCount,
  2640. specifications
  2641. );
  2642. if (!isFlag) return;
  2643. }
  2644. // ***
  2645. //抽检计量整样小样或者抽检计重小样
  2646. if (!this.validateMeasureQuantity(measureQ, unit, sampleCount))
  2647. return;
  2648. if (unit === 'KG' && !this.validateWeight(measureQ, sampleCount))
  2649. return; // 若计量单位为重量,还需验证总重量是否足够
  2650. console.log('getNewFullSampleList');
  2651. if (this.conditionType == '1' && this.baseForm.type == '3') {
  2652. console.log(1111111111111111111);
  2653. await this.handleWeightFullSample(sampleCount, specifications);
  2654. } else {
  2655. console.log('2222222222222 --', Math.ceil(sampleCount));
  2656. await this.getNewFullSampleList(
  2657. Math.ceil(sampleCount),
  2658. // sampleCount,
  2659. measureQ,
  2660. unit,
  2661. specifications
  2662. );
  2663. }
  2664. } else if (this.isWeightStandardFullSample()) {
  2665. //抽检取计重取整样
  2666. if (!this.validateSampleCount(sampleCount, specifications))
  2667. return;
  2668. await this.handleWeightFullSample(sampleCount, specifications);
  2669. }
  2670. this.activeName = '2';
  2671. } catch (error) {
  2672. console.error('取样处理失败:', error);
  2673. this.$message.error('取样处理失败');
  2674. }
  2675. });
  2676. },
  2677. // 当计量类型 是数量的时候 取整样 校验
  2678. validateSampleQuantity(sampleCount, specifications) {
  2679. console.log(this.selectedList, 'this.selectedList 9999');
  2680. console.log(specifications, 'specificationsspecifications');
  2681. let packingUnit = this.selectedList[0].packingUnit?.trim() || '';
  2682. console.log(packingUnit, 'packingUnitpackingUnit');
  2683. let totalS = 0;
  2684. let labelKey =
  2685. packingUnit == specifications.conversionUnit.trim()
  2686. ? 'packingQuantity'
  2687. : 'measureQuantity';
  2688. let labelName = labelKey == 'packingQuantity' ? '包装数量' : '计量数量';
  2689. totalS = this.selectedList.reduce(
  2690. (total, el) => total + el[labelKey],
  2691. 0
  2692. );
  2693. if (sampleCount > totalS) {
  2694. this.$message.info(
  2695. `所填的条目数量不能超过所选${labelName}总和${totalS}`
  2696. );
  2697. return false;
  2698. }
  2699. return true;
  2700. },
  2701. validateSelection() {
  2702. if (!this.selectedList?.length) {
  2703. this.$message.warning('请先选择样品!');
  2704. return false;
  2705. }
  2706. return true;
  2707. },
  2708. isStandard1OrWeightSample() {
  2709. return (
  2710. this.baseForm.inspectionStandards === 1 ||
  2711. (this.baseForm.inspectionStandards === 2 && this.conditionType == 2)
  2712. );
  2713. },
  2714. isWeightStandardFullSample() {
  2715. return (
  2716. this.baseForm.inspectionStandards === 2 && this.conditionType == 1
  2717. );
  2718. },
  2719. validateMeasureQuantity(measureQ, unit, sampleCount) {
  2720. if (this.conditionType == 2 && measureQ <= 0) {
  2721. this.$message.info('取样计量数量必须大于0');
  2722. return false;
  2723. }
  2724. const totalQuantity = this.selectedList.reduce(
  2725. (sum, item) => sum + item.measureQuantity,
  2726. 0
  2727. );
  2728. if (
  2729. (this.selectedList[0].measureUnit === unit ||
  2730. this.conditionType == 1) &&
  2731. measureQ * sampleCount > totalQuantity
  2732. ) {
  2733. this.$message.info('取样计量数量不能大于总计量数量');
  2734. return false;
  2735. }
  2736. console.log(this.selectedList, '33333333333');
  2737. console.log(measureQ, 'measureQ 0000');
  2738. const invalidItem = this.selectedList.find(
  2739. (item) => item.measureQuantity < measureQ
  2740. );
  2741. if (invalidItem) {
  2742. this.$message.info('条目计量数量小于取样计量数量');
  2743. return false;
  2744. }
  2745. return true;
  2746. },
  2747. validateWeight(measureQ, sampleCount) {
  2748. let totalMaxPossible = 0;
  2749. this.selectedList.forEach((item) => {
  2750. totalMaxPossible += item.measureQuantity / measureQ;
  2751. });
  2752. if (totalMaxPossible < sampleCount) {
  2753. this.formData.portion = totalMaxPossible;
  2754. this.$message.info(`最大取样条数为${totalMaxPossible}`);
  2755. return false;
  2756. }
  2757. let totalWeight = this.selectedList.reduce(
  2758. (sum, item) => sum + item.weight,
  2759. 0
  2760. );
  2761. const weightUnit = this.selectedList[0].weightUnit;
  2762. if (weightUnit === 'G') totalWeight /= 1000;
  2763. console.log(measureQ * sampleCount, totalWeight);
  2764. if (measureQ * sampleCount > totalWeight) {
  2765. this.$message.info('取样计量重量不能大于总计量重量');
  2766. return false;
  2767. }
  2768. const invalidItem = this.selectedList.find((item) => {
  2769. const weight =
  2770. item.weightUnit === 'G' ? item.weight / 1000 : item.weight;
  2771. return weight < measureQ;
  2772. });
  2773. if (invalidItem) {
  2774. this.$message.info('勾选条目重量小于取样重量');
  2775. return false;
  2776. }
  2777. return true;
  2778. },
  2779. validateSampleCount(sampleCount, specifications) {
  2780. // const invalidItem = this.selectedList.find(
  2781. // (item) => item.measureQuantity < sampleCount
  2782. // );
  2783. // const totalNumber = this.sourceList.reduce((acc, pro) => {
  2784. // return pro.measureQuantity ? acc + Number(pro.measureQuantity) : acc;
  2785. // }, 0);
  2786. // 新增校验 ***
  2787. let isFlag = this.validateSampleQuantity(sampleCount, specifications);
  2788. if (!isFlag) {
  2789. return false;
  2790. }
  2791. // ***
  2792. const chooseNumber = this.selectedList.reduce((acc, pro) => {
  2793. return pro.measureQuantity ? acc + Number(pro.measureQuantity) : acc;
  2794. }, 0);
  2795. const invalidItem = chooseNumber < sampleCount;
  2796. if (invalidItem) {
  2797. this.$message.info('所选的条目计量数量小于取样计量数量');
  2798. return false;
  2799. }
  2800. return true;
  2801. },
  2802. async handleWeightFullSample(sampleCount, specifications) {
  2803. // console.log(sampleCount, 'sampleCount');
  2804. // console.log(this.selectedList, 'this.selectedList');
  2805. let currentNum = sampleCount - this.selectedList.length;
  2806. let currentNum1 = sampleCount;
  2807. let list = [];
  2808. this.selectedList.forEach((item) => {
  2809. if (sampleCount >= this.selectedList.length) {
  2810. list.push({
  2811. ...item,
  2812. measureQuantity: 1, //作为计量数量
  2813. weight: item.singleWeight
  2814. ? (Number(item.singleWeight) * Number(sampleCount)).toFixed(2)
  2815. : item.outboundNum
  2816. ? (
  2817. (Number(item.weight) / Number(item.outboundNum)) *
  2818. Number(sampleCount)
  2819. ).toFixed(2)
  2820. : item.weight
  2821. });
  2822. } else {
  2823. if (list.length < sampleCount) {
  2824. list.push({
  2825. ...item,
  2826. measureQuantity: currentNum1 > 1 ? 1 : currentNum1, //作为计量数量
  2827. weight: item.singleWeight
  2828. ? (Number(item.singleWeight) * Number(sampleCount)).toFixed(2)
  2829. : item.outboundNum
  2830. ? (
  2831. (Number(item.weight) / Number(item.outboundNum)) *
  2832. Number(sampleCount)
  2833. ).toFixed(2)
  2834. : item.weight
  2835. });
  2836. currentNum1 -= 1;
  2837. }
  2838. }
  2839. if (sampleCount > this.selectedList.length) {
  2840. list.forEach((item) => {
  2841. if (currentNum > 0) {
  2842. let data = this.selectedList.find((val) => val.id == item.id);
  2843. item['measureQuantity'] =
  2844. data.measureQuantity - 1 - currentNum > 0
  2845. ? currentNum + 1
  2846. : data.measureQuantity;
  2847. currentNum = currentNum - (data.measureQuantity - 1);
  2848. }
  2849. });
  2850. }
  2851. // ...item,
  2852. // // measureQuantity: sampleCount,
  2853. // weight: item.singleWeight
  2854. // ? (Number(item.singleWeight) * Number(sampleCount)).toFixed(2)
  2855. // : item.outboundNum
  2856. // ? (
  2857. // (Number(item.weight) / Number(item.outboundNum)) *
  2858. // Number(sampleCount)
  2859. // ).toFixed(2)
  2860. // : item.weight
  2861. // weight: item.singleWeight ? Number(item.singleWeight) : item.weight
  2862. });
  2863. // if (this.selectedList.length > sampleCount) {
  2864. // const newList = list.splice(0, sampleCount);
  2865. // await this.updatePackingList(newList);
  2866. // } else {
  2867. // await this.updatePackingList(list);
  2868. // }
  2869. // 更改 从新计算 样品清单 取整样 数据
  2870. if (specifications && specifications.id) {
  2871. // let proportion = (obj.weight / obj.measureQuantity).toFixed(2);
  2872. console.log(list, 'dataList 这里是重量');
  2873. console.log(specifications, 'specifications ===');
  2874. list.map((el) => {
  2875. el.measureQuantity =
  2876. el.measureQuantity * specifications.packageCellTotal;
  2877. el.weight = this.formatNumber(
  2878. el.measureQuantity,
  2879. el.weightProportion
  2880. );
  2881. });
  2882. }
  2883. await this.updatePackingList(list);
  2884. },
  2885. handDel(index) {
  2886. console.log(index);
  2887. this.schemeList.splice(index, 1);
  2888. }
  2889. }
  2890. };
  2891. </script>
  2892. <style lang="scss" scoped>
  2893. .location-warp {
  2894. display: flex;
  2895. .detail {
  2896. margin-left: 10px;
  2897. }
  2898. }
  2899. :deep(.el-form-item__content .el-input-group__prepend) {
  2900. background-color: #fff;
  2901. }
  2902. :deep(
  2903. .el-dialog:not(.ele-dialog-form)
  2904. .el-dialog__body
  2905. .el-form
  2906. .el-form-item:last-child
  2907. ) {
  2908. margin-bottom: 22px;
  2909. }
  2910. .add-product {
  2911. width: 100%;
  2912. display: flex;
  2913. align-items: center;
  2914. justify-content: flex-end;
  2915. font-size: 30px;
  2916. color: #1890ff;
  2917. margin: 10px 0;
  2918. cursor: pointer;
  2919. }
  2920. .el-pagination {
  2921. padding: 12px 16px;
  2922. background: #fff;
  2923. border: 1px solid#ebeef5;
  2924. border-top: none;
  2925. }
  2926. .flex {
  2927. display: flex;
  2928. align-items: center;
  2929. }
  2930. </style>