| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583 |
- <template>
- <view>
- <u-popup :show="visible" :round="0" :closeOnClickOverlay="false" :zIndex="99999"
- @close="closePopup">
- <view class="popup-content">
- <view class="popup-header">
- <text class="popup-title">{{ title }}</text>
- <view class="close-btn" @click="closePopup">×</view>
- </view>
- <scroll-view class="popup-body" scroll-y>
- <view class="form-section">
- <view class="section-title">基本信息</view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">工单编码</text>
- <view class="value-wrap" @click="selectQualityWorkOrder"
- v-if="!isSampleRecord || (isSampleRecord && type != 'add')">
- <u-input v-model="form.qualityWorkOrderCode" disabled placeholder=" "
- border="none"></u-input>
- </view>
- <view class="value-wrap" v-else>
- <u-input v-model="form.qualityWorkOrderCode" disabled placeholder=" "
- border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">工单名称</text>
- <view class="value-wrap">
- <u-input v-model="form.qualityWorkOrderName" disabled placeholder=" "
- border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">编码</text>
- <view class="value-wrap">
- <u-input v-model="form.productCode" disabled placeholder=" "
- border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">名称</text>
- <view class="value-wrap">
- <u-input v-model="form.productName" disabled placeholder=" "
- border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">批次号</text>
- <view class="value-wrap">
- <u-input v-model="form.batchNo" disabled placeholder=" " border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">规格</text>
- <view class="value-wrap">
- <u-input v-model="form.specification" disabled placeholder=" "
- border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">型号</text>
- <view class="value-wrap">
- <u-input v-model="form.modelType" disabled placeholder=" " border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">牌号</text>
- <view class="value-wrap">
- <u-input v-model="form.brandNo" disabled placeholder=" " border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">总数</text>
- <view class="value-wrap">
- <u-input v-model="form.total" disabled placeholder=" " border="none">
- <template #suffix>{{
- tableList[0] && tableList[0].measureUnit
- }}</template>
- </u-input>
- </view>
- </view>
- </view>
- </view>
- <view class="form-section">
- <view class="section-title">来源清单</view>
- <view class="table-info">
- <text>累计请样数量:{{ workSampleQuantity
- }}{{
- (sampleList[0] && sampleList[0].measureUnit) ||
- form.measureUnit
- }}</text>
- </view>
- <view class="table-wrapper">
- <scroll-view scroll-x scroll-y class="table-scroll">
- <view class="source-table">
- <view class="table-header">
- <view class="table-cell select-cell">
- <checkbox :checked="isAllSelected" @click="toggleSelectAll" />
- </view>
- <view class="table-cell" v-for="col in displaySourceColumns.filter(
- (c) => c.prop !== 'select',
- )" :key="col.prop">{{ col.label }}</view>
- </view>
- <view class="table-body">
- <view class="table-row" v-for="(item, index) in tableList" :key="index">
- <view class="table-cell select-cell">
- <checkbox :checked="isSelected(item)" @click="toggleSelect(item)" />
- </view>
- <view class="table-cell" v-for="col in displaySourceColumns.filter(
- (c) => c.prop !== 'select',
- )" :key="col.prop">
- {{ item[col.prop] || "-" }}
- </view>
- </view>
- <view class="table-empty" v-if="!tableList || tableList.length === 0">
- <text>暂无数据</text>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- <view class="form-section">
- <view class="section-title">请样信息</view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">请样目的</text>
- <view class="value-wrap">
- <u-input v-model="form.pleasePurpose" placeholder="请输入" border="none" :disabled="type=='view'"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">质检方式</text>
- <view class="value-wrap">
- <DictSelection v-model="form.qualityMode" @change="handleQualityModeChange"
- :disabled="form.isFirstSampling != '1'||type=='view'" dictName="取样类型"></DictSelection>
- </view>
- </view>
- </view>
- <view class="form-row">
- <view class="form-item">
- <text class="label">记录方法</text>
- <view class="value-wrap" @click="selectRecordingMethod"
- :class="{ disabled: form.isFirstSampling != '1'||type=='view' }">
- <u-input :value="recordingMethodList.find(item=>item.value==form.recordingMethod)&&recordingMethodList.find(item=>item.value==form.recordingMethod).label" placeholder="请选择" border="none" disabled>
- <template #suffix>
- <text class="arrow">›</text>
- </template>
- </u-input>
- </view>
- </view>
- </view>
- <view class="form-section-inner" v-if="form.qualityMode == '2'">
- <view class="form-row">
- <view class="form-item">
- <text class="label">请样类型</text>
- <view class="value-wrap" @click="selectConditionType"
- :class="{ disabled: form.isFirstSampling != '1'||type=='view' }">
- <u-input :value="conditionTypeColumns.find(item=>item.value==form.conditionType)&&conditionTypeColumns.find(item=>item.value==form.conditionType).label" placeholder="请选择" border="none"
- disabled>
- <template #suffix>
- <text class="arrow">›</text>
- </template>
- </u-input>
- </view>
- </view>
- </view>
- <view class="form-row" v-if="form.conditionType == 2">
- <view class="form-item">
- <text class="label">数量</text>
- <view class="value-wrap">
- <u-input v-model="form.quantity" :disabled="type=='view'" placeholder="请输入" border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row" v-if="form.conditionType == 2">
- <view class="form-item">
- <text class="label">单位</text>
- <view class="value-wrap" @click="selectUnit"
- :class="{ disabled: form.isFirstSampling != '1'||type=='view' }">
- <u-input v-model="form.unit" placeholder="请选择" border="none" disabled>
- <template #suffix>
- <text class="arrow">›</text>
- </template>
- </u-input>
- </view>
- </view>
- </view>
- <view class="form-row" v-if="form.conditionType == 2">
- <view class="form-item">
- <text class="label">条数</text>
- <view class="value-wrap">
- <u-input v-model="form.portion" :disabled="type=='view'" placeholder="请输入" border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row" v-if="form.conditionType == 1">
- <view class="form-item">
- <text class="label">数量</text>
- <view class="value-wrap">
- <u-input v-model="form.portion" :disabled="type=='view'" placeholder="请输入" border="none"></u-input>
- </view>
- </view>
- </view>
- <view class="form-row" v-if="form.conditionType == 1">
- <view class="form-item">
- <text class="label">单位</text>
- <view class="value-wrap" @click="selectPackingUnit"
- :class="{ disabled: form.isFirstSampling != '1'||type=='view' }">
- <u-input v-model="form.unit" placeholder="请选择" border="none" disabled>
- <template #suffix>
- <text class="arrow">›</text>
- </template>
- </u-input>
- </view>
- </view>
- </view>
- <view class="confirm-btn-wrap" v-if="type != 'view'">
- <u-button type="primary" @click="handleSampleSubmit">确认</u-button>
- </view>
- </view>
- </view>
- <view class="form-section">
- <view class="section-title">样品信息</view>
- <view class="table-wrapper">
- <scroll-view scroll-x scroll-y class="table-scroll">
- <view class="sample-table">
- <view class="table-header">
- <view class="table-cell" v-for="col in displaySampleColumns" :key="col.prop">
- {{ col.label }}
- </view>
- </view>
- <view class="table-body">
- <view class="table-row" v-for="(item, index) in sampleList" :key="index">
- <view class="table-cell" v-for="col in displaySampleColumns"
- :key="col.prop">
- {{ item[col.prop] || "-" }}
- </view>
- </view>
- <view class="table-empty" v-if="!sampleList || sampleList.length === 0">
- <text>暂无数据</text>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- </scroll-view>
- <view class="popup-footer">
- <u-button type="default" @click="closePopup">关闭</u-button>
- <u-button type="primary" @click="save()" v-if="type != 'view'" :loading="loading">保存</u-button>
- <!-- <u-button type="success" @click="save('submit')" v-if="type != 'view' && isSamplingApproval == 1"
- :loading="loading">提交</u-button> -->
- </view>
- </view>
- <u-toast ref="uToast"></u-toast>
- </u-popup>
- <!-- 质检工单选择弹窗 -->
- <inspectionWorkDialog ref="inspectionWorkDialog" @changeParent="changeParent"></inspectionWorkDialog>
- <!-- 质检方式选择 -->
- <u-picker :show="showQualityModePicker" :columns="qualityModeColumns" @confirm="confirmQualityMode"
- @cancel="showQualityModePicker = false"></u-picker>
- <!-- 记录方法选择 -->
- <u-picker :show="showRecordingMethodPicker" :columns="[recordingMethodList]" @confirm="confirmRecordingMethod"
- @cancel="showRecordingMethodPicker = false"></u-picker>
- <!-- 请样类型选择 -->
- <u-picker :show="showConditionTypePicker" :columns="[conditionTypeColumns]" @confirm="confirmConditionType"
- @cancel="showConditionTypePicker = false"></u-picker>
- <!-- 单位选择 -->
- <u-picker :show="showUnitPicker" :columns="unitColumns" @confirm="confirmUnit"
- @cancel="showUnitPicker = false"></u-picker>
- <!-- 包装单位选择 -->
- <u-picker :show="showPackingUnitPicker" :columns="packingUnitColumns" @confirm="confirmPackingUnit"
- @cancel="showPackingUnitPicker = false"></u-picker>
- </view>
- </template>
- <script>
- import {
- recordingMethodList
- } from "@/utils/utils.js";
- import DictSelection from "@/components/Dict/DictSelection.vue";
- const defForm = {
- code: "", //编码
- name: "", //名称
- conditionType: "",
- quantity: "",
- unit: "",
- portion: "",
- qualityMode: "",
- qualityModeName: "",
- recordingMethod: 1,
- recordingMethodName: "",
- pleaseQuantity: "",
- pleasePurpose: "",
- pleaseUnit: "",
- sampleQuantity: "",
- qualityWorkOrderId: "",
- qualityWorkOrderCode: "",
- qualityWorkOrderName: "",
- isFirstSampling: "",
- measureUnit:''
- };
- import {
- queryQualityInventory,
- queryQualityTempleContent,
- } from "@/api/inspectionWork";
- import {
- samplingrecordSave,
- getById,
- samplingrecordUpdate,
- samplingRecordsPage,
- } from "@/api/samplingRecords";
- import inspectionWorkDialog from "./components/inspectionWorkDialog.vue";
- import { getCodeList, getCode, parameterGetByCode } from '@/api/pda/picking.js'
- export default {
- components: {
- inspectionWorkDialog,
- DictSelection
- },
- data() {
- return {
- recordingMethodList,
- form: {
- ...defForm
- },
- activeComp: "main",
- tabOptions: [{
- key: "main",
- name: "请样详情"
- },
- {
- key: "bpm",
- name: "流程详情"
- },
- ],
- workSampleQuantity: 0,
- visible: false,
- loading: false,
- sampleNumberList: [{
- label: "全检",
- value: 1
- },
- {
- label: "抽检",
- value: 2
- },
- ],
- selection: [],
- // 弹窗相关
- showQualityModePicker: false,
- showRecordingMethodPicker: false,
- showConditionTypePicker: false,
- showUnitPicker: false,
- showPackingUnitPicker: false,
- qualityModeColumns: [],
- recordingMethodPickerColumns: [],
- conditionTypeColumns: [{
- label: "请整样",
- value: 1
- },
- {
- label: "请小样",
- value: 2
- },
- ],
- unitColumns: [
- []
- ],
- packingUnitColumns: [
- []
- ],
- // 显示的表格列
- displaySourceColumns: [{
- label: "",
- prop: "select",
- type: "selection"
- },
- {
- label: "名称",
- prop: "categoryName"
- },
- {
- label: "计量数量",
- prop: "measureQuantity"
- },
- {
- label: "计量单位",
- prop: "measureUnit"
- },
- {
- label: "包装数量",
- prop: "packingQuantity"
- },
- {
- label: "包装单位",
- prop: "packingUnit"
- },
- ],
- displaySampleColumns: [{
- label: "样品编码",
- prop: "sampleCode"
- },
- {
- label: "名称",
- prop: "categoryName"
- },
- {
- label: "计量数量",
- prop: "measureQuantity"
- },
- {
- label: "计量单位",
- prop: "measureUnit"
- },
- {
- label: "包装数量",
- prop: "packingQuantity"
- },
- {
- label: "包装单位",
- prop: "packingUnit"
- }
- ],
- packingSpecificationOption: [],
- sampleList: [],
- schemeList: [],
- tableList: [],
- type: "add",
- title: "",
- isSamplingApproval: 0,
- isSampleRecord: false,
- isAllSelected: false,
- };
- },
- computed: {
- allSelected() {
- return (
- this.tableList.length > 0 &&
- this.selection.length === this.tableList.length
- );
- },
- },
- created() {},
- methods: {
- // 切换全选
- toggleSelectAll() {
- if (this.isAllSelected) {
- this.selection = [];
- } else {
- this.selection = [...this.tableList];
- }
- this.isAllSelected = !this.isAllSelected;
- },
- // 切换单选
- toggleSelect(item) {
- const index = this.selection.findIndex((row) => row.id === item.id);
- if (index > -1) {
- this.selection.splice(index, 1);
- } else {
- this.selection.push(item);
- }
- this.isAllSelected = this.selection.length === this.tableList.length;
- },
- // 判断是否选中
- isSelected(item) {
- return this.selection.findIndex((row) => row.id === item.id) > -1;
- },
- closePopup() {
- this.cancel();
- },
- async open(type, row) {
- // this.activeComp = 'main';
- this.visible = true;
- this.type = type;
- // this.parameterGetByCode();
- this.title =
- type == "add" ? "请样" : type == "edit" ? "修改请样" : "详情";
- if (type == "add") {
- if (row) {
- this.init(row);
- }
- } else {
- this.getById(row.id);
- }
- },
- // 选择质检工单
- selectQualityWorkOrder() {
- this.$refs.inspectionWorkDialog.open();
- },
- // 质检方式选择
- selectQualityMode() {
- if (this.form.isFirstSampling != "1") return;
- this.qualityModeColumns = [this.sampleNumberList];
- this.showQualityModePicker = true;
- },
- confirmQualityMode(e) {
- this.form.qualityMode = e.value[0].value;
- this.form.qualityModeName = e.value[0].label;
- this.handleQualityModeChange(e.value[0].value);
- this.showQualityModePicker = false;
- },
- // 记录方法选择
- selectRecordingMethod() {
- if (this.form.isFirstSampling != "1") return;
- // this.recordingMethodPickerColumns = [this.recordingMethodList];
- this.showRecordingMethodPicker = true;
- },
- confirmRecordingMethod(e) {
- this.form.recordingMethod = e.value[0].value;
- this.form.recordingMethodName = e.value[0].label;
- this.showRecordingMethodPicker = false;
- },
- // 请样类型选择
- selectConditionType() {
- if (this.form.isFirstSampling != "1") return;
- this.showConditionTypePicker = true;
- },
- confirmConditionType(e) {
- this.form.conditionType = e.value[0].value;
- this.form.conditionTypeName = e.value[0].label;
- this.showConditionTypePicker = false;
- },
- // 单位选择
- selectUnit() {
- if (this.form.isFirstSampling != "1") return;
- let unitList = this.packingSpecificationOption.map(
- (item) => item.conversionUnit,
- );
- this.unitColumns = [unitList];
- this.showUnitPicker = true;
- },
- confirmUnit(e) {
- this.form.unit = e.value[0];
- this.showUnitPicker = false;
- },
- // 包装单位选择
- selectPackingUnit() {
- if (this.form.isFirstSampling != "1") return;
- let unitList = this.packingSpecificationOption.map(
- (item) => item.conversionUnit,
- );
- this.packingUnitColumns = [unitList];
- this.showPackingUnitPicker = true;
- },
- confirmPackingUnit(e) {
- let selectedItem = this.packingSpecificationOption.find(
- (item) => item.conversionUnit === e.value[0],
- );
- if (selectedItem) {
- this.form.packingUnit = selectedItem.id;
- this.form.packingUnitName = selectedItem.conversionUnit;
- this.form.unit = selectedItem.conversionUnit;
- }
- this.showPackingUnitPicker = false;
- },
- parameterGetByCode() {
- parameterGetByCode({
- code: "sampling_approval",
- }).then((res) => {
- this.isSamplingApproval = res.value;
- });
- },
- async init(row) {
- let isPackingUnit = false;
- let data = await samplingRecordsPage({
- qualityWorkOrderId: row.id,
- });
- let list = data.list.filter(
- (item) => item.status === 0 || item.status === 4,
- );
- let list1 = data.list.filter((item) => item.status != 3);
- if (list?.length) {
- this.getById(list[0].id);
- this.type = "edit";
- this.title = "修改请样";
- } else {
- row.sourceCode = row.qualityPlanCode || row.workOrderCode;
- this.form = JSON.parse(JSON.stringify(row));
- this.form.qualityWorkOrderId = row.id;
- this.form.qualityWorkOrderCode = row.code;
- this.form.qualityWorkOrderName = row.name;
- this.workSampleQuantity = Number(row.sampleQuantity) || 0;
- if (!list1?.length) {
- this.form.isFirstSampling = 1;
- isPackingUnit = true;
- if (this.form.conditionType == 1) {
- this.$set(this.form, "packingUnit", "111");
- }
- } else {
- this.$set(this.form, "unit", list1[0].unit);
- this.$set(this.form, "measureUnit", list1[0].measureUnit);
- }
- await this.datasource(list1[0]?.unit, isPackingUnit);
- await this.queryQualityTempleContent(
- !list1.length && row.qualityMode == 1,
- );
- }
- },
- getById(id) {
- getById(id).then((res) => {
- this.workSampleQuantity =
- Number(res.qualityWorkOrderVO.sampleQuantity) || 0;
- [
- "id",
- "code",
- "name",
- "createTime",
- "createUserId",
- "status",
- "approvalStatus",
- "approvalUserId",
- "sampleQuantity",
- "processInstanceId",
- ].forEach((it) => {
- delete res.qualityWorkOrderVO[it];
- });
- this.form = {
- ...res,
- ...res.qualityWorkOrderVO
- };
- this.datasource(this.form.unit);
- this.queryQualityTempleContent();
- if (this.form.qualityMode == 2) {
- if (res.qualityWorkOrderVO.conditionType == 1) {
- this.$set(this.form, "portion", res.quantity);
- this.$set(this.form, "quantity", 0);
- } else {
- this.$set(this.form, "portion", res.copies);
- }
- }
- this.sampleList = res.qualitySampleList;
- });
- },
- /* 查询质检模板内容 */
- async queryQualityTempleContent(is) {
- const res = await queryQualityTempleContent({
- qualityWorkerId: this.form.qualityWorkOrderId,
- page: 1,
- size: 10000,
- });
- this.schemeList = res.list;
- if (is) {
- this.updatePackingList();
- }
- },
- cancel() {
- this.form = {
- ...defForm,
- };
- this.workSampleQuantity=0
- this.schemeList = [];
- this.packingSpecificationOption = [];
- this.sampleList = [];
- this.tableList = [];
- this.visible = false;
- },
- changeParent(row) {
- this.init(row);
- },
- async datasource(unit, isPackingUnit) {
- const res = await queryQualityInventory({
- qualityWorkerId: this.form.qualityWorkOrderId,
- pageNum: 1,
- size: -1,
- });
- console.log(res, "res");
- let o = res.list[0];
- let listArr = [];
- if (o.measureUnit) {
- listArr.push({
- packageCellTotal: 1,
- conversionUnit: o.measureUnit,
- id: "111",
- });
- }
- if (o.packingUnit) {
- listArr.push({
- packageCellTotal: o.measureQuantity - 0,
- conversionUnit: o.packingUnit,
- id: "222",
- });
- }
- if (unit) {
- this.$set(
- this.form,
- "packingUnit",
- listArr.find((item) => unit == item.conversionUnit)?.id,
- );
- }
- if (isPackingUnit) {
- this.$set(this.form, "unit", res.list[0]?.measureUnit);
- }
- this.form.pleaseUnit = res.list[0]?.measureUnit;
- res.list.map((el) => {
- el.weightProportion = el.weight ?
- (el.weight / el.measureQuantity).toFixed(4) :
- 0;
- el.weightProportion = el.weightProportion - 0;
- });
- this.packingSpecificationOption = listArr;
- this.tableList = res.list;
- return res;
- },
- handleSampleSubmit() {
- let params = {
- conditionType: this.form.conditionType,
- quantity: this.form.quantity,
- sampleUnit: this.form.unit,
- portion: this.form.portion,
- };
- let specifications = this.packingSpecificationOption.find(
- (el) => el.id == this.form.packingUnit,
- );
- this.sampleFn(params, specifications);
- },
- async sampleFn(data, specifications) {
- console.log(this.selection, 'this.selection')
- this.sampleList = [];
- if (!this.selection || this.selection.length == 0) {
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: "请先选择来源清单!",
- }, )
- return;
- }
- const quantity = data.quantity || 1;
- const unit = data.sampleUnit;
- const sampleCount = Number(data.portion);
- try {
- // 2 取小样
- if (this.form.conditionType == 2) {
- if (!this.validateMeasureQuantity(quantity, unit, sampleCount))
- return; //取样数量验证
- if (unit === "KG" && !this.validateWeight(quantity, sampleCount))
- return; // 若计量单位为重量,还需验证总重量是否足够
- await this.getNewFullSampleList(
- Math.ceil(sampleCount),
- quantity,
- unit,
- specifications,
- );
- } else {
- let isFlag = this.validateSampleQuantity(sampleCount, specifications);
- if (!isFlag) return;
- if (this.form.inspectionStandards == 1) {
- await this.getNewFullSampleList(
- Math.ceil(sampleCount),
- quantity,
- unit,
- specifications,
- );
- } else {
- await this.handleWeightFullSample(sampleCount, specifications);
- }
- }
- } catch (error) {
- console.error("请样处理失败:", error);
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: "请样处理失败!",
- }, )
- }
- },
- validateWeight(quantity, sampleCount) {
- let totalMaxPossible = 0;
- this.selection.forEach((item) => {
- totalMaxPossible += item.measureQuantity / quantity;
- });
- if (totalMaxPossible < sampleCount) {
- console.error("请样处理失败:", error);
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: `最大请样条数为${totalMaxPossible}`,
- }, )
- return false;
- }
- let totalWeight = this.selection.reduce(
- (sum, item) => sum + item.weight,
- 0,
- );
- const weightUnit = this.selection[0].weightUnit;
- if (weightUnit === "G") totalWeight /= 1000;
- if (quantity * sampleCount > totalWeight) {
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: `请样计量重量不能大于总计量重量`,
- }, )
- return false;
- }
- const invalidItem = this.selection.find((item) => {
- const weight =
- item.weightUnit === "G" ? item.weight / 1000 : item.weight;
- return weight < quantity;
- });
- if (invalidItem) {
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: `勾选条目重量小于请样重量`,
- }, )
- return false;
- }
- return true;
- },
- validateMeasureQuantity(quantity, unit, sampleCount) {
- if (quantity <= 0) {
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: `请样计量数量必须大于`,
- }, )
- return false;
- }
- const totalQuantity =
- this.selection.reduce((sum, item) => sum + item.measureQuantity, 0) -
- this.workSampleQuantity;
- if (
- this.selection[0].measureUnit === unit &&
- quantity * sampleCount > totalQuantity
- ) {
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: `请样计量数量不能大于总计量数量`,
- }, )
- return false;
- }
- const invalidItem = this.selection.find(
- (item) => item.measureQuantity < quantity,
- );
- if (invalidItem) {
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: `条目计量数量小于请样计量数量`,
- }, )
- return false;
- }
- return true;
- },
- async handleWeightFullSample(sampleCount, specifications) {
- const dataList = [];
- let currentNum = sampleCount - this.selection.length;
- let currentNum1 = sampleCount;
- for (const item of this.selection) {
- const qualitySampleTemplateList = item.qualitySampleTemplateList?.length ?
- JSON.parse(JSON.stringify(item.qualitySampleTemplateList)) :
- JSON.parse(
- JSON.stringify(
- this.schemeList.map((item) => {
- item["qualityResults"] = 1;
- return item;
- }),
- ),
- );
- if (sampleCount >= this.selection.length) {
- dataList.push({
- ...item,
- measureQuantity: 1, //作为计量数量
- sampleCode: await getCode("sample_code"),
- qualitySampleTemplateList,
- });
- } else {
- if (dataList.length < sampleCount) {
- dataList.push({
- ...item,
- measureQuantity: currentNum1 > 1 ? 1 : currentNum1, //作为计量数量
- sampleCode: await getCode("sample_code"),
- qualitySampleTemplateList,
- });
- currentNum1 -= 1;
- }
- }
- }
- if (sampleCount > this.selection.length) {
- dataList.forEach((item) => {
- if (currentNum > 0) {
- let data = this.selection.find((val) => val.id == item.id);
- item["measureQuantity"] =
- data.measureQuantity - 1 - currentNum > 0 ?
- currentNum + 1 :
- data.measureQuantity;
- currentNum = currentNum - (data.measureQuantity - 1);
- }
- });
- }
- // 更改 从新计算 样品清单 取整样 数据
- if (specifications && specifications.id) {
- dataList.map((el) => {
- el.measureQuantity =
- el.measureQuantity * specifications.packageCellTotal;
- el.weight = this.formatNumber(
- el.measureQuantity,
- el.weightProportion,
- );
- });
- }
- // 更改
- this.sampleList = dataList;
- this.getTotal();
- },
- // 小数点数据判断
- formatNumber(a, b, maxDecimals = 4) {
- if (a == 0 || b == 0 || !a || !b) {
- return 0;
- }
- const product = a * b;
- const rounded = Number(product.toFixed(maxDecimals));
- const str = rounded.toString();
- if (str.indexOf(".") !== -1) {
- return str.replace(/\.?0+$/, "");
- }
- return str;
- },
- //从来源数组取样到目标数组
- async getNewFullSampleList(
- sampleCount,
- sampleQuantity,
- sampleUnit,
- specifications,
- ) {
- const sourceArray = this.selection;
- const isUnitMismatch =
- sourceArray.length > 0 && sourceArray[0].measureUnit !== sampleUnit;
- const items = sourceArray.map((item) => ({
- ...item,
- remainingQuantity: isUnitMismatch ? Infinity : item["measureQuantity"],
- maxPossible: item["measureQuantity"] / sampleQuantity,
- }));
- const result = [];
- let remainingCount = sampleCount;
- let count = Math.ceil(remainingCount);
- const codeList = await this.batchCodes(count);
- let codeIdx = 0;
- while (remainingCount > 0) {
- items.sort(
- (a, b) =>
- b.remainingQuantity / b["measureQuantity"] -
- a.remainingQuantity / a["measureQuantity"],
- );
- let distributed = false;
- for (const item of items) {
- if (
- !isUnitMismatch ||
- (item.remainingQuantity >= sampleQuantity && remainingCount > 0)
- ) {
- let qualitySampleTemplateList = [];
- if (
- item.qualitySampleTemplateList == undefined ||
- item.qualitySampleTemplateList == null ||
- item.qualitySampleTemplateList.length == 0
- ) {
- qualitySampleTemplateList = JSON.parse(
- JSON.stringify(this.schemeList),
- );
- } else {
- qualitySampleTemplateList = item.qualitySampleTemplateList;
- }
- let sampleCode = codeList[codeIdx];
- if (
- this.form.conditionType == 1 &&
- this.form.inspectionStandards == 1
- ) {
- result.push({
- ...item,
- measureQuantity: 1,
- sampleCode,
- qualitySampleTemplateList,
- });
- } else if (this.form.conditionType == 2) {
- let weight = (item.weight / item.maxPossible).toFixed(2);
- result.push({
- ...item,
- measureQuantity: sampleQuantity,
- measureUnit: sampleUnit,
- sampleCode,
- weight,
- qualitySampleTemplateList,
- });
- }
- if (!isUnitMismatch) {
- item.remainingQuantity -= sampleQuantity;
- }
- remainingCount = (remainingCount - 1).toFixed(2);
- codeIdx++;
- distributed = true;
- }
- }
- if (!distributed) {
- break;
- }
- }
- if (this.form.conditionType == 1 && specifications && specifications.id) {
- result.map((el) => {
- el.measureQuantity =
- el.measureQuantity * specifications.packageCellTotal;
- el.weight = this.formatNumber(
- el.measureQuantity,
- el.weightProportion,
- );
- });
- }
- this.sampleList = result;
- if (this.sampleList.length > sampleCount) {
- this.sampleList = this.sampleList.splice(0, sampleCount);
- }
- this.getTotal();
- },
- // 当计量类型 是数量的时候 取整样 校验
- validateSampleQuantity(sampleCount, specifications) {
- let packingUnit = this.selection[0].packingUnit?.trim() || "";
- let totalS = 0;
- let measureQuantityCount = 0;
- let labelKey =
- packingUnit == specifications.conversionUnit.trim() ?
- "packingQuantity" :
- "measureQuantity";
- let labelName = labelKey == "packingQuantity" ? "包装数量" : "计量数量";
- totalS = this.selection.reduce((total, el) => total + el[labelKey], 0);
- let formTotalS = this.tableList.reduce(
- (total, el) => total + el.measureQuantity,
- 0,
- );
- if (sampleCount > totalS) {
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: `所填的条目数量不能超过所选${labelName}总和${totalS}`,
- }, )
- return false;
- }
- if (labelKey == "packingQuantity") {
- measureQuantityCount = sampleCount * this.selection[0].measureQuantity;
- } else {
- measureQuantityCount = sampleCount;
- }
- if (measureQuantityCount > formTotalS - this.workSampleQuantity) {
- this.$refs.uToast.show({
- type: "error",
- icon: false,
- message: `请样数量不能大于${formTotalS - this.workSampleQuantity} ${
- this.selection[0].measureUnit
- }`,
- }, )
- return false;
- }
- return true;
- },
- handleQualityModeChange(val) {
- if (val == 1) {
- this.updatePackingList();
- } else {
- this.sampleList = [];
- this.getTotal();
- }
- },
- // 全检
- async updatePackingList() {
- let list = this.tableList;
- const dataList = [];
- let count = list ? list.length : 0;
- const codeList = await this.batchCodes(count);
- for (const [index, item] of list.entries()) {
- const qualitySampleTemplateList = item.qualitySampleTemplateList?.length ?
- JSON.parse(JSON.stringify(item.qualitySampleTemplateList)) :
- JSON.parse(
- JSON.stringify(
- this.schemeList.map((item) => {
- item["qualityResults"] = 1;
- return item;
- }),
- ),
- );
- dataList.push({
- ...item,
- measureQuantity: item.measureQuantity,
- sampleCode: codeList[index],
- qualitySampleTemplateList,
- });
- }
- this.sampleList = dataList;
- this.getTotal();
- },
- getTotal() {
- this.form.sampleQuantity = this.sampleList
- .reduce((total, el) => total + Number(el.measureQuantity), 0)
- .toFixed(2);
- this.form.sampleWeight = this.sampleList
- .reduce((total, el) => total + Number(el.weight), 0)
- .toFixed(2);
- },
- async batchCodes(count) {
- if (count <= 0) return;
- let params = {
- count
- };
- const res = await getCodeList("sample_code", params);
- return res;
- },
- /* 保存编辑 */
- save(type) {
- if (this.type == "add") {
- [
- "id",
- "code",
- "name",
- "createTime",
- "createUserId",
- "status",
- "approvalStatus",
- "approvalUserId",
- ].forEach((key) => {
- delete this.form[key];
- });
- }
- let data = JSON.parse(JSON.stringify(this.form));
- // 验证
- if (!this.form.qualityWorkOrderCode) {
- uni.showToast({
- title: "请选择质检工单",
- icon: "none"
- });
- return;
- }
- if (!this.form.qualityMode) {
- uni.showToast({
- title: "请选择质检方式",
- icon: "none"
- });
- return;
- }
- if (!this.form.recordingMethod) {
- uni.showToast({
- title: "请选择记录方法",
- icon: "none"
- });
- return;
- }
- if (this.form.qualityMode == "2" && !this.form.conditionType) {
- uni.showToast({
- title: "请选择请样类型",
- icon: "none"
- });
- return;
- }
- if (!this.sampleList.length) {
- uni.showToast({
- title: "样品清单不能为空!",
- icon: "none"
- });
- return;
- }
- //抽检
- if (data.qualityMode == 2) {
- //取整样
- if (data.conditionType == 1) {
- data.quantity = data.portion;
- } else {
- data.copies = data.portion;
- }
- }
- data.measureUnit = this.sampleList[0].measureUnit;
- let api = this.type == "add" ? samplingrecordSave : samplingrecordUpdate;
- this.loading = true;
- api({
- ...data,
- sampleList: this.sampleList,
- })
- .then((res) => {
- this.loading = false;
- uni.showToast({
- title: "操作成功",
- icon: "success"
- });
- if (type == "submit") {
- this.approvalSubmit(this.type == "add" ? res : data.id);
- } else {
- this.cancel();
- this.$emit("reload");
- }
- })
- .catch(() => {
- this.loading = false;
- });
- },
- async approvalSubmit(id) {
- const res = await getById(id);
- this.processSubmitDialogFlag = true;
- this.$nextTick(() => {
- let params = {
- businessId: res.id,
- businessKey: "sampling_approval_process",
- formCreateUserId: res.createUserId,
- variables: {
- businessCode: res.code,
- businessName: "请样",
- businessType: res.qualityWorkOrderVO.conditionType == 1 ? "整样" : "小样",
- },
- };
- this.$refs.processSubmitDialogRef.init(params);
- });
- },
- search() {
- this.cancel();
- this.$emit("reload");
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .popup-content {
- width: 100vw;
- height: 90vh;
- background: #fff;
- border-radius: 0;
- display: flex;
- flex-direction: column;
- }
- .popup-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx;
- border-bottom: 1rpx solid #e5e5e5;
- .popup-title {
- font-size: 36rpx;
- font-weight: bold;
- color: #333;
- }
- .close-btn {
- width: 60rpx;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 60rpx;
- color: #999;
- line-height: 1;
- }
- }
- .popup-body {
- flex: 1;
- overflow-y: auto;
- padding: 0 30rpx 30rpx;
- }
- .form-section {
- margin-top: 30rpx;
- .section-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333;
- margin-bottom: 20rpx;
- padding-left: 20rpx;
- border-left: 6rpx solid #157a2c;
- }
- .form-row {
- margin-bottom: 20rpx;
- .form-item {
- display: flex;
- align-items: center;
- padding: 20rpx 0;
- border-bottom: 1rpx solid #f5f5f5;
- .label {
- width: 150rpx;
- font-size: 28rpx;
- color: #333;
- flex-shrink: 0;
- &::after {
- content: ":";
- }
- }
- .value-wrap {
- flex: 1;
- min-height: 60rpx;
- display: flex;
- align-items: center;
- position: relative;
- &.disabled {
- opacity: 0.6;
- }
- .arrow {
- color: #999;
- font-size: 40rpx;
- line-height: 1;
- }
- }
- }
- }
- }
- .table-info {
- padding: 20rpx;
- font-size: 28rpx;
- color: #666;
- background: #f9f9f9;
- border-radius: 8rpx;
- margin-bottom: 20rpx;
- }
- .table-wrapper {
- border: 1rpx solid #e5e5e5;
- border-radius: 8rpx;
- overflow: hidden;
- max-height: 400rpx;
- }
- .table-scroll {
- width: 100%;
- height: 400rpx;
- }
- .source-table {
- min-width: 100%;
- width: 950rpx;
- }
- .table-header {
- display: flex;
- background: #f5f5f5;
- z-index: 10;
- min-width: 100%;
- box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.05);
- .table-cell {
- padding: 20rpx 10rpx;
- font-size: 26rpx;
- font-weight: bold;
- color: #333;
- text-align: center;
- border-right: 1rpx solid #e5e5e5;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- flex-shrink: 0;
- &.select-cell {
- width: 80rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 20rpx;
- }
- &:nth-child(2) {
- width: 300rpx;
- }
- &:nth-child(3),
- &:nth-child(4),
- &:nth-child(5),
- &:nth-child(6) {
- width: 140rpx;
- }
- &:last-child {
- border-right: none;
- }
- }
- }
- .sample-table {
- min-width: 100%;
- width: 1040rpx;
- }
- .table-body {
- .table-row {
- display: flex;
- border-bottom: 1rpx solid #e5e5e5;
- &:last-child {
- border-bottom: none;
- }
- .table-cell {
- padding: 20rpx 10rpx;
- font-size: 24rpx;
- color: #666;
- text-align: center;
- border-right: 1rpx solid #e5e5e5;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- flex-shrink: 0;
- &.select-cell {
- width: 80rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 20rpx;
- }
- &:nth-child(2) {
- width: 300rpx;
- }
- &:nth-child(3),
- &:nth-child(4),
- &:nth-child(5),
- &:nth-child(6) {
- width: 140rpx;
- }
- &:last-child {
- border-right: none;
- }
- }
- }
- .table-empty {
- padding: 60rpx 0;
- text-align: center;
- font-size: 28rpx;
- color: #999;
- }
- }
- // 样品信息表格特定样式
- .sample-table {
- .table-header {
- .table-cell {
- &:nth-child(1) {
- width: 200rpx;
- }
- &:nth-child(2) {
- width: 250rpx;
- }
- &:nth-child(3),
- &:nth-child(4),
- &:nth-child(5),
- &:nth-child(6) {
- width: 140rpx;
- }
- }
- }
- .table-body {
- .table-cell {
- &:nth-child(1) {
- width: 200rpx;
- }
- &:nth-child(2) {
- width: 250rpx;
- }
- &:nth-child(3),
- &:nth-child(4),
- &:nth-child(5),
- &:nth-child(6) {
- width: 140rpx;
- }
- }
- }
- }
- .confirm-btn-wrap {
- margin-top: 20rpx;
- padding: 0 20rpx;
- }
- .popup-footer {
- display: flex;
- padding: 20rpx 30rpx;
- border-top: 1rpx solid #e5e5e5;
- gap: 20rpx;
- /deep/ .u-button {
- flex: 1;
- }
- }
- </style>
|