new-edit.vue 103 KB

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