<template>
	<el-dialog
		title="检验"
		v-model="visible"
		:size="1200"
		destroy-on-close
		@closed="$emit('closed')"
	>
		<el-container v-loading="loading">
			<el-main style="padding: 0 20px 20px 20px">
				<el-form
					ref="dialogForm"
					:model="form"
					:rules="rules"
					label-width="140px"
				>
					<!-- 半成品 -->
					<el-row
						v-if="
							(type == 'do_in' && cate == 'halfgood') ||
							type == 'other_in'
						"
					>
						<el-col :md="12" :sm="24">
							<el-form-item label="检验日期" prop="test_date">
								<el-date-picker
									v-model="form.test_date"
									type="date"
									value-format="YYYY-MM-DD"
									style="width: 100%"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="检验人" prop="test_user">
								<el-select
									v-model="form.test_user"
									placeholder="检验人"
									clearable
									style="width: 100%"
								>
									<el-option
										v-for="item in userList"
										:key="item.id"
										:label="item.name"
										:value="item.id"
									/>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="不合格数">
								<el-input-number
									v-model="form.count_notok"
									:min="0"
									style="width: 100%"
									disabled
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="炸纹">
								<el-input-number
									v-model="form.count_n_zw"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="条纹">
								<el-input-number
									v-model="form.count_n_tw"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="气泡">
								<el-input-number
									v-model="form.count_n_qp"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="弯曲">
								<el-input-number
									v-model="form.count_n_wq"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="断裂">
								<el-input-number
									v-model="form.count_n_dl"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="偏壁">
								<el-input-number
									v-model="form.count_n_pb"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="大小头">
								<el-input-number
									v-model="form.count_n_dxt"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="结石">
								<el-input-number
									v-model="form.count_n_js"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="气线">
								<el-input-number
									v-model="form.count_n_qx"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="划伤">
								<el-input-number
									v-model="form.count_n_hs"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="杂质">
								<el-input-number
									v-model="form.count_n_zz"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="颜色青">
								<el-input-number
									v-model="form.count_n_ysq"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="扁">
								<el-input-number
									v-model="form.count_n_b"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="其他">
								<el-input-number
									v-model="form.count_n_qt"
									@change="countNotOkSun"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="备注">
								<el-input v-model="form.test_note"> </el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<!-- 成品 -->
					<el-row v-if="type == 'do_in' && cate == 'good'">
						<el-col :md="12" :sm="24">
							<el-form-item label="批次号：">
								{{ objitem.batch }}
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="总数：">
								{{ objitem.count }}
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="检验日期" prop="test_date">
								<el-date-picker
									v-model="form.test_date"
									type="date"
									value-format="YYYY-MM-DD"
									style="width: 100%"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="抽检数">
								<el-input-number
									v-model="form.count"
									:min="0"
									style="width: 100%"
									@change="countChange"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="划伤">
								<el-input-number
									v-model="form.count_n_hs"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="划伤"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="挫伤">
								<el-input-number
									v-model="form.count_n_cs"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="挫伤"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="杂质">
								<el-input-number
									v-model="form.count_n_zz"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="杂质"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="条纹">
								<el-input-number
									v-model="form.count_n_tw"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="条纹"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="锥度大">
								<el-input-number
									v-model="form.count_n_zdd"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="锥度大"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="短">
								<el-input-number
									v-model="form.count_n_d"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="短"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="炸纹">
								<el-input-number
									v-model="form.count_n_zw"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="炸纹"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<!-- 棒 -->
						<el-col :md="12" :sm="24">
							<el-form-item label="断裂">
								<el-input-number
									v-model="form.count_n_dl"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="断裂"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="气泡">
								<el-input-number
									v-model="form.count_n_qp"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="气泡"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="不亮">
								<el-input-number
									v-model="form.count_n_bl"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="不亮"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="横纹">
								<el-input-number
									v-model="form.count_n_hw"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="横纹"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="有皮">
								<el-input-number
									v-model="form.count_n_yp"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="有皮"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="爆皮">
								<el-input-number
									v-model="form.count_n_bp"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="爆皮"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="色差">
								<el-input-number
									v-model="form.count_n_sc"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="色差"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<!-- 管 -->
						<el-col :md="12" :sm="24">
							<el-form-item label="气线">
								<el-input-number
									v-model="form.count_n_qx"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="气线"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="结石">
								<el-input-number
									v-model="form.count_n_js"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="结石"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="椭圆度大">
								<el-input-number
									v-model="form.count_n_tydd"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="椭圆度大"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="水雾">
								<el-input-number
									v-model="form.count_n_sw"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="水雾"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="壁厚偏差大">
								<el-input-number
									v-model="form.count_n_bhpcd"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="壁厚偏差大"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="弯">
								<el-input-number
									v-model="form.count_n_wq"
									controls-position="right"
									:min="0"
									:step="1"
									:step-strictly="true"
									style="width: 100%"
									placeholder="弯"
									@change="countNotOkSun"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="合计">
								<el-input-number
									v-model="form.count_notok"
									controls-position="right"
									style="width: 100%"
									placeholder="合计"
									disabled
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="备注">
								<el-input
									v-model="form.test_note"
									tyle="width:100%"
									placeholder="备注"
								></el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<!-- 入厂检验 -->
					<el-row v-if="type == 'pur_in'">
						<el-col :md="12" :sm="24">
							<el-form-item label="产品名称:">
								{{ objitem.material_name }}
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="入厂批次号:">
								{{ objitem.batch }}
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item
								:label="project_code === 'gx'? '总数': '总袋（桶）数'"
							>
								<el-input-number
									v-model="form.count_bag"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="抽样数量">
								<!-- 光芯 -->
								<el-input-number
									v-if="project_code === 'gx'"
									v-model="form.count_sampling"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
								<!-- 光子 -->
								<el-input
									v-else
									disabled
									v-model="form.count_sampling"
									placeholder="抽样数量"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="检验日期" prop="test_date">
								<el-date-picker
									v-model="form.test_date"
									type="date"
									value-format="YYYY-MM-DD"
									style="width: 100%"
								/>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="检验员" prop="test_user">
								<el-select
									v-model="form.test_user"
									placeholder="检验员"
									clearable
									filterable
									style="width: 100%"
								>
									<el-option
										v-for="item in userList"
										:key="item.id"
										:label="item.name"
										:value="item.id"
									/>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="检验合格" prop="is_testok">
								<el-select
									v-model="form.is_testok"
									placeholder="检验合格"
									clearable
									style="width: 100%"
								>
									<el-option label="是" :value="true" />
									<el-option label="否" :value="false" />
								</el-select>
							</el-form-item>
						</el-col>
						<!-- 光子 -->
						<el-col :md="12" :sm="24" v-if="project_code == 'gz'">
							<el-form-item label="抽样计算总重量/Kg">
								<el-input-number
									v-model="form.count_bag_weight_all"
									:min="0"
									style="width: 100%"
									controls-position="right"
								>
								</el-input-number>
							</el-form-item>
						</el-col>
						<el-col :md="12" :sm="24">
							<el-form-item label="备注">
								<el-input v-model="form.test_note"> </el-input>
							</el-form-item>
						</el-col>
					</el-row>
					<!-- 光子 -->
					<el-row v-if="project_code == 'gz'">
						<el-col>
							<el-form-item label="称重记录/Kg">
								<el-button
									type="primary"
									icon="el-icon-plus"
									@click="addWeight"
								></el-button>
							</el-form-item>
						</el-col>
						<el-col
							:md="12"
							:sm="24"
							v-for="(item, ind) in weight_kgs"
							:key="item"
							style="position: relative"
						>
							<el-form-item :label-width="50">
								<el-input-number
									v-model="item.value"
									:min="0"
									style="width: 90%"
									controls-position="right"
									@change="countSun"
								/>
							</el-form-item>
							<el-button
								@click="delWeight(ind)"
								type="danger"
								icon="el-icon-delete"
								circle
								style="position: absolute; right: -10px; top: 0"
							/>
						</el-col>
					</el-row>
				</el-form>
			</el-main>
			<el-footer v-if="mode == 'add'">
				<el-button type="primary" :loading="isSaveing" @click="submit"
					>提交</el-button
				>
				<el-button @click="visible = false">取消</el-button>
			</el-footer>
		</el-container>
	</el-dialog>
	<el-drawer
		v-model="visibleDrawer"
		title="检验"
		:size="'90%'"
		destroy-on-close
		@closed="$emit('closed')"
	>
		<el-container v-loading="loading">
			<el-main style="padding: 0 20px 20px 20px">
				<el-table :data="mioitemwList" border>
					<el-table-column label="物料编号" prop="number">
					</el-table-column>
					<el-table-column label="操作" fixed="right" width="130">
						<template #default="scope">
							<el-button @click="changeCheckItem(scope.row)" type="text">检验</el-button>
							<el-button v-if="scope.row.wpr" @click="changeCheckRecord(scope.row)" type="text">检验记录</el-button>
						</template>
					</el-table-column>
				</el-table>
				<scTable v-if="checkRecordShow" :data="recordList" row-key="id" height="300px" stripe>
					<el-table-column type="index" width="50" />
					<el-table-column label="检验日期" prop="test_date"></el-table-column>
					<el-table-column label="检验人" prop="test_user_name"></el-table-column>
					<el-table-column label="是否合格" prop="is_ok">
						<template #default="scope">
							<el-tag v-if="scope.row.is_ok" type="success">合格</el-tag>
							<el-tag v-else type="warning">不合格</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="操作" fixed="right" width="80">
						<template #default="scope">
							<el-button @click="checkFormDetail(scope.row)" type="text">查看</el-button>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
			<!-- <el-footer v-if="mode == 'add'">
				<el-button type="primary" :loading="isSaveing" @click="submit">提交</el-button>
				<el-button @click="visibleDrawer = false">取消</el-button>
			</el-footer> -->
		</el-container>
	</el-drawer>
	<checkform-dialog
		v-if="checkShow"
		ref="checkFormDialog"
		:material="objitem.material"
		:mioitemw="mioitemw"
		@success="checkFormSuccess"
		@closed="checkShow= false"
	>
	</checkform-dialog>
</template>
<script>
import checkformDialog from "./mioitemCheckForm.vue";
export default {
	emits: ["success", "closed"],
	components: {
		checkformDialog
	},
	props: {
		mioitemId: { type: String, default: "" },
		type: { type: String, default: "" },
		cate: { type: String, default: "" },
		objitem: { type: Object, default: () => {} },
	},
	data() {
		return {
			tableData:[],
			loading: false,
			form: {
				weight_kgs: [],
				ftestitems: [],
			},
			rules: {
				test_date: [
					{
						required: true,
						message: "请选择检验日期",
						trigger: "blur",
					},
				],
				test_time: [
					{
						required: true,
						message: "请选择检验时间",
						trigger: "blur",
					},
				],
				test_user: [
					{
						required: true,
						message: "请选择检验人",
						trigger: "blur",
					},
				],
			},
			formbw:{
				number:'',
				note:'',
				mioitem:'',
				test_date:'',
				test_user:'',
			},
			project_code: null,
			mioItem: {},
			weight_kgs: [{ value: 0 }],
			checkShow:false,
			checkShowsss:false,
			visible: false,
			visibleDrawer:false,
			isSaveing: false,
			checkRecordShow:false,
			recordList:[],
			userList: [],
			processOptions: [],
			deptOptions: [],
			selectionFilters: [],
			setFiltersVisible: false,
			belong_dept_options: [],
			group: [],
			mioitemwList:[],
			qctId:'',
			mioitemwId:'',
		};
	},
	mounted() {
		let that = this;
		let config_base = that.$TOOL.data.get("BASE_INFO").base;
		that.project_code = config_base.base_code;
		that.getUserList();
		if(that.project_code=='bxerp'){
			that.mioitemwId = that.objitem.mioitemw[0].id;
			that.formbw.number = that.objitem.mioitemw[0].number;
			that.formbw.mioitem = that.objitem.mioitemw[0].mioitem;
			this.getMioitemw();
		}else{
			if (that.type == "pur_in") {
				console.log("objitem", that.objitem);
				that.form.material_name = that.objitem.material_name;
				that.form.batch = that.objitem.batch;
				that.form.count_bag = that.objitem.count_bag;
			}
			if (
				(that.type == "do_in" && that.cate == "halfgood") ||
				that.type == "other_in"
			) {
				this.form.count_notok = 0;
				this.form.count_n_zw = 0;
				this.form.count_n_tw = 0;
				this.form.count_n_qp = 0;
				this.form.count_n_wq = 0;
				this.form.count_n_dl = 0;
				this.form.count_n_pb = 0;
				this.form.count_n_dxt = 0;
				this.form.count_n_js = 0;
				this.form.count_n_qx = 0;
				this.form.count_n_hs = 0;
				this.form.count_n_ysq = 0;
				this.form.count_n_zz = 0;
				this.form.count_n_b = 0;
				this.form.count_n_qt = 0;
			}
			if (that.type == "do_in" && that.cate == "good") {
				this.form.count_notok = 0;
				this.form.count_n_hs = 0;
				this.form.count_n_cs = 0;
				this.form.count_n_zz = 0;
				this.form.count_n_tw = 0;
				this.form.count_n_d = 0;
				this.form.count_n_zdd = 0;
				this.form.count_n_zw = 0;
				this.form.count_n_dl = 0;
				//棒
				this.form.count_n_qp = 0;
				this.form.count_n_bl = 0;
				this.form.count_n_hw = 0;
				this.form.count_n_yp = 0;
				this.form.count_n_bp = 0;
				this.form.count_n_sc = 0;
				//管
				this.form.count_n_qx = 0;
				this.form.count_n_js = 0;
				this.form.count_n_tydd = 0;
				this.form.count_n_sw = 0;
				this.form.count_n_bhpcd = 0;
				this.form.count_n_wq = 0;
			}
		}
	},
	methods: {
		//显示
		open(mode = "add") {
			this.mode = mode;
			let config_base = this.$TOOL.data.get("BASE_INFO").base.base_code;
			if(config_base=='bxerp'){
				this.visibleDrawer = true;
			}else{
				this.visible = true;
			}
			return this;
		},
		changeCheckItem(row){
			let that = this;
			that.mioitemw = row;
			that.checkShow = true;
			console.log("row",row);
			console.log("checkFormDialog");
			that.$nextTick(() => {
				that.$refs.checkFormDialog.open("add");
			})
		},
		checkFormDetail(row){
			let that = this;
			that.mioitemw = row;
			that.checkShow = true;
			that.$nextTick(() => {
				that.$refs.checkFormDialog.open("show").setData(row);
			})
		},
		changeCheckRecord(row){
			let that = this;
			this.mioitemwWpr = row.wpr;
			that.$API.qm.ftest.list.req({ mioitemw_ftest__wpr: row.wpr,page:0 }).then((res) => {
			    that.recordList = res;
			})
			that.checkShow = false;
			that.checkRecordShow = true;
		},
		getMioitemw(){
			let that = this;
			that.$API.inm.mioitemw.list.req({ mioitem: that.mioitemId,page:0 }).then((res) => {
				that.mioitemwList = res;
			});
		},
		//获取员工
		getUserList() {
			let that = this;
			this.$API.system.user.list
				.req({ page: 0, posts__code__contains: "check" })
				.then((res) => {
					that.userList = res;
				});
		},
		addWeight() {
			this.weight_kgs.push({ value: 0 });
			this.form.count_sampling = this.weight_kgs.length;
		},
		delWeight(index) {
			this.weight_kgs.splice(index, 1);
			this.form.count_sampling = this.weight_kgs.length;
		},
		countSun() {
			let that = this;
			let sum = 0;
			console.log("change");
			that.weight_kgs.forEach((item) => {
				sum = sum + item.value;
			});
			that.form.count_bag_weight_all =
				(sum / that.weight_kgs.length) * that.form.count_bag;
		},
		countChange() {},
		countNotOkSun() {
			let that = this;
			if (
				(that.type == "do_in" && that.cate == "halfgood") ||
				that.type == "other_in"
			) {
				this.form.count_notok =
					this.form.count_n_zw +
					this.form.count_n_tw +
					this.form.count_n_qp +
					this.form.count_n_wq +
					this.form.count_n_dl +
					this.form.count_n_pb +
					this.form.count_n_dxt +
					this.form.count_n_js +
					this.form.count_n_qx +
					this.form.count_n_hs +
					this.form.count_n_ysq +
					this.form.count_n_zz +
					this.form.count_n_b +
					this.form.count_n_qt;
			}
			if (that.type == "do_in" && that.cate == "good") {
				this.form.count_notok =
					this.form.count_n_hs +
					this.form.count_n_cs +
					this.form.count_n_zz +
					this.form.count_n_tw +
					this.form.count_n_d +
					this.form.count_n_zdd +
					this.form.count_n_zw +
					this.form.count_n_dl +
					//棒
					this.form.count_n_qp +
					this.form.count_n_bl +
					this.form.count_n_hw +
					this.form.count_n_yp +
					this.form.count_n_bp +
					this.form.count_n_sc +
					//管
					this.form.count_n_qx +
					this.form.count_n_js +
					this.form.count_n_tydd +
					this.form.count_n_sw +
					this.form.count_n_bhpcd +
					this.form.count_n_wq;
			}
		},
		//提交
		submit() {
			let that = this;
			if (
				(that.type == "do_in" && that.cate == "halfgood") ||
				that.type == "other_in"
			) {
				this.form.count_notok =
					this.form.count_n_zw +
					this.form.count_n_tw +
					this.form.count_n_qp +
					this.form.count_n_wq +
					this.form.count_n_dl +
					this.form.count_n_pb +
					this.form.count_n_dxt +
					this.form.count_n_js +
					this.form.count_n_qx +
					this.form.count_n_hs +
					this.form.count_n_ysq +
					this.form.count_n_zz +
					this.form.count_n_b +
					this.form.count_n_qt;
			}
			if (that.type == "do_in" && that.cate == "good") {
				this.form.count_notok =
					this.form.count_n_hs +
					this.form.count_n_cs +
					this.form.count_n_zz +
					this.form.count_n_tw +
					this.form.count_n_d +
					this.form.count_n_zdd +
					this.form.count_n_zw +
					this.form.count_n_dl +
					//棒
					this.form.count_n_qp +
					this.form.count_n_bl +
					this.form.count_n_hw +
					this.form.count_n_yp +
					this.form.count_n_bp +
					this.form.count_n_sc +
					//管
					this.form.count_n_qx +
					this.form.count_n_js +
					this.form.count_n_tydd +
					this.form.count_n_sw +
					this.form.count_n_bhpcd +
					this.form.count_n_wq;
			}
			that.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					that.isSaveing = true;
					try {
						if (that.type == "pur_in") {
							console.log(that.form);
							let arr = [];
							that.weight_kgs.forEach((item) => {
								arr.push(item.value);
							});
							that.form.weight_kgs = arr;
							console.log('that.form',that.form);
							that.$API.inm.mioitem.testpurin
								.req(that.mioitemId, that.form)
								.then((res) => {
									that.isSaveing = false;
									that.$emit("success");
									that.visible = false;
									that.$message.success("操作成功");
								});
						} else {
							that.$API.inm.mioitem.test
								.req(that.mioitemId, that.form)
								.then((res) => {
									that.isSaveing = false;
									that.$emit("success");
									that.visible = false;
									that.$message.success("操作成功");
								});
						}
					} catch (err) {
						//可以处理校验错误
						this.isSaveing = false;
						return err;
					}
				}
			});
		},
		//表单注入数据
		setData(data) {
			let that = this;
			Object.assign(that.form, data);
			// that.form.test_group = that.form.split(',');
			that.weight_kgs = [];
			if (data.weight_kgs.length > 0) {
				that.form.count_sampling = data.weight_kgs.length;
				let sum = 0;
				data.weight_kgs.forEach((item) => {
					sum = sum + item;
					let obj = {};
					obj.value = item;
					that.weight_kgs.push(obj);
				});
				that.form.count_bag_weight_all =
					(sum / data.weight_kgs.length) * data.count_bag;
			}
		},
		checkFormSuccess(){},
		//设置过滤项
		setFilters(filters) {
			this.selectionFilters = filters;
			this.setFiltersVisible = true;
		},
	},
};
</script>

<style>
.width-100{
	width: 100%;
}
</style>
