new-edit.vue 84 KB

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