edit.vue 73 KB

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