| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639 |
- <template>
- <div class="ele-body">
- <el-card shadow="never">
- <header-title title="基本信息">
- <el-button @click="cancel">返回</el-button>
- <el-button type="primary" @click="save" :loading="loading" v-if="type != 'detail'">保存</el-button>
- <el-button type="primary" @click="handleReporting" :loading="loading" v-if="type != 'detail'">报工完成</el-button>
- </header-title>
- <base-info ref="baseInfoRefs" v-if="form" :form="form" :btnType="type" :qualityType1="qualityType"
- @changeModel="changeModel" @changeNumber="changeNumber"></base-info>
- <quality-content-tabs ref="tabsRef" :type="type" :ids="this.$route.query.id" :sample-list="sampleList"
- :scheme-list="schemeList" :loading="loading" :form="form" @selection-change="handleSelectionChange1"
- @batch-quality="batchQuality" @handleDetail="handleDetail" @inputWeight="inputWeight"
- @handleDispose="handleDispose" @changeSamUnit="changeSamUnit" @handleSample1="handleSample1"
- @handleSampleSubmit="handleSampleSubmit" />
- </el-card>
- <sampleListDialog ref="detailRef" @handleConfirm="handleConfirm" @handleDispose="handleDispose"></sampleListDialog>
- <sampleDisposeDialog ref="disposeRef" @handleDisposeConfirm="handleDisposeConfirm"></sampleDisposeDialog>
- </div>
- </template>
- <script>
- import baseInfo from './components/baseInfo.vue';
- import QualityContentTabs from './components/QualityContentTabs.vue'
- import { getCode } from '@/api/login';
- import { save, update, getById, exeReportWork, queryQualitySamplContent, queryQualityTempleContent, queryQualityInventory } from '@/api/inspectionWork';
- import dictMixins from '@/mixins/dictMixins';
- // import term from './term';
- import sampleListDialog from './components/sampleListDialog.vue';
- import sampleDisposeDialog from './components/sampleDisposeDialog.vue';
- import { finishPageTab } from '@/utils/page-tab-util';
- export default {
- components: {
- baseInfo,
- QualityContentTabs,
- sampleListDialog,
- sampleDisposeDialog
- },
- mixins: [dictMixins],
- data() {
- const defaultForm = function () {
- return {
- code: '',
- qualityType: null,
- qualityModeproduceRoutingId: '',
- produceRoutingName: '',
- produceTaskId: '',
- produceTaskName: '',
- productName: '',
- productCode: '',
- batchNo: '',
- specification: '',
- modelType: '',
- brandNo: '',
- total: '',
- qualifiedNumber: '',
- noQualifiedNumber: '',
- groupId: '',
- groupName: '',
- qualityId: '',
- qualityName: '',
- qualityTime: '',
- hours: '',
- qualificationRate: '',
- noQualificationRate: '',
- totalWeight: '',
- sampleNumber: '',
- imgUrl: [],
- qualityTimeStart: '',
- qualityTimeEnd: '',
- sampleMeasureUnit: ''
- };
- };
- return {
- defaultForm,
- // 表单数据
- form: { ...defaultForm() },
- voList: [],
- // 表单验证规则
- categoryParamList: [],
- type: '',
- title: '',
- loading: false,
- tabTaskId: null,
- // activeName: '2',
- packingList: [],
- sampleList: [],
- schemeList: [],
- isValid: true,
- isStatus: true,
- SampleListbyReportList: [],
- qualityTimeStart: '',
- isReportProcessProduce: false,
- };
- },
- watch: {
- '$route.query.id': {
- handler(id) {
- if (id) {
- this.getDetail();
- } else {
- this.form = { ...defaultForm() };
- }
- }
- },
- },
- created() {
- this.open()
- if (this.$route.query.id) {
- this.getDetail();
- }
- },
- methods: {
- //切换检验方式
- changeModel(val, flag) {
- this.$refs.tabsRef.tableSelClear()
- this.sampleList = [];
- this.$refs.tabsRef.tabsChange('1')
- this.form.qualityMode = val;
- //检验方式 全检
- if (this.form.qualityMode == 1) {
- this.form.sampleNumber = ''
- const sData = this.$refs.tabsRef.$refs.sourceTable.getData()
- if (sData.length == 0) {
- for (let i = 0; i < sData.length; i++) {
- this.$set(sData[i], 'qualityStatus', 2)
- }
- }
- console.log(this.$refs.tabsRef.$refs.sourceTable.getData(), 'packingList')
- this.getProSamList(sData)
- } else {
- if (!flag) {
- this.sampleList = [];
- }
- }
- },
- //根据类型判断样品清单现实列表数据
- getProSamList(list) {
- //生产检验
- if (this.qualityType == 2) {
- if (this.form.qualityMode != null) {
- const ProductSampleList = [];
- console.log(list, 'list')
- list.forEach(oldItem => {
- const count = oldItem.measureQuantity;
- const newMeasureQuantity = oldItem.measureQuantity / count;
- const newWeight = parseFloat((oldItem.weight / count).toFixed(2))
- console.log(typeof (oldItem.qualitySampleTemplateList), 'ssssss')
- // 遍历新数组设置 qualityResults 默认值
- this.schemeList.forEach(item => {
- if (typeof item === 'object' && item !== null) {
- item.qualityResults = 1; // 设置默认值
- }
- delete item.id;
- });
- console.log(oldItem, 'oldItem')
- console.log(count, newMeasureQuantity, newWeight)
- delete oldItem.id;
- if (oldItem.qualitySampleTemplateList == undefined || oldItem.qualitySampleTemplateList == null || oldItem.qualitySampleTemplateList.length == 0) {
- oldItem.qualitySampleTemplateList = JSON.parse(JSON.stringify(this.schemeList))
- for (let i = 0; i < count; i++) {
- ProductSampleList.push({
- ...oldItem,
- measureQuantity: newMeasureQuantity,
- weight: newWeight,
- qualitySampleTemplateList: JSON.parse(JSON.stringify(this.schemeList))
- });
- }
- console.log(ProductSampleList, 'ProductSampleList')
- this.sampleList = ProductSampleList;
- const pNum = ProductSampleList.reduce((sum, item) => {
- return sum + Number(item.weight || 0);
- }, 0);
- this.form.totalWeight = parseFloat(pNum.toFixed(2));
- }
- });
- }
- } else {
- this.sampleList = list;
- }
- },
- //输入取样数量
- changeNumber(val) {
- if (this.form.qualityMode !== 2) {
- return;
- }
- if (val <= 0) {
- this.$refs.showPackingListTable.clearSelection();
- return;
- }
- if (this.qualityType == 2) {
- //生产检验的抽检逻辑
- if (val > this.packingList[0].measureQuantity) {
- this.$message.warning('取样数量不能大于来源清单的计量数量!');
- return;
- }
- const ProductSampleList = [];
- this.packingList.forEach(oldItem => {
- const count = oldItem.measureQuantity;
- const newMeasureQuantity = oldItem.measureQuantity / count;
- const newWeight = parseFloat((oldItem.weight / count).toFixed(2))
- console.log(count, newMeasureQuantity, newWeight)
- delete oldItem.id;
- // 遍历新数组设置 qualityResults 默认值
- this.schemeList.forEach(item => {
- if (typeof item === 'object' && item !== null) {
- item.qualityResults = 1; // 设置默认值
- }
- delete item.id;
- });
- for (let i = 0; i < val; i++) {
- ProductSampleList.push({
- ...oldItem,
- measureQuantity: newMeasureQuantity,
- weight: newWeight,
- qualitySampleTemplateList: JSON.parse(JSON.stringify(this.schemeList))
- });
- }
- });
- this.sampleList = ProductSampleList;
- const pNum = ProductSampleList.reduce((sum, item) => {
- return sum + Number(item.weight || 0);
- }, 0);
- this.form.totalWeight = parseFloat(pNum.toFixed(2));
- } else {
- if (val > this.packingList.length) {
- this.$message.warning('取样数量不能大于物料明细总数!');
- return;
- }
- const rows = this.packingList.slice(0, val);
- rows.forEach((row) => {
- this.$refs.showPackingListTable.toggleRowSelection(row);
- });
- }
- },
- getNowDate() {
- let date = new Date(),
- obj = {
- year: date.getFullYear(), //获取当前月份(0-11,0代表1月)
- month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
- strDate: date.getDate(), // 获取当前日(1-31)
- hour: date.getHours(), //获取当前小时(0 ~ 23)
- minute: date.getMinutes(), //获取当前分钟(0 ~ 59)
- second: date.getSeconds() //获取当前秒数(0 ~ 59)
- };
- Object.keys(obj).forEach((key) => {
- if (obj[key] < 10) obj[key] = `0${obj[key]}`;
- });
- return obj;
- },
- //来源清单勾选事件
- handleSelectionChange1(selection) {
- console.log(selection, '勾选列表');
- this.form.sampleNumber = selection.length;
- if (this.form.qualityMode === 2) {
- this.selectedList = selection;
- if (this.schemeList.length == 0) {
- for (let i = 0; i < selection.length; i++) {
- console.log(selection[i], 'selection[i]')
- this.$set(selection[i], 'qualityStatus', 2)
- // 遍历新数组设置 qualityResults 默认值
- this.schemeList.forEach(item => {
- if (typeof item === 'object' && item !== null) {
- item.qualityResults = 1; // 设置默认值
- }
- delete item.id;
- });
- this.$set(selection[i], 'qualitySampleTemplateList', JSON.parse(JSON.stringify(this.schemeList)))
- }
- }
- this.sampleList = selection;
- //赋值取样数量
- this.form.sampleNumber = selection.length;
- }
- },
- async open() {
- this.type = this.$route.query.type;
- this.qualityType = this.$route.query.qualityType;
- this.title = this.type == 'add' ? '新增' : this.type == 'edit' ? '报工' : '详情';
- if (this.type == 'add') {
- const code = await getCode('quality_work_order_code');
- this.form.code = code;
- } else {
- if (this.$route.query.qualityTimeStart != '' || this.$route.query.qualityTimeStart != null || this.$route.query.qualityTimeStart != undefined) {
- this.qualityTimeStart = this.getNowTime();
- }
- }
- },
- getNowTime() {
- const nowDate = this.getNowDate()
- return nowDate.year + '-' + nowDate.month + '-' + nowDate.strDate + ' ' + nowDate.hour + ':' + nowDate.minute + ':' + nowDate.second
- },
- getNowTimes() {
- const nowDate = this.getNowDate()
- return nowDate.year + '-' + nowDate.month + '-' + nowDate.strDate
- },
- async getDetail() {
- getById(this.$route.query.id).then((res) => {
- this.form = res.data;
- this.isReportProcessProduce = this.form.isReportProcessProduce == 1 ? true : false;
- this.tabTaskId =
- this.categoryParamList[0] && this.categoryParamList[0].id;
- if (this.form.groupId) {
- this.$nextTick(() => {
- this.$refs.baseInfoRefs?.getUserList({
- groupId: this.form.groupId
- });
- });
- }
- if (this.form.produceRoutingId) {
- this.$nextTick(() => {
- this.$refs.baseInfoRefs?.getTaskList();
- })
- }
- });
- // await this.queryQualityInventory()
- await this.queryQualityTempleContent()
- await this.queryQualitySamplContent()
- },
- // getNewData(val) {
- // console.log(val, '清单列表')
- // this.packingList = val
- // },
- // async queryQualityInventory() {
- // let res = await queryQualityInventory({ qualityWorkerId: this.$route.query.id });
- // console.log(res, '清单列表');
- // this.packingList = res;
- // },
- changeSamUnit(val) {
- this.$set(this.form, 'sampleMeasureUnit', val)
- },
- handleSample1(val, data) {
- this.sampleList = []
- if (val == 1) {
- this.sampleList = data
- this.$message.success('取样成功!');
- } else if (val == 2) {
- console.log(data, 'datadatadatadataxiaoyang')
- }
- },
- handleSampleSubmit(data) {
- console.log(data, 'data123确认')
- if (data.conditionType == 1) {
- this.sampleList = this.selectedList
- } else {
- let measureQ = data.measureQ;
- let unit = data.sampleUnit;
- let nums = Number(data.portion);
- console.log(measureQ, '计量数量')
- console.log(unit, '所选单位')
- console.log(nums, '数量')
- this.getNewSampleList(measureQ, unit, nums)
- }
- },
- getNewSampleList(measureQ, unit, nums) {
- this.sampleList = [];
- let data = [];
- console.log(this.selectedList, 'this.selectedList')
- if (!this.selectedList || this.selectedList.length == 0) {
- this.$message.warning('请先选择来源清单!');
- return;
- }
- this.selectedList.forEach(oldItem => {
- delete oldItem.id;
- for (let i = 0; i < nums; i++) {
- data.push({
- ...oldItem,
- measureQuantity: measureQ,
- measureUnit: unit
- });
- }
- });
- console.log(data, 'datadatadatadatadatadata', nums)
- this.$refs.tabsRef.tabsChange('2')
- this.sampleList = data;
- },
- async queryQualitySamplContent() {
- const res = await queryQualitySamplContent({ qualityWorkerId: this.$route.query.id })
- let addStatus = res.list.map((item) => {
- item.isValid = true;
- item.disposeTime = item.disposeTime ? item.disposeTime.split(' ')[0] : null;
- item.sampleDate = item.sampleDate ? item.sampleDate.split(' ')[0] : null;
- return {
- ...item
- }
- })
- console.log(addStatus, '样品清单12123123')
- if (addStatus.length > 0) {
- this.sampleList = addStatus;
- } else {
- this.getProSamList(this.packingList)
- }
- },
- async queryQualityTempleContent() {
- const res = await queryQualityTempleContent({ qualityWorkerId: this.$route.query.id })
- console.log(res, '质检方案');
- this.schemeList = res.list;
- },
- /* 保存编辑 */
- save() {
- this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
- if (!valid) {
- return false;
- }
- this.loading = true;
- let URL =
- this.type == 'add' ? save : this.type == 'edit' ? update : '';
- this.form.qualityTimeStart = new Date(this.qualityTimeStart)
- delete this.form['qualityTimeEnd']
- let params = {
- ...this.form,
- sampleList: this.sampleList,
- planTemplateList: this.schemeList,
- qualityInventoryList: this.packingList
- }
- URL(params)
- .then((msg) => {
- this.loading = false;
- this.$message.success(msg);
- this.cancel();
- this.$emit('done');
- })
- .catch((e) => {
- this.loading = false;
- });
- });
- },
- update() {
- this.loading = true;
- this.form['status'] = 1;
- update({ ...this.form })
- .then((msg) => {
- this.loading = false;
- this.$message.success(msg);
- this.$emit('done');
- })
- .catch((e) => {
- this.loading = false;
- });
- },
- restForm() {
- this.form = { ...this.defaultForm() };
- this.$nextTick(() => {
- this.$refs.baseInfoRefs.$refs.form1.clearValidate();
- });
- },
- cancel() {
- finishPageTab();
- this.$router.go(-1);
- },
- handleDetail(index, row, type) {
- if (!this.sampleList[index] || !this.schemeList) {
- return;
- }
- const selectedData = [];
- selectedData.push(this.sampleList[index])
- this.$refs.detailRef.openDia(index, row, type, selectedData, null);
- },
- inputWeight(row, index) {
- console.log(row, index, '输入重量')
- const pNum = this.sampleList.reduce((sum, item) => {
- return sum + Number(item.weight || 0);
- }, 0);
- this.form.totalWeight = parseFloat(pNum.toFixed(2));
- },
- handleDispose(index, row, type) {
- if (!this.sampleList[index]) {
- return;
- }
- this.sampleList[index].sampleDate = this.getNowTimes();
- this.sampleList[index].disposeTime = this.getNowTimes();
- console.log(index, row, type, this.qualityType)
- this.$refs.disposeRef.openDispose(index, row, type, this.qualityType);
- },
- // 报工
- handleReporting(index, row) {
- this.$refs.baseInfoRefs.$refs.form1.validate((valid) => {
- if (!valid) {
- return false;
- }
- this.loading = true;
- if (this.qualityType == 2 && this.isReportProcessProduce) {
- for (let i = 0; i < this.sampleList.length; i++) {
- const disposalStatus = this.sampleList[i].disposalStatus;
- console.log(disposalStatus, 'disposalStatus')
- if (disposalStatus == null) {
- this.$message.error('请完成以下样品处置!')
- this.loading = false;
- return
- }
- }
- }
- for (let i = 0; i < this.sampleList.length; i++) {
- const qualityStatus = this.sampleList[i].qualityStatus;
- if (qualityStatus == '2') {
- this.$message.error('请完成以下样品质检!')
- this.loading = false;
- return
- }
- }
- this.form.qualityTimeEnd = new Date(this.getNowTime())
- this.form.qualityTimeStart = new Date(this.qualityTimeStart)
- let params = {
- ...this.form,
- sampleList: this.sampleList,
- planTemplateList: this.schemeList,
- qualityInventoryList: this.packingList
- }
- console.log(params, 'params')
- exeReportWork(params)
- .then((msg) => {
- this.loading = false;
- this.$message.success(msg);
- this.cancel();
- this.$emit('done');
- })
- .catch((e) => {
- this.loading = false;
- });
- })
- },
- // 处理确认事件
- handleDisposeConfirm(row, index) {
- if (index > -1) {
- this.$set(this.sampleList, index, row)
- }
- },
- //确认报工
- handleConfirm(list, index) {
- console.log(list)
- // 检查有效性
- // for (const item of list) {
- // for (const child of item.qualitySampleTemplateList) {
- //
- // console.log(child, 'child')
- // if (!child.qualityResultContent || !child.qualityResults) {
- // this.$message.error('请完善报工内容!');
- // return;
- // }
- // }
- // }
- console.log(list, 'listlistlistlist')
- list.forEach((item) => {
- if (item.qualitySampleTemplateList.some(child => child.qualityResults === 2)) {
- item.isValid = false;
- item.qualityResults = 2;
- }
- else {
- item.isValid = true;
- item.qualityResults = 1;
- }
- item.qualityStatus = 1;
- })
- if (index != null) {
- this.$set(this.sampleList, index, list[0]);
- } else {
- this.$set(this.sampleList, null, list);
- }
- console.log(this.sampleList, '222表')
- },
- // 批量质检
- batchQuality(index, row, type) {
- this.$refs.detailRef.openDia(null, null, 'report', this.sampleList, null)
- }
- }
- };
- </script>
- <style lang="scss" scoped></style>
|