<template>
	<div style="height:100%;">
		<div class="searchForm-header">
			<el-form :model="query" label-width="100px" inline="">
				<el-row>
					<el-form-item label="库房名称" style="margin-left: -15px">
						<el-select v-model="query.wareName" clearable size="small" style="width:120px;margin-left: -8px">
							<el-option v-for="item in optionsWare" :key="item.id" :label="item.name" :value="item.name">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="垛位名称" style="margin-left: -35px">
						<el-input v-model="query.stackName" size="small" style="width:120px;margin-left: -8px"></el-input>
					</el-form-item>
					<el-form-item label="钢板号" style="margin-left: -15px">
						<el-input v-model="query.plateNo" size="small" style="width:120px;margin-left: -8px" @input="getPltList">
						</el-input>
					</el-form-item>
					<el-form-item label="物料名称" style="margin-left: -35px">
						<el-input v-model="query.materialName" size="small" style="width:120px;margin-left: -8px">
							<el-button slot="append" icon="el-icon-search" @click="showMaterial"></el-button>
						</el-input>
					</el-form-item>
					<el-form-item label="钢种" style="margin-left: -35px">
						<el-input v-model="query.standard" size="small" style="width:150px;margin-left: -8px">
							<el-button slot="append" icon="el-icon-search" @click="showMaterial"></el-button>
						</el-input>
					</el-form-item>
					<el-form-item label="客户名称" style="margin-left: -35px">
						<el-select v-model="query.fkcustmerName" filterable placeholder="请选择客户名称" clearable size="small" style="margin-left: 5px; width: 170px">
							<el-option v-for="item in optionsCust" :key="item.name" :label="item.name" :value="item.name" >
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="订单客户" style="margin-left: -35px">
						<el-select v-model="query.customerName" filterable placeholder="请选择订单客户" clearable size="small" style="margin-left: 5px; width: 170px">
							<el-option v-for="item in optionsCust" :key="item.name" :label="item.name" :value="item.name" >
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="规格型号" style="margin-left: -15px">
						<el-input v-model="query.model" size="small" style="width:120px;margin-left: -8px">
						</el-input>
					</el-form-item>
					
					<el-form-item label="订单号" style="margin-left: -15px">
						<el-input v-model="query.ordNo" size="small" style="width:120px;margin-left: -8px" @input="getOrdList">
						</el-input>
					</el-form-item>

					<el-form-item label="垛位备注" style="margin-left: -15px">
						<el-input v-model="query.remark1" size="small" style="width:120px;margin-left: -8px">
						</el-input>
					</el-form-item>
					<el-form-item label="" style="margin-top: 0px;margin-left: 10px">
						<el-button @click="handleSearch" size="small"  type="primary">查询</el-button>
						<el-button @click="showChangeCustomer" size="small"  type="primary">货权转移</el-button>
						<!-- <el-button size="medium" type="primary" @click="handleImport">导入</el-button>
						<el-button size="medium" type="primary" @click="handleDownload">下载模板</el-button>
						<el-button size="medium" type="success" @click="showIn">入库</el-button>
						<el-button size="medium" type="danger" @click="handleInBack">取消入库</el-button> -->
						<el-button type="primary" size="small"  @click="showDistribution">配货</el-button>
            			<el-button type="primary" size="small"  @click="showOut">出库</el-button>
            			
						<el-button type="primary" size="small"  @click="resetButton" :disabled="backAble">重置</el-button>
						<el-button type="primary" size="small"  @click="handleRemark1" :disabled="backAble">修改垛位备注</el-button>
            			<el-button type="success" size="small"  @click="handleExport" >导出记录</el-button>
						
					</el-form-item>
					<el-form-item label="" style="margin-top: 0px;margin-left: 10px">
						<el-dropdown placement="bottom" trigger="click" @command="batchOperate">
							<el-button type="danger" size="small"> 其他操作<i class="el-icon-arrow-down el-icon--right"></i></el-button>
							<el-dropdown-menu slot="dropdown">
								<el-dropdown-item command="handleInBack" style="background-color: #f5f5f5;">取消入库</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>
						
					</el-form-item>
						<!-- <el-button type="primary" @click="showOut">出库</el-button> -->
					<!-- 	<el-form-item label=" ">
						<el-button @click="showChangeAddress" type="primary">修改地址</el-button>
					</el-form-item> -->
					<el-form-item label="数量" style="margin-left: -15px">
						<el-input v-model="sumCount" size="small" style="width:120px;margin-left: -8px">
						</el-input>
					</el-form-item>
					<el-form-item label="重量" style="margin-left: -15px">
						<el-input v-model="sumWeight" size="small" style="width:120px;margin-left: -8px">
						</el-input>
					</el-form-item>
				</el-row>
				
			</el-form>
		</div>
		<div class="tabledata-grid">
			<el-table :data="tableData" height="100%"   border style="width: 97%;" v-loading="loading" ref="multipleTable"	@select="handleTableSelect"	 @selection-change="handleSelectionChange" @select-all = "selectAll">
				<el-table-column type="selection" width="40" header-align="center" align="center"></el-table-column>
				<el-table-column prop="layer" label="层数" width="60" show-overflow-tooltip header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="stack.name" label="垛位" width="120" show-overflow-tooltip header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="material.name" label="货物品名" width="100" show-overflow-tooltip header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="material.standard" label="材质" width="100" show-overflow-tooltip header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="plateNo" label="钢板号" width="200" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="model" label="规格型号" width="160" show-overflow-tooltip header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="count" label="数量" width="120" show-overflow-tooltip align="right" header-align="center">
				</el-table-column>
				<el-table-column prop="weight" label="重量" width="120" show-overflow-tooltip align="right" header-align="center">
				</el-table-column>
				<el-table-column prop="ordNo" label="订单号" width="180" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="contractNo" label="合约号" width="180" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="customer.name" label="订单客户" width="300" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="fkComponyId" label="客户名称" width="300" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="receiveAddress" label="收货地址" width="300" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="productionPlace" label="产地" width="250" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="remark" label="备注" width="150" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="remark1" label="垛位备注" width="200" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="addTime" label="入库时间" width="200" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="carNo" label="入库车号" width="200" show-overflow-tooltip header-align="center">
				</el-table-column>
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
			 :page-sizes="pageSizes" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalRows">
			</el-pagination>
		</div>

		<popup-material ref="PopupMaterial" @receviceFromChild="receviceFromMaterial"></popup-material>
		<popup-customer ref="PopupCustomer" @receviceFromChild="receviceFromCustomer"></popup-customer>
		<popup-customer ref="PopupFKcustmer" @receviceFromChild="receviceFKcustmerr"></popup-customer>
		<popup-customer ref="PopupNewCustomer" @receviceFromChild="receviceFromNewCustomer"></popup-customer>
		<popup-address ref="PopupAddress" @receviceFromChild="receviceFromAddress"></popup-address>
		<popup-distribution ref="PopupDistribution" @receviceFromChild="receviceFromDistreibution" :selectRows="selectRows"></popup-distribution>
		<popup-out ref="PopupOut" @receviceFromChild="receviceFromOut"></popup-out>
		<popup-in ref="PopupIn" @receviceFromChild="receviceFromIn" :wares="options" :wareId="query.wareId" :stack="moveFromStack"></popup-in>
		<el-dialog title="货权转移" :visible.sync="customerDialogVisible" width="500px">
			<el-form>
				<el-form-item label="旧货主">
					<el-input v-model="oldCustomer">
					</el-input>
				</el-form-item>
				<el-form-item label="新货主">
					<el-select v-model="newCustomer.name" filterable placeholder="请选择订单客户" clearable>
						<el-option v-for="item in optionsCust" :key="item.id" :label="item.name" :value="item.id" >
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="修改地址">
					<el-input v-model="newAddress">
						<el-button slot="append" icon="el-icon-search" @click="showAddress"></el-button>
					</el-input>
				</el-form-item>
				<el-form-item label=" ">
					<el-button type="success" @click="handleCustomerSave">保存</el-button>
					<el-button type="danger" @click="handleCustomerCancelSave">取消</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>

		<el-dialog title="垛位备注" :visible.sync="stackDialogVisible" width="500px">
			<el-form>
				<el-form-item label="库房名称" style="margin-left: -15px">
					<el-select v-model="newWare" clearable size="small" style="width:120px;margin-left: -8px">
						<el-option v-for="item in optionsWare" :key="item.id" :label="item.name" :value="item.name">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="新垛位">
					<el-input v-model="newStack">
					</el-input>
				</el-form-item>
				<el-form-item label="新垛位备注">
					<el-input v-model="newRemark1">
					</el-input>
				</el-form-item>
				<el-form-item label=" ">
					<el-button type="success" @click="handleStackSave">保存</el-button>
					<el-button type="danger" @click="handleStackCancelSave">取消</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
		<el-dialog title="库房明细" :visible.sync="importDialogVisible" width="1000px">

			<el-upload class="upload-demo" action="" :on-change="handleChange" :on-exceed="handleExceed" :on-remove="handleRemove"
			 ref="upload" :limit="1" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
			 :auto-upload="false">
				<el-button slot="trigger" size="small" type="primary">选择文件</el-button>
				<el-button size="small" type="success" @click="inImport">保存</el-button>
				<!-- 				<div slot="tip" class="el-upload__tip">只 能 上 传 xlsx / xls 文 件</div> -->
			</el-upload>

			<el-table :data="imTableData" border>
				<el-table-column prop="层数" label="层数" width="60" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="库房" label="库房" width="100" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="垛位" label="垛位" width="120" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="物料" label="物料" width="120" show-overflow-tooltip align="center" header-align="center">
				</el-table-column>
				<el-table-column prop="钢种" label="钢种" width="120" show-overflow-tooltip align="center" header-align="center">
				</el-table-column>
				<el-table-column prop="钢板号" label="钢板号" width="200" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="规格型号" label="规格型号" width="120" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="数量" label="数量" width="120" show-overflow-tooltip align="right" header-align="center">
				</el-table-column>
				<el-table-column prop="重量" label="重量" width="120" show-overflow-tooltip align="right" header-align="center">
				</el-table-column>
				<el-table-column prop="客户" label="客户" width="300" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="备注" label="备注" width="150" show-overflow-tooltip header-align="center">
				</el-table-column>
			</el-table>

		</el-dialog>
	</div>
</template>

<script>
	import axios from '@/axios'
	import PopupStack from '@/components/PopupStack.vue'
	import PopupMaterial from '@/components/PopupMaterial.vue'
	import PopupCustomer from '@/components/PopupCustomer.vue'
	import PopupAddress from '@/components/PopupAddress.vue'
	import PopupDistribution from '@/components/PopupDistribution.vue'
	import PopupOut from '@/components/PopupOut.vue'
	import PopupIn from '@/components/PopupIn.vue'
	import Export2Excel from '../../excel/Export2Excel.js'
	import {
		mapState
	} from 'vuex'
	export default {
		components: {
			PopupStack,
			PopupMaterial,
			PopupCustomer,
			PopupAddress,
			PopupDistribution,
			PopupOut,
			PopupIn,
		},
		computed: {
			// splitCount: function() {
			// 	let result = Number(this.split.originalCount) - Number(this.split.count)
			// 	return result
			// },
			// splitWeight: function() {
			// 	let result = Number(this.split.originalWeight) - Number(this.split.weight)
			// 	return result
			// },
			...mapState({
				serverName: state => state.app.serverName,
				// wareBackgroundColor: state => state.color.wareBackgroundColor,
				// stackColor: state => state.color.stackColor,
				// stackSelectedColor: state => state.color.stackSelectedColor,
				// lockColor: state => state.color.lockColor,
			})
		},
		data() {
			return {
				addressDialogVisible: false,
				customerDialogVisible: false,
				query: {
					wareName: '',
					stackName: '',
					model: '',
					materialName: '',
					standard: '',
					customerName: '',
					plateNo: [],
					wareId:'',
					ordNo:[],
					fkcustmerName:'',
					remark1:''
				},
				multipleSelection: [],
				tableData: [],
				optionsWare: [],

				oldCustomer:'',
				newCustomer: {
					id: '',
					name: ''
				},
				newAddress: '',

				currentPage: 1,
				totalRows: 0,
				pageSizes: [50, 100, 200,1000],
				pageSize: 1000,
				HideAndShow: 0,


				loading: false,
				importDialogVisible: false,
				selectRows: [],
				options: [],
				moveFromStack: {}, //移除垛位
				fileTemp: [],
				imTableData: [],
				moveStore: {},
                optionsCust: [],
				sumCount:'',
				sumWeight:'',

				stackDialogVisible: false,
				newWare:'',
				newStack:'',
				newRemark1:'',
			};
		},
		mounted() {
			this.getWare()
			this.getAllCustomer()
			//this.getTableData()
		},
		methods: {
			showMaterial() {
				this.$refs.PopupMaterial.show()
			},
			receviceFromMaterial(material) {
				this.query.materialName = material.name
				this.query.standard = material.standard
			},
			batchOperate(command) {
				switch (command) {
					case "handleInBack":
						this.handleInBack();
						break;
				}
			},

			showCustomer() {
				this.$refs.PopupCustomer.show()
			},
			receviceFromCustomer(customer) {
				this.query.customerName = customer.name
			},

			
			showFKcustmer() {
				this.$refs.PopupFKcustmer.show()
			},
			receviceFKcustmerr(customer) {
				this.query.fkcustmerName = customer.name
			},

			showNewCustomer() {
				this.$refs.PopupNewCustomer.show()
			},
			receviceFromNewCustomer(customer) {
				this.newCustomer = customer
				this.newAddress = customer.address
			},
			showAddress() {
				this.$refs.PopupAddress.show(this.newCustomer.id)
			},
			receviceFromAddress(address) {
				this.newAddress = address.address
			},

			handleSearch() {
				this.currentPage = 1
				this.getTableData()
			},
			handleImport() {
				this.importDialogVisible = true
			},
			handleDownload() {
				window.open(this.serverName.substr(0, this.serverName.lastIndexOf('/', this.serverName.lastIndexOf('/') - 1)) +
					'/import.xls')
			},
			showIn() {
				// if (this.query.wareId == '') {
				// 	this.$message({
				// 		type: 'error',
				// 		message: '请选择入库库房'
				// 	});
				// 	return
				// }
				// if (this.query.stackId == '') {
				// 	this.$message({
				// 		type: 'error',
				// 		message: '请选择入库垛位'
				// 	});
				// 	return
				// }
				this.$refs.PopupIn.show()
			},
			handleInBack() {
				this.$confirm("确认删除吗?", "提示", {
					confirmButtonText:'确认',
					cancelButtonText:'取消',
					type: "warning"
				}).then(() => {
					if (this.selectRows.length < 1) {
						this.$message({
						type: 'error',
						message: '至少选择一条数据！',
						});
						return
					} else {
						var url = 'WareIn/back.do'
						var param = {
							json: JSON.stringify(this.selectRows),
						}
						axios.post(url, param).then(response => {
							if (response.data.code == 0) {
								this.getStoreByStackId(response.data.data)
							} else {
								this.$message({
									type: 'error',
									message: '操作失败；' + response.data.msg,
								});
							}
						});
					}
				}).catch(() => {});
				
			},
			resetButton(){      //查询条件重置
				this.query.wareName = '',
				this.query.stackName = '',
				this.query.model = '',
				this.query.materialName = '',
				this.query.standard = '',
				this.query.customerName = '',
				this.query.plateNo = '',
				this.query.wareId = '',
				this.query.ordNo = '',
				this.query.fkcustmerName = ''
			},
			showDistribution() {
				//console.log(this.selectRows.length)
				if (this.selectRows.length < 1) {
					this.$message({
						type: 'warning',
						message: '至少选择一条数据！',
					});
				}
				this.$refs.PopupDistribution.show()

			},
			showOut() {
				this.$refs.PopupOut.show()
			},
			getWare() {
				var url = 'MaintWare/queryByUserId.do'
				var param = {}
				axios.get(url, param).then(response => {
					this.optionsWare = response.data.data
					if (response.data.data.length == 1) {
						this.wareName = response.data.data[0].name

					}
				});
			},
			getAllCustomer() {
				var url = 'MaintCustomer/queryByUserId.do'
				var param = {}
				axios.get(url, param).then(response => {
					this.optionsCust = response.data.data
				});
			},
			handleSizeChange(val) {
				this.pageSize = val
				this.getTableData()
			},

			handleCurrentChange(val) {
				this.currentPage = val
				this.getTableData()
			},

			search() {
				this.currentPage = 1
				this.getTableData()
			},

			getTableData() {
				this.loading = true
				var url = 'WareStore/queryStore.do'
				var param = {
					page: this.currentPage,
					rows: this.pageSize,
					wareName: this.query.wareName,
					stackName: this.query.stackName,
					model: this.query.model,
					materialName: this.query.materialName,
					standard: this.query.standard,
					customerName: this.query.customerName,
					fkcustmerName: this.query.fkcustmerName,
					plateNo: this.query.plateNo.length == 0 ? '' : this.query.plateNo.join(','),
					ordNo: this.query.ordNo == 0 ? '' : this.query.ordNo.join(','),
					remark1: this.query.remark1
				}
				//console.log(param);
				axios.get(url, param).then(response => {
					if (response.data.code == 0) {
						//console.log(response.data.data.list);
						this.tableData = response.data.data.list
						this.totalRows = response.data.data.total
					} else {
						this.$message({
							type: 'error',
							message: '操作失败；' + response.data.msg,
						});
					}
					this.loading = false
				});
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
				this.sumCount =0;
				this.sumWeight=0;
				for (var i = 0; i < this.multipleSelection.length; i++){
					this.sumCount = parseInt(this.multipleSelection[i].count)+parseInt(this.sumCount);
					this.sumWeight = parseFloat(this.multipleSelection[i].weight)+parseFloat(this.sumWeight);
				}
				this.sumWeight = this.sumWeight.toFixed(3);
			},
			showChangeCustomer() {
				if (this.multipleSelection.length < 1) {
					this.$message({
						type: 'error',
						message: '至少选择一条记录！',
					});
					return
				}
				var customerAddress = this.multipleSelection[0].customer.address
				var boolean = true
				for (var i = 0; i < this.multipleSelection.length; i++) {
					if (this.multipleSelection[i].customer.address == customerAddress) {

					} else {
						boolean = boolean && false
						customerAddress = this.multipleSelection[i].customer.address
					}
				}
				if (boolean) {
					this.oldCustomer = this.multipleSelection[0].customer.name
					//this.newAddress = this.multipleSelection[0].receiveAddress
					this.newCustomer.name = "",
					this.newCustomer.id = "",
					this.customerDialogVisible = true
					
				} else {
					this.$message({
						type: 'error',
						message: '请选择同一客户！',
					});
				}
			},

			handleCustomerSave() {
				this.newCustomer.id = this.newCustomer.name;
				var url = 'WareChange/changeCustomer.do'
				var param = {

					json: JSON.stringify(this.multipleSelection),
					customer: JSON.stringify(this.newCustomer),
					address: this.newAddress
				}
				axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						this.getTableData()
						this.customerDialogVisible = false
					} else {
						this.$message({
							type: 'error',
							message: '操作失败；' + response.data.msg,
						});
					}
				});
			},
			handleCustomerCancelSave() {
				this.customerDialogVisible = false
			},
			handleRemark1(){
				this.stackDialogVisible= true;
				this.newStack='';
				this.newRemark1='';
			},
			handleStackSave(){
				var url = 'WareStore/changeStack.do'
				var param = {

					json: JSON.stringify(this.multipleSelection),
					newWare: this.newWare,
					newStack: this.newStack,
					newRemark1: this.newRemark1
				}
				axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						this.getTableData()
						this.stackDialogVisible = false
					} else {
						this.$message({
							type: 'error',
							message: '操作失败；' + response.data.msg,
						});
					}
				});
			},
			handleStackCancelSave(){
				this.stackDialogVisible = false
			},
			inImport() {
				var url = 'WareIn/inImport.do'
				var json = JSON.stringify(this.imTableData)
				var param = {
					json: json
				}
				axios.post(url, param).then(response => {
					if (response.data.code == '0') {
						this.$message({
							type: 'success',
							message: '入库成功!',
						});
						this.importDialogVisible = false
						this.imTableData = []
						this.fileTemp = null
					} else {
						this.$message({
							type: 'error',
							message: '入库失败!' + response.data.msg
						});

					}
				});
			},
			handleTableSelectionChange(val) {
				this.selectRows = val
				this.setLayerColor()
			},
			receviceFromDistreibution() {
				this.getStoreByStackId(null)
			},
			getStoreByStackId(moveSelect) {
				this.tableDataLoading = true
				var url = 'WareStore/queryByWareIdStackId.do'
				var param = {
					wareId: this.query.wareId,
					stackId: this.moveFromStack.id
				}
				axios.get(url, param).then(response => {
					if (response.data.code == 0) {
						this.tableData = response.data.data
						this.selectRows = []
						// if (this.isLayer == '0') {
						// 	this.drawStoreNoLayer(response.data.data)
						// } else if (this.isLayer == '1') {    //1是A开头的，2是B开头的，3是C开头的。
						// 	this.drawStoreAutoLayer(response.data.data)
						// } else if (this.isLayer == '2') {
						// 	this.drawStoreManulLayer(response.data.data)
						// }
						if (moveSelect) {
							this.$refs.multipleTable.clearSelection();
							for (let i = 0; i < this.tableData.length; i++) {
								for (let j = 0; j < moveSelect.length; j++) {
									if (moveSelect[j].layer === this.tableData[i].layer) {
										this.selectRows.push(this.tableData[i])
									}
								}
							}
							this.$nextTick(() => {
								this.toggleSelection(this.selectRows, true)
								this.setLayerColor()
							})

						}
					} else {
						this.$message({
							type: 'error',
							message: '保存失败' + response.data.msg,
						});
					}
					this.tableDataLoading = false
				});
			},
			receviceFromOut(customer) {
				this.getStoreByStackId()
			},
			receviceFromIn() {
				this.getStoreByStackId()
			},
			handleChange(file, fileList) {
				this.fileTemp = file.raw
				if (this.fileTemp) {
					if ((this.fileTemp.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') || (this.fileTemp.type ==
							'application/vnd.ms-excel')) {
						this.importfxx(this.fileTemp)
					} else {
						this.$message({
							type: 'warning',
							message: '附件格式错误，请删除后重新上传！'
						})
					}
				} else {
					this.$message({
						type: 'warning',
						message: '请上传附件！'
					})
				}

			},
			handleExceed(file, fileList) {},
			handleRemove(file, fileList) {
				this.fileTemp = null
			},
			toggleSelection(rows, selected) {
				if (rows) {
					rows.forEach(row => {
						this.$refs.multipleTable.toggleRowSelection(row, selected);  //接受两个参数，row传递被勾选行的数据，selected设置是否选中
					});
				}
			},
			setLayerColor() {
				if (this.selectRows.length == 0) {
					for (let i = 0; i < this.moveStore.storage._roots.length; i++) {
						if (this.tableData[i].lockFlag == '1') {
							this.moveStore.storage._roots[i].attr('style', {
								fill: this.lockColor,
							})
						} else {
							this.moveStore.storage._roots[i].attr('style', {
								fill: this.stackColor,
							})
						}
					}
				} else {
					for (let i = 0; i < this.moveStore.storage._roots.length; i++) {
						for (let j = 0; j < this.selectRows.length; j++) {
							if (this.tableData[i] === this.selectRows[j]) {
								this.moveStore.storage._roots[i].attr('style', {
									fill: this.stackSelectedColor,
								})
								break;
							} else {
								if (this.tableData[i].lockFlag == '1') {
									this.moveStore.storage._roots[i].attr('style', {
										fill: this.lockColor,
									})
								} else {
									this.moveStore.storage._roots[i].attr('style', {
										fill: this.stackColor,
									})
								}
							}
						}

					}
				}
			},
			handleTableSelect(selection, row) {  //第一个参数是目前所有选中的数据
				console.log(JSON.stringify(row))
				if (row.lockFlag == '1') {
					// this.$message({
					// 	type: 'error',
					// 	message: '该行已被配货锁定',
					// });
					alert("该行已被配货锁定")
					this.toggleSelection([row], false)
					// for(let i = 0;i<selection.length;i++){
					//  if(selection[i]==row){
					// 	 selection.splice(i,1)
					//  }
					// }
				} else {
					this.selectRows = selection
					this.setLayerColor()
				}
			},
			selectAll(selection){
				this.selectRows = selection;
			},
			getlist(){
				const replaceResult = this.query.plateNo.replace(/[；,，;\s\r\n]+/g, ",").split(",");
				this.query.plateNo = replaceResult;
			},
			getPltList(){
				const replaceResult = this.query.plateNo.replace(/[；,，;\s\r\n]+/g, ",").split(",");
				this.query.plateNo = replaceResult;
			},
			getOrdList(){
				const replaceResult = this.query.ordNo.replace(/[；,，;\s\r\n]+/g, ",").split(",");
				this.query.ordNo = replaceResult;
			},

			handleExport() {
				var imptData = [];
				var url = 'WareStore/queryStore.do'
				var param = {
					page: -1,
					rows: -1,
					wareName: this.query.wareName,
					stackName: this.query.stackName,
					model: this.query.model,
					materialName: this.query.materialName,
					standard: this.query.standard,
					customerName: this.query.customerName,
					fkcustmerName: this.query.fkcustmerName,
					plateNo: this.query.plateNo.length == 0 ? '' : this.query.plateNo.join(','),
					ordNo: this.query.ordNo == 0 ? '' : this.query.ordNo.join(','),
					remark1: this.query.remark1
				}


				axios.get(url, param).then(response => {

					if (response.data.code == 0) {
						console.log(response);
						var imptData = response.data.data;
						if (imptData.length == 0) {
							this.$alert('无法导出，没有库存', '提示', {
								confirmButtonText: '确定',
								callback: action => {}
							});
						} else {

							this.exportExcel(imptData)
						}
					} else {
						this.$message({
							type: 'error',
							message: '操作失败；' + response.data.msg,
						});
					}

				});
				
			},
			exportExcel(imptData) {
				// alert(JSON.stringify(imptData))
				const header = ["层数"
								,"垛位"
								,"货物品名"
								,"材质"
								,"钢板号"
								,"规格型号"
								,"数量"
								,"重量"
								,"订单号"
								,"合约号"
								,"订单客户"
								,"客户名称"
								,"收货地址"
								,"产地"
								,"备注"
								,"垛位备注"
								,"入库时间"
								,"入库车号"

				] // 导出的表头名
				const filterVal = ["layer"
									,"stackName"
									,"materialName"
									,"materialStandard"
									,"plateNo"
									,"model"
									,"count"
									,"weight"
									,"ordNo"
									,"contractNo"
									,"customerName"
									,"customerName"
									,"receiveAddress"
									,"productionPlace"
									,"remark"
									,"remark1"
									,"addTime"
									,"carNo"
				]
				for(var i=0;i<imptData.length;i++){
					imptData[i]["stackName"] 			= imptData[i].stack.name;
					imptData[i]["materialName"]     	= imptData[i].material.name;
					imptData[i]["materialStandard"]     = imptData[i].material.standard;
					imptData[i]["customerName"]     	= imptData[i].customer.name;
				}
				const list = imptData
				const data = this.formatJson(filterVal, list)

				const filename = '库存信息' + (new Date()).toLocaleDateString();
				Export2Excel.export_json_to_excel({
					header,
					data,
					filename
				})
			},
			formatJson(filterVal, jsonData) {
				return jsonData.map(v => filterVal.map(j => {
					return v[j]
				}))
			},

			//showChangeAddress() {},
			// handleAddressSave() {
			// },
			// handleAddressCancelSave() {
			// 	this.addressDialogVisible = false
			// },
		},
	}
</script>

<style>
.option_btn{
	margin-left: 30px
}
.searchForm-header{
		height: auto;
		margin-left: 10px;
	}
	.tabledata-grid{
		font-size: 20px;
		margin-left: 5px;
		height: calc(100% - 100px);

	}
</style>
