<!-- 日志详情 mlog信息以及mlogb -->
<template>
	<el-drawer v-model="visible" :size="'95%'" :show-close="false" destroy-on-close="true"> 
		<template #header>
			<h4>日志详情</h4>
			<el-button type="danger" @click="closedPage()">关闭</el-button>
		</template>
		<div>
			<el-card style="width: 100%" header="基本信息" shadow="never">
				<el-descriptions>
					<el-descriptions-item label="工艺路线" v-if="!mlogItem.is_fix" style="width: 100%;">
						{{mlogItem.material_in_name}}->{{mlogItem.material_out_name}}
					</el-descriptions-item>
					<el-descriptions-item label="返工" v-if="mlogItem.is_fix">
						<span v-if="mlogItem.material_in_name!==null">{{mlogItem.material_in_name}}</span>
						<span v-if="mlogItem.material_out_name!==null">->{{mlogItem.material_out_name}}</span>
					</el-descriptions-item>
				</el-descriptions>
				<el-descriptions>
					<el-descriptions-item label="工段名称">{{mlogItem.mgroup_name}}</el-descriptions-item>
					<el-descriptions-item label="生产设备" v-if="mlogItem.equipment_name!==null">{{mlogItem.equipment_name}}</el-descriptions-item>
					<el-descriptions-item label="部门/车间">{{mlogItem.belong_dept_name}}</el-descriptions-item>
					<el-descriptions-item label="处理人">{{mlogItem.handle_user_name}}</el-descriptions-item>
					<template v-for="item in oinfo_json" :key="item">
						<el-descriptions-item :label="item.key" v-if="item.key!=='imageUrl'">{{item.value}}</el-descriptions-item>
					</template>
					<el-descriptions-item label="创建时间">{{mlogItem.create_time}}</el-descriptions-item>
					<el-descriptions-item label="操作日期">{{mlogItem.handle_date}}</el-descriptions-item>
					<el-descriptions-item label="开始时间">{{mlogItem.work_start_time}}</el-descriptions-item>
					<el-descriptions-item label="结束时间">{{mlogItem.work_end_time}}</el-descriptions-item>
					<el-descriptions-item label="指导文件" v-if="route_file!==null">
						<el-button @click="showFile">查看</el-button>
					</el-descriptions-item>
					<el-descriptions-item label="工艺图纸" v-if="imageUrl!==null">
						<el-image
							style="width: 100px; height: 100px"
							:src="imageUrl"
							:zoom-rate="1.2"
							:max-scale="7"
							:min-scale="0.2"
							:preview-src-list="srcList"
							show-progress
							:initial-index="0"
							fit="fill"
						/>
					</el-descriptions-item>
					<el-descriptions-item label="工序路径">
						<el-tag v-if="lastProcessName!==''" type="danger">{{ lastProcessName }}</el-tag>
						<span v-if="lastProcessName!==''">—></span>
						<el-tag v-if="currentProcessName!==''" type="success">{{ currentProcessName }}</el-tag>
						<span v-if="nextProcessName!==''">—></span>
						<el-tag v-if="nextProcessName!==''" type="primary">{{ nextProcessName }}</el-tag>
					</el-descriptions-item>
					
				</el-descriptions>
				<div style="padding: 5px 10px;display: flex;justify-content: end;">
					<el-button
						type="primary"
						v-if="mlogItem.submit_time == null"
						@click="mlogUpdate"
						style="margin-right: 10px;"
						v-auth="'mlog.update'"
					>
						编辑
					</el-button>
					<el-button
						type="primary"
						v-if="mlogItem.submit_time == null"
						:loading="isSaveing"
						@click="mlogSubmit"
						>提交</el-button
					>
				</div>
			</el-card>
			<!-- 子工序操作记录 该工序拥有子工序-->
			<el-card
				v-if="processOptions.length>0"
				style="width: 100%; margin: 1vh 0;position: relative"
				header="子工序操作记录"
				shadow="never"
			>
				<sc-form-table
					hideDelete
					:tableHeight="tableHeight"
					v-model="processLists"
					:addTemplate="addTemplate"
					placeholder="暂无数据"
				>
					<el-table-column label="工序">
						<template #default="scope">
							<el-select
								v-if="scope.row.isEdit"
								v-model="scope.row.process"
								placeholder="请选择子工序"
								class="width-100"
							>
								<el-option
									v-for="item in processOptions"
									:key="item.id"
									:label="item.name"
									:value="item.id"
								></el-option>
							</el-select>
							<div v-else>
								<span v-if="scope.row.process!==null">{{ scope.row.process_name}}</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column label="操作人">
						<template #default="scope">
							<ehsSelect
								v-if="scope.row.isEdit"
								v-model="scope.row.handle_user"
								:showName="scope.row.handle_user_name"
								:apiObj="this.$API.system.user.list"
								:params="{ depts: dept }"
								class="width-100"
							></ehsSelect>
							<div v-else>
								<span v-if="scope.row.handle_user_name!==null">{{ scope.row.handle_user_name}}</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column label="使用设备">
						<template #default="scope">
							<el-select
								v-if="scope.row.isEdit"
								v-model="scope.row.equipment"
								placeholder="设备"
								class="width-100"
							>
								<el-option
									v-for="item in equipmentOtions"
									:key="item.id"
									:label="item.name"
									:value="item.id"
								>
								</el-option>
							</el-select>
							<div v-else>
								<span v-if="scope.row.equipment!==null">{{ scope.row.equipment_name}}</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column label="操作时间">
						<template #default="scope">
							<el-date-picker
								v-if="scope.row.isEdit"
								v-model="scope.row.work_start_time"
								type="datetime"
								value-format="YYYY-MM-DD HH:mm"
								formatter="YYYY-MM-DD HH:mm"
								style="width: 100%;"
							/>
							<div v-else>
								<span v-if="scope.row.work_start_time!==null">{{ scope.row.work_start_time}}</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column label="班次" prop="shift_name">
						<!-- <template #default="scope">
							<el-select
								v-if="scope.row.isEdit"
								v-model="scope.row.shift"
								placeholder="班次"
								class="width-100"
							>
								<el-option
									v-for="item in shiftOtions"
									:key="item.id"
									:label="item.name"
									:value="item.id"
								>
								</el-option>
							</el-select>
							<div v-else>
								<span v-if="scope.row.shift_name!==null">{{ scope.row.shift_name}}</span>
							</div>
						</template> -->
					</el-table-column>
					<el-table-column label="操作" fixed="right" align="center" width="150px">
						<template #default="scope">
							<el-button v-if="scope.row.isEdit" type="success" @click="saveMuserSubmit(scope.row)">保存</el-button>
							<el-button v-else type="danger" @click="table_muser_del(scope.row)">删除</el-button>
						</template>
					</el-table-column>
				</sc-form-table>
			</el-card>
			<!-- 输入物料 -->
			<el-card
				style="width: 100%; margin: 1vh 0;position: relative"
				header="输入物料"
				shadow="never"
			>
				<el-button
					type="primary"
					v-if="mlogItem.submit_time == null&&(mlogItem.ticket==null||(mlogItem.ticket_&&mlogItem.ticket_.state_.type==1))"
					icon="el-icon-plus"
					@click="table_add"
					style="position: absolute; left: 100px; top: 5px"
				>新增</el-button>
				<span class="warningText" v-if="route_code=='ladansi'||route_code=='yicifusi'||route_code=='ercifusi'">注：请扫码录入单个棒！一个棒对应一个日志，方便于采集数据对应</span>
				<span class="warningText" v-if="route_code=='paiyicibang'||route_code=='paiban'">注：请输入单个棒的料！一个棒的料对应一个日志，方便于自动排号</span>
				<span class="warningText" v-if="route_code=='zlybcl'">请扫码录入单个板段，一个板段对应一个日志，方便于采集数据对应</span>
				<scTable
					ref="tableIn"
					:apiObj="apiObj"
					row-key="id"
					stripe
					:params="paramsIn"
					hidePagination   
					hideDo                                                
				>
					<el-table-column type="index" width="50" />
					<el-table-column
						label="物料"
						prop="material_in_name"
						show-overflow-tooltip
					></el-table-column>
					<el-table-column label="批次号" prop="batch">
					</el-table-column>
					<el-table-column label="领用数量" prop="count_use">
					</el-table-column>
					<el-table-column label="主要批次" prop="is_main_batchin">
						<template #default="scope">
							<el-tag :type="scope.row.parent==null ? 'success': 'info'">
								{{scope.row.parent==null ? '是' : '否'}}
							</el-tag>
						</template>
					</el-table-column>
					<el-table-column
						label="创建时间"
						prop="create_time"
						show-overflow-tooltip
					>
					</el-table-column>
					<el-table-column
						label="操作"
						fixed="right"
						align="center"
						width="160px"
					>
						<template #default="scope">
							<el-button
								type="primary"
								@click="table_in_edit(scope.row)"
								v-if="mlogItem.submit_time== null&&mlogItem.material_in_&&mlogItem.material_in_.tracking==10"
							>编辑</el-button>
							<el-button
								type="warning"
								v-if="mlogItem.material_in_&&mlogItem.material_in_.tracking==20"
								@click="table_out_check_single(scope.row,'ins')"
							>详情</el-button>
							<el-button
								:disabled="mlogItem.submit_time !== null"
								type="danger"
								style="margin-left: 10px;"
								@click="table_in_del(scope.row)"
							>删除</el-button>
						</template>
					</el-table-column>
				</scTable>
			</el-card>
			<!-- 输入物料编辑 -->
			<el-dialog v-model="saveInDialog" title="编辑">
				<el-form
					:model="saveInForm"
					:rules="rules"
					label-width="100px"
					ref="saveInForm"
				>
					<el-row>
						<el-col :span="23">
							<el-form-item label="领取数量" prop="count_use">
								<el-input-number
									v-model="saveInForm.count_use"
									:min="1"
									style="width: 100%"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
						<el-col :span="23" v-if="base_code!=='bxerp'">
							<el-form-item label="加工前不良" prop="count_pn_jgqbl">
								<el-input-number
									v-model="saveInForm.count_pn_jgqbl"
									:min="0"
									style="width: 100%"
									controls-position="right"
								/>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
				<template #footer>
					<el-button
						type="primary"
						:loading="isSaveing"
						@click="saveInSubmit()"
						>保 存</el-button
					>
				</template>
			</el-dialog>
			<!-- 输出物料  输出物料追踪类型为批次-->
			<el-card v-if="mlogItem.material_out_&&mlogItem.material_out_.tracking==10" style="width: 100%;margin-bottom:1vh" header="输出物料" shadow="never">
				<scTable
					ref="tableOut"
					:apiObj="apiObj"
					row-key="id"
					stripe
					height="250px"
					:params="paramsOut"
					hidePagination
				>
					<el-table-column type="index" width="50" />
					<el-table-column
						label="产出物料"
						prop="material_out_name"
						show-overflow-tooltip
					></el-table-column>
					<el-table-column label="批次号" prop="batch">
					</el-table-column>
					<el-table-column label="数量" prop="count_real">
					</el-table-column>
					<el-table-column label="合格数" prop="count_ok">
					</el-table-column>
					<el-table-column label="不合格数量" prop="count_notok">
					</el-table-column>
					<el-table-column
						label="创建时间"
						prop="create_time"
						show-overflow-tooltip
					>
					</el-table-column>
					<el-table-column
						label="操作"
						fixed="right"
						align="center"
						width="160px"
					>
						<template #default="scope">
							<el-button
								 type="primary"
								 v-if="mlogItem.submit_time == null&&(mlogItem.material_out_&&mlogItem.material_out_.tracking==10||scope.row.material_out_tracking==10)"
								 style="margin-right: 10px;"
								@click="table_out_check(scope.row)"
							>编辑</el-button>
						</template>
					</el-table-column>
				</scTable>
			</el-card>
			<!-- 输出物料  输出物料追踪类型为单个-->
			<el-card v-else style="width: 100%;margin-bottom:1vh" header="输出物料" shadow="never">
				<check-table
					v-if="checkTableShow"
					ref="checkTable"
					:mlogId="mlogId"
					:qct="mlogItem.qct"
					:wm = "wm"
					:dept="deptId"
					:mgroup="mgroup"
					:cutCount="cutCount"
					:material_in="materialIn"
					:material_out="mlogItem.material_out"
					:mgroupName= "mlogItem.mgroup_name"
					:test_file="mlogItem.test_file"
					:isSubmit="isSubmit"
					:batchNumber="batchNumber"
					:handle_user="mlogItem.handle_user"
					:handle_date="mlogItem.handle_date"
					:processType="processType"
					style="width: 100%;height: 500px;"
				></check-table>
			</el-card>
			<save-dialog
				v-if="dialog.save"
				ref="saveDialog"
				:mlog="mlogId"
				:mgroup="mgroup"
				:isfix = "mlogItem.is_fix"
				:routeId ="routeId"
				:tracking="tracking"
				:material_in="materialIn"
				:hasRoute = "hasRoute"
				:process="process"
				@success="handleSaveSuccess"
				@closed="saveMlogbInClose"
			>
			</save-dialog>
			<check-dialog
				v-if="dialog.check"
				ref="checkDialog"
				:material="materialOut"
				@success="handleCheckSuccess"
				@closed="checkDialogClose"
			>
			</check-dialog>
			<scheck-dialog
				v-if="dialog.check_single"
				ref="checkDialogSingle"
				:mlogb="mlogb"
				:wm = "wm"
				:dept="deptId"
				:mgroup="mgroup"
				:material_in="material_in"
				:material_out="material_out"
				:mgroupName= "mlogItem.mgroup_name"
				:isSubmit="isSubmit"
				:batchNumber="batchNumber"
				:handle_user="handle_user"
				:handle_date="handle_date"
				:processType="processType"
				@success="handlesCheckSuccess"
				@closed="scheckClose"
			></scheck-dialog>
			<edit-dialog
				v-if="dialog.edit"
				ref="editDialog"
				:dept="dept"
				:process="process"
				:mgroupName= "mlogItem.mgroup_name"
				@success="handleEditSuccess"
				@closed="dialog.edit = false"
			>
			</edit-dialog>
			<el-dialog v-model="printVisible" width="1200px">
				<print :baseData="mlogItem" :tableData="tableData" :tableData2="tableData2" type="102"  @closePrint="printVisible=false"/>
			</el-dialog>
		</div>
		<div v-if="fileVisible" class="file_show">
			<div style="display: flex;justify-content: flex-end;padding: 10px 20px;">
				<el-icon size="30" class="el-dialog__close" @click="fileVisible=false"><el-icon-close/></el-icon>
			</div>
			<iframe :src="route_file"  style="width: 100%;height: 90%;">预览</iframe>
		</div>
	</el-drawer>
</template>
<script>
import editDialog from "./mlog_form.vue";
import saveDialog from "./mlogb_form.vue";
import checkDialog from "./mlogb_check.vue";
import scheckDialog from "./mlogbw_check.vue";
import checkTable from "./mlogbw_check_table.vue";
import print from "./../setting/print/A4.vue";
export default {
	props: {
		mlogId: {
			type: String,
			default: "",
		},
		process:{
			type: String,
			default: "",
		},
		dept:{
			type: String,
			default: "",
		},
		mgroup:{
			type: String,
			default: "",
		},
		processType:{
		    type: String,
			default: "",
		}
	},
	components: {
		checkTable,
		editDialog,
		saveDialog,
		checkDialog,
		scheckDialog,
		print
	},
	emits: ["success", "closed"],
	data() {
		return {
			base_code: this.$TOOL.data.get('BASE_INFO').base.base_code,
			loading: false,
			//表单数据
			form: {},
			dialog: {
				save: false,
				edit: false,
				check: false,
				print_m:false,
				check_single: false,
			},
			apiObj: null,
			imageUrl:null,
			apiObjMuser:null,
			paramsIn: {
				page: 0,
				mlog: "",
				parent__isnull:true,
				with_children:'yes',
				material_in__isnull: 0,
			},
			paramsOut: {
				page: 0,
				mlog: "",
				material_out__isnull: 0,
			},
			paramsMuser:{
				mlog:""
			},
			tracking:10,
			mlogb:"",
			mlogItem: {},
			saveInForm: {
				count_use: 0,
				count_pn_jgqbl: 0,
			},
			srcList:[],
			fileList:[],
			options: [],
			tableData:[],
			tableData2:[],
			oinfo_json:[],
			mlogbwlist:[],
			// shiftOtions:[],
			tableDataWm:[],
			qct_defects:[],
			equipmentOtions:[],
			defectOptions:[],
			qct_testitems:[],
			processLists:[],
			processOptions:[],
			test_file:'',
			deptId: "",
			isSingle:true,
			hideAdd: true,
			visible: false,
			isSaveing: false,
			canMultiple:false,
			printVisible:false,
			saveInDialog: false,
			checkTableShow:false,
			setFiltersVisible: false,
			rules: {
				count_use: [{required: true,message: "请输入领取数量",trigger: "blur"}],
				process:[{required: true,message: "请选择工序",trigger: "blur"}],
				shift:[{required: true,message: "请选择班次",trigger: "blur"}],
				work_start_time:[{required: true,message: "请选择开始时间",trigger: "blur"}],
				handle_user:[{required: true,message: "请选择操作人",trigger: "blur"}],
				process:[{required: true,message: "请选择子工序",trigger: "blur"}],
				equipment:[{required: true,message: "请选择设备",trigger: "blur"}],
			},
			route_file:null,
			handle_date:'',
			handle_user:'',
			wm:'',
			route_code:'',
			materialOut:'',
			material_in:'',
			material_out:'',
			batchContains:'',
			lastProcessName:'',
			nextProcessName:'',
			currentProcessName:'',
			apiObjPrint:this.$API.cm.labelmat.fromWm,
			printer_name:localStorage.getItem("printer_name"),
			addTemplate:{
				mlog: "",
				shift:"",
                process: "",
				equipment: "",
                handle_user: "",
				work_start_time: "",
				handle_user_name: "",
                isEdit: true,
            },
			qct:null,
			defectlist:[],
			cutCount:0,
			batchNumber:'',
			hasRoute:false,
			isSubmit:false,
			fileVisible:false,
		};
	},
	mounted() {
		let that = this;
		that.mlogItem = {};
		this.paramsIn.mlog = "";
		this.paramsOut.mlog = "";
		this.apiObj = "";
		this.route_code = this.$route.path.split("/")[2];
		this.paramsIn.mlog = this.mlogId;
		this.paramsOut.mlog = this.mlogId;
		this.apiObj = this.$API.wpm.mlogb.list;
		let userInfo = that.$TOOL.data.get("USER_INFO");
		that.addTemplate.equipment = "";
		that.addTemplate.handle_user = userInfo.id;
		that.addTemplate.handle_user_name = userInfo.name;
		that.addTemplate.work_start_time = this.$TOOL.dateFormat(new Date());
		that.$API.wpm.mlogb.list.req(that.paramsIn).then((res) => {
			that.tableData = res;
		})
		that.getMlogItem();
		that.getPreocess();
		// that.getShift();
		that.getEquipment();
		that.getProcessList();
	},
	methods: {
		open() {
			this.visible = true;
		},
		getMlogItem() {
			let that = this;
			that.$API.wpm.mlog.item.req(that.mlogId).then((res) => {
				that.mlogItem = res;
				that.addTemplate.mlog = that.mlogItem.id;
				that.isSubmit = res.submit_time==null?false:true;
				if(that.processType=='10'&&that.mlogItem.material_out_&&that.mlogItem.material_out_.tracking==20){
					that.getMlogbw();
				}
				if(res.route!==null){
					that.hasRoute = true;
					that.$API.mtm.route.item.req(res.route).then((routeRes) => {
						let params_json = routeRes.params_json;
						that.currentProcessName = routeRes.process_name;
						that.getroutepack(routeRes.material_in,routeRes.material_out,routeRes.routepack);
						if(params_json.fileurl){
							let fileurl = JSON.parse(params_json.fileurl);
							that.imageUrl = fileurl[0].path;
							that.srcList.push(fileurl[0].path);
						}
					})
				}
				that.oinfo_json = [];
				if(res.oinfo_json_&&res.oinfo_json_!==null){
					for(let key in res.oinfo_json_){
						let obj = {};
						obj.key = key;
						obj.value = res.oinfo_json_[key];
						that.oinfo_json.push(obj);
					}
				}
				that.routeId = res.route;
				that.tracking = res.material_in_!==null?res.material_in_.tracking:null;
				if(res.test_file!==null){
					that.fileList = [{name:res.test_file,url:res.test_file}];
					that.form.test_file = res.test_file;
				}
				that.materialIn = res.material_in!==null?res.material_in:res.mlogb_full[0]?res.mlogb_full[0].material_in:null;
				that.deptId = res.belong_dept;
				that.checkTableShow = true;
				that.apiObjWm = that.$API.wpm.wmaterial.list;
				that.$API.wpm.mlogb.list.req(that.paramsOut).then((res) => {
					that.tableData2 = res;
				})
				if(!res.is_fix){
					that.getcutCount(res.material_in);
					that.$API.mtm.routepack.list.req({page:0,search:res.routepack_name}).then((res) => {
						that.route_file = res[0].document_!==null?res[0].document_.path:null;
					})
				}
			});
		},
		getroutepack(inId,outId,routepack){
			let that = this;
			that.$API.mtm.route.list.req({routepack:routepack,page:0}).then(res=>{
				res.forEach(item=>{
					//上一道工序
					if(item.material_out==inId){
						that.lastProcessName = item.process_name;
					}
					//下一道工序
					if(item.material_in==outId){
						that.nextProcessName = item.process_name;
					}
				})
			})
		},
		getEquipment(){
			let that = this;
			that.$API.em.equipment.list.req({page:0,belong_dept:that.dept}).then((res) => {
				that.equipmentOtions = res;
			})
		},
		//获取指定工序的切分数量
		getcutCount(material_id){
			let that = this;
			that.$API.mtm.route.list.req({ nprocess_name: "板段滚圆", material_in_has:material_id, page: 0,query:'{div_number}' }).then((res) => {
				if(res.length>0){
					that.cutCount = res[0].div_number;
				}
			});
		},
		getPreocess(){
			let that = this;
			that.$API.mtm.process.list.req({page:0,parent:that.process}).then((res) => {
			    that.processOptions = res;
				if(res.length>0){
					that.paramsMuser.mlog = that.mlogId;
					that.apiObjMuser = that.$API.wpm.mloguser.list;
				}
			})
		},
		getProcessList(){
			let that = this;
			that.$API.wpm.mloguser.list.req({page:0,mlog:that.mlogId}).then((res) => {
			    that.processLists = res;
			})
		},
		getShift(){
			let that = this;
			that.$API.mtm.shift.list.req({ page: 0 }).then((res) => {
				that.shiftOtions = res;
			});
		},
		getMlogbw(){
		    let that = this;
			let params = {};
			that.mlogbwlist = [];
			params.page = 0;
			params.type = 'out';
			params.mlogb__mlog = that.mlogId;
			that.$API.wpm.mlogbw.list.req(params).then((res) => {
				if(res.length>0){
					res.forEach((item) => {
						let obj = {};
					    obj = Object.assign({},item);
                    	obj.isEdit = false;
						if(item.ftest!=null){
							if(item.ftest.ftestdefects!==undefined&&item.ftest.ftestdefects!==''&&item.ftest.ftestdefects!==null&&item.ftest.ftestdefects.length>0){
								item.ftest.ftestdefects.forEach((item1) => {
									obj[item1.defect_name] = item1.has;
								})
							}
							if(item.ftest.ftestitems!==undefined&&item.ftest.ftestitems!==''&&item.ftest.ftestitems!==null&&item.ftest.ftestitems.length>0){
								item.ftest.ftestitems.forEach((item2) => {
									obj[item2.testitem_name] = item2.test_val_json;
								})
							}
						}else{
							that.qct_defects.forEach((item1) => {
								obj[item1.defect_name] = false;
							})
							that.qct_testitems.forEach((item2) => {
								obj[item2.testitem_name] = null;
							})
						}
						that.mlogbwlist.push(obj);
					})
				}
			})
		},
		//输出编辑
		formTableEdit(row) {
            let that = this;
            that.mlogbwlist.forEach((item, index) => {
				if (item.id == row.id) {
					that.mlogbwlist[index].isEdit = true;
					let date = new Date();
					if(that.mlogbwlist[index].work_start_time==''||that.mlogbwlist[index].work_start_time==null){
						that.mlogbwlist[index].work_start_time = that.$TOOL.dateFormat(date, 'yyyy-MM-dd hh:mm:ss');
					}
				}
			});
        },
		//输出保存
		formTableSave(row) {
			let that = this;
			let obj = {};
			obj.number = row.number;
			obj.mlogb = row.mlogb;
			obj.wpr = row.wpr;
			obj.note = row.note;
			//qct不为空，有检验表
			if(that.qct!==''&&that.qct!==null){
				that.qct_defects_origin.forEach(item => {
					if(item.rule_expression!==''&&item.rule_expression!==undefined&&item.rule_expression!==null){
						let str = item.rule_expression.replace(/`/g, '');
						str = str.replace(/\${(.*?)}/g, 'row.\$1')
						let judge = eval(str);
						row[item.defect_name] = judge;
					}
				});
				obj.ftest = {};
				obj.ftest.ftestitems = [];
				obj.ftest.ftestdefects = [];
				obj.ftest.qct = that.qct;
				obj.ftest.test_date = that.handle_date!=null?that.handle_date:that.currentDate;
				obj.ftest.test_user = that.handle_user;
				if(that.qct_defects.length>0){
					that.qct_defects.forEach((item) => {
						let itemObj = {};
						itemObj.defect = item.defect;
						itemObj.test_user = that.handle_user;
						itemObj.has = row[item.defect_name]?row[item.defect_name]:false;
						obj.ftest.ftestdefects.push(itemObj);
					})
				}
				if(that.qct_testitems.length>0){
					that.qct_testitems.forEach((item1) => {
						let itemObj1 = {};
						itemObj1.testitem = item1.testitem;
						itemObj1.test_user = that.handle_user;
						itemObj1.addto_wpr = item1.addto_wpr;
						itemObj1.test_val_json = row[item1.testitem_name];
						obj.ftest.ftestitems.push(itemObj1);
					})
				}
			}else{
				obj.ftest = null;
			}
            if(row.id!==''&&row.id!==undefined&&row.id!==null){
				obj.id = row.id;
				that.$API.wpm.mlogbw.update.req(row.id,obj).then((res) => {
					that.$message.success("保存成功");
					that.getMlogbw();
					return res;
				}).catch((err) => {
					return err;
				});
			}else{
				that.$API.wpm.mlogbw.create.req(obj).then((res) => {
					that.$message.success("添加成功");
					that.getMlogbw();
					return res;
				}).catch((err) => {
					return err;
				});
			}
		},
		//输出取消编辑
		formTableCancel(row){
			this.mlogbwlist.forEach((item, index) => {
				if (item.id == row.id) {
					this.mlogbwlist[index].isEdit = false;
				}
			});
		},
		formTableDelet(row){
			this.mlogbwlist.pop();
		},
		//删除
		formTableDel(id) {
            let that = this;
			that.$confirm(`确定删除吗？`, "提示", {
				type: "warning",
			}).then(() => {
                that.$API.wpm.mlogbw.delete.req(id).then((res) => {
					// that.getList();
                    that.$message.success("删除成功");
                }).catch((err) => {
                    return err;
                });
            }).catch(() => {});
		},
		//表单注入数据
		setData(data) {
			Object.assign(this.form, data);
			// this.getRoute(data.id);
		},
		showFile(){
			this.fileVisible = true;
		},
		//编辑
		mlogUpdate() {
			this.dialog.edit = true;
			this.$nextTick(() => {
				this.$refs.editDialog.open("edit",'rework').setData(this.mlogItem);
			});
		},
		table_add() {
			this.dialog.save = true;
			this.$nextTick(() => {
				this.$refs.saveDialog.open();
			});
		},
		mlogbinSuccess(){
			this.$refs.tableIn.refresh();
			this.$refs.tableOut.refresh();
		},
		//自检
		table_in_edit(row) {
			this.saveInForm = row;
			this.saveInDialog = true;
		},
		//提交自检
		saveInSubmit() {
			let that = this;
			that.$refs.saveInForm.validate(async (valid) => {
				if (valid) {
					that.isSaveing = true;
					let obj = {};
					obj.count_use = that.saveInForm.count_use;
					obj.count_pn_jgqbl = that.saveInForm.count_pn_jgqbl;
					that.$API.wpm.mlogb.updateIn
						.req(that.saveInForm.id, obj)
						.then((res) => {
							that.isSaveing = false;
							that.$message.success("操作成功");
							that.saveInDialog = false;
							that.$refs.tableIn.refresh();
							that.$refs.tableOut.refresh();
						})
						.catch(() => {
							that.isSaveing = false;
						});
				}
			});
		},
		table_in_del(row) {
			let that = this;
			that.$confirm("确定删除吗？").then(() => {
				that.$API.wpm.mlogb.delIn.req(row.id).then((res) => {
					that.$message.success("操作成功");
					that.$refs.tableIn.refresh();
					if(that.mlogItem.material_out_&&that.mlogItem.material_out_.tracking==10){
						that.$refs.tableOut.refresh();
					}else{
						that.$refs.checkTable.refreshfun();
					}
					//删除in记录后，out也要删除相应的记录
				});
			});
		},
		table_out_check(row) {
			this.dialog.check = true;
			this.materialOut = row.material_out;
			let obj = {};
			Object.assign(obj, row);
			obj.mgroup_name = this.mlogItem.mgroup_name;
			this.$nextTick(() => {
				this.$refs.checkDialog.open(obj);
			});
		},
		table_out_check_single(row,type){
			let that = this;
			that.mlogb = row.id;
			that.wm = row.wm_in;
			that.batchNumber = row.batch;
			that.material_in = row.material_in;
			that.material_out = row.material_out;
			that.handle_date=that.mlogItem.handle_date;
			that.handle_user = that.mlogItem.handle_user;
			that.dialog.check_single = true;
			that.qct = row.qct;
			that.$nextTick(() => {
				that.$refs.checkDialogSingle.open(type,that.qct);
			});
		},
		//表单提交方法
		mlogSubmit() {
			let that = this;
			if(that.route_code=='tuomoceliang'){
				let canSubmit = this.$refs.checkTable.hasNull();
				console.log('canSubmit',canSubmit)
				if(canSubmit){
					that.submitFun();
				}else{
					that.$message.error('有未填的检测项，请完善后提交。');
				}
			}else{
				that.submitFun();
			}
		},
		submitFun(){
			let that = this;
			that.isSaveing = true;
			that.$API.wpm.mlog.submit.req(that.mlogItem.id).then((res) => {
				that.isSaveing = false;
				that.visible = false;
				that.$emit('closed',false);
				that.$message.success("操作成功");
			}).catch(() => {
				that.isSaveing = false;
			});
		},
		saveMuserSubmit(row){
			let that = this;
			that.isSaveing = true;
			row.mlog = that.mlogId;
			that.$API.wpm.mloguser.create.req(row).then((res) => {
				that.isSaveing = false;
				that.$message.success("操作成功");
				that.getProcessList();
			}).catch(() => {
				that.isSaveing = false;
			})
		},
		table_muser_del(row){
			let that = this;
			that.$confirm("确定删除吗？").then(res=>{
				that.$API.wpm.mloguser.delete.req(row.id).then((res) => {
					that.$message.success("删除成功");
					that.getProcessList();
				})
			})
		},
		table_muser_edit(row){
			let that = this;
			console.log('row',row);
			let index = that.processLists.indexOf(row);
			console.log('index',index);
			that.processLists[index].isEdit = true;

		},
		handleSaveSuccess() {
			this.$refs.tableIn.refresh();
			if(this.mlogItem.material_out_&&this.mlogItem.material_out_.tracking==10){
				this.$refs.tableOut.refresh();
			}else{
				this.$refs.checkTable.refreshfun();
			}
		},
		handleCheckSuccess() {
			this.$refs.tableOut.refresh();
		},
		handlesCheckSuccess(){
			this.$refs.tableIn.refresh();
			this.$refs.tableOut.refresh();
		},
		fileUPSuccess(res) {
			let that = this;
			console.log('res',res);
			this.test_file = res.path;
		},
		saveMlogbInClose(){
			this.dialog.save = false;
			this.$refs.tableIn.refresh();
			if(this.mlogItem.material_out_&&this.mlogItem.material_out_.tracking==10){
				this.$refs.tableOut.refresh();
			}else{
				this.$refs.checkTable.refreshfun();
			}
		},
		//编辑成功后的方法调用
		handleEditSuccess() {
			this.getMlogItem();
		},
		//设置过滤项
		setFilters(filters) {
			this.selectionFilters = filters;
			this.setFiltersVisible = true;
		},
		scheckClose(){
			this.dialog.check_single = false;
			this.$refs.tableIn.refresh();
			if(this.mlogItem.material_out_&&this.mlogItem.material_out_.tracking==10){
				this.$refs.tableOut.refresh();
			}else{
				this.$refs.checkTable.refreshfun();
			}
		},
		checkDialogClose(){
			this.dialog.check = false;
			this.$refs.tableIn.refresh();
			this.$refs.tableOut.refresh();
		},
		handlePrint(){
			let that = this;
			that.printVisible = true;
		},
		//打签
		printMaterial(row){
			let that = this;
			that.apiObjPrint.req({tid:row.id}).then((res) => {
				let code = res.code_label;
				let str = [
					"SIZE 40 mm,70 mm",
					"GAP 7 mm,7 mm",
					"CLS",
					"REFERENCE 0,0",
					'QRCODE 30,400,H,5,A,0,"' +code +'"',
					"WINTEXT 200,550,28,90,0,0,Simhei," + res.material_name,
					"WINTEXT 240,550,28,90,0,0,Simhei,"  +"批次号："+ res.batch,
					"WINTEXT 280,550,28,90,0,0,Simhei,"  +"数量：" + row.count,
					"PRINT 1",
				]; 
				let obj = {};
				obj.printer_commands = str;
				obj.printer_name = that.printer_name;
                let printer_ip=localStorage.getItem("printer_ip")||'127.0.0.1';
that.$API.wpm.prints.req(printer_ip, obj).then((response) => {
                    that.$message.success("打印成功");
				});
			})
		},
		closedPage(){
			let that = this;
			that.visible = false;
			that.$emit('closed',that.isSubmit);
		},
	},
};
</script>

<style scoped>
.file_show{
	position: absolute;
	width: 100%;
	height: 100%;
	top: 0;
	background: rgb(255,255,255);
	z-index: 999;
}
.warningText{
	position: absolute; 
	left: 200px; 
	top: 5px;
	font-size: 16px; 
	line-height:35px;
	color: red;
	font-weight: 600;
}
</style>
