edit.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <header-title title="基本信息">
  5. <el-button @click="cancel">返回</el-button>
  6. <el-button type="primary" @click="save" :loading="loading" v-if="type != 'detail'">保存</el-button>
  7. <el-button type="primary" @click="handleReporting" :loading="loading" v-if="type != 'detail'">报工完成</el-button>
  8. </header-title>
  9. <base-info ref="baseInfoRefs" v-if="form" :form="form" :btnType="type" :qualityType1="qualityType"
  10. @changeModel="changeModel" @changeNumber="changeNumber"></base-info>
  11. <quality-content-tabs ref="tabsRef" :type="type" :ids="this.$route.query.id" :sample-list="sampleList"
  12. :scheme-list="schemeList" :loading="loading" :form="form" @selection-change="handleSelectionChange1"
  13. @batch-quality="batchQuality" @handleDetail="handleDetail" @inputWeight="inputWeight"
  14. @handleDispose="handleDispose" @changeSamUnit="changeSamUnit" @handleSample1="handleSample1"
  15. @handleSampleSubmit="handleSampleSubmit" />
  16. </el-card>
  17. <sampleListDialog ref="detailRef" @handleConfirm="handleConfirm" @handleDispose="handleDispose"></sampleListDialog>
  18. <sampleDisposeDialog ref="disposeRef" @handleDisposeConfirm="handleDisposeConfirm"></sampleDisposeDialog>
  19. </div>
  20. </template>
  21. <script>
  22. import baseInfo from './components/baseInfo.vue';
  23. import QualityContentTabs from './components/QualityContentTabs.vue'
  24. import { getCode } from '@/api/login';
  25. import { save, update, getById, exeReportWork, queryQualitySamplContent, queryQualityTempleContent, queryQualityInventory } from '@/api/inspectionWork';
  26. import dictMixins from '@/mixins/dictMixins';
  27. // import term from './term';
  28. import sampleListDialog from './components/sampleListDialog.vue';
  29. import sampleDisposeDialog from './components/sampleDisposeDialog.vue';
  30. import { finishPageTab } from '@/utils/page-tab-util';
  31. export default {
  32. components: {
  33. baseInfo,
  34. QualityContentTabs,
  35. sampleListDialog,
  36. sampleDisposeDialog
  37. },
  38. mixins: [dictMixins],
  39. data() {
  40. const defaultForm = function () {
  41. return {
  42. code: '',
  43. qualityType: null,
  44. qualityModeproduceRoutingId: '',
  45. produceRoutingName: '',
  46. produceTaskId: '',
  47. produceTaskName: '',
  48. productName: '',
  49. productCode: '',
  50. batchNo: '',
  51. specification: '',
  52. modelType: '',
  53. brandNo: '',
  54. total: '',
  55. qualifiedNumber: '',
  56. noQualifiedNumber: '',
  57. groupId: '',
  58. groupName: '',
  59. qualityId: '',
  60. qualityName: '',
  61. qualityTime: '',
  62. hours: '',
  63. qualificationRate: '',
  64. noQualificationRate: '',
  65. totalWeight: '',
  66. sampleNumber: '',
  67. imgUrl: [],
  68. qualityTimeStart: '',
  69. qualityTimeEnd: '',
  70. sampleMeasureUnit: ''
  71. };
  72. };
  73. return {
  74. defaultForm,
  75. // 表单数据
  76. form: { ...defaultForm() },
  77. voList: [],
  78. // 表单验证规则
  79. categoryParamList: [],
  80. type: '',
  81. title: '',
  82. loading: false,
  83. tabTaskId: null,
  84. // activeName: '2',
  85. packingList: [],
  86. sampleList: [],
  87. schemeList: [],
  88. isValid: true,
  89. isStatus: true,
  90. SampleListbyReportList: [],
  91. qualityTimeStart: '',
  92. isReportProcessProduce: false,
  93. };
  94. },
  95. watch: {
  96. '$route.query.id': {
  97. handler(id) {
  98. if (id) {
  99. this.getDetail();
  100. } else {
  101. this.form = { ...defaultForm() };
  102. }
  103. }
  104. },
  105. },
  106. created() {
  107. this.open()
  108. if (this.$route.query.id) {
  109. this.getDetail();
  110. }
  111. },
  112. methods: {
  113. //切换检验方式
  114. changeModel(val, flag) {
  115. this.$refs.tabsRef.tableSelClear()
  116. this.sampleList = [];
  117. this.$refs.tabsRef.tabsChange('1')
  118. this.form.qualityMode = val;
  119. //检验方式 全检
  120. if (this.form.qualityMode == 1) {
  121. this.form.sampleNumber = ''
  122. const sData = this.$refs.tabsRef.$refs.sourceTable.getData()
  123. if (sData.length == 0) {
  124. for (let i = 0; i < sData.length; i++) {
  125. this.$set(sData[i], 'qualityStatus', 2)
  126. }
  127. }
  128. console.log(this.$refs.tabsRef.$refs.sourceTable.getData(), 'packingList')
  129. this.getProSamList(sData)
  130. } else {
  131. if (!flag) {
  132. this.sampleList = [];
  133. }
  134. }
  135. },
  136. //根据类型判断样品清单现实列表数据
  137. getProSamList(list) {
  138. //生产检验
  139. if (this.qualityType == 2) {
  140. if (this.form.qualityMode != null) {
  141. const ProductSampleList = [];
  142. console.log(list, 'list')
  143. list.forEach(oldItem => {
  144. const count = oldItem.measureQuantity;
  145. const newMeasureQuantity = oldItem.measureQuantity / count;
  146. const newWeight = parseFloat((oldItem.weight / count).toFixed(2))
  147. console.log(typeof (oldItem.qualitySampleTemplateList), 'ssssss')
  148. // 遍历新数组设置 qualityResults 默认值
  149. this.schemeList.forEach(item => {
  150. if (typeof item === 'object' && item !== null) {
  151. item.qualityResults = 1; // 设置默认值
  152. }
  153. delete item.id;
  154. });
  155. console.log(oldItem, 'oldItem')
  156. console.log(count, newMeasureQuantity, newWeight)
  157. delete oldItem.id;
  158. if (oldItem.qualitySampleTemplateList == undefined || oldItem.qualitySampleTemplateList == null || oldItem.qualitySampleTemplateList.length == 0) {
  159. oldItem.qualitySampleTemplateList = JSON.parse(JSON.stringify(this.schemeList))
  160. for (let i = 0; i < count; i++) {
  161. ProductSampleList.push({
  162. ...oldItem,
  163. measureQuantity: newMeasureQuantity,
  164. weight: newWeight,
  165. qualitySampleTemplateList: JSON.parse(JSON.stringify(this.schemeList))
  166. });
  167. }
  168. console.log(ProductSampleList, 'ProductSampleList')
  169. this.sampleList = ProductSampleList;
  170. const pNum = ProductSampleList.reduce((sum, item) => {
  171. return sum + Number(item.weight || 0);
  172. }, 0);
  173. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  174. }
  175. });
  176. }
  177. } else {
  178. this.sampleList = list;
  179. }
  180. },
  181. //输入取样数量
  182. changeNumber(val) {
  183. if (this.form.qualityMode !== 2) {
  184. return;
  185. }
  186. if (val <= 0) {
  187. this.$refs.showPackingListTable.clearSelection();
  188. return;
  189. }
  190. if (this.qualityType == 2) {
  191. //生产检验的抽检逻辑
  192. if (val > this.packingList[0].measureQuantity) {
  193. this.$message.warning('取样数量不能大于来源清单的计量数量!');
  194. return;
  195. }
  196. const ProductSampleList = [];
  197. this.packingList.forEach(oldItem => {
  198. const count = oldItem.measureQuantity;
  199. const newMeasureQuantity = oldItem.measureQuantity / count;
  200. const newWeight = parseFloat((oldItem.weight / count).toFixed(2))
  201. console.log(count, newMeasureQuantity, newWeight)
  202. delete oldItem.id;
  203. // 遍历新数组设置 qualityResults 默认值
  204. this.schemeList.forEach(item => {
  205. if (typeof item === 'object' && item !== null) {
  206. item.qualityResults = 1; // 设置默认值
  207. }
  208. delete item.id;
  209. });
  210. for (let i = 0; i < val; i++) {
  211. ProductSampleList.push({
  212. ...oldItem,
  213. measureQuantity: newMeasureQuantity,
  214. weight: newWeight,
  215. qualitySampleTemplateList: JSON.parse(JSON.stringify(this.schemeList))
  216. });
  217. }
  218. });
  219. this.sampleList = ProductSampleList;
  220. const pNum = ProductSampleList.reduce((sum, item) => {
  221. return sum + Number(item.weight || 0);
  222. }, 0);
  223. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  224. } else {
  225. if (val > this.packingList.length) {
  226. this.$message.warning('取样数量不能大于物料明细总数!');
  227. return;
  228. }
  229. const rows = this.packingList.slice(0, val);
  230. rows.forEach((row) => {
  231. this.$refs.showPackingListTable.toggleRowSelection(row);
  232. });
  233. }
  234. },
  235. getNowDate() {
  236. let date = new Date(),
  237. obj = {
  238. year: date.getFullYear(), //获取当前月份(0-11,0代表1月)
  239. month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
  240. strDate: date.getDate(), // 获取当前日(1-31)
  241. hour: date.getHours(), //获取当前小时(0 ~ 23)
  242. minute: date.getMinutes(), //获取当前分钟(0 ~ 59)
  243. second: date.getSeconds() //获取当前秒数(0 ~ 59)
  244. };
  245. Object.keys(obj).forEach((key) => {
  246. if (obj[key] < 10) obj[key] = `0${obj[key]}`;
  247. });
  248. return obj;
  249. },
  250. //来源清单勾选事件
  251. handleSelectionChange1(selection) {
  252. console.log(selection, '勾选列表');
  253. this.form.sampleNumber = selection.length;
  254. if (this.form.qualityMode === 2) {
  255. this.selectedList = selection;
  256. if (this.schemeList.length == 0) {
  257. for (let i = 0; i < selection.length; i++) {
  258. console.log(selection[i], 'selection[i]')
  259. this.$set(selection[i], 'qualityStatus', 2)
  260. // 遍历新数组设置 qualityResults 默认值
  261. this.schemeList.forEach(item => {
  262. if (typeof item === 'object' && item !== null) {
  263. item.qualityResults = 1; // 设置默认值
  264. }
  265. delete item.id;
  266. });
  267. this.$set(selection[i], 'qualitySampleTemplateList', JSON.parse(JSON.stringify(this.schemeList)))
  268. }
  269. }
  270. this.sampleList = selection;
  271. //赋值取样数量
  272. this.form.sampleNumber = selection.length;
  273. }
  274. },
  275. async open() {
  276. this.type = this.$route.query.type;
  277. this.qualityType = this.$route.query.qualityType;
  278. this.title = this.type == 'add' ? '新增' : this.type == 'edit' ? '报工' : '详情';
  279. if (this.type == 'add') {
  280. const code = await getCode('quality_work_order_code');
  281. this.form.code = code;
  282. } else {
  283. if (this.$route.query.qualityTimeStart != '' || this.$route.query.qualityTimeStart != null || this.$route.query.qualityTimeStart != undefined) {
  284. this.qualityTimeStart = this.getNowTime();
  285. }
  286. }
  287. },
  288. getNowTime() {
  289. const nowDate = this.getNowDate()
  290. return nowDate.year + '-' + nowDate.month + '-' + nowDate.strDate + ' ' + nowDate.hour + ':' + nowDate.minute + ':' + nowDate.second
  291. },
  292. getNowTimes() {
  293. const nowDate = this.getNowDate()
  294. return nowDate.year + '-' + nowDate.month + '-' + nowDate.strDate
  295. },
  296. async getDetail() {
  297. getById(this.$route.query.id).then((res) => {
  298. this.form = res.data;
  299. this.isReportProcessProduce = this.form.isReportProcessProduce == 1 ? true : false;
  300. this.tabTaskId =
  301. this.categoryParamList[0] && this.categoryParamList[0].id;
  302. if (this.form.groupId) {
  303. this.$nextTick(() => {
  304. this.$refs.baseInfoRefs?.getUserList({
  305. groupId: this.form.groupId
  306. });
  307. });
  308. }
  309. if (this.form.produceRoutingId) {
  310. this.$nextTick(() => {
  311. this.$refs.baseInfoRefs?.getTaskList();
  312. })
  313. }
  314. });
  315. // await this.queryQualityInventory()
  316. await this.queryQualityTempleContent()
  317. await this.queryQualitySamplContent()
  318. },
  319. // getNewData(val) {
  320. // console.log(val, '清单列表')
  321. // this.packingList = val
  322. // },
  323. // async queryQualityInventory() {
  324. // let res = await queryQualityInventory({ qualityWorkerId: this.$route.query.id });
  325. // console.log(res, '清单列表');
  326. // this.packingList = res;
  327. // },
  328. changeSamUnit(val) {
  329. this.$set(this.form, 'sampleMeasureUnit', val)
  330. },
  331. handleSample1(val, data) {
  332. this.sampleList = []
  333. if (val == 1) {
  334. this.sampleList = data
  335. this.$message.success('取样成功!');
  336. } else if (val == 2) {
  337. console.log(data, 'datadatadatadataxiaoyang')
  338. }
  339. },
  340. handleSampleSubmit(data) {
  341. console.log(data, 'data123确认')
  342. if (data.conditionType == 1) {
  343. this.sampleList = this.selectedList
  344. } else {
  345. let measureQ = data.measureQ;
  346. let unit = data.sampleUnit;
  347. let nums = Number(data.portion);
  348. console.log(measureQ, '计量数量')
  349. console.log(unit, '所选单位')
  350. console.log(nums, '数量')
  351. this.getNewSampleList(measureQ, unit, nums)
  352. }
  353. },
  354. getNewSampleList(measureQ, unit, nums) {
  355. this.sampleList = [];
  356. let data = [];
  357. console.log(this.selectedList, 'this.selectedList')
  358. if (!this.selectedList || this.selectedList.length == 0) {
  359. this.$message.warning('请先选择来源清单!');
  360. return;
  361. }
  362. this.selectedList.forEach(oldItem => {
  363. delete oldItem.id;
  364. for (let i = 0; i < nums; i++) {
  365. data.push({
  366. ...oldItem,
  367. measureQuantity: measureQ,
  368. measureUnit: unit
  369. });
  370. }
  371. });
  372. console.log(data, 'datadatadatadatadatadata', nums)
  373. this.$refs.tabsRef.tabsChange('2')
  374. this.sampleList = data;
  375. },
  376. async queryQualitySamplContent() {
  377. const res = await queryQualitySamplContent({ qualityWorkerId: this.$route.query.id })
  378. let addStatus = res.list.map((item) => {
  379. item.isValid = true;
  380. item.disposeTime = item.disposeTime ? item.disposeTime.split(' ')[0] : null;
  381. item.sampleDate = item.sampleDate ? item.sampleDate.split(' ')[0] : null;
  382. return {
  383. ...item
  384. }
  385. })
  386. console.log(addStatus, '样品清单12123123')
  387. if (addStatus.length > 0) {
  388. this.sampleList = addStatus;
  389. } else {
  390. this.getProSamList(this.packingList)
  391. }
  392. },
  393. async queryQualityTempleContent() {
  394. const res = await queryQualityTempleContent({ qualityWorkerId: this.$route.query.id })
  395. console.log(res, '质检方案');
  396. this.schemeList = res.list;
  397. },
  398. /* 保存编辑 */
  399. save() {
  400. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  401. if (!valid) {
  402. return false;
  403. }
  404. this.loading = true;
  405. let URL =
  406. this.type == 'add' ? save : this.type == 'edit' ? update : '';
  407. this.form.qualityTimeStart = new Date(this.qualityTimeStart)
  408. delete this.form['qualityTimeEnd']
  409. let params = {
  410. ...this.form,
  411. sampleList: this.sampleList,
  412. planTemplateList: this.schemeList,
  413. qualityInventoryList: this.packingList
  414. }
  415. URL(params)
  416. .then((msg) => {
  417. this.loading = false;
  418. this.$message.success(msg);
  419. this.cancel();
  420. this.$emit('done');
  421. })
  422. .catch((e) => {
  423. this.loading = false;
  424. });
  425. });
  426. },
  427. update() {
  428. this.loading = true;
  429. this.form['status'] = 1;
  430. update({ ...this.form })
  431. .then((msg) => {
  432. this.loading = false;
  433. this.$message.success(msg);
  434. this.$emit('done');
  435. })
  436. .catch((e) => {
  437. this.loading = false;
  438. });
  439. },
  440. restForm() {
  441. this.form = { ...this.defaultForm() };
  442. this.$nextTick(() => {
  443. this.$refs.baseInfoRefs.$refs.form1.clearValidate();
  444. });
  445. },
  446. cancel() {
  447. finishPageTab();
  448. this.$router.go(-1);
  449. },
  450. handleDetail(index, row, type) {
  451. if (!this.sampleList[index] || !this.schemeList) {
  452. return;
  453. }
  454. const selectedData = [];
  455. selectedData.push(this.sampleList[index])
  456. this.$refs.detailRef.openDia(index, row, type, selectedData, null);
  457. },
  458. inputWeight(row, index) {
  459. console.log(row, index, '输入重量')
  460. const pNum = this.sampleList.reduce((sum, item) => {
  461. return sum + Number(item.weight || 0);
  462. }, 0);
  463. this.form.totalWeight = parseFloat(pNum.toFixed(2));
  464. },
  465. handleDispose(index, row, type) {
  466. if (!this.sampleList[index]) {
  467. return;
  468. }
  469. this.sampleList[index].sampleDate = this.getNowTimes();
  470. this.sampleList[index].disposeTime = this.getNowTimes();
  471. console.log(index, row, type, this.qualityType)
  472. this.$refs.disposeRef.openDispose(index, row, type, this.qualityType);
  473. },
  474. // 报工
  475. handleReporting(index, row) {
  476. this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
  477. if (!valid) {
  478. return false;
  479. }
  480. this.loading = true;
  481. if (this.qualityType == 2 && this.isReportProcessProduce) {
  482. for (let i = 0; i < this.sampleList.length; i++) {
  483. const disposalStatus = this.sampleList[i].disposalStatus;
  484. console.log(disposalStatus, 'disposalStatus')
  485. if (disposalStatus == null) {
  486. this.$message.error('请完成以下样品处置!')
  487. this.loading = false;
  488. return
  489. }
  490. }
  491. }
  492. for (let i = 0; i < this.sampleList.length; i++) {
  493. const qualityStatus = this.sampleList[i].qualityStatus;
  494. if (qualityStatus == '2') {
  495. this.$message.error('请完成以下样品质检!')
  496. this.loading = false;
  497. return
  498. }
  499. }
  500. this.form.qualityTimeEnd = new Date(this.getNowTime())
  501. this.form.qualityTimeStart = new Date(this.qualityTimeStart)
  502. let params = {
  503. ...this.form,
  504. sampleList: this.sampleList,
  505. planTemplateList: this.schemeList,
  506. qualityInventoryList: this.packingList
  507. }
  508. console.log(params, 'params')
  509. exeReportWork(params)
  510. .then((msg) => {
  511. this.loading = false;
  512. this.$message.success(msg);
  513. this.cancel();
  514. this.$emit('done');
  515. })
  516. .catch((e) => {
  517. this.loading = false;
  518. });
  519. })
  520. },
  521. // 处理确认事件
  522. handleDisposeConfirm(row, index) {
  523. if (index > -1) {
  524. this.$set(this.sampleList, index, row)
  525. }
  526. },
  527. //确认报工
  528. handleConfirm(list, index) {
  529. console.log(list)
  530. // 检查有效性
  531. // for (const item of list) {
  532. // for (const child of item.qualitySampleTemplateList) {
  533. //
  534. // console.log(child, 'child')
  535. // if (!child.qualityResultContent || !child.qualityResults) {
  536. // this.$message.error('请完善报工内容!');
  537. // return;
  538. // }
  539. // }
  540. // }
  541. console.log(list, 'listlistlistlist')
  542. list.forEach((item) => {
  543. if (item.qualitySampleTemplateList.some(child => child.qualityResults === 2)) {
  544. item.isValid = false;
  545. item.qualityResults = 2;
  546. }
  547. else {
  548. item.isValid = true;
  549. item.qualityResults = 1;
  550. }
  551. item.qualityStatus = 1;
  552. })
  553. if (index != null) {
  554. this.$set(this.sampleList, index, list[0]);
  555. } else {
  556. this.$set(this.sampleList, null, list);
  557. }
  558. console.log(this.sampleList, '222表')
  559. },
  560. // 批量质检
  561. batchQuality(index, row, type) {
  562. this.$refs.detailRef.openDia(null, null, 'report', this.sampleList, null)
  563. }
  564. }
  565. };
  566. </script>
  567. <style lang="scss" scoped></style>