edit.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. <!-- 用户编辑弹窗 -->
  2. <template>
  3. <ele-modal :title="title" :visible.sync="visible" :before-close="handleClose" :close-on-click-modal="false"
  4. :close-on-press-escape="false" append-to-body width="80%" :maxable="true">
  5. <header-title title="基本信息"></header-title>
  6. <base-info ref="baseInfoRefs" v-if="baseForm" :form="baseForm" :btnType="btnType" @resetTable="resetTable"
  7. @changeModel="changeModel" @getList="getList" @table2="table2" :packingLists="packingList"
  8. @getCategoryInfo="getCategoryInfo"></base-info>
  9. <el-row>
  10. <header-title title="质检内容"></header-title>
  11. <el-tabs v-model="activeName" @tab-click="handleClick">
  12. <el-tab-pane label="来源清单" name="1">
  13. <!-- 来料列表表格 -->
  14. <ele-pro-table ref="table12" :columns="tableColumns" :datasource="datasource"
  15. @selection-change="handleSelectionChange" :initLoad="false">
  16. <template v-slot:toolbar v-if="this.baseForm.qualityMode == 2 && btnType != 'detail'">
  17. <el-dropdown trigger="click" @command="handleSampleNumber">
  18. <el-link type="primary" icon="el-icon-plus">取样</el-link>
  19. <el-dropdown-menu slot="dropdown">
  20. <el-dropdown-item command="1">取整样</el-dropdown-item>
  21. <el-dropdown-item command="2">取小样</el-dropdown-item>
  22. </el-dropdown-menu>
  23. </el-dropdown>
  24. </template>
  25. <template v-slot:toolkit v-if="this.baseForm.qualityMode == 2 && conditionType == 2">
  26. <el-row>
  27. <el-form ref="ruleForm" :model="formData" label-width="60px" size="mini" :rules="rules" class="flex"
  28. :show-message="false">
  29. <el-col :span="6">
  30. <el-form-item prop="number" label-width="0" style="margin-bottom: 0;">
  31. <el-input v-model="formData.number" placeholder="请输入" size="mini"
  32. @change="handleInputNumber"></el-input>
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="6">
  36. <el-form-item prop="sampleUnit" label-width="0" style="margin: 0;">
  37. <DictSelection dictName="计量单位" clearable v-model="formData.sampleUnit" size="mini"
  38. @change="changeSamUnit">
  39. </DictSelection>
  40. </el-form-item>
  41. </el-col>
  42. <el-col :span="8">
  43. <el-form-item prop="portion" label="数量" style="margin: 0;">
  44. <el-input v-model="formData.portion" placeholder="请输入" size="mini" @change="handleInput"
  45. :disabled="conditionType == 1"></el-input>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="4" style="text-align: right;">
  49. <el-button type="primary" size="mini" @click="handleSampleSubmit"
  50. style="margin-right: 12px;">确认</el-button>
  51. </el-col>
  52. </el-form>
  53. </el-row>
  54. </template>
  55. </ele-pro-table>
  56. </el-tab-pane>
  57. <el-tab-pane label="样品清单" name="2">
  58. <el-table v-show="activeName === '2'" v-if="sampleList.length > 0" ref="showSampleListTable"
  59. :data="paginatedSampleList" tooltip-effect="dark" :max-height="300" border row-key="id">
  60. <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
  61. <template v-for="column in tableColumns2">
  62. <el-table-column :label="column.label" :prop="column.prop" :show-overflow-tooltip="true"
  63. :width="column.width" :align="column.align"></el-table-column>
  64. </template>
  65. </el-table>
  66. <el-pagination v-show="activeName === '2' && sampleList.length > 0" @size-change="handleSampleSizeChange"
  67. @current-change="handleSampleCurrentChange" :current-page="samplePagination.currentPage"
  68. :page-sizes="[10, 20, 50, 100]" :page-size="samplePagination.pageSize"
  69. layout="total, sizes, prev, pager, next, jumper" :total="sampleList.length"
  70. style="margin-top: 10px"></el-pagination>
  71. </el-tab-pane>
  72. <el-tab-pane label="质检方案" name="3">
  73. <el-table v-show="activeName === '3'" v-if="schemeList.length > 0" ref="showSchemeListTable"
  74. :data="paginatedSchemeList" tooltip-effect="dark" :max-height="300" border row-key="id">
  75. <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
  76. <el-table-column label="质检方案编码" prop="qualitySchemeTemplateCode" align="center">
  77. </el-table-column>
  78. <el-table-column label="质检方案名称" prop="qualitySchemeTemplateName" align="center"></el-table-column>
  79. <el-table-column label="质检类型" prop="categoryLevelClassName" align="center"></el-table-column>
  80. <el-table-column label="质检项编码" prop="inspectionCode" align="center"></el-table-column>
  81. <el-table-column label="质检项名称" prop="inspectionName" align="center"></el-table-column>
  82. <el-table-column label="工艺参数" prop="defaultValue" align="center">
  83. </el-table-column>
  84. </el-table>
  85. <el-pagination v-show="activeName === '3' && schemeList.length > 0" @size-change="handleSchemeSizeChange"
  86. @current-change="handleSchemeCurrentChange" :current-page="schemePagination.currentPage"
  87. :page-sizes="[10, 20, 50, 100]" :page-size="schemePagination.pageSize"
  88. layout="total, sizes, prev, pager, next, jumper" :total="schemeList.length"
  89. style="margin-top: 10px"></el-pagination>
  90. </el-tab-pane>
  91. </el-tabs>
  92. </el-row>
  93. <template v-slot:footer>
  94. <el-button @click="handleClose">取消</el-button>
  95. <el-button v-if="btnType != 'detail' && btnType != 'issued'" type="primary" :loading="loading"
  96. @click="handleSave">
  97. 保存
  98. </el-button>
  99. <el-button v-if="btnType != 'detail'" type="primary" :loading="loading" @click="handleIssued">
  100. 下发
  101. </el-button>
  102. </template>
  103. </ele-modal>
  104. </template>
  105. <script>
  106. import baseInfo from './baseInfo.vue';
  107. import { getCode } from '@/api/login';
  108. import { save, update, planIssued } from '@/api/inspectionPlan';
  109. import {
  110. getQualityTemplateList,
  111. getTemplateListByPlanId,
  112. getSampleListByPlanId,
  113. getInventoryListByPlanId,
  114. outInRecordsPage,
  115. getBatchInfoData
  116. } from '@/api/inspectionPlan/index.js';
  117. export default {
  118. components: {
  119. baseInfo
  120. },
  121. data() {
  122. const defaultForm = function () {
  123. return {
  124. id: '',
  125. code: '',
  126. name: '',
  127. type: '',
  128. qualityMode: '',
  129. inspectionStandards: '',
  130. autoOrder: '',
  131. groupId: '',
  132. groupName: '',
  133. executeId: '',
  134. executeName: '',
  135. planStartTime: '',
  136. planEndTime: '',
  137. standard: '',
  138. planSource: '',
  139. planSourceCode: '',
  140. productName: '',
  141. productCode: '',
  142. batchNo: '',
  143. specification: '',
  144. modelType: '',
  145. brandNo: '',
  146. productNumber: '',
  147. qualifiedNumber: '',
  148. unqualifiedNumber: '',
  149. qualificationRate: '',
  150. totalWeight: '',
  151. sampleNumber: null,
  152. sampleMeasureUnit: '',
  153. sampleProportion: '',
  154. supplierMark: '',
  155. remark: '',
  156. accessory: [],
  157. conditionType: 1,
  158. };
  159. };
  160. return {
  161. defaultForm,
  162. // 表单数据
  163. baseForm: { ...defaultForm() },
  164. tableColumns2: [
  165. {
  166. label: '样品编码',
  167. prop: 'sampleCode',
  168. width: '150',
  169. align: 'center'
  170. },
  171. {
  172. label: '编码',
  173. prop: 'categoryCode',
  174. width: '150',
  175. align: 'center'
  176. },
  177. {
  178. label: '名称',
  179. prop: 'categoryName',
  180. width: '150',
  181. align: 'center'
  182. },
  183. { label: '批次号', prop: 'batchNo', align: 'center', width: 120, },
  184. { label: '发货条码', prop: 'barcodes', align: 'center' },
  185. { label: '包装编码', prop: 'packageNo', align: 'center' },
  186. { label: '计量数量', prop: 'measureQuantity', align: 'center' },
  187. { label: '计量单位', prop: 'measureUnit', align: 'center' },
  188. { label: '物料代号', prop: 'materielDesignation', align: 'center' },
  189. { label: '客户代号', prop: 'clientCode', align: 'center' },
  190. { label: '刻码', prop: 'engrave', align: 'center' },
  191. { prop: 'specification', label: '规格', align: 'center', width: 100, showOverflowTooltip: true },
  192. { prop: 'brandNum', label: '牌号', align: 'center', width: 100, showOverflowTooltip: true },
  193. { prop: 'modelType', label: '型号', align: 'center', width: 100, showOverflowTooltip: true },
  194. { label: '重量', prop: 'weight', align: 'center' },
  195. { label: '重量单位', prop: 'weightUnit', align: 'center' },
  196. { label: '仓库', prop: 'warehouseName', align: 'center' },
  197. { label: '货区', prop: 'areaName', align: 'center' },
  198. { label: '货架', prop: 'goodsShelfName', align: 'center' },
  199. { label: '货位', prop: 'goodsAllocationName', align: 'center' },
  200. { label: '生产日期', prop: 'productionDate', align: 'center' },
  201. { label: '采购日期', prop: 'purchaseDate', align: 'center' }
  202. ],
  203. packingList: [],
  204. sampleList: [],
  205. samplePagination: {
  206. currentPage: 1,
  207. pageSize: 10,
  208. total: 0
  209. },
  210. schemeList: [],
  211. schemePagination: {
  212. currentPage: 1,
  213. pageSize: 10,
  214. total: 0
  215. },
  216. // 表单验证规则
  217. visible: false,
  218. btnType: null,
  219. title: null,
  220. loading: false,
  221. listPage: [],
  222. activeName: '1',
  223. selectedList: [],
  224. isCheck: false,
  225. rowIds: '',
  226. formData: {
  227. number: 1,
  228. sampleUnit: '',
  229. portion: null
  230. },
  231. rules: {
  232. number: [
  233. {
  234. required: true,
  235. message: '请输入',
  236. trigger: 'blur'
  237. },
  238. ],
  239. sampleUnit: [
  240. {
  241. required: true,
  242. message: '请选择样品单位',
  243. trigger: 'change'
  244. }
  245. ],
  246. portion: [
  247. {
  248. required: true,
  249. message: '请输入',
  250. trigger: 'blur'
  251. }
  252. ]
  253. },
  254. isConsumable: '',
  255. conditionType: null,
  256. sampleListCode: ''
  257. };
  258. },
  259. computed: {
  260. tableColumns() {
  261. let arr = [
  262. // (this.btnType !== 'issued' || this.baseForm.qualityMode === 2)
  263. // ? {
  264. // columnKey: 'selection',
  265. // type: 'selection',
  266. // width: 45,
  267. // align: 'center'
  268. // }
  269. // : null,
  270. {
  271. columnKey: 'selection',
  272. type: 'selection',
  273. width: 45,
  274. align: 'center'
  275. },
  276. {
  277. columnKey: 'index',
  278. label: '序号',
  279. type: 'index',
  280. width: 55,
  281. align: 'center',
  282. fixed: 'left'
  283. },
  284. {
  285. label: '编码',
  286. prop: 'categoryCode',
  287. width: 150,
  288. align: 'center',
  289. showOverflowTooltip: true
  290. },
  291. {
  292. label: '名称',
  293. prop: 'categoryName',
  294. width: '150',
  295. align: 'center',
  296. width: 120,
  297. showOverflowTooltip: true
  298. },
  299. { label: '批次号', prop: 'batchNo', align: 'center', width: 120, },
  300. { label: '发货条码', prop: 'barcodes', align: 'center' },
  301. {
  302. label: '包装编码', prop: 'packageNo', align: 'center',
  303. width: 120,
  304. showOverflowTooltip: true
  305. },
  306. { label: '包装数量', prop: 'packingQuantity', align: 'center' },
  307. { label: '包装单位', prop: 'packingUnit', align: 'center' },
  308. { label: '计量数量', prop: 'measureQuantity', align: 'center' },
  309. { label: '计量单位', prop: 'measureUnit', align: 'center' },
  310. { label: '物料代号', prop: 'materielDesignation', align: 'center' },
  311. { label: '客户代号', prop: 'clientCode', align: 'center' },
  312. { label: '供应商名称', prop: 'supplierName', align: 'center', width: 120, showOverflowTooltip: true },
  313. { label: '供应商代号', prop: 'supplierCode', align: 'center', width: '120' },
  314. { label: '刻码', prop: 'engrave', align: 'center' },
  315. { label: '重量', prop: 'weight', align: 'center' },
  316. { label: '重量单位', prop: 'weightUnit', align: 'center' },
  317. {
  318. label: '仓库', prop: 'warehouseName', align: 'center',
  319. width: 120,
  320. showOverflowTooltip: true
  321. },
  322. { label: '货区', prop: 'areaName', align: 'center' },
  323. { label: '货架', prop: 'goodsShelfName', align: 'center' },
  324. { label: '货位', prop: 'goodsAllocationName', align: 'center' },
  325. {
  326. label: '生产日期', prop: 'productionDate', align: 'center',
  327. width: 120,
  328. showOverflowTooltip: true
  329. },
  330. {
  331. label: '采购日期', prop: 'purchaseDate', align: 'center',
  332. width: 120,
  333. showOverflowTooltip: true
  334. }
  335. ]
  336. return arr
  337. },
  338. // 分页后的样品列表
  339. paginatedSampleList() {
  340. const { currentPage, pageSize } = this.samplePagination;
  341. const start = (currentPage - 1) * pageSize;
  342. const end = start + pageSize;
  343. return this.sampleList.slice(start, end);
  344. },
  345. // 分页后的质检方案列表
  346. paginatedSchemeList() {
  347. const { currentPage, pageSize } = this.schemePagination;
  348. const start = (currentPage - 1) * pageSize;
  349. const end = start + pageSize;
  350. return this.schemeList.slice(start, end);
  351. }
  352. },
  353. created() { },
  354. methods: {
  355. async datasource({ page, limit, where }) {
  356. const res = await getInventoryListByPlanId({ ...where, page, limit });
  357. if (res.list.length > 1) {
  358. this.isCheck = true
  359. } else {
  360. this.isCheck = false
  361. }
  362. this.packingList = res.list;
  363. return res.list;
  364. },
  365. // 切换质检内容
  366. handleClick(tab) {
  367. this.activeName = tab.name;
  368. },
  369. async open(type, row) {
  370. this.visible = true;
  371. this.activeName = '1';
  372. this.btnType = type;
  373. this.title = type == 'add' ? '新增' : type == 'edit' ? '编辑' : type == 'issued' ? '下发' : '详情';
  374. if (this.btnType === 'add') {
  375. const code = await getCode('qms_plan_code');
  376. this.baseForm.code = code;
  377. return;
  378. } else {
  379. await this.handleEditOrDetail(row);
  380. }
  381. },
  382. async handleEditOrDetail(row) {
  383. console.log('row====', row);
  384. row.accessory = row.accessory || [];
  385. this.baseForm = {
  386. ...JSON.parse(JSON.stringify(row)),
  387. groupId: row.groupId,
  388. qualityMode: row.qualityMode
  389. };
  390. this.$nextTick(() => {
  391. if (this.$refs.baseInfoRefs) {
  392. // 获取人员
  393. if (this.baseForm.groupId) {
  394. this.$refs.baseInfoRefs.getUserList({
  395. groupId: this.baseForm.groupId
  396. });
  397. }
  398. //根据类型获取计划来源
  399. if (this.baseForm.type) {
  400. this.$refs.baseInfoRefs.typeChange(this.baseForm.type);
  401. }
  402. if (this.baseForm.productId) {
  403. this.$refs.baseInfoRefs.getProductDetails(this.baseForm.productId);
  404. }
  405. }
  406. });
  407. // 如果是编辑或者详情,则查询物料清单、质检方案和样品列表
  408. if (row.id) {
  409. this.rowIds = row.id;
  410. //操作行点击时查询清单
  411. // await this.getInventoryList();
  412. await this.reload({ planId: row.id });
  413. //操作行点击时查询样品
  414. await this.getSampleList(row.id);
  415. //操作行点击时查询质检
  416. await this.getTemplateList(row.id);
  417. }
  418. },
  419. reload(where) {
  420. this.$nextTick(() => {
  421. if (this.$refs.table12 && this.$refs.table12.reload)
  422. this.$refs.table12.reload({ page: 1, where: where });
  423. })
  424. },
  425. async getSampleList(id) {
  426. let res = await getSampleListByPlanId({
  427. planId: id
  428. });
  429. console.log(res.list, 'yyyyyyyyyyyyyy样品----------------------------');
  430. this.sampleList = res?.list || [];
  431. this.samplePagination.currentPage = 1;
  432. this.samplePagination.total = this.sampleList.length;
  433. },
  434. async getTemplateList(id) {
  435. let res = await getTemplateListByPlanId({
  436. planId: id
  437. });
  438. console.log(res.list, 'fffffffffffffff方案--------------------------');
  439. this.schemeList = res?.list || [];
  440. this.schemePagination.currentPage = 1;
  441. this.schemePagination.total = this.schemeList.length;
  442. },
  443. async getList(receiveNo, productCode, productCategoryId, productCategoryName, categoryid, batchNo, supplierName, supplierMark) {
  444. //通过来源和产品 获取来料清单
  445. await this.getGoodsList(receiveNo, productCode, null, productCategoryId, productCategoryName, categoryid, batchNo, supplierName, supplierMark);
  446. //通过来源和产品 获取质检方案
  447. await this.getQualityTemplate(productCode);
  448. },
  449. async getGoodsList(receiveNo, productCode, ids, productCategoryId, productCategoryName, categoryid, batchNo, supplierName, supplierMark) {
  450. this.$refs.table12.setData([])
  451. let res;
  452. const res1 = await outInRecordsPage({
  453. sourceBizNo: receiveNo,
  454. categoryCode: productCode,
  455. categoryId: categoryid,
  456. qualityQlanId: ids,
  457. size: -1
  458. });
  459. console.log(res1, 'res1')
  460. if (res1.list.length > 0) {
  461. console.log(res1.list[0].status, 'status=2 不赋值')
  462. if (res1.list[0].status != 2) {
  463. res = res1.list
  464. this.isCheck = true;
  465. console.log('this.isCheck=true', this.isCheck)
  466. } else {
  467. res = []
  468. this.$message.error('此数据已质检,无需再次质检!');
  469. return
  470. }
  471. } else {
  472. let resData = await getBatchInfoData({
  473. sourceBizNo: receiveNo,
  474. categoryCode: productCode,
  475. batchNo: batchNo,
  476. });
  477. console.log(resData, 'resData')
  478. if (resData) {
  479. if (resData.qualityControl != 2) {
  480. this.isCheck = false;
  481. res = [resData];
  482. console.log('this.isCheck=false')
  483. } else {
  484. res = []
  485. this.$message.error('此数据已质检,无需再次质检!');
  486. return
  487. }
  488. }
  489. }
  490. console.log(res, '来料清单');
  491. if (res.length > 0) {
  492. const _arr1 = res.map((m) => {
  493. m.sourceId = m.id;
  494. m.productCategoryId = productCategoryId;
  495. m.productCategoryName = productCategoryName;
  496. delete m.id;
  497. return { ...m };
  498. });
  499. console.log(_arr1, '1234567890')
  500. this.packingList = _arr1;
  501. this.$refs.table12.setData(_arr1);//赋值
  502. const _arr2 = this.$refs.table12.getData();
  503. if (_arr2.length > 1) {
  504. this.baseForm.productNumber = _arr2.length;
  505. } else {
  506. this.baseForm.productNumber = _arr2[0].measureQuantity;
  507. }
  508. //处理样品清单
  509. await this.handleSampleList();
  510. } else {
  511. this.$refs.table12.setData([]);
  512. }
  513. },
  514. async handleSampleList() {
  515. let packingList = this.$refs.table12.getData();
  516. //全检时
  517. if (this.baseForm.qualityMode == 1) {
  518. this.sampleList = [];
  519. console.log(this.baseForm, '---isUnpack---')
  520. if (this.baseForm.isUnpack != null && this.baseForm.isUnpack != undefined && this.baseForm.isUnpack != '') {
  521. //拆包
  522. if (this.baseForm.isUnpack == 1) {
  523. await this.updatePackingList(packingList);
  524. // await this.handleUnpackCase(packingList);
  525. } else if (this.baseForm.isUnpack == 0) {
  526. await this.updatePackingList(packingList);
  527. }
  528. } else {
  529. console.log(this.isCheck, 'this.isCheck')
  530. if (!this.isCheck) {
  531. await this.updatePackingList(packingList);
  532. // await this.handleUnpackCase(packingList);
  533. } else {
  534. await this.updatePackingList(packingList);
  535. }
  536. }
  537. } else {
  538. this.sampleList = [];
  539. }
  540. },
  541. //拆包处理样品清单数据
  542. async handleUnpackCase(packingList) {
  543. const num = Number(this.baseForm.productNumber || 0);
  544. if (num) {
  545. await this.getUnpackSamList(packingList, num);
  546. }
  547. },
  548. //获取样品编码
  549. async getSampleCode() {
  550. return await getCode('sample_code');
  551. },
  552. async updatePackingList(list) {
  553. for (let i = 0; i < list.length; i++) {
  554. list[i].sampleCode = await this.getSampleCode();
  555. }
  556. this.sampleList = list;
  557. console.log(this.sampleList, 'this.sampleList222')
  558. this.samplePagination.currentPage = 1;
  559. this.samplePagination.total = list.length;
  560. },
  561. async getUnpackSamList(list, num) {
  562. console.log('拆包getUnpackSamList')
  563. let data = [];
  564. list.forEach(oldItem => {
  565. const newMeasureQuantity = oldItem.measureQuantity / this.baseForm.productNumber;
  566. const newWeight = parseFloat((oldItem.weight / this.baseForm.productNumber).toFixed(2))
  567. delete oldItem.id;
  568. for (let i = 0; i < num; i++) {
  569. data.push({
  570. ...oldItem,
  571. measureQuantity: newMeasureQuantity,
  572. weight: newWeight
  573. });
  574. }
  575. });
  576. console.log(data, '样品数据-条数', num)
  577. await this.updatePackingList(data);
  578. },
  579. async getQualityTemplate(productCode, ids) {
  580. await getQualityTemplateList({
  581. productCode: productCode,
  582. qualityQlanId: ids
  583. }).then((res) => {
  584. if (Object.keys(res).length === 0) {
  585. this.$message.error('请确认该物品是否配置质检方案!');
  586. return;
  587. }
  588. this.baseForm.sampleProportion = res.checkProportion;
  589. this.baseForm.inspectionStandards = res?.inspectionStandards;
  590. let combinedList = [];
  591. for (let i = 0; i < res.qualityTemplateVOList.length; i++) {
  592. res.qualityTemplateVOList[i].inspectionItemVOList = res.qualityTemplateVOList[i]?.inspectionItemVOList.map(
  593. (item) => {
  594. item.templateId = res.qualityTemplateVOList[i]?.id;
  595. item.qualitySchemeTemplateCode =
  596. res.qualityTemplateVOList[i]?.qualitySchemeTemplateCode;
  597. item.qualitySchemeTemplateName =
  598. res.qualityTemplateVOList[i]?.qualitySchemeTemplateName;
  599. delete item.id;
  600. return {
  601. ...item
  602. };
  603. }
  604. );
  605. combinedList = combinedList.concat(res.qualityTemplateVOList[i].inspectionItemVOList);
  606. console.log(combinedList, '质检方案');
  607. this.schemeList = combinedList;
  608. this.schemePagination.currentPage = 1;
  609. this.schemePagination.total = this.schemeList.length;
  610. }
  611. });
  612. },
  613. //来料列表表格选择事件
  614. handleSelectionChange(selection) {
  615. console.log(selection, '勾选')
  616. this.selectedList = selection;
  617. this.formData.portion = selection.length;
  618. this.baseForm.sampleNumber = selection.length;
  619. //如果取小样
  620. if (this.conditionType == 2) {
  621. const data1 = this.$refs.table12.getData()
  622. this.$set(this.formData, 'sampleUnit', data1[0]?.measureUnit);
  623. this.$set(this.baseForm, 'sampleMeasureUnit', data1[0]?.measureUnit);
  624. }
  625. },
  626. //取样方式选择
  627. handleSampleNumber(val) {
  628. console.log(val, 'val');
  629. this.conditionType = val;
  630. //清空样品清单列表
  631. this.sampleList = []
  632. const dataS = this.$refs.table12.getData();
  633. //取整样
  634. if (val == 1) {
  635. this.sampleList = dataS;
  636. this.formData.portion = dataS.length;
  637. this.$refs.table12.toggleAllSelection();
  638. this.activeName = '2';
  639. this.$message.success('取样成功!');
  640. } else if (val == 2) {
  641. this.formData.sampleUnit = dataS[0].measureUnit;
  642. this.$refs.table12.clearSelection();
  643. //小样
  644. if (this.selectedList.length == 0) {
  645. this.$message.warning('请先选择样品!');
  646. } else {
  647. if (this.formData.number == null || this.formData.sampleUnit == '') {
  648. this.$message.warning('请先选择取样的数量和单位!');
  649. }
  650. }
  651. }
  652. },
  653. handleInputNumber(val) {
  654. let packingList = this.$refs.table12.getData()
  655. const maxValue = packingList.length > 1 ? packingList.length : packingList[0].measureQuantity;
  656. if (val > maxValue) {
  657. this.$message.warning('数量不能大于计量数量!');
  658. this.formData.number = maxValue;
  659. return;
  660. }
  661. },
  662. handleInput(val) {
  663. if (val == 0 || val == '' || val == null) {
  664. this.$refs.table12.clearSelection();
  665. return
  666. }
  667. let packingList = this.$refs.table12.getData();
  668. if (!packingList || packingList.length === 0) {
  669. return;
  670. }
  671. const portion = Number(this.formData.portion);
  672. if (this.isCheck) {
  673. if (portion > packingList.length) {
  674. this.$message.warning('取样数量不能大于来源清单数量!');
  675. this.formData.portion = packingList.length;
  676. return;
  677. }
  678. packingList.slice(0, this.formData.portion).forEach(row => {
  679. this.$refs.table12.toggleRowSelection(row);
  680. });
  681. } else {
  682. const maxQuantity = Number(packingList[0].measureQuantity);
  683. if (portion > maxQuantity) {
  684. this.$message.warning('取样数量不能大于计量数量!');
  685. this.formData.portion = maxQuantity;
  686. return;
  687. }
  688. }
  689. },
  690. getCategoryInfo(val) {
  691. this.baseForm.isUnpack = val.categoryWms.isUnpack;
  692. this.isConsumable = val.category.isConsumable;
  693. },
  694. changeSamUnit(val) {
  695. this.$refs.baseInfoRefs.getsampleMeasureUnit(val);
  696. },
  697. //抽样确认按钮事件-样品列表右上角确认按钮
  698. handleSampleSubmit() {
  699. this.$refs.ruleForm.validate((valid) => {
  700. if (valid) {
  701. this.sampleList = []
  702. this.baseForm.sampleMeasureUnit = this.formData.sampleUnit
  703. if (this.conditionType == 1) {
  704. this.sampleList = this.selectedList
  705. } else {
  706. let measureQ = this.formData.number;
  707. let unit = this.formData.sampleUnit;
  708. let nums = Number(this.formData.portion);
  709. console.log(measureQ, unit, nums, 'measureQ, unit, nums')
  710. this.getNewSampleList(measureQ, unit, nums)
  711. }
  712. this.activeName = '2'
  713. }
  714. });
  715. },
  716. //更新计量数量、单位后重新生成样品列表数据
  717. getNewSampleList(measureQ, unit, nums) {
  718. this.sampleList = [];
  719. if (!this.selectedList || this.selectedList.length == 0) {
  720. this.$message.warning('请先选择样品!');
  721. return;
  722. }
  723. this.sampleList = this.selectedList.map(oldItem => {
  724. const newItem = JSON.parse(JSON.stringify(oldItem));
  725. newItem.measureQuantity = measureQ;
  726. newItem.measureUnit = unit;
  727. return newItem;
  728. });
  729. },
  730. //监听类型变化
  731. resetTable() {
  732. this.$nextTick(() => {
  733. this.table1();
  734. this.table2();
  735. });
  736. },
  737. table1() {
  738. this.$refs.table12.setData([])
  739. this.schemeList = [];
  740. },
  741. table2() {
  742. this.$nextTick(() => {
  743. this.sampleList = [];
  744. });
  745. },
  746. resetForm() {
  747. this.baseForm = { ...this.defaultForm() };
  748. },
  749. handleClose() {
  750. this.resetForm();
  751. this.resetTable();
  752. this.visible = false;
  753. },
  754. /* 保存编辑 */
  755. handleSave() {
  756. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  757. if (!valid) {
  758. return false;
  759. }
  760. this.loading = true;
  761. if (this.baseForm.isUnpack == null || this.baseForm.isUnpack == '') {
  762. this.baseForm.isUnpack = this.isCheck ? 1 : 2;
  763. }
  764. this.baseForm.conditionType = this.conditionType;
  765. let params = {
  766. ...this.baseForm,
  767. qualityInventoryList: this.$refs.table12.getData(),
  768. sampleList: this.sampleList,
  769. planTemplateList: this.schemeList,
  770. };
  771. console.log(params, 'params');
  772. if (this.btnType == 'issued' && this.schemeList.length < 1) {
  773. this.$message.warning('质检方案不能为空!');
  774. this.loading = false;
  775. return;
  776. }
  777. let URL =
  778. this.btnType == 'add' ? save : this.btnType == 'edit' ? update : '';
  779. console.log(params, 'params')
  780. URL(params)
  781. .then((msg) => {
  782. this.loading = false;
  783. this.$message.success(msg);
  784. this.handleClose();
  785. this.$emit('done');
  786. })
  787. .catch((e) => {
  788. this.loading = false;
  789. });
  790. });
  791. },
  792. handleIssued() {
  793. if (this.sampleList.length == 0) {
  794. this.$message.warning('样品清单为空!先进行修改操作再下发!');
  795. return;
  796. }
  797. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  798. if (!valid) {
  799. return false;
  800. }
  801. this.loading = true;
  802. if (this.baseForm.isUnpack == null || this.baseForm.isUnpack == '') {
  803. this.baseForm.isUnpack = this.isCheck ? 1 : 2;
  804. }
  805. this.baseForm.conditionType = this.conditionType;
  806. let params = {
  807. ...this.baseForm,
  808. qualityInventoryList: this.$refs.table12.getData(),
  809. sampleList: this.sampleList,
  810. planTemplateList: this.schemeList,
  811. };
  812. console.log(params, 'params');
  813. if (this.btnType == 'issued' && this.schemeList.length < 1) {
  814. this.$message.warning('质检方案不能为空!');
  815. this.loading = false;
  816. return;
  817. }
  818. planIssued(params)
  819. .then((msg) => {
  820. this.loading = false;
  821. this.$message.success(msg);
  822. this.handleClose();
  823. this.$emit('done');
  824. })
  825. .catch((e) => {
  826. this.loading = false;
  827. });
  828. });
  829. },
  830. // 样品列表分页方法
  831. handleSampleSizeChange(val) {
  832. this.samplePagination.pageSize = val;
  833. this.samplePagination.currentPage = 1;
  834. },
  835. handleSampleCurrentChange(val) {
  836. this.samplePagination.currentPage = val;
  837. },
  838. // 质检方案分页方法
  839. handleSchemeSizeChange(val) {
  840. this.schemePagination.pageSize = val;
  841. this.schemePagination.currentPage = 1;
  842. },
  843. handleSchemeCurrentChange(val) {
  844. this.schemePagination.currentPage = val;
  845. },
  846. //检验方式改变时,重新获取样品列表
  847. changeModel(val) {
  848. this.baseForm.qualityMode = val;
  849. this.baseForm.sampleNumber = '';
  850. console.log(this.baseForm.productNumber, 'productNumberproductNumber数量')
  851. if (this.baseForm.qualityMode == 1) {
  852. this.handleSampleList();
  853. } else {
  854. this.sampleList = [];
  855. }
  856. },
  857. }
  858. };
  859. </script>
  860. <style lang="scss" scoped>
  861. .location-warp {
  862. display: flex;
  863. .detail {
  864. margin-left: 10px;
  865. }
  866. }
  867. :deep(.el-form-item__content .el-input-group__prepend) {
  868. background-color: #fff;
  869. }
  870. :deep(.el-dialog:not(.ele-dialog-form) .el-dialog__body .el-form .el-form-item:last-child) {
  871. margin-bottom: 22px;
  872. }
  873. .add-product {
  874. width: 100%;
  875. display: flex;
  876. align-items: center;
  877. justify-content: flex-end;
  878. font-size: 30px;
  879. color: #1890ff;
  880. margin: 10px 0;
  881. cursor: pointer;
  882. }
  883. .el-pagination {
  884. padding: 12px 16px;
  885. background: #fff;
  886. border: 1px solid#ebeef5;
  887. border-top: none;
  888. }
  889. .flex {
  890. display: flex;
  891. align-items: center;
  892. }
  893. </style>