new-edit.vue 86 KB

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