edit.vue 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288
  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. @getInspectionStandards="getInspectionStandards"
  26. :packingLists="packingList"
  27. @getCategoryInfo="getCategoryInfo"
  28. @changeProductNumberModel="changeProductNumberModel"
  29. @changesStokledgerNumberModal="changesStokledgerNumberModal"
  30. @getQualityTemplate="getQualityTemplate"
  31. ></base-info>
  32. <el-row>
  33. <header-title title="质检内容"></header-title>
  34. <el-tabs v-model="activeName" @tab-click="handleClick">
  35. <el-tab-pane label="来源清单" name="1">
  36. <ele-pro-table
  37. ref="table12"
  38. :columns="tableColumns"
  39. :datasource="datasource"
  40. :needPage="
  41. btnType == 'add' ||
  42. (btnType == 'edit' && !isFormNumber && !isOrder)
  43. ? false
  44. : true
  45. "
  46. @selection-change="handleSelectionChange"
  47. >
  48. <template
  49. v-slot:toolbar
  50. v-if="this.baseForm.qualityMode == 2 && btnType != 'detail'"
  51. >
  52. <el-dropdown trigger="click" @command="handleSampleNumber">
  53. <el-link type="primary" icon="el-icon-plus">取样</el-link>
  54. <el-dropdown-menu slot="dropdown">
  55. <el-dropdown-item command="1">取整样</el-dropdown-item>
  56. <el-dropdown-item command="2">取小样</el-dropdown-item>
  57. </el-dropdown-menu>
  58. </el-dropdown>
  59. </template>
  60. <template v-slot:toolkit v-if="this.baseForm.qualityMode == 2">
  61. <el-row>
  62. <el-form
  63. ref="ruleForm"
  64. :model="formData"
  65. label-width="60px"
  66. size="mini"
  67. :rules="rules"
  68. class="flex"
  69. :show-message="false"
  70. >
  71. <el-col :span="6" v-if="conditionType == 2">
  72. <el-form-item
  73. prop="number"
  74. label-width="0"
  75. style="margin-bottom: 0"
  76. >
  77. <el-input
  78. v-model="formData.number"
  79. placeholder="请输入"
  80. size="mini"
  81. ></el-input>
  82. </el-form-item>
  83. </el-col>
  84. <el-col :span="6" v-if="conditionType == 2">
  85. <el-form-item
  86. prop="sampleUnit"
  87. label-width="0"
  88. style="margin: 0"
  89. >
  90. <DictSelection
  91. dictName="计量单位"
  92. clearable
  93. v-model="formData.sampleUnit"
  94. size="mini"
  95. @change="changeSamUnit"
  96. ></DictSelection>
  97. </el-form-item>
  98. </el-col>
  99. <el-col :span="8" v-if="conditionType == 2">
  100. <el-form-item prop="portion" label="数量" style="margin: 0">
  101. <el-input
  102. v-model="formData.portion"
  103. placeholder="请输入"
  104. size="mini"
  105. clearable
  106. ></el-input>
  107. </el-form-item>
  108. </el-col>
  109. <el-col :span="24" v-if="conditionType == 1">
  110. <el-form-item prop="portion" label="数量" style="margin: 0">
  111. <el-input
  112. v-model="formData.portion"
  113. placeholder="请输入"
  114. size="mini"
  115. clearable
  116. ></el-input>
  117. </el-form-item>
  118. </el-col>
  119. <el-col
  120. :span="4"
  121. style="text-align: right"
  122. v-if="conditionType == 1"
  123. >
  124. <el-button
  125. type="primary"
  126. size="mini"
  127. @click="handleExtractFull"
  128. style="margin-right: 12px"
  129. >确认</el-button
  130. >
  131. </el-col>
  132. <el-col
  133. :span="4"
  134. style="text-align: right"
  135. v-if="conditionType == 2"
  136. >
  137. <el-button
  138. type="primary"
  139. size="mini"
  140. @click="handleExtractFull"
  141. style="margin-right: 12px"
  142. >确认</el-button
  143. >
  144. </el-col>
  145. </el-form>
  146. </el-row>
  147. </template>
  148. </ele-pro-table>
  149. <!-- 来料列表表格 -->
  150. <!-- <ele-pro-table
  151. ref="table12"
  152. :columns="tableColumns"
  153. :datasource="datasource"
  154. :needPage="
  155. btnType == 'add' ||
  156. (btnType == 'edit' && !isFormNumber && !isOrder)
  157. ? false
  158. : true
  159. "
  160. @selection-change="handleSelectionChange"
  161. >
  162. <template
  163. v-slot:toolbar
  164. v-if="this.baseForm.qualityMode == 2 && btnType != 'detail'"
  165. >
  166. <el-dropdown trigger="click" @command="handleSampleNumber">
  167. <el-link type="primary" icon="el-icon-plus">取样</el-link>
  168. <el-dropdown-menu slot="dropdown">
  169. <el-dropdown-item command="1">取整样</el-dropdown-item>
  170. <el-dropdown-item command="2">取小样</el-dropdown-item>
  171. </el-dropdown-menu>
  172. </el-dropdown>
  173. </template>
  174. <template v-slot:toolkit v-if="this.baseForm.qualityMode == 2">
  175. <el-row>
  176. <el-form
  177. ref="ruleForm"
  178. :model="formData"
  179. label-width="60px"
  180. size="mini"
  181. :rules="rules"
  182. class="flex"
  183. :show-message="false"
  184. >
  185. <el-col :span="6" v-if="conditionType == 2">
  186. <el-form-item
  187. prop="number"
  188. label-width="0"
  189. style="margin-bottom: 0"
  190. >
  191. <el-input
  192. v-model="formData.number"
  193. placeholder="请输入"
  194. size="mini"
  195. ></el-input>
  196. </el-form-item>
  197. </el-col>
  198. <el-col :span="6" v-if="conditionType == 2">
  199. <el-form-item
  200. prop="sampleUnit"
  201. label-width="0"
  202. style="margin: 0"
  203. >
  204. <DictSelection
  205. dictName="计量单位"
  206. clearable
  207. v-model="formData.sampleUnit"
  208. size="mini"
  209. @change="changeSamUnit"
  210. ></DictSelection>
  211. </el-form-item>
  212. </el-col>
  213. <el-col :span="8" v-if="conditionType == 2">
  214. <el-form-item prop="portion" label="数量" style="margin: 0">
  215. <el-input
  216. v-model="formData.portion"
  217. placeholder="请输入"
  218. size="mini"
  219. clearable
  220. ></el-input>
  221. </el-form-item>
  222. </el-col>
  223. <el-col :span="24" v-if="conditionType == 1">
  224. <el-form-item prop="portion" label="数量" style="margin: 0">
  225. <el-input
  226. v-model="formData.portion"
  227. placeholder="请输入"
  228. size="mini"
  229. clearable
  230. ></el-input>
  231. </el-form-item>
  232. </el-col>
  233. <el-col
  234. :span="4"
  235. style="text-align: right"
  236. v-if="conditionType == 1"
  237. >
  238. <el-button
  239. type="primary"
  240. size="mini"
  241. @click="handleExtractFull"
  242. style="margin-right: 12px"
  243. >确认</el-button
  244. >
  245. </el-col>
  246. <el-col
  247. :span="4"
  248. style="text-align: right"
  249. v-if="conditionType == 2"
  250. >
  251. <el-button
  252. type="primary"
  253. size="mini"
  254. @click="handleExtractFull"
  255. style="margin-right: 12px"
  256. >确认</el-button
  257. >
  258. </el-col>
  259. </el-form>
  260. </el-row>
  261. </template>
  262. </ele-pro-table> -->
  263. </el-tab-pane>
  264. <el-tab-pane label="样品清单" name="2">
  265. <el-table
  266. v-show="activeName === '2'"
  267. v-if="sampleList.length > 0"
  268. ref="showSampleListTable"
  269. :data="paginatedSampleList"
  270. tooltip-effect="dark"
  271. :max-height="300"
  272. border
  273. row-key="id"
  274. >
  275. <el-table-column
  276. label="序号"
  277. type="index"
  278. width="50"
  279. align="center"
  280. ></el-table-column>
  281. <template v-for="column in tableColumns2">
  282. <el-table-column
  283. :key="column.prop"
  284. :label="column.label"
  285. :prop="column.prop"
  286. :show-overflow-tooltip="true"
  287. :width="column.width"
  288. :align="column.align"
  289. ></el-table-column>
  290. </template>
  291. </el-table>
  292. <el-pagination
  293. v-show="activeName === '2' && sampleList.length > 0"
  294. @size-change="handleSampleSizeChange"
  295. @current-change="handleSampleCurrentChange"
  296. :current-page="samplePagination.currentPage"
  297. :page-sizes="[10, 20, 50, 100]"
  298. :page-size="samplePagination.pageSize"
  299. layout="total, sizes, prev, pager, next, jumper"
  300. :total="samplePagination.total"
  301. style="margin-top: 10px"
  302. ></el-pagination>
  303. </el-tab-pane>
  304. <el-tab-pane label="质检方案" name="3">
  305. <el-button
  306. @click="addInspectionTemplate"
  307. type="primary"
  308. style="margin-top: 5px"
  309. >选择质检方案</el-button
  310. >
  311. <el-table
  312. v-show="activeName === '3'"
  313. v-if="schemeList.length > 0"
  314. ref="showSchemeListTable"
  315. :data="paginatedSchemeList"
  316. tooltip-effect="dark"
  317. :max-height="300"
  318. border
  319. row-key="id"
  320. >
  321. <el-table-column
  322. label="序号"
  323. type="index"
  324. width="50"
  325. align="center"
  326. ></el-table-column>
  327. <el-table-column
  328. label="质检方案编码"
  329. prop="qualitySchemeTemplateCode"
  330. align="center"
  331. width="170"
  332. ></el-table-column>
  333. <el-table-column
  334. label="质检方案名称"
  335. prop="qualitySchemeTemplateName"
  336. align="center"
  337. width="170"
  338. ></el-table-column>
  339. <el-table-column
  340. label="质检类型"
  341. prop="categoryLevelClassName"
  342. align="center"
  343. width="170"
  344. ></el-table-column>
  345. <el-table-column
  346. label="质检项编码"
  347. prop="inspectionCode"
  348. align="center"
  349. width="170"
  350. ></el-table-column>
  351. <el-table-column
  352. label="质检项名称"
  353. prop="inspectionName"
  354. align="center"
  355. ></el-table-column>
  356. <el-table-column
  357. label="工艺参数"
  358. prop="defaultValue"
  359. align="center"
  360. >
  361. <template slot-scope="scope">
  362. <div style="display: flex; flex-direction: row">
  363. <DictSelection
  364. v-if="btnType != 'detail'"
  365. style="width: 85px"
  366. clearable
  367. dictName="数学字符"
  368. v-model="scope.row.symbol"
  369. ></DictSelection>
  370. <el-input
  371. :disabled="btnType == 'detail'"
  372. v-model="scope.row.defaultValue"
  373. placeholder="请输入内容"
  374. style="width: 120px"
  375. ></el-input>
  376. <DictSelection
  377. v-if="btnType != 'detail'"
  378. dictName="工艺参数单位"
  379. clearable
  380. filterable
  381. v-model="scope.row.unitName"
  382. style="width: 100px"
  383. >
  384. </DictSelection>
  385. </div>
  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. <inspectionTemplateDialog
  420. ref="inspectionTemplateRef"
  421. @choose="inspectionTemplateSuccess"
  422. ></inspectionTemplateDialog>
  423. </template>
  424. </ele-modal>
  425. </template>
  426. <script>
  427. import baseInfo from './baseInfo.vue';
  428. import inspectionTemplateDialog from '@/views/inspectionTemplate/components/inspectionTemplateDialog.vue';
  429. import { getCode } from '@/api/login';
  430. import { save, update, planIssued } from '@/api/inspectionPlan';
  431. import {
  432. getQualityTemplateList,
  433. getTemplateListByPlanId,
  434. getSampleListByPlanId,
  435. getInventoryListByPlanId,
  436. outInRecordsPage,
  437. getBatchInfoData,
  438. getProductOrder,
  439. getProductSteup
  440. } from '@/api/inspectionPlan/index.js';
  441. import { getQualityTemplateByIds } from '@/api/inspectionTemplate';
  442. export default {
  443. components: {
  444. baseInfo,
  445. inspectionTemplateDialog
  446. },
  447. data() {
  448. const defaultForm = function () {
  449. return {
  450. id: '',
  451. code: '',
  452. name: '',
  453. type: '',
  454. qualityMode: '',
  455. inspectionStandards: '',
  456. autoOrder: '',
  457. groupId: '',
  458. groupName: '',
  459. executeId: '',
  460. executeName: '',
  461. planStartTime: '',
  462. planEndTime: '',
  463. standard: '',
  464. planSource: '',
  465. planSourceCode: '',
  466. productName: '',
  467. productCode: '',
  468. batchNo: '',
  469. specification: '',
  470. modelType: '',
  471. brandNo: '',
  472. productNumber: '',
  473. qualifiedNumber: '',
  474. unqualifiedNumber: '',
  475. qualificationRate: '',
  476. totalWeight: '',
  477. sampleNumber: null,
  478. sampleMeasureUnit: '',
  479. sampleProportion: '',
  480. supplierMark: '',
  481. remark: '',
  482. accessory: [],
  483. conditionType: 1
  484. };
  485. };
  486. return {
  487. defaultForm,
  488. // 表单数据
  489. baseForm: { ...defaultForm() },
  490. tableColumns2: [
  491. {
  492. label: '样品编码',
  493. prop: 'sampleCode',
  494. width: '150',
  495. align: 'center'
  496. },
  497. {
  498. label: '编码',
  499. prop: 'categoryCode',
  500. width: '150',
  501. align: 'center'
  502. },
  503. {
  504. label: '名称',
  505. prop: 'categoryName',
  506. width: '150',
  507. align: 'center'
  508. },
  509. { label: '批次号', prop: 'batchNo', align: 'center', width: 120 },
  510. { label: '发货条码', prop: 'barcodes', align: 'center' },
  511. { label: '包装编码', prop: 'packageNo', align: 'center' },
  512. { label: '计量数量', prop: 'measureQuantity', align: 'center' },
  513. { label: '计量单位', prop: 'measureUnit', align: 'center' },
  514. { label: '物料代号', prop: 'materielDesignation', align: 'center' },
  515. { label: '客户代号', prop: 'clientCode', align: 'center' },
  516. { label: '刻码', prop: 'engrave', align: 'center' },
  517. // { prop: 'specification', label: '规格', align: 'center', width: 100, showOverflowTooltip: true },
  518. // { prop: 'brandNum', label: '牌号', align: 'center', width: 100, showOverflowTooltip: true },
  519. // { prop: 'modelType', label: '型号', align: 'center', width: 100, showOverflowTooltip: true },
  520. { label: '重量', prop: 'weight', align: 'center' },
  521. { label: '重量单位', prop: 'weightUnit', align: 'center' },
  522. { label: '仓库', prop: 'warehouseName', align: 'center' },
  523. { label: '货区', prop: 'areaName', align: 'center' },
  524. { label: '货架', prop: 'goodsShelfName', align: 'center' },
  525. { label: '货位', prop: 'goodsAllocationName', align: 'center' },
  526. { label: '生产日期', prop: 'productionDate', align: 'center' },
  527. { label: '采购日期', prop: 'purchaseDate', align: 'center' }
  528. ],
  529. packingList: [],
  530. sampleList: [],
  531. samplePagination: {
  532. currentPage: 1,
  533. pageSize: 10,
  534. total: 0
  535. },
  536. schemeList: [],
  537. schemePagination: {
  538. currentPage: 1,
  539. pageSize: 10,
  540. total: 0
  541. },
  542. // 表单验证规则
  543. visible: false,
  544. btnType: null,
  545. title: null,
  546. loading: false,
  547. listPage: [],
  548. activeName: '1',
  549. selectedList: [],
  550. isCheck: false, // 是否拆包 false 不拆包 true 拆包
  551. rowIds: '',
  552. formData: {
  553. number: 1,
  554. sampleUnit: '',
  555. portion: null
  556. },
  557. rules: {
  558. number: [
  559. {
  560. required: true,
  561. message: '请输入',
  562. trigger: 'blur'
  563. }
  564. ],
  565. sampleUnit: [
  566. {
  567. required: true,
  568. message: '请选择样品单位',
  569. trigger: 'change'
  570. }
  571. ],
  572. portion: [
  573. {
  574. required: true,
  575. message: '请输入',
  576. trigger: 'blur'
  577. }
  578. ]
  579. },
  580. isScheme: true,
  581. isOrder: true,
  582. isConsumable: '', //0 单件 1批量
  583. netWeight: '', // 净重
  584. conditionType: null,
  585. isFormNumber: true,
  586. sampleListCode: '',
  587. productItem: {}, //产品信息
  588. isUpdateData: true,
  589. isChangeNumber: true,
  590. isChangeType: true,
  591. isOnce: true
  592. };
  593. },
  594. computed: {
  595. tableColumns() {
  596. let arr = [
  597. // (this.btnType !== 'issued' || this.baseForm.qualityMode === 2)
  598. // ? {
  599. // columnKey: 'selection',
  600. // type: 'selection',
  601. // width: 45,
  602. // align: 'center'
  603. // }
  604. // : null,
  605. {
  606. columnKey: 'selection',
  607. type: 'selection',
  608. width: 45,
  609. align: 'center'
  610. },
  611. {
  612. columnKey: 'index',
  613. label: '序号',
  614. type: 'index',
  615. width: 55,
  616. align: 'center',
  617. fixed: 'left'
  618. },
  619. {
  620. label: '编码',
  621. prop: 'categoryCode',
  622. width: 150,
  623. align: 'center',
  624. showOverflowTooltip: true
  625. },
  626. {
  627. label: '名称',
  628. prop: 'categoryName',
  629. width: '150',
  630. align: 'center',
  631. width: 120,
  632. showOverflowTooltip: true
  633. },
  634. { label: '批次号', prop: 'batchNo', align: 'center', width: 120 },
  635. { label: '发货条码', prop: 'barcodes', align: 'center' },
  636. {
  637. label: '包装编码',
  638. prop: 'packageNo',
  639. align: 'center',
  640. width: 120,
  641. showOverflowTooltip: true
  642. },
  643. { label: '包装数量', prop: 'packingQuantity', align: 'center' },
  644. { label: '包装单位', prop: 'packingUnit', align: 'center' },
  645. { label: '计量数量', prop: 'measureQuantity', align: 'center' },
  646. { label: '计量单位', prop: 'measureUnit', align: 'center' },
  647. { label: '物料代号', prop: 'materielDesignation', align: 'center' },
  648. { label: '客户代号', prop: 'clientCode', align: 'center' },
  649. {
  650. label: '供应商名称',
  651. prop: 'supplierName',
  652. align: 'center',
  653. width: 120,
  654. showOverflowTooltip: true
  655. },
  656. {
  657. label: '供应商代号',
  658. prop: 'supplierCode',
  659. align: 'center',
  660. width: '120'
  661. },
  662. { label: '刻码', prop: 'engrave', align: 'center' },
  663. { label: '重量', prop: 'weight', align: 'center' },
  664. { label: '重量单位', prop: 'weightUnit', align: 'center' },
  665. {
  666. label: '仓库',
  667. prop: 'warehouseName',
  668. align: 'center',
  669. width: 120,
  670. showOverflowTooltip: true
  671. },
  672. { label: '货区', prop: 'areaName', align: 'center' },
  673. { label: '货架', prop: 'goodsShelfName', align: 'center' },
  674. { label: '货位', prop: 'goodsAllocationName', align: 'center' },
  675. {
  676. label: '生产日期',
  677. prop: 'productionDate',
  678. align: 'center',
  679. width: 120,
  680. showOverflowTooltip: true
  681. },
  682. {
  683. label: '采购日期',
  684. prop: 'purchaseDate',
  685. align: 'center',
  686. width: 120,
  687. showOverflowTooltip: true
  688. }
  689. ];
  690. return arr;
  691. },
  692. // 分页后的样品列表
  693. paginatedSampleList() {
  694. if (this.rowIds && this.isOrder) {
  695. console.log(this.sampleList, 'sampleList');
  696. return this.sampleList;
  697. }
  698. const { currentPage, pageSize } = this.samplePagination;
  699. const start = (currentPage - 1) * pageSize;
  700. const end = start + pageSize;
  701. return this.sampleList.slice(start, end);
  702. },
  703. // 分页后的质检方案列表
  704. paginatedSchemeList() {
  705. if (this.rowIds && this.isScheme) {
  706. console.log('101010');
  707. console.log(this.schemeList, 'test');
  708. return this.schemeList;
  709. }
  710. const { currentPage, pageSize } = this.schemePagination;
  711. const start = (currentPage - 1) * pageSize;
  712. const end = start + pageSize;
  713. console.log('131314');
  714. return this.schemeList.slice(start, end);
  715. }
  716. },
  717. created() {},
  718. methods: {
  719. //成品检验类型,计划来源主数据,修改数量生成来源清单
  720. changeProductNumberModel(num) {
  721. // if (
  722. // this.btnType == 'add' ||
  723. // (this.btnType == 'edit' && !this.isUpdateData)
  724. // ) {
  725. // this.$refs.table12.setData([]);
  726. // this.isOrder = false;
  727. // let nums = Number(num);
  728. // let p = this.productItem;
  729. // let list = [];
  730. // if (this.isConsumable == 0) {
  731. // for (let i = 0; i < nums; i++) {
  732. // let obj = {
  733. // id: p.id,
  734. // batchNo: p.batchNo,
  735. // categoryCode: p.code, //编码
  736. // categoryName: p.name, //名称
  737. // measureQuantity: 1,
  738. // measureUnit: p.measuringUnit, //计量单位
  739. // weightUnit: p.weightUnit, //重量单位
  740. // weight: p.netWeight //重量
  741. // };
  742. // list.push(obj);
  743. // }
  744. // } else if (this.isConsumable == 1) {
  745. // let obj = {
  746. // id: p.id,
  747. // batchNo: p.batchNo,
  748. // categoryCode: p.code, //编码
  749. // categoryName: p.name, //名称
  750. // measureQuantity: nums, //计量数量
  751. // measureUnit: p.measuringUnit, //计量单位
  752. // weightUnit: p.weightUnit, //重量单位
  753. // weight: p.netWeight * nums //重量
  754. // };
  755. // list.push(obj);
  756. // }
  757. // this.$refs.table12.setData(list);
  758. // // *** 如果检验方式是全量的话 还需要同步样品清单数据
  759. // if (
  760. // this.baseForm.qualityMode == 1 &&
  761. // this.baseForm.inspectionStandards
  762. // ) {
  763. // this.isFormNumber = false;
  764. // this.handleSampleList();
  765. // }
  766. // console.log(this.baseForm, 'form --');
  767. // }
  768. console.log('数据33333');
  769. this.$refs.table12.setData([]);
  770. this.isOrder = false;
  771. let nums = Number(num);
  772. let p = this.productItem;
  773. let list = [];
  774. if (this.isConsumable == 0) {
  775. for (let i = 0; i < nums; i++) {
  776. let obj = {
  777. id: p.id,
  778. batchNo: p.batchNo,
  779. categoryCode: p.code, //编码
  780. categoryName: p.name, //名称
  781. measureQuantity: 1,
  782. measureUnit: p.measuringUnit, //计量单位
  783. weightUnit: p.weightUnit, //重量单位
  784. weight: p.netWeight //重量
  785. };
  786. list.push(obj);
  787. }
  788. } else if (this.isConsumable == 1) {
  789. let obj = {
  790. id: p.id,
  791. batchNo: p.batchNo,
  792. categoryCode: p.code, //编码
  793. categoryName: p.name, //名称
  794. measureQuantity: nums, //计量数量
  795. measureUnit: p.measuringUnit, //计量单位
  796. weightUnit: p.weightUnit, //重量单位
  797. weight: p.netWeight * nums //重量
  798. };
  799. list.push(obj);
  800. }
  801. console.log('数据22222');
  802. console.log(this.isOrder);
  803. this.$refs.table12.setData(list);
  804. // *** 如果检验方式是全量的话 还需要同步样品清单数据
  805. if (
  806. this.baseForm.qualityMode == 1 &&
  807. this.baseForm.inspectionStandards
  808. ) {
  809. this.isFormNumber = false;
  810. console.log('+++++++++2');
  811. this.handleSampleList();
  812. }
  813. console.log(this.baseForm, 'form --');
  814. },
  815. //成品类型检验类型,计划来源库存台账, 生成来源清单
  816. changesStokledgerNumberModal(val, dimension) {
  817. console.log('数据11111');
  818. this.$refs.table12.setData([]);
  819. if (dimension == 3) return this.$refs.table12.setData(val);
  820. let item = val[0];
  821. let num = Number(item.outboundNum);
  822. let list = [];
  823. let weight = (item.weight / item.measureQuantity).toFixed(2);
  824. for (let i = 0; i < num; i++) {
  825. list.push({
  826. ...item,
  827. id: i + 1,
  828. packingQuantity: null,
  829. measureQuantity: 1,
  830. weight
  831. });
  832. }
  833. console.log('数据1221212121 list list',list);
  834. this.$refs.table12.setData(list);
  835. },
  836. //获取基本信息中计量方式
  837. getInspectionStandards(data) {
  838. console.log(data, 'data');
  839. console.log(this.baseForm.type, 'type');
  840. console.log(this.baseForm.planSource, 'planSource');
  841. this.baseForm.inspectionStandards = data;
  842. console.log(1313322);
  843. if (this.baseForm.type == '3' && this.baseForm.planSource == '6') {
  844. // this.isOrder = false;
  845. console.log('...........');
  846. this.handleSampleList();
  847. }
  848. if (this.btnType == 'edit' && !this.isOnce) {
  849. this.isOrder = false;
  850. console.log('98989898');
  851. this.handleSampleList();
  852. }
  853. this.isOnce = false;
  854. },
  855. async datasource({ page, limit, where }) {
  856. console.log(this.btnType);
  857. console.log(this.isScheme, this.isOrder);
  858. const res = await getInventoryListByPlanId({
  859. ...where,
  860. pageNum: page,
  861. size: limit
  862. });
  863. this.packingList = res.list;
  864. return res;
  865. },
  866. // 切换质检内容
  867. handleClick(tab) {
  868. this.activeName = tab.name;
  869. },
  870. async open(type, row) {
  871. this.visible = true;
  872. this.activeName = '1';
  873. this.btnType = type;
  874. this.title =
  875. type == 'add'
  876. ? '新增'
  877. : type == 'edit'
  878. ? '编辑'
  879. : type == 'issued'
  880. ? '下发'
  881. : '详情';
  882. if (this.btnType === 'add') {
  883. const code = await getCode('qms_plan_code');
  884. this.baseForm.code = code;
  885. this.rowIds = '';
  886. return;
  887. } else {
  888. await this.handleEditOrDetail(row);
  889. }
  890. },
  891. addInspectionTemplate() {
  892. this.$refs.inspectionTemplateRef.open();
  893. },
  894. async inspectionTemplateSuccess(select) {
  895. let data = await getQualityTemplateByIds({
  896. templateIds: select.map((item) => item.id)
  897. });
  898. console.log('---------------------------');
  899. this.isScheme = false;
  900. this.schemeList.push(...data);
  901. this.schemePagination.total = this.schemeList.length;
  902. },
  903. async handleEditOrDetail(row) {
  904. console.log('row====', row);
  905. row.accessory = row.accessory || [];
  906. this.baseForm = {
  907. ...JSON.parse(JSON.stringify(row)),
  908. groupId: row.groupId,
  909. qualityMode: row.qualityMode
  910. };
  911. console.log('baseInfo:' + this.baseForm);
  912. this.$nextTick(() => {
  913. if (this.$refs.baseInfoRefs) {
  914. // 获取人员
  915. if (this.baseForm.groupId) {
  916. this.$refs.baseInfoRefs.getUserList({
  917. groupId: this.baseForm.groupId
  918. });
  919. }
  920. //根据类型获取计划来源
  921. if (this.baseForm.type) {
  922. this.$refs.baseInfoRefs.typeChange(this.baseForm.type);
  923. }
  924. if (this.baseForm.productId) {
  925. this.$refs.baseInfoRefs.getProductDetails(
  926. this.baseForm.productId
  927. );
  928. }
  929. }
  930. });
  931. // 如果是编辑或者详情,则查询物料清单、质检方案和样品列表
  932. if (row.id) {
  933. this.rowIds = row.id;
  934. this.isScheme = true;
  935. this.schemePagination.currentPage = 1;
  936. this.schemePagination.pageSize = 10;
  937. this.schemePagination.total = 0;
  938. this.samplePagination.pageSize = 10;
  939. this.samplePagination.currentPage = 1;
  940. this.samplePagination.total = 0;
  941. this.isFormNumber = true;
  942. this.isOrder = true;
  943. console.log('edit true');
  944. if (row.isUnpack === 1) {
  945. this.isCheck = true;
  946. } else {
  947. this.isCheck = false;
  948. }
  949. //操作行点击时查询清单
  950. // await this.getInventoryList();
  951. await this.reload({ planId: row.id });
  952. //操作行点击时查询样品
  953. await this.getSampleList(row.id);
  954. //操作行点击时查询质检
  955. await this.getTemplateList(row.id);
  956. }
  957. },
  958. reload(where) {
  959. this.$nextTick(() => {
  960. if (this.$refs.table12 && this.$refs.table12.reload)
  961. this.$refs.table12.reload({ page: 1, where: where });
  962. });
  963. },
  964. async getSampleList(id) {
  965. let res = await getSampleListByPlanId({
  966. planId: id,
  967. pageNum: this.samplePagination.currentPage,
  968. size: this.samplePagination.pageSize
  969. });
  970. console.log(res.list, 'yyyyyyyyyyyyyy样品----------------------------');
  971. this.sampleList = res?.list || [];
  972. console.log(this.sampleList);
  973. this.samplePagination.total = res.count;
  974. },
  975. async getTemplateList(id) {
  976. let res = await getTemplateListByPlanId({
  977. planId: id,
  978. pageNum: this.schemePagination.currentPage,
  979. size: this.schemePagination.pageSize
  980. });
  981. console.log(res.list, 'fffffffffffffff方案--------------------------');
  982. this.schemeList = res?.list || [];
  983. this.schemePagination.total = res.count;
  984. },
  985. async getList(
  986. receiveNo,
  987. productCode,
  988. productCategoryId,
  989. productCategoryName,
  990. categoryid,
  991. batchNo,
  992. supplierName,
  993. supplierMark
  994. ) {
  995. //通过来源和产品 获取来料清单
  996. console.log(999999);
  997. await this.getGoodsList(
  998. receiveNo,
  999. productCode,
  1000. null,
  1001. productCategoryId,
  1002. productCategoryName,
  1003. categoryid,
  1004. batchNo,
  1005. supplierName,
  1006. supplierMark
  1007. );
  1008. //通过来源和产品 获取质检方案
  1009. await this.getQualityTemplate(productCode);
  1010. },
  1011. async getGoodsList(
  1012. receiveNo,
  1013. productCode,
  1014. ids,
  1015. productCategoryId,
  1016. productCategoryName,
  1017. categoryid,
  1018. batchNo,
  1019. supplierName,
  1020. supplierMark
  1021. ) {
  1022. console.log('数据1-1-1-1-1');
  1023. this.$refs.table12.setData([]);
  1024. console.log(999999);
  1025. let res;
  1026. const res1 = await outInRecordsPage({
  1027. sourceBizNo: receiveNo,
  1028. categoryCode: productCode,
  1029. categoryId: categoryid,
  1030. qualityQlanId: ids,
  1031. size: -1
  1032. });
  1033. console.log(res1, 'res1');
  1034. if (res1.list.length > 0) {
  1035. console.log(res1.list[0].status, 'status=2 不赋值');
  1036. if (res1.list[0].status != 2) {
  1037. res = res1.list;
  1038. this.isCheck = true;
  1039. console.log('this.isCheck=true', this.isCheck);
  1040. } else {
  1041. res = [];
  1042. this.$message.error('此数据已质检,无需再次质检!');
  1043. return;
  1044. }
  1045. } else {
  1046. let resData = await getBatchInfoData({
  1047. sourceBizNo: receiveNo,
  1048. categoryCode: productCode,
  1049. batchNo: batchNo
  1050. });
  1051. console.log(resData, 'resData');
  1052. if (resData) {
  1053. if (resData.qualityControl != 2) {
  1054. this.isCheck = false;
  1055. res = [resData];
  1056. } else {
  1057. res = [];
  1058. this.$message.error('此数据已质检,无需再次质检!');
  1059. return;
  1060. }
  1061. }
  1062. }
  1063. console.log(res, '来料清单');
  1064. if (res.length > 0) {
  1065. const _arr1 = res.map((m) => {
  1066. m.sourceId = m.id;
  1067. m.productCategoryId = productCategoryId;
  1068. m.productCategoryName = productCategoryName;
  1069. delete m.id;
  1070. return { ...m };
  1071. });
  1072. console.log(_arr1, '1234567890');
  1073. this.packingList = _arr1;
  1074. console.log('数据1010101010');
  1075. this.$refs.table12.setData(_arr1); //赋值
  1076. const _arr2 = this.$refs.table12.getData();
  1077. if (_arr2.length > 1) {
  1078. this.baseForm.productNumber = _arr2.length;
  1079. } else {
  1080. this.baseForm.productNumber = _arr2[0].measureQuantity;
  1081. }
  1082. //处理样品清单
  1083. console.log('+++++++++3');
  1084. await this.handleSampleList();
  1085. } else {
  1086. console.log('数据99999');
  1087. this.$refs.table12.setData([]);
  1088. }
  1089. },
  1090. async handleSampleList() {
  1091. // let packingList = this.$refs.table12.getData();
  1092. console.log(
  1093. this.baseForm.qualityMode,
  1094. this.baseForm.inspectionStandards,
  1095. this.btnType
  1096. );
  1097. if (this.baseForm.type == '1' && this.btnType != 'detail') {
  1098. if (this.baseForm.inspectionStandards == '2') {
  1099. console.log(13131313213);
  1100. this.sampleList = [];
  1101. let list = [];
  1102. if (this.baseForm.productNumber) {
  1103. let p = this.productItem;
  1104. console.log(p);
  1105. let obj = {
  1106. id: p.id,
  1107. batchNo: p.batchNo,
  1108. categoryCode: p.code, //编码
  1109. categoryName: p.name, //名称
  1110. measureQuantity: this.baseForm.productNumber, //计量数量
  1111. measureUnit: p.measuringUnit, //计量单位
  1112. weightUnit: p.weightUnit, //重量单位
  1113. weight: p.netWeight * this.baseForm.productNumber //重量
  1114. };
  1115. list.push(obj);
  1116. }
  1117. if (list.length > 0 && list[0].categoryCode) {
  1118. this.$refs.table12.setData(list);
  1119. let packList = this.$refs.table12.getData();
  1120. this.getFullInspectionWeight(packList);
  1121. }
  1122. // this.$refs.table12.setData(list);
  1123. // let packList = this.$refs.table12.getData();
  1124. // console.log(list);
  1125. // console.log(1654646);
  1126. // this.getFullInspectionWeight(packList);
  1127. // this.getFullInspectionWeight(list);
  1128. } else {
  1129. if (this.$refs.table12) {
  1130. let packingList = this.$refs.table12.getData();
  1131. if (
  1132. Math.ceil(Number(this.baseForm.productNumber || 0)) ===
  1133. packingList.length
  1134. ) {
  1135. console.log(
  1136. '--->',
  1137. Math.ceil(Number(this.baseForm.productNumber || 0))
  1138. );
  1139. console.log('--->', packingList.length);
  1140. await this.handleUnpackCase(packingList);
  1141. return;
  1142. } else {
  1143. this.getFullInspectionWeight(packingList);
  1144. }
  1145. }
  1146. // let packingList = this.$refs.table12.getData();
  1147. // if (
  1148. // Math.ceil(Number(this.baseForm.productNumber || 0)) ===
  1149. // packingList.length
  1150. // ) {
  1151. // await this.handleUnpackCase(packingList);
  1152. // return;
  1153. // } else {
  1154. // this.getFullInspectionWeight(packingList);
  1155. // }
  1156. }
  1157. }
  1158. //全检时 计量时
  1159. else if (
  1160. this.baseForm.qualityMode == 1 &&
  1161. this.baseForm.inspectionStandards == 1 &&
  1162. this.btnType != 'detail'
  1163. ) {
  1164. this.sampleList = [];
  1165. console.log(this.baseForm, '---isUnpack---');
  1166. if (this.baseForm.productNumber) {
  1167. console.log('数据777777');
  1168. if (this.$refs.table12) {
  1169. this.$refs.table12.setData([]);
  1170. let nums = Number(this.baseForm.productNumber);
  1171. let p = this.productItem;
  1172. let list = [];
  1173. for (let i = 0; i < nums; i++) {
  1174. let obj = {
  1175. id: p.id,
  1176. batchNo: p.batchNo,
  1177. categoryCode: p.code, //编码
  1178. categoryName: p.name, //名称
  1179. measureQuantity: 1,
  1180. measureUnit: p.measuringUnit, //计量单位
  1181. weightUnit: p.weightUnit, //重量单位
  1182. weight: p.netWeight //重量
  1183. };
  1184. list.push(obj);
  1185. }
  1186. console.log('数据666666');
  1187. this.$refs.table12.setData(list);
  1188. let packList = this.$refs.table12.getData();
  1189. await this.handleUnpackCase(packList);
  1190. return;
  1191. }
  1192. // this.$refs.table12.setData([]);
  1193. // let nums = Number(this.baseForm.productNumber);
  1194. // let p = this.productItem;
  1195. // let list = [];
  1196. // for (let i = 0; i < nums; i++) {
  1197. // let obj = {
  1198. // id: p.id,
  1199. // batchNo: p.batchNo,
  1200. // categoryCode: p.code, //编码
  1201. // categoryName: p.name, //名称
  1202. // measureQuantity: 1,
  1203. // measureUnit: p.measuringUnit, //计量单位
  1204. // weightUnit: p.weightUnit, //重量单位
  1205. // weight: p.netWeight //重量
  1206. // };
  1207. // list.push(obj);
  1208. // }
  1209. // console.log('数据666666');
  1210. // this.$refs.table12.setData(list);
  1211. // let packList = this.$refs.table12.getData();
  1212. // await this.handleUnpackCase(packList);
  1213. // return;
  1214. }
  1215. // if (this.rowIds) {
  1216. // const res = await getInventoryListByPlanId({
  1217. // planId: this.rowIds,
  1218. // pageNum: 1,
  1219. // size: 5000
  1220. // });
  1221. // // console.log(res.list);
  1222. // if (res.list.length > 0) {
  1223. // await this.handleUnpackCase(res.list);
  1224. // }
  1225. // } else {
  1226. // await this.handleUnpackCase(packingList);
  1227. // }
  1228. // if (this.baseForm.isUnpack != null && this.baseForm.isUnpack != undefined && this.baseForm.isUnpack != '') {
  1229. // //拆包
  1230. // if (this.baseForm.isUnpack == 1) {
  1231. // await this.handleUnpackCase(packingList);
  1232. // } else if (this.baseForm.isUnpack == 0) {
  1233. // await this.updatePackingList(packingList);
  1234. // }
  1235. // } else {
  1236. // console.log(this.isCheck, 'this.isCheck')
  1237. // if (!this.isCheck) {
  1238. // await this.handleUnpackCase(packingList);
  1239. // } else {
  1240. // await this.updatePackingList(packingList);
  1241. // }
  1242. // }
  1243. //全检 计重时
  1244. } else if (
  1245. this.baseForm.qualityMode == 1 &&
  1246. this.baseForm.inspectionStandards == 2 &&
  1247. this.btnType != 'detail'
  1248. // (this.btnType != 'detail' || this.btnType != 'edit')
  1249. // this.btnType == 'add'
  1250. ) {
  1251. this.sampleList = [];
  1252. let list = [];
  1253. if (this.baseForm.productNumber) {
  1254. let p = this.productItem;
  1255. let obj = {
  1256. id: p.id,
  1257. batchNo: p.batchNo,
  1258. categoryCode: p.code, //编码
  1259. categoryName: p.name, //名称
  1260. measureQuantity: this.baseForm.productNumber, //计量数量
  1261. measureUnit: p.measuringUnit, //计量单位
  1262. weightUnit: p.weightUnit, //重量单位
  1263. weight: p.netWeight * this.baseForm.productNumber //重量
  1264. };
  1265. list.push(obj);
  1266. }
  1267. console.log('数据55555');
  1268. console.log(list);
  1269. if (list.length > 0 && list[0].categoryCode) {
  1270. this.$refs.table12.setData(list);
  1271. let packList = this.$refs.table12.getData();
  1272. this.getFullInspectionWeight(packList);
  1273. }
  1274. // this.$refs.table12.setData(list);
  1275. // let packList = this.$refs.table12.getData();
  1276. // this.getFullInspectionWeight(packList);
  1277. // this.getFullInspectionWeight(packList);
  1278. } else {
  1279. this.sampleList = [];
  1280. }
  1281. },
  1282. //全检 计重时生成样品清单
  1283. async getFullInspectionWeight(packingList) {
  1284. this.updatePackingList(packingList);
  1285. },
  1286. //拆包处理样品清单数据
  1287. async handleUnpackCase(packingList) {
  1288. const num = Number(this.baseForm.productNumber || 0);
  1289. console.log('num:' + num);
  1290. if (num) {
  1291. await this.getUnpackSamList(packingList, num);
  1292. }
  1293. },
  1294. //获取样品编码
  1295. async getSampleCode() {
  1296. return await getCode('sample_code');
  1297. },
  1298. //更新样品清单数据
  1299. async updatePackingList(list) {
  1300. console.log(list);
  1301. console.log(this.isScheme, this.isOrder);
  1302. for (let i = 0; i < list.length; i++) {
  1303. list[i].sampleCode = await this.getSampleCode();
  1304. }
  1305. this.sampleList = list;
  1306. this.baseForm.sampleNumber = list.length;
  1307. this.samplePagination.currentPage = 1;
  1308. this.samplePagination.total = list.length;
  1309. // this.samplePagination.total = this.sampleList.length;
  1310. },
  1311. async getUnpackSamList(list, num) {
  1312. console.log(list, num);
  1313. let data = [];
  1314. list.forEach((oldItem, index) => {
  1315. const newMeasureQuantity =
  1316. oldItem.measureQuantity / this.baseForm.productNumber;
  1317. const newWeight = parseFloat(
  1318. (oldItem.weight / this.baseForm.productNumber).toFixed(2)
  1319. );
  1320. // 将 measureQuantity 转换为数字
  1321. const measureQuantity = Number(oldItem.measureQuantity);
  1322. // 判断是否有小数部分
  1323. const hasDecimal = measureQuantity % 1 !== 0;
  1324. let roundedQuantity;
  1325. if (hasDecimal) {
  1326. // 有小数部分,向上取整
  1327. roundedQuantity = Math.ceil(measureQuantity);
  1328. } else {
  1329. roundedQuantity = measureQuantity;
  1330. }
  1331. delete oldItem.id;
  1332. for (let i = 0; i < roundedQuantity; i++) {
  1333. data.push({
  1334. ...oldItem,
  1335. measureQuantity: 1,
  1336. weight: this.netWeight || 0
  1337. // weight:
  1338. // num - index >= 1
  1339. // ? this.netWeight
  1340. // : ((num * 100000 - index * 100000) / 100000) * this.netWeight
  1341. });
  1342. }
  1343. });
  1344. console.log(data, '样品数据-条数', num);
  1345. await this.updatePackingList(data);
  1346. },
  1347. async getQualityTemplate(productCode, ids) {
  1348. await getQualityTemplateList({
  1349. productCode: productCode,
  1350. qualityQlanId: ids
  1351. }).then((res) => {
  1352. if (Object.keys(res).length === 0) {
  1353. return;
  1354. }
  1355. this.baseForm.sampleProportion = res.checkProportion;
  1356. // this.baseForm.inspectionStandards = res?.inspectionStandards;
  1357. let combinedList = [];
  1358. for (let i = 0; i < res.qualityTemplateVOList.length; i++) {
  1359. res.qualityTemplateVOList[i].inspectionItemVOList =
  1360. res.qualityTemplateVOList[i]?.inspectionItemVOList.map((item) => {
  1361. item.templateId = res.qualityTemplateVOList[i]?.id;
  1362. item.qualitySchemeTemplateCode =
  1363. res.qualityTemplateVOList[i]?.qualitySchemeTemplateCode;
  1364. item.qualitySchemeTemplateName =
  1365. res.qualityTemplateVOList[i]?.qualitySchemeTemplateName;
  1366. delete item.id;
  1367. return {
  1368. ...item
  1369. };
  1370. });
  1371. combinedList = combinedList.concat(
  1372. res.qualityTemplateVOList[i].inspectionItemVOList
  1373. );
  1374. console.log(combinedList, '质检方案');
  1375. this.schemeList = combinedList;
  1376. this.schemePagination.currentPage = 1;
  1377. this.schemePagination.total = this.schemeList.length;
  1378. }
  1379. });
  1380. },
  1381. //来料列表表格选择事件
  1382. handleSelectionChange(selection) {
  1383. console.log(selection, '勾选');
  1384. this.selectedList = selection;
  1385. //如果取小样
  1386. if (this.conditionType == 2) {
  1387. if (this.isCheck) {
  1388. this.formData.portion = selection.length;
  1389. this.baseForm.sampleNumber = selection.length;
  1390. } else {
  1391. this.baseForm.sampleNumber = this.formData.portion;
  1392. }
  1393. const data1 = this.$refs.table12.getData();
  1394. this.$set(this.formData, 'sampleUnit', data1[0]?.measureUnit);
  1395. this.$set(this.baseForm, 'sampleMeasureUnit', data1[0]?.measureUnit);
  1396. } else if (this.conditionType == 1) {
  1397. this.baseForm.sampleNumber = this.formData.portion;
  1398. this.formData.number = 0;
  1399. }
  1400. },
  1401. //取样方式选择
  1402. async handleSampleNumber(val) {
  1403. console.log(val, 'val');
  1404. this.conditionType = val;
  1405. //清空样品清单列表
  1406. this.sampleList = [];
  1407. // const dataS = this.$refs.table12.getData();
  1408. //取整样
  1409. // if (val == 1) {
  1410. // if (this.selectedList.length == 0) {
  1411. // this.$message.warning('请先选择样品!');
  1412. // } else {
  1413. // if (this.isCheck) {
  1414. // for (let i = 0; i < this.selectedList.length; i++) {
  1415. // for (let j = 0; j < this.selectedList[i].measureQuantity; j++) {
  1416. // // this.selectedList[i].sampleCode = await this.getSampleCode();
  1417. // this.sampleList.push({
  1418. // ...this.selectedList[i],
  1419. // sampleCode: await this.getSampleCode(),
  1420. // measureQuantity: 1,
  1421. // weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
  1422. // });
  1423. // }
  1424. // }
  1425. // } else {
  1426. // for (let i = 0; i < this.selectedList.length; i++) {
  1427. // let forNum = 0;
  1428. // if (this.formData.portion != null && this.formData.portion != '') {
  1429. // forNum = this.formData.portion;
  1430. // } else {
  1431. // forNum = this.selectedList[i].measureQuantity;
  1432. // }
  1433. // for (let j = 0; j < forNum; j++) {
  1434. // // this.selectedList[i].sampleCode = await this.getSampleCode();
  1435. // this.sampleList.push({
  1436. // ...this.selectedList[i],
  1437. // sampleCode: await this.getSampleCode(),
  1438. // measureQuantity: 1,
  1439. // weight: this.selectedList[i].weight / this.selectedList[i].measureQuantity
  1440. // });
  1441. // }
  1442. // }
  1443. // }
  1444. // this.formData.portion = this.sampleList.length;
  1445. // this.activeName = '2';
  1446. // this.$message.success('取样成功!');
  1447. // }
  1448. // } else if (val == 2) {
  1449. // this.formData.sampleUnit = dataS[0].measureUnit;
  1450. // this.$refs.table12.clearSelection();
  1451. // //小样
  1452. // if (this.selectedList.length == 0) {
  1453. // this.$message.warning('请先选择样品!');
  1454. // } else {
  1455. // if (this.formData.number == null || this.formData.sampleUnit == '') {
  1456. // this.$message.warning('请先选择取样的数量和单位!');
  1457. // }
  1458. // }
  1459. // }
  1460. },
  1461. handleInputNumber(val) {
  1462. let packingList = this.$refs.table12.getData();
  1463. const maxValue =
  1464. packingList.length > 1
  1465. ? packingList.length
  1466. : packingList[0].measureQuantity;
  1467. if (val > maxValue) {
  1468. this.$message.warning('数量不能大于计量数量!');
  1469. this.formData.number = maxValue;
  1470. return;
  1471. }
  1472. },
  1473. // 整样输入框事件
  1474. handleInput(val) {
  1475. if (val == 0 || val == '' || val == null) {
  1476. this.$refs.table12.clearSelection();
  1477. return;
  1478. }
  1479. let packingList = this.$refs.table12.getData();
  1480. if (!packingList || packingList.length === 0) {
  1481. return;
  1482. }
  1483. // 计算 packingList 中 measureQuantity 字段的总和
  1484. const measureQuantitySum = packingList.reduce((sum, item) => {
  1485. const quantity = Number(item.measureQuantity) || 0;
  1486. return sum + quantity;
  1487. }, 0);
  1488. const portion = Number(this.formData.portion);
  1489. // 清空当前选中
  1490. this.$refs.table12.clearSelection();
  1491. if (this.conditionType == 2) {
  1492. // 取小样
  1493. // 确保 portion 不超过数据列表长度
  1494. const safePortion = Math.min(portion, packingList.length);
  1495. if (this.isCheck) {
  1496. // 是否拆包 false 不拆包
  1497. if (portion > packingList.length) {
  1498. this.$message.warning('取样数量不能大于来源清单数量!');
  1499. this.formData.portion = packingList.length;
  1500. }
  1501. } else {
  1502. const maxQuantity = Number(packingList[0].measureQuantity);
  1503. if (portion > maxQuantity) {
  1504. this.$message.warning('取样数量不能大于计量数量!');
  1505. this.formData.portion = maxQuantity;
  1506. }
  1507. }
  1508. // 选中前 safePortion 行
  1509. packingList.slice(0, safePortion).forEach((row) => {
  1510. this.$refs.table12.toggleRowSelection(row, true);
  1511. });
  1512. } else if (this.conditionType == 1) {
  1513. // 确保 portion 不超过数据列表长度
  1514. const safePortion = Math.min(portion, measureQuantitySum);
  1515. if (portion > measureQuantitySum) {
  1516. this.$message.warning('取样数量不能大于计量数量!');
  1517. this.formData.portion = measureQuantitySum;
  1518. }
  1519. // 选中前 safePortion 行
  1520. packingList.slice(0, safePortion).forEach((row) => {
  1521. this.$refs.table12.toggleRowSelection(row, true);
  1522. });
  1523. }
  1524. },
  1525. async getCategoryInfo(val) {
  1526. console.log(this.baseForm.type, this.baseForm.planSource);
  1527. // this.baseForm.isUnpack = val.categoryWms.isUnpack;
  1528. console.log(val, '产品信息');
  1529. if (this.baseForm.type == 2 && this.baseForm.planSource == '4') {
  1530. if (val.category.id) {
  1531. const res1 = await getProductSteup(val.category.id);
  1532. const index = res1.findIndex(
  1533. (item) => item.taskId == val.category.taskId
  1534. );
  1535. if (index) {
  1536. const res2 = await getProductOrder({
  1537. taskId: res1[index - 1].taskId,
  1538. workOrderId: val.category.id
  1539. });
  1540. if (res2[0].semiProductList.length > 1) {
  1541. this.baseForm.productNumber = res2[0].semiProductList.length;
  1542. } else {
  1543. this.baseForm.productNumber =
  1544. res2[0].semiProductList.measureQuantity;
  1545. }
  1546. }
  1547. this.isConsumable = val.category.isConsumable;
  1548. this.netWeight = val.category.netWeight;
  1549. this.productItem = val.category;
  1550. console.log('+++++++++');
  1551. this.handleSampleList();
  1552. return;
  1553. }
  1554. }
  1555. console.log('+++++++++9');
  1556. this.isConsumable = val.category.isConsumable;
  1557. this.netWeight = val.category.netWeight;
  1558. this.productItem = val.category; //产品信息
  1559. },
  1560. changeSamUnit(val) {
  1561. this.$refs.baseInfoRefs.getsampleMeasureUnit(val);
  1562. },
  1563. //整样确认按钮-样品列表右上角确认按钮
  1564. // handleExtractFull() {
  1565. // this.$refs.ruleForm.validate((valid) => {
  1566. // if (valid) {
  1567. // if (!this.selectedList || this.selectedList.length == 0) {
  1568. // this.$message.warning('请先选择样品!');
  1569. // return;
  1570. // }
  1571. // this.sampleList = []
  1572. // //取样条数
  1573. // let safePortion = Number(this.formData.portion);
  1574. // //计量数量
  1575. // let measureQ = this.formData.number || 1;
  1576. // //计量单位
  1577. // let unit = this.formData.sampleUnit;
  1578. // //抽检计量整样小样或者抽检计重小样
  1579. // if ((this.baseForm.inspectionStandards === 1) || (this.baseForm.inspectionStandards === 2 && this.conditionType == 2)) {
  1580. // if (this.conditionType == 2) {
  1581. // if (measureQ <= 0) {
  1582. // this.$message.info('取样计量数量必须大于0');
  1583. // return
  1584. // }
  1585. // }
  1586. // // 计算总计量数量
  1587. // const totalQuantity = this.selectedList.reduce((sum, item) => sum + item['measureQuantity'], 0);
  1588. // // 验证取样总量不超过总计量数量,只有计量单位相同才进行验证
  1589. // if (this.selectedList[0].measureUnit == unit || this.conditionType == 1) {
  1590. // if (measureQ * safePortion > totalQuantity) {
  1591. // this.$message.info('取样计量数量不能大于总计量数量');
  1592. // return
  1593. // }
  1594. // // 验证每条数据的计量数量都大于等于取样计量数量
  1595. // for (const item of this.selectedList) {
  1596. // if (item['measureQuantity'] < measureQ) {
  1597. // this.$message.info(`条目计量数量小于取样计量数量`);
  1598. // return
  1599. // }
  1600. // }
  1601. // }
  1602. // if (unit === 'KG') {
  1603. // let totalMaxPossible = 0;
  1604. // this.selectedList.map(item => {
  1605. // const maxPossible = item['measureQuantity'] / measureQ;
  1606. // totalMaxPossible += maxPossible;});
  1607. // if (totalMaxPossible < safePortion) {
  1608. // this.formData.portion = totalMaxPossible;
  1609. // return this.$message.info(`最大取样条数为${totalMaxPossible}`);
  1610. // }
  1611. // // 计算总重量
  1612. // let totalWeight = this.selectedList.reduce((sum, item) => sum + item['weight'], 0);
  1613. // let weightUnit = this.selectedList[0].weightUnit;
  1614. // if (weightUnit === 'G') {
  1615. // totalWeight = totalWeight / 1000
  1616. // }
  1617. // if (measureQ * safePortion > totalWeight) {
  1618. // this.$message.info('取样计量重量不能大于总计量重量');
  1619. // return
  1620. // }
  1621. // for (const item of this.selectedList) {
  1622. // let weight = weightUnit === 'G' ? item.weight / 1000 : item.weight
  1623. // if (weight < measureQ) {
  1624. // this.$message.info(`勾选条目重量小于取样重量`);
  1625. // return
  1626. // }
  1627. // }
  1628. // }
  1629. // this.getNewFullSampleList(Math.ceil(safePortion), measureQ, unit);
  1630. // //抽检计重整样
  1631. // } else if (this.baseForm.inspectionStandards === 2 && this.conditionType == 1) {
  1632. // for (const item of this.selectedList) {
  1633. // if (item['measureQuantity'] < safePortion) {
  1634. // this.$message.info(`所选的条目计量数量小于取样计量数量`);
  1635. // return
  1636. // }
  1637. // }
  1638. // let list = [];
  1639. // for (let i = 0; i < this.selectedList.length; i++) {
  1640. // list.push({
  1641. // ...this.selectedList[i],
  1642. // measureQuantity: safePortion, //作为计量数量
  1643. // });
  1644. // }
  1645. // this.updatePackingList(list);
  1646. // }
  1647. // this.activeName = '2'
  1648. // }
  1649. // });
  1650. // },
  1651. //从来源数组取样到目标数组
  1652. async getNewFullSampleList(sampleCount, sampleQuantity, sampleUnit) {
  1653. console.log('从来源数组取样到目标数组');
  1654. const sourceArray = this.selectedList;
  1655. // 检查单位是否匹配
  1656. const isUnitMismatch =
  1657. sourceArray.length > 0 && sourceArray[0].measureUnit !== sampleUnit;
  1658. // 创建副本并计算初始可取样数量
  1659. const items = sourceArray.map((item) => ({
  1660. ...item,
  1661. remainingQuantity: isUnitMismatch
  1662. ? Infinity
  1663. : item['measureQuantity'], // 剩余可取样数量
  1664. maxPossible: item['measureQuantity'] / sampleQuantity // 最大取样次数
  1665. }));
  1666. const result = [];
  1667. let remainingCount = sampleCount;
  1668. // 尽可能均匀地从各条目取样
  1669. while (remainingCount > 0) {
  1670. // 按剩余可取样比例排序
  1671. items.sort(
  1672. (a, b) =>
  1673. b.remainingQuantity / b['measureQuantity'] -
  1674. a.remainingQuantity / a['measureQuantity']
  1675. );
  1676. let distributed = false;
  1677. for (const item of items) {
  1678. if (
  1679. (!isUnitMismatch && remainingCount > 0) ||
  1680. (item.remainingQuantity >= sampleQuantity && remainingCount > 0)
  1681. ) {
  1682. // 添加到结果数组
  1683. this.samplePagination.total = 0;
  1684. let sampleCode = await this.getSampleCode();
  1685. if (
  1686. this.conditionType == 1 &&
  1687. this.baseForm.inspectionStandards == 1
  1688. ) {
  1689. result.push({ ...item, measureQuantity: 1, sampleCode });
  1690. } else if (
  1691. this.conditionType == 2 &&
  1692. (this.baseForm.inspectionStandards == 1 ||
  1693. this.baseForm.inspectionStandards == 2)
  1694. ) {
  1695. let weight = (item.weight / item.maxPossible).toFixed(2);
  1696. result.push({
  1697. ...item,
  1698. measureQuantity: sampleQuantity,
  1699. measureUnit: sampleUnit,
  1700. sampleCode,
  1701. weight
  1702. });
  1703. }
  1704. // 更新剩余数量
  1705. if (!isUnitMismatch) {
  1706. item.remainingQuantity -= sampleQuantity;
  1707. }
  1708. remainingCount--;
  1709. distributed = true;
  1710. }
  1711. }
  1712. // 如果没有分配任何取样
  1713. if (!distributed) {
  1714. break;
  1715. }
  1716. }
  1717. console.log('样品清单', this.sampleList);
  1718. this.sampleList = result;
  1719. this.samplePagination.total = result.length;
  1720. this.baseForm.sampleNumber = this.sampleList.length; // 更新样品数量
  1721. this.changeSamUnit(sampleUnit);
  1722. },
  1723. //抽样确认按钮事件-样品列表右上角确认按钮
  1724. handleSampleSubmit() {
  1725. this.$refs.ruleForm.validate((valid) => {
  1726. if (valid) {
  1727. this.sampleList = [];
  1728. this.baseForm.sampleMeasureUnit = this.formData.sampleUnit;
  1729. let measureQ = this.formData.number;
  1730. let unit = this.formData.sampleUnit;
  1731. let nums = Number(this.formData.portion);
  1732. console.log(measureQ, unit, nums, 'measureQ, unit, nums');
  1733. this.getNewFullSampleList(nums, measureQ, unit);
  1734. // if (this.conditionType == 1) {
  1735. // this.sampleList = this.selectedList
  1736. // } else {
  1737. // let measureQ = this.formData.number;
  1738. // let unit = this.formData.sampleUnit;
  1739. // let nums = Number(this.formData.portion);
  1740. //
  1741. // console.log(measureQ, unit, nums, 'measureQ, unit, nums')
  1742. // this.getNewSampleList(measureQ, unit, nums)
  1743. // }
  1744. this.activeName = '2';
  1745. }
  1746. });
  1747. },
  1748. //更新计量数量、单位后重新生成样品列表数据
  1749. // async getNewSampleList(measureQ, unit, nums) {
  1750. // this.sampleList = [];
  1751. // if (!this.selectedList || this.selectedList.length == 0) {
  1752. // this.$message.warning('请先选择样品!');
  1753. // return;
  1754. // }
  1755. // if (!this.isCheck) {
  1756. // let measureQuantity = 1;
  1757. // if (this.conditionType == 2) {
  1758. // measureQuantity = this.formData.number;
  1759. // }
  1760. // for (let i = 0; i < nums; i++) {
  1761. // this.sampleList.push({
  1762. // ...this.selectedList[0],
  1763. // sampleCode: await this.getSampleCode(),
  1764. // measureQuantity: measureQuantity,
  1765. // measureUnit: unit,
  1766. // weight: this.netWeight || 0
  1767. // });
  1768. // }
  1769. // } else {
  1770. // if (this.conditionType == 1) {
  1771. // measureQ = 1;
  1772. // }
  1773. // for (let i = 0; i < this.selectedList.length; i++) {
  1774. // this.sampleList.push({
  1775. // ...this.selectedList[i],
  1776. // sampleCode: await this.getSampleCode(),
  1777. // measureQuantity: measureQ,
  1778. // measureUnit: unit,
  1779. // weight: this.netWeight || 0
  1780. // });
  1781. // }
  1782. // }
  1783. // },
  1784. //监听类型变化
  1785. resetTable() {
  1786. this.$nextTick(() => {
  1787. this.table1();
  1788. this.table2();
  1789. });
  1790. },
  1791. table1() {
  1792. this.$refs.table12.setData([]);
  1793. this.schemeList = [];
  1794. },
  1795. table2() {
  1796. this.$nextTick(() => {
  1797. // if (this.btnType == 'edit' && !this.isOnce) {
  1798. // this.isOrder = false;
  1799. this.sampleList = [];
  1800. // }
  1801. });
  1802. },
  1803. resetForm() {
  1804. this.baseForm = { ...this.defaultForm() };
  1805. },
  1806. handleClose() {
  1807. this.$nextTick(() => {
  1808. // 关闭后,销毁所有的表单数据
  1809. this.resetForm();
  1810. this.resetTable();
  1811. this.isScheme = true;
  1812. this.isOrder = true;
  1813. this.packingList = [];
  1814. this.sampleList = [];
  1815. this.samplePagination = {
  1816. currentPage: 1,
  1817. pageSize: 10,
  1818. total: 0
  1819. };
  1820. (this.schemeList = []),
  1821. (this.schemePagination = {
  1822. currentPage: 1,
  1823. pageSize: 10,
  1824. total: 0
  1825. });
  1826. // 表单验证规则
  1827. this.visible = false;
  1828. this.btnType = null;
  1829. this.title = null;
  1830. this.loading = false;
  1831. this.listPage = [];
  1832. this.activeName = '1';
  1833. this.selectedList = [];
  1834. this.isCheck = false; // 是否拆包 false 不拆包 true 拆包
  1835. this.rowIds = '';
  1836. (this.formData = {
  1837. number: 1,
  1838. sampleUnit: '',
  1839. portion: null
  1840. }),
  1841. (this.rules = {
  1842. number: [
  1843. {
  1844. required: true,
  1845. message: '请输入',
  1846. trigger: 'blur'
  1847. }
  1848. ],
  1849. sampleUnit: [
  1850. {
  1851. required: true,
  1852. message: '请选择样品单位',
  1853. trigger: 'change'
  1854. }
  1855. ],
  1856. portion: [
  1857. {
  1858. required: true,
  1859. message: '请输入',
  1860. trigger: 'blur'
  1861. }
  1862. ]
  1863. });
  1864. this.isConsumable = ''; //0 单件 1批量
  1865. this.netWeight = ''; // 净重
  1866. this.conditionType = null;
  1867. this.isFormNumber = true;
  1868. this.sampleListCode = '';
  1869. this.productItem = {}; //产品信息
  1870. this.$refs['baseInfoRefs'] &&
  1871. this.$refs['baseInfoRefs'].$refs.form1.resetFields();
  1872. this.visible = false;
  1873. this.baseForm.groupId = '';
  1874. this.baseForm.qualityMode = '';
  1875. this.baseForm = { ...this.defaultForm() };
  1876. this.isChangeNumber = true;
  1877. this.isChangeType = true;
  1878. this.isOnce = true;
  1879. });
  1880. },
  1881. /* 保存编辑 */
  1882. handleSave() {
  1883. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  1884. if (!valid) {
  1885. return false;
  1886. }
  1887. this.loading = true;
  1888. if (this.baseForm.isUnpack == null || this.baseForm.isUnpack == '') {
  1889. this.baseForm.isUnpack = this.isCheck ? 1 : 2;
  1890. }
  1891. this.baseForm.conditionType = this.conditionType;
  1892. let params = {
  1893. ...this.baseForm,
  1894. qualityInventoryList: this.$refs.table12.getData(),
  1895. sampleList: this.sampleList,
  1896. planTemplateList: this.schemeList
  1897. };
  1898. console.log(params, 'params');
  1899. if (this.btnType == 'issued' && this.schemeList.length < 1) {
  1900. this.$message.warning('质检方案不能为空!');
  1901. this.loading = false;
  1902. return;
  1903. }
  1904. let URL =
  1905. this.btnType == 'add' ? save : this.btnType == 'edit' ? update : '';
  1906. console.log(params, 'params');
  1907. URL(params)
  1908. .then((msg) => {
  1909. this.loading = false;
  1910. this.$message.success(msg);
  1911. this.handleClose();
  1912. this.$emit('done');
  1913. })
  1914. .catch((e) => {
  1915. this.loading = false;
  1916. });
  1917. });
  1918. },
  1919. handleIssued() {
  1920. if (this.sampleList.length == 0) {
  1921. this.$message.warning('样品清单为空!先进行修改操作再下发!');
  1922. return;
  1923. }
  1924. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  1925. if (!valid) {
  1926. return false;
  1927. }
  1928. this.loading = true;
  1929. if (this.baseForm.isUnpack == null || this.baseForm.isUnpack == '') {
  1930. this.baseForm.isUnpack = this.isCheck ? 1 : 2;
  1931. }
  1932. this.baseForm.conditionType = this.conditionType;
  1933. let params = {
  1934. ...this.baseForm,
  1935. qualityInventoryList: this.$refs.table12.getData(),
  1936. sampleList: this.sampleList,
  1937. planTemplateList: this.schemeList
  1938. };
  1939. console.log(params, 'params');
  1940. if (this.btnType == 'issued' && this.schemeList.length < 1) {
  1941. this.$message.warning('质检方案不能为空!');
  1942. this.loading = false;
  1943. return;
  1944. }
  1945. planIssued(params)
  1946. .then((msg) => {
  1947. this.loading = false;
  1948. this.$message.success(msg);
  1949. this.handleClose();
  1950. this.$emit('done');
  1951. })
  1952. .catch((e) => {
  1953. this.loading = false;
  1954. });
  1955. });
  1956. },
  1957. // 样品列表分页方法
  1958. async handleSampleSizeChange(val) {
  1959. this.samplePagination.pageSize = val;
  1960. this.samplePagination.currentPage = 1;
  1961. if (this.rowIds && this.isOrder) {
  1962. await this.getSampleList(this.rowIds);
  1963. }
  1964. //操作行点击时查询样品
  1965. },
  1966. async handleSampleCurrentChange(val) {
  1967. this.samplePagination.currentPage = val;
  1968. if (this.rowIds && this.isOrder) {
  1969. await this.getSampleList(this.rowIds);
  1970. }
  1971. },
  1972. // 质检方案分页方法
  1973. async handleSchemeSizeChange(val) {
  1974. this.schemePagination.pageSize = val;
  1975. this.schemePagination.currentPage = 1;
  1976. //操作行点击时查询质检
  1977. if (this.rowIds && this.isScheme) {
  1978. await this.getTemplateList(this.rowIds);
  1979. }
  1980. },
  1981. async handleSchemeCurrentChange(val) {
  1982. this.schemePagination.currentPage = val;
  1983. //操作行点击时查询质检
  1984. if (this.rowIds && this.isScheme) {
  1985. await this.getTemplateList(this.rowIds);
  1986. }
  1987. },
  1988. //检验方式改变时,重新获取样品列表
  1989. changeModel(val) {
  1990. this.baseForm.qualityMode = val;
  1991. if (this.btnType != 'issued') {
  1992. this.baseForm.sampleNumber = '';
  1993. }
  1994. console.log(
  1995. this.baseForm.productNumber,
  1996. 'productNumberproductNumber数量'
  1997. );
  1998. if (this.baseForm.qualityMode == 1) {
  1999. console.log('+++++++++1');
  2000. this.handleSampleList();
  2001. } else {
  2002. this.sampleList = [];
  2003. }
  2004. },
  2005. //确定按钮
  2006. handleExtractFull() {
  2007. this.$refs.ruleForm.validate(async (valid) => {
  2008. if (!valid || !this.validateSelection()) return;
  2009. this.baseForm.sampleMeasureUnit = this.formData.sampleUnit;
  2010. this.sampleList = [];
  2011. const sampleCount = Number(this.formData.portion);
  2012. const measureQ = this.formData.number || 1;
  2013. const unit = this.formData.sampleUnit;
  2014. console.log(this.conditionType, this.baseForm.inspectionStandards);
  2015. try {
  2016. if (this.isStandard1OrWeightSample()) {
  2017. //抽检计量整样小样或者抽检计重小样
  2018. if (!this.validateMeasureQuantity(measureQ, unit, sampleCount))
  2019. return;
  2020. if (unit === 'KG' && !this.validateWeight(measureQ, sampleCount))
  2021. return; // 若计量单位为重量,还需验证总重量是否足够
  2022. console.log('getNewFullSampleList');
  2023. await this.getNewFullSampleList(
  2024. Math.ceil(sampleCount),
  2025. measureQ,
  2026. unit
  2027. );
  2028. } else if (this.isWeightStandardFullSample()) {
  2029. console.log('handleWeightFullSample');
  2030. //抽检取计重取整样
  2031. if (!this.validateSampleCount(sampleCount)) return;
  2032. await this.handleWeightFullSample(sampleCount);
  2033. }
  2034. this.activeName = '2';
  2035. } catch (error) {
  2036. console.error('取样处理失败:', error);
  2037. this.$message.error('取样处理失败');
  2038. }
  2039. });
  2040. },
  2041. validateSelection() {
  2042. if (!this.selectedList?.length) {
  2043. this.$message.warning('请先选择样品!');
  2044. return false;
  2045. }
  2046. return true;
  2047. },
  2048. isStandard1OrWeightSample() {
  2049. return (
  2050. this.baseForm.inspectionStandards === 1 ||
  2051. (this.baseForm.inspectionStandards === 2 && this.conditionType == 2)
  2052. // this.baseForm.inspectionStandards === 1 ||
  2053. // (this.baseForm.inspectionStandards === 2 &&
  2054. // this.conditionType == 2) ||
  2055. // (this.baseForm.inspectionStandards === 2 && this.conditionType == 2)
  2056. );
  2057. },
  2058. isWeightStandardFullSample() {
  2059. return (
  2060. this.baseForm.inspectionStandards === 2 && this.conditionType == 1
  2061. );
  2062. },
  2063. validateMeasureQuantity(measureQ, unit, sampleCount) {
  2064. if (this.conditionType == 2 && measureQ <= 0) {
  2065. this.$message.info('取样计量数量必须大于0');
  2066. return false;
  2067. }
  2068. const totalQuantity = this.selectedList.reduce(
  2069. (sum, item) => sum + item.measureQuantity,
  2070. 0
  2071. );
  2072. if (
  2073. (this.selectedList[0].measureUnit === unit ||
  2074. this.conditionType == 1) &&
  2075. measureQ * sampleCount > totalQuantity
  2076. ) {
  2077. this.$message.info('取样计量数量不能大于总计量数量');
  2078. return false;
  2079. }
  2080. const invalidItem = this.selectedList.find(
  2081. (item) => item.measureQuantity < measureQ
  2082. );
  2083. if (invalidItem) {
  2084. this.$message.info('条目计量数量小于取样计量数量');
  2085. return false;
  2086. }
  2087. return true;
  2088. },
  2089. validateWeight(measureQ, sampleCount) {
  2090. let totalMaxPossible = 0;
  2091. this.selectedList.forEach((item) => {
  2092. totalMaxPossible += item.measureQuantity / measureQ;
  2093. });
  2094. if (totalMaxPossible < sampleCount) {
  2095. this.formData.portion = totalMaxPossible;
  2096. this.$message.info(`最大取样条数为${totalMaxPossible}`);
  2097. return false;
  2098. }
  2099. let totalWeight = this.selectedList.reduce(
  2100. (sum, item) => sum + item.weight,
  2101. 0
  2102. );
  2103. const weightUnit = this.selectedList[0].weightUnit;
  2104. if (weightUnit === 'G') totalWeight /= 1000;
  2105. console.log(measureQ * sampleCount, totalWeight);
  2106. if (measureQ * sampleCount > totalWeight) {
  2107. this.$message.info('取样计量重量不能大于总计量重量');
  2108. return false;
  2109. }
  2110. const invalidItem = this.selectedList.find((item) => {
  2111. const weight =
  2112. item.weightUnit === 'G' ? item.weight / 1000 : item.weight;
  2113. return weight < measureQ;
  2114. });
  2115. if (invalidItem) {
  2116. this.$message.info('勾选条目重量小于取样重量');
  2117. return false;
  2118. }
  2119. return true;
  2120. },
  2121. validateSampleCount(sampleCount) {
  2122. const invalidItem = this.selectedList.find(
  2123. (item) => item.measureQuantity < sampleCount
  2124. );
  2125. if (invalidItem) {
  2126. this.$message.info('所选的条目计量数量小于取样计量数量');
  2127. return false;
  2128. }
  2129. return true;
  2130. },
  2131. async handleWeightFullSample(sampleCount) {
  2132. const list = this.selectedList.map((item) => ({
  2133. ...item,
  2134. measureQuantity: sampleCount
  2135. }));
  2136. await this.updatePackingList(list);
  2137. }
  2138. }
  2139. };
  2140. </script>
  2141. <style lang="scss" scoped>
  2142. .location-warp {
  2143. display: flex;
  2144. .detail {
  2145. margin-left: 10px;
  2146. }
  2147. }
  2148. :deep(.el-form-item__content .el-input-group__prepend) {
  2149. background-color: #fff;
  2150. }
  2151. :deep(
  2152. .el-dialog:not(.ele-dialog-form)
  2153. .el-dialog__body
  2154. .el-form
  2155. .el-form-item:last-child
  2156. ) {
  2157. margin-bottom: 22px;
  2158. }
  2159. .add-product {
  2160. width: 100%;
  2161. display: flex;
  2162. align-items: center;
  2163. justify-content: flex-end;
  2164. font-size: 30px;
  2165. color: #1890ff;
  2166. margin: 10px 0;
  2167. cursor: pointer;
  2168. }
  2169. .el-pagination {
  2170. padding: 12px 16px;
  2171. background: #fff;
  2172. border: 1px solid#ebeef5;
  2173. border-top: none;
  2174. }
  2175. .flex {
  2176. display: flex;
  2177. align-items: center;
  2178. }
  2179. </style>