<template>
	<div class="main-container order-mc-bg">
		<div class="sale-container">
			<!-- 顶部按钮组 -->
			<toolBtn @actionhandel="actionhandel" :btnType="btnType"></toolBtn>
			<!-- 列表 -->
			<div class="sale-page-body">
				<!-- 表头 -->
				<div class="sale-page-table-header" ref="getSaleTableHeader">
					<el-form :inline="true" ref="form" :model="fromData">
						<el-row class="form-row1">
							<el-col :span="20">
								<el-row :gutter="2">
									<el-col :span="4">
										<el-form-item
											class="Iisshow"
											label="父项物料"
										>
											<el-input
												v-model.trim="fromData.mateF"
												placeholder="请输入父项物料编码/名称/规格型号"
												@keyup.enter="
													searchCom(mateF, 'mateF')
												"
												:maxlength="255"
												class="f-12"
											></el-input>
											<div
												:data-clipboard-text="
													fromData.mateF
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item
											class="Iisshow"
											label="BOM版本"
										>
											<el-input
												v-model.trim="
													fromData.bomVersion
												"
												placeholder="请输入BOM版本"
												@keyup.enter="
													searchCom(
														bomVersion,
														'bomVersion'
													)
												"
												:maxlength="255"
												class="f-12"
											></el-input>
											<div
												:data-clipboard-text="
													fromData.bomVersion
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item
											class="Iisshow"
											label="子项物料"
										>
											<el-input
												v-model.trim="fromData.mateC"
												placeholder="请输入子项物料编码/名称/规格型号"
												@keyup.enter="
													searchCom(
														material,
														'material'
													)
												"
												:maxlength="255"
												class="f-12"
											></el-input>
											<div
												:data-clipboard-text="
													fromData.mateC
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</el-col>
									<el-col :span="3">
										<el-form-item
											class="Iisshow"
											label="用量"
										>
											<el-input
												v-model="fromData.useMin"
												placeholder="用量下限"
												@input="
													numberRexgu(
														fromData.useMin,
														'useMin'
													)
												"
												@keyup.enter="
													searchCom3(
														material,
														'material'
													)
												"
												@blur="
													clearZero(
														fromData.useMin,
														'useMin'
													)
												"
												:maxlength="255"
												class="f-12"
											></el-input>
											<div
												:data-clipboard-text="
													fromData.useMin
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</el-col>
									<el-col :span="3">
										<el-form-item
											label="——"
											class="Iisshow"
										>
											<el-input
												v-model="fromData.useMax"
												placeholder="用量上限"
												@keyup.enter="
													searchCom4(
														material,
														'material'
													)
												"
												@blur="
													clearZero(
														fromData.useMax,
														'useMax'
													)
												"
												@input="
													numberRexgu(
														fromData.useMax,
														'useMax'
													)
												"
												:maxlength="255"
												class="f-12"
											></el-input>
											<div
												:data-clipboard-text="
													fromData.useMax
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</el-col>
								</el-row>
							</el-col>
							<el-col :span="4" class="form-row-lastcol">
								<el-row :gutter="2">
									<el-col :span="24">
										<el-form-item class="form-group1">
											<div
												class="alias-open"
												@click="openRow"
											>
												<span
													class="iconfont"
													:class="[
														isDown
															? 'icon-shuangjiantouzhankai-xia'
															: 'icon-shuangjiantoushouqi-shang',
													]"
												></span>
											</div>
											<el-button
												size="small"
												@click="resetData"
												>重置</el-button
											>
											<el-button
												type="primary"
												size="small"
												@click="searchData"
												>搜索</el-button
											>
										</el-form-item>
									</el-col>
								</el-row>
							</el-col>
						</el-row>
						<el-row class="form-row2" v-if="rowShow">
							<el-col :span="4">
								<el-form-item label="单据状态">
									<el-select
										v-model="fromData.documentStatus"
										filterable
										placeholder="选择状态"
										:clearable="true"
										@change="
											clearCom(
												fromData.documentStatus,
												'documentStatus'
											)
										"
									>
										<el-option
											class="f_12"
											v-for="item in bills"
											@click="
												searchComC(
													fromData.documentStatus,
													'documentStatus'
												)
											"
											:key="item.id"
											:label="item.name"
											:value="item.id"
										></el-option>
									</el-select>
								</el-form-item>
							</el-col>
							<el-col :span="4">
								<el-form-item label="是否禁用">
									<el-select
										v-model="fromData.isDisable"
										filterable
										placeholder="请选择"
										:clearable="true"
										@change="
											clearCom(
												fromData.isDisable,
												'isDisable'
											)
										"
									>
										<el-option
											class="f_12"
											v-for="item in isDisablelist"
											@click="
												searchComC(
													fromData.isDisable,
													'isDisable'
												)
											"
											:key="item.id"
											:label="item.name"
											:value="item.id"
										></el-option>
									</el-select>
								</el-form-item>
							</el-col>
							<el-col :span="4">
								<el-form-item label="是否失效">
									<el-select
										v-model="fromData.isEffect"
										filterable
										placeholder="请选择"
										:clearable="true"
										@change="
											clearCom(
												fromData.isEffect,
												'isEffect'
											)
										"
									>
										<el-option
											class="f_12"
											v-for="item in isEffectlist"
											@click="
												searchComC(
													fromData.isEffect,
													'isEffect'
												)
											"
											:key="item.id"
											:label="item.name"
											:value="item.id"
										></el-option>
									</el-select>
								</el-form-item>
							</el-col>
							<el-col :span="4">
								<el-form-item label="位置号/模号/备注">
									<el-input
										v-model.trim="fromData.remark"
										placeholder="请输入位置号/模号/备注"
										@keyup.enter="
											searchCom(remark, 'fromData.remark')
										"
										@input="getremark"
										:maxlength="255"
										class="f-12"
									></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="4">
								<el-form-item label="是否关键件">
									<el-select
										v-model="fromData.isKeyComponent"
										filterable
										placeholder="请选择"
										:clearable="true"
										@change="
											clearCom(
												fromData.isKeyComponent,
												'isKeyComponent'
											)
										"
									>
										<el-option
											class="f_12"
											v-for="item in isKeyComponentlist"
											@click="
												searchComC(
													fromData.isKeyComponent,
													'isKeyComponent'
												)
											"
											:key="item.id"
											:label="item.name"
											:value="item.id"
										></el-option>
									</el-select>
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<!-- 列表 -->
				<div class="sale-page-table-body">
					<el-table
						class="table-box"
						:data="tableData"
						border
						v-loading="isLoading"
						ref="tableInfoRef"
						element-loading-text="加载中，请稍后..."
						element-loading-spinner="el-icon-loading"
						style="width: 100%; font-size: 12px"
						:max-height="heightNum"
						:row-style="tableRowClassName"
						@selection-change="handleSelectionChange"
						@row-dblclick="rowDblclick"
					>
						<el-table-column
							type="selection"
							align="center"
							width="40"
							fixed
						/>
						<el-table-column
							prop="version"
							label="BOM版本"
							align="left"
							fixed
							width="180"
						>
							<template #default="scope">
								<span
									style="color: #4178d5"
									@click="toDetail(scope.row)"
									>{{ scope.row.version }}</span
								>
							</template>
						</el-table-column>
						<el-table-column
							prop="materialNumber"
							label="父项物料编码"
							align="left"
							fixed
							width="150"
						></el-table-column>
						<el-table-column
							prop="specification"
							label="规格型号"
							align="left"
							width="280"
						/>
						<el-table-column
							prop="materialName"
							label="物料名称"
							align="left"
							width="100"
						></el-table-column>
						<el-table-column
							prop="unit"
							label="父项基本单位"
							align="center"
							width="100"
						/>
						<el-table-column
							prop="documentStatus"
							label="单据状态"
							align="center"
							width="72"
						/>
						<!-- <el-table-column prop="seq" label="序号" align="center" width="60" /> -->
						<el-table-column
							prop="childMaterialNumber"
							label="子项物料编码"
							align="left"
							width="150"
						/>
						<el-table-column
							prop="childSpecification"
							label="子项规格型号"
							align="left"
							width="280"
						/>
						<el-table-column
							prop="childMaterialName"
							label="子项物料名称"
							align="left"
							width="120"
						/>
						<el-table-column
							prop="childUnit"
							label="子项单位"
							align="center"
							width="81"
						></el-table-column>
						<el-table-column
							prop="numerator"
							label="用量：分子"
							align="center"
							width="81"
						></el-table-column>
						<el-table-column
							prop="denominator"
							label="用量：分母"
							align="center"
							width="81"
						/>
						<el-table-column
							prop="isDisable"
							label="是否禁用"
							align="center"
							width="72"
						>
							<template #default="scope">
								<span>{{
									scope.row.isDisable === true ? '是' : '否'
								}}</span>
							</template>
						</el-table-column>
						<el-table-column
							prop="isEffect"
							label="是否失效"
							align="center"
							width="72"
						>
							<template #default="scope">
								<span>{{
									scope.row.isEffect === true ? '是' : '否'
								}}</span>
							</template>
						</el-table-column>
						<el-table-column
							prop="cost"
							label="成本"
							align="center"
							width="81"
						/>
						<el-table-column
							prop="remark"
							label="位置号/模号/备注"
							align="center"
							width="150"
						/>
					</el-table>
				</div>
				<!-- 底部 -->
				<div class="sale-page-footer">
					<div class="footer-right">
						<el-pagination
							:page-sizes="[50, 100, 150]"
							:page-size="search.pageSize"
							layout="slot,sizes, total,prev,pager, next,jumper"
							:total="total"
							popper-class="每页显示"
							:currentPage="search.pageNo"
							@size-change="handleSizeChange"
							@current-change="handleCurrentChange"
						>
							<span class="total-select-item">
								共选中
								<text
									style="
										text-align: center;
										color: #4178d5;
										padding: 0 1px;
									"
									>{{ selectionLen }}</text
								>行
							</span>
						</el-pagination>
					</div>
					<div class="footer-pagination-total-page">
						<span>共{{ totalPage }}页</span>
					</div>
				</div>
				<!-- 操作结果 -->
				<el-dialog
					title="操作结果"
					v-model="dialogVisible"
					width="40%"
					:before-close="beforeClose"
				>
					<div class="sale-page-table-body">
						<el-table
							class="table-box"
							:data="tableInfo"
							height="300"
							border
							:header-cell-class-name="headerRigthMethod"
							id="tableInfo-table2"
						>
							<el-table-column
								prop="date"
								label="序号"
								width="50"
							>
								<template #default="scope">
									<span>{{ scope.$index + 1 }}</span>
								</template>
							</el-table-column>
							<el-table-column
								prop="orderNo"
								label="BOM版本"
								width="200"
							></el-table-column>
							<el-table-column prop="a" label="指令" width="110">
								<template #default>
									<span>{{
										actionType === 'submit'
											? '提交'
											: actionType === 'revoke'
											? '撤销'
											: actionType === 'audit'
											? '审核'
											: actionType === 'de-approval'
											? '反审'
											: actionType === 'delet'
											? '删除'
											: actionType === 'disabled'
											? '禁用'
											: actionType === 'de-disabled'
											? '反禁用'
											: ''
									}}</span>
								</template>
							</el-table-column>
							<el-table-column label="结果" width="80">
								<template #default="scope">
									<span
										:style="{
											'txt-Red': scope.row.isSuccess,
										}"
										>{{
											scope.row.isSuccess
												? '成功'
												: '失败'
										}}</span
									>
								</template>
							</el-table-column>
							<el-table-column prop="msg" label="信息">
								<template #default="scope">
									<span class="txt-Red">{{
										scope.row.msg
									}}</span>
								</template>
							</el-table-column>
						</el-table>
					</div>
					<template #footer>
						<span class="dialog-footer">
							<span
								class="f-12 ext-black-light"
								style="margin-right: 25px"
								>共{{
									tableInfo && tableInfo.length > 0
										? tableInfo.length
										: 0
								}}条</span
							>
							<el-button
								size="small"
								@click="
									handelhtmlToExcel(
										'tableInfo-table2',
										'操作结果'
									)
								"
								>导 出</el-button
							>
							<el-button
								type="primary"
								size="small"
								@click="beforeClose"
								>关 闭</el-button
							>
						</span>
					</template>
				</el-dialog>
			</div>
		</div>
	</div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import { orderCopy } from '@/utils/takeMethods';
import { exporthandel, htmlToExcel } from '@/utils/pubulic.js';
export default {
	name: 'MateBomIndex',
	data() {
		return {
			isLoading: false, //表格加载数据
			dialogVisible: false, //操作结果弹窗
			bills: [],
			fromData: {
				mateF: '', //父项物料
				mateC: '', // 子项物料
				bomVersion: '', //bom版本
				useMax: '', //用量上限
				useMin: '', //用量下限
				documentStatus: '', // 单据类型
				isDisable: '',
				isEffect: '',
				remark: '',
				isKeyComponent: '',
			}, // 顶部form搜索条件
			bomList: [], //物料下拉列表
			supplyList: [], //供应链列表
			isEffectlist: [
				{
					name: '是',
					id: true,
				},
				{
					name: '否',
					id: false,
				},
			],
			isDisablelist: [
				{
					name: '是',
					id: true,
				},
				{
					name: '否',
					id: false,
				},
			],

			isKeyComponentlist: [
				{
					name: '是',
					id: true,
				},
				{
					name: '否',
					id: false,
				},
			],
			is211List: [
				{
					id: false,
					name: '否',
				},
				{
					id: true,
					name: '是',
				},
			], //是否211列表
			orgList: [], //供应组织列表
			defaultSupplyList: [], //默认供应商列表
			// 搜索条件
			search: {
				product: '', //父项 物料名称/编码/SKU
				childProduct: '', //子项 物料名称/编码/SKU
				bomVersion: '', //bom版本
				number: '', //用量
				pageNo: 1, // 页码
				pageSize: 50, // 页数
				documentStatus: '',
				isDisable: '',
				isEffect: '',
				remark: '',
				isKeyComponent: '',
			},
			tableData: [],
			isDown: true,
			rowShow: false,
			multipleSelection: [],
			selectionLen: 0, //选中的行数
			total: 0,
			totalPage: 0, //总页数
			heightNum: 0,
			actionType: '',
			tableInfo: [], //操作结果
			OrdedetailIds: [], // 勾选的明细id集合
			OrderNoNames: [], // 选择的物料编码集合
			materialList: [], //物料查询结果
			btnType: [
				'save',
				'disabled',
				'de-disabled',
				'push-down',
				'close',
				'de-close',
				'query',
				'print-aterial-list',
				'finish',
				'close-case',
				'de-excute-start',
				'de-excute-finish',
				'print-brower',
			], // 不需要显示的顶部按钮类型
			saveParams: {
				id: 0,
				materialId: '',
				details: [
					{
						id: 0,
						seq: 1,
						materialId: '',
						numerator: 0,
						denominator: 0,
						ffixscrapqty: 0,
						materialBear: 0,
						overRatio: 0,
						stockId: 0,
						fissueType: 1,
						isEffect: true,
					},
				],
				blacks: [
					{
						id: 0,
						seq: 1,
						orgId: '',
					},
				],
			}, //提交参数
		};
	},
	computed: {
		...mapState({
			orgId: (state) => (state && state.user ? state.user.orgId : null),
			orgArr: (state) => (state ? state.user.orgId : nullArr),
			enumType: (state) => state.storeData.enumType,
		}),
	},
	activated() {
		// this.$refs.tableInfoRef.clearSelection()
	},
	watch: {},
	created() {
		this.windowHeight = document.documentElement.clientHeight;
		this.heightNum =
			this.windowHeight - (40 + 30 + 54 + 34 + 34 + 34 + 16 + 16);
		this.Init();
	},
	methods: {
		...mapActions({
			setEnumType: 'storeData/setEnumType',
		}),
		Init() {
			// 枚举 - 订单类型、状态
			if (this.enumType && JSON.stringify(this.enumType) !== '{}') {
				for (const key in this.enumType.documentStatus) {
					// 单据状态
					this.bills.push({
						id: key,
						name: this.enumType.documentStatus[key],
					});
				}
			} else {
				this.$http
					.showLoading(false)
					.get('SalOrder/GetEnum')
					.then((req) => {
						// 获取状态和类型
						if (req.status === 200) {
							if (req.data) {
								this.setEnumType(req.data);
								for (const key in req.data.documentStatus) {
									// 单据状态
									this.bills.push({
										id: key,
										name: req.data.documentStatus[key],
									});
								}
							}
						}
					});
			}
			this.getList();
			// this.getBaseData()
		},
		// 验证输入百分比是数字，0，或者小数，首位不允许多个0
		numberRexgu(value, key) {
			if (value) {
				if (value.toString().indexOf('.') != -1) {
					let value_after = parseInt(
						value.toString().substring(0, value.indexOf('.'))
					);
					let value_before = value.replace(/\d+\.(\d*)/, '$1');
					if (value_after.toString().length > 8) {
						let newValue =
							value_after.toString().substring(0, 8) +
							'.' +
							value_before;
						this.fromData[key] = (newValue
							.toString()
							.match(/\d{1,8}(\.\d{0,6})?/) || [''])[0];
					} else {
						this.fromData[key] = (value
							.toString()
							.match(/\d{1,8}(\.\d{0,6})?/) || [''])[0];
					}
				}
				this.fromData[key] = (value
					.toString()
					.match(/\d{1,8}(\.\d{0,6})?/) || [''])[0];
			} else {
				this.fromData[key] = '';
			}
		},
		// 去0
		clearZero(value, key) {
			if (value) {
				this.fromData[key] = value * 1;
				if (key == 'useMax') {
					if (this.fromData[key] < this.fromData.useMin) {
						this.fromData[key] = this.fromData.useMin;
					}
				}
			}
		},
		// 操作弹框导出
		handelhtmlToExcel(domid, title) {
			htmlToExcel(domid, title);
		},
		// 物料禁用字体为红色
		tableRowClassName({ row, rowIndex }) {
			if (row.isDisable) {
				return 'color: red!important;';
			}
		},
		// 搜索数据重置
		resetData() {
			this.fromData = {
				mateF: '', //父项物料
				mateC: '', // 子项物料
				bomVersion: '', //bom版本
				useMax: '', //用量上限
				useMin: '', //用量下限
				documentStatus: '',
				isDisable: '',
				isEffect: '',
				remark: '',
				isKeyComponent: '',
			};
			this.search = {
				product: '', //父项 物料名称/编码/SKU
				childProduct: '', //子项 物料名称/编码/SKU
				bomVersion: '', //bom版本
				number: '', //用量
				pageNo: 1, // 页码
				pageSize: 50, // 页数
				documentStatus: '',
				isDisable: '',
				isEffect: '',
				remark: '',
				isKeyComponent: '',
			};
			this.getList();
		},
		searchCom3(val) {
			// 下限
			if (val) {
				this.fromData.useMin = val;
				if (this.fromData.useMin <= this.fromData.useMax) {
					this.search.number =
						this.fromData.useMin + '|' + this.fromData.useMax;
					// this.getList()
				}
			}
			this.getList();
		},
		searchCom4(val) {
			// 上限
			if (val) {
				this.fromData.useMax = val;
				if (this.fromData.useMax >= this.fromData.useMin) {
					this.search.number =
						this.fromData.useMin + '|' + this.fromData.useMax;
					// this.getList()
				}
			}
			this.getList();
		},
		clearCom(val, key) {
			if (val == '' || !val) {
				this.search[key] = '';
			}
		},
		searchComC(val, key) {
			this.search[key] = val;
		},
		searchCom(val) {
			if (val) {
				// 父项物料
				this.fromData.mateF = val;
			}
			this.getList();
		},
		searchCom1(val) {
			if (val) {
				// bom版本
				this.fromData.bomVersion = val;
			}
			this.getList();
		},
		searchCom2(val) {
			if (val) {
				// 子项物料
				this.fromData.mateC = val;
			}
			this.getList();
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},

		//双击列表行
		rowDblclick(row, column, event) {
			// console.log(row, column, event)
			this.$router.push({
				path: '/material/mateBom/mateBomSet',
				query: { type: 'edit', id: row.id },
			});
		},
		// 获取列表数据
		getList() {
			this.search.product = this.fromData.mateF;
			this.search.childProduct = this.fromData.mateC;
			this.search.bomVersion = this.fromData.bomVersion;
			this.search.number =
				this.fromData.useMin + '|' + this.fromData.useMax;
			this.$http
				.post('MaterialBom/MaterialBomQuery', this.search)
				.then((res) => {
					if (res.status == 200) {
						this.tableData = res.data.list;
						this.total = res.data.total;
						this.totalPage = Math.ceil(
							this.total / this.search.pageSize
						); //总页数
						if (
							this.multipleSelection.length &&
							this.multipleSelection.length > 0
						) {
							let detailsIds = [
								...new Set(
									this.multipleSelection.map((item) => {
										return item.detailId;
									})
								),
							];
							this.tableData.forEach((el, ind) => {
								if (detailsIds.indexOf(el.detailId) !== -1) {
									this.$refs.tableInfoRef.toggleRowSelection(
										this.tableData[ind],
										true
									);
								}
							});
						}
					}
				});
		},
		// 修改禁用状态
		disableChange(val, id) {
			// console.log(val)
			let ids = [];
			ids[0] = id;
			if (val == true) {
				this.$http
					.post('MaterialBom/Disable', { ids: ids })
					.then((res) => {
						if (res.status == 200) {
							this.$message({
								type: 'success',
								message: res.message,
								showClose: true,
							});
							this.getList();
						} else {
							this.$message({
								type: 'success',
								message: res.message,
								showClose: true,
							});
						}
					});
			} else {
				this.$http
					.post('MaterialBom/NoDisable', { ids: ids })
					.then((res) => {
						if (res.status == 200) {
							this.$message({
								type: 'success',
								message: res.message,
								showClose: true,
							});
							this.getList();
						} else {
							this.$message({
								type: 'success',
								message: res.message,
								showClose: true,
							});
						}
					});
			}
		},
		// 获取位置号
		getremark(value) {
			this.fromData.remark = value;
			this.search.remark = value;
		},
		// 物料分类、组织，供应商
		// getBaseData() {
		// 物料分类
		// this.$http.get('MaterialGroup/GetDropDownAll').then(res => {
		//   if (res.status == 200) {
		//     this.bomList = res.data
		//   }
		// })
		// // 供应组织
		// this.$http.get('SysConfig/GetOrganizations').then(res => {
		//   if (res.status == 200) {
		//     this.orgList = res.data
		//   }
		// })
		// 供应商
		// this.$http.get('SysConfig/supplier/select').then(res => {
		//   if (res.status == 200) {
		//     this.defaultSupplyList = res.data
		//   }
		// })
		// },
		// 根据物料编码/规格型号 查询物料
		matterCodeChange(val) {
			if (val !== '') {
				setTimeout(() => {
					this.$http
						.showLoading(false)
						.post('SysConfig/GetMaterial', { name: val, file: '' })
						.then((res) => {
							if (res.status === 200) {
								this.materialList = res.data;
							}
						});
				}, 200);
			} else {
				this.materialList = [];
			}
		},
		metterChange(val) {
			// console.log(val)
			let metterInfo = {};
			if (this.materialList.length != 0) {
				this.materialList.forEach((item) => {
					if (item.id == val) {
						metterInfo = item;
					}
				});
				this.fromData.mateF = metterInfo.number;
				this.search.product = metterInfo.number;
				this.getList();
			}
		},
		// 子项物料
		metterChange1(val, type) {
			// console.log(val, type)
			let metterInfo = {};
			if (this.materialList.length != 0) {
				this.materialList.forEach((item) => {
					if (item.id == val) {
						metterInfo = item;
					}
				});
				this.fromData.mateC = metterInfo.number;
				this.search.childProduct = metterInfo.number;
				this.getList();
			}
		},
		handleSelectionChange(val) {
			this.multipleSelection = val;
			this.selectionLen = val.length;
		},
		handleSizeChange(val) {
			this.search.pageSize = val;
			this.Init();
		},
		handleCurrentChange(val) {
			this.search.pageNo = val;
			this.Init();
		},
		// 搜索事件
		searchData() {
			this.search.pageNo = 1;
			this.getList();
		},
		headerRigthMethod({ row, column, rowIndex, columnIndex }) {
			return 'headerRight';
		},
		// 搜索切换高度
		openRow() {
			this.isDown = !this.isDown;
			this.rowShow = !this.rowShow;
			if (this.rowShow) {
				this.heightNum = this.heightNum - 40;
			} else {
				this.heightNum = this.heightNum + 40;
			}
		},
		// 顶部公共按钮操作
		actionhandel(type) {
			this.actionType = type;
			// 点击新增
			if (type === 'add') {
				this.$router.push({
					path: '/material/mateBom/mateBomSet',
					query: { type: 'add', id: '', tags: Math.random() * 36 },
				});
			}
			if (this.multipleSelection && this.multipleSelection.length > 0) {
				// console.log(this.multipleSelection)
				let nweArysize = 0;
				// 物料id集合 （有去重）
				let newArry = [
					...new Set(
						this.multipleSelection.map((item) => {
							return item.id;
						})
					),
				];
				// 物料id 集合的size
				nweArysize = new Set(
					this.multipleSelection.map((item) => {
						return item.id;
					})
				).size;
				// 点击复制
				if (type === 'copy') {
					if (nweArysize > 1) {
						this.$message.error({
							message: '只能克隆版本相同的物料',
							showClose: true,
						});
					} else {
						this.$router.push({
							path: '/material/mateBom/mateBomSet',
							query: {
								type: 'copy',
								id: this.multipleSelection[0].id,
								tags: Math.random() * 36,
							},
						});
					}
				}
				// 点击提交
				if (type === 'submit') {
					this.toolarFn('MaterialBom/CommitList', newArry);
				}
				// 点击撤销
				if (type === 'revoke') {
					this.toolarFn('MaterialBom/Revoke', newArry);
				}
				// 点击审核
				if (type === 'audit') {
					this.toolarFn('MaterialBom/Check', newArry);
				}
				// 点击反审核
				if (type === 'de-approval') {
					this.toolarFn('MaterialBom/NoCheck', newArry);
				}
				// 点击删除
				if (type === 'delet') {
					this.toolarFn('MaterialBom/Delete', newArry);
				}
				// 禁用
				if (type === 'disabled') {
					this.toolarFn('MaterialBom/Disable', newArry);
				}
				//反禁用
				if (type === 'de-disabled') {
					this.toolarFn('MaterialBom/NoDisable', newArry);
				}
			} else {
				//按列表字段导出,点击全部导出
				if (
					type !== 'add' &&
					type !== 'refresh' &&
					type !== 'list-export' &&
					type !== 'all-export'
				) {
					this.$message.error({
						message: '请先勾选',
						showClose: true,
					});
				}
			}
			if (type === 'list-export' || type === 'all-export') {
				if (type === 'list-export') {
					exporthandel('MaterialBom/Export', this.search);
				}
				if (type === 'all-export') {
					exporthandel('MaterialBom/ExportAll', this.search);
				}
			}
			// 点击刷新
			if (type === 'refresh') {
				this.resetData();
			}
		},
		// 顶部操作方法-公共部分封装
		toolarFn(path, newArry) {
			let formdata = { ids: newArry };
			this.$http.post(path, formdata).then((res) => {
				if (res.status === 200) {
					this.dialogVisible = true;
					this.tableInfo = res.data;
				}
			});
		},
		beforeClose() {
			this.dialogVisible = false;
			this.search.pageNo = 1;
			this.search.pageSize = 50;
			this.getList();
		},
		// 详情
		toDetail(item) {
			this.$router.push({
				path: '/material/mateBom/mateBomSet',
				query: { type: 'edit', id: item.id },
			});
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderList.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
