<template>
	<div style="height:100%;">
		<div class="searchForm-header"> <!-- 查询、操作按钮框 -->
			<el-form :model="query" label-width="100px" inline="">
				<el-row>
					<el-form-item label="库房名称"> <!-- 库房查询条件 -->
						<el-select v-model="query.wareName" clearable size="small" style="width:150px">
							<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="query.stackName" size="small" style="width:150px"></el-input>
					</el-form-item>
					<el-form-item label="品名"> <!-- 品名查询条件 -->
						<el-input v-model="query.materialName" size="small" style="width:150px">
						</el-input>
					</el-form-item>
					<el-form-item label="钢种"> <!-- 钢种查询条件 -->
						<el-input v-model="query.standard" size="small" style="width:150px">
						</el-input>
					</el-form-item>
					<el-form-item label="规格型号"> <!-- 规格型号查询条件 -->
						<el-input v-model="query.model" clearable size="small" style="width:120px">
						</el-input>
					</el-form-item>
					<el-form-item label="捆包号"> <!-- 捆包号查询条件 -->
						<el-input v-model="query.packNo" clearable size="small" style="width:120px" @input="getPackList">
						</el-input>
					</el-form-item>
					<el-form-item label="材料号"> <!-- 材料号查询条件 -->
						<el-input v-model="query.plateNo" clearable size="small" style="width:120px" @input="getPltList">
						</el-input>
					</el-form-item>
					<el-form-item label="订单号"> <!-- 订单号查询条件 -->
						<el-input v-model="query.ordNo" clearable size="small" style="width:120px" @input="getOrdList">
						</el-input>
					</el-form-item>
					<el-form-item label="合约号"> <!-- 合约号查询条件 -->
						<el-input v-model="query.contractNo" clearable size="small" style="width:120px" @input="getContractList">
						</el-input>
					</el-form-item>
					<el-form-item label="货权单位"> <!-- 货权单位查询条件 -->
						<el-select v-model="query.fkcustmerName" filterable placeholder="请选择货权单位" clearable size="small" style="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="客户名称"> <!-- 客户名称查询条件 -->
						<el-select v-model="query.customerName" filterable placeholder="请选择订单客户" clearable size="small" style="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="是否已出库"> <!-- 在库状态查询条件 -->
						<el-select v-model="query.outFlag" filterable placeholder="请选择在库状态" clearable size="small" style="width: 170px">
							<el-option v-for="item in optionsOutFlag" :key="item.value" :label="item.label" :value="item.value" >
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="入库时间">  <!-- 入库时间查询条件 -->
						<el-date-picker size="small" v-model="query.inRecordDate"  style="width:330px" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
						</el-date-picker>
					</el-form-item>

					<el-form-item label=""> <!-- 常规使用的操作按钮 -->
						<el-button @click="handleSearch" 		size="small"  type="primary">查询</el-button>
						<el-button @click="showChangeCustomer" 	size="small"  type="primary">货权转移</el-button>
						<el-button @click="showDistribution" 	size="small"  type="primary">配货</el-button>
            			<el-button @click="showOut" 			size="small"  type="primary">出库</el-button>
						<el-button @click="resetButton"			size="small"  type="primary">重置</el-button>
            			<el-button @click="handleExport"		size="small"  type="success">导出记录</el-button>
					</el-form-item>

					<el-form-item label=""> <!-- 防止异常操作隐藏起来的的操作按钮1 -->
						<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-item command="handleChangeCustomer" style="background-color: #f5f5f5;">批量修改</el-dropdown-item>
								<el-dropdown-item command="handleChangeStack" style="background-color: #f5f5f5;">批量倒垛</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>
					</el-form-item>

					<el-form-item label=""> <!-- 防止异常操作隐藏起来的的操作按钮2 -->
						<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="handleLock" style="background-color: #f5f5f5;">封锁</el-dropdown-item>
								<el-dropdown-item command="handleUnLock" style="background-color: #f5f5f5;">取消封锁</el-dropdown-item>
								<el-dropdown-item command="handleOutbound" style="background-color: #f5f5f5;">入仓</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>
						
					</el-form-item>
				</el-row>
			</el-form>
			<!-- 数据统计用的框 -->
			<total-block ref="totalBlock" style="margin-left: -25px;font-size: 13px;margin-left: 5px" v-bind:childParam="childParam" v-bind:childUrl = 'childUrl'></total-block>
		</div>

		<div class="tabledata-grid"> <!-- 数据展示框(包含翻页功能) -->
			<el-table :data="tableData" height="100%" border style="width: 97%;" v-loading="loading" ref="multipleTable"	@select="handleTableSelect" @select-all = "selectAll" 
			:row-class-name="tableRowClassName">
				<el-table-column type="selection" width="40" header-align="center" align="center" fixed></el-table-column>
				<el-table-column label="操作">
					<template slot-scope="scope">
						<el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
					</template>
				</el-table-column>
				<el-table-column prop="stack.name" label="垛位" width="100" show-overflow-tooltip 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="material.name" label="品名" width="120" show-overflow-tooltip header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="material.standard" label="钢种" width="120" show-overflow-tooltip header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="plateNo" label="产品编号" width="150" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="ordNo" label="订单号" width="120" 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="weight" label="重量" width="80" show-overflow-tooltip align="left" header-align="center">
				</el-table-column>
				<el-table-column prop="count" label="数量" width="60" show-overflow-tooltip align="left" header-align="center">
				</el-table-column>
				<el-table-column prop="contractNo" label="合约号" width="100" show-overflow-tooltip align="left" header-align="center">
				</el-table-column>
				<el-table-column prop="fkCustomerName" label="货权单位" width="240" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="customer.name" label="客户名称" width="240" 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="ware.name" label="仓库名称" width="100" show-overflow-tooltip header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="carNo" label="入库车号" width="120" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="addTime" label="入库时间" width="180" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="productionPlace" label="产地" width="160" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="packNo" label="捆包号" width="140" 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="lockFlag" label="锁定状态" width="100" show-overflow-tooltip header-align="center" :formatter="lockFormatter">
				</el-table-column>
				<el-table-column prop="addUser.userDesc" label="入库操作人" width="120px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="tallyPeople" label="吊装工" width="100" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="wgtDcnMtcCd" label="计量方式" width="100" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="payWay" label="月付方式" width="100" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="outBound" label="是否出仓" width="100" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="inwareDay" label="存储天数" width="100" 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>

		<el-dialog title="货权转移" :visible.sync="customerDialogVisible" width="500px">
			<el-form>
				<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-select v-model="newfkCustomer.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-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-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="changeCUSTDialogVisible" width="500px">
			<el-form>
				<el-form-item label="新客户名称" >
					<el-select v-model="newCustomername" filterable placeholder="请选择客户名称" clearable size="small" >
						<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="新货权单位" >
					<el-select v-model="newFKCustomername" filterable placeholder="请选择货权单位" clearable size="small" >
						<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="新订单号">
					<el-input v-model="newOrdno" style="width:200px;margin-left: 0px">
					</el-input>
				</el-form-item>
				<el-form-item label="新合约号">
					<el-input v-model="newContractno" style="width:200px;margin-left: 0px">
					</el-input>
				</el-form-item>
				<el-form-item label="新收货地址">
					<el-input v-model="newReceiveaddress" style="width:260px;margin-left: 0px">
					</el-input>
				</el-form-item>
				<el-form-item label="新产地">
					<el-input v-model="newProductionplace" style="width:260px;margin-left: 0px">
					</el-input>
				</el-form-item>
				<el-form-item label="新捆包号">
					<el-input v-model="newPackno" style="width:200px;margin-left: 0px">
					</el-input>
				</el-form-item>

				<el-form-item label=" ">
					<el-button type="success" @click="handleChangeCUSTSave">确定</el-button>
					<el-button type="danger" @click="handleChangeCUSTCancelSave">取消</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>

		<el-dialog title="修改材料信息" :visible.sync="storedialogVisible" width="900px">
			<el-form :model="store" label-position="right" label-width="80px">
				<el-row>
					<el-col :span="9">
						<el-form-item label="材料编号">
							<el-input v-model.number="store.plateNo"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="9">
						<el-form-item label="规格型号">
							<el-input v-model.number="store.model"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="9">
						<el-form-item label="品名">
							<el-input v-model.number="store.material.name"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="9">
						<el-form-item label="钢种">
							<el-input v-model.number="store.material.standard"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="9">
						<el-form-item label="数量">
							<el-input v-model.number="store.count"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="9">
						<el-form-item label="重量">
							<el-input v-model.number="store.weight"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="9">
						<el-form-item label="订单号">
							<el-input v-model.number="store.ordNo"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="9">
						<el-form-item label="合约号">
							<el-input v-model.number="store.contractNo"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="9">
						<el-form-item label="捆包号">
							<el-input v-model.number="store.packNo"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="9">
						<el-form-item label="产地">
							<el-input v-model.number="store.productionPlace"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<!-- 第六行 -->
				<el-row>
					<el-col :span="9">
						<el-form-item label="货权单位">
							<el-select v-model="store.fkCustomerName" filterable placeholder="请选择客户名称" clearable >
								<el-option v-for="item in optionsCust" :key="item.id" :label="item.name" :value="item.name" >
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="9">
						<el-form-item label="客户名称">
							<el-select v-model="store.customer.name" filterable placeholder="请选择客户名称" clearable >
								<el-option v-for="item in optionsCust" :key="item.id" :label="item.name" :value="item.name" >
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="18">
						<el-form-item label="收货地址">
							<el-input v-model="store.receiveAddress"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="18">
						<el-form-item label="备注">
							<el-input v-model="store.remark"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-button size="medium" type="success" @click="handleChangeStore(store)">确定</el-button>
					<el-button size="medium" type="danger" @click="handleChangeStoreCancelSave()">取消</el-button>
				</el-row>
			</el-form>
		</el-dialog>

		<!-- 调用外部界面的弹窗索引 -->
		<popup-distribution ref="PopupDistribution" @receviceFromChild="receviceFromDistreibution" :selectRows="selectRows"></popup-distribution>
		<popup-out ref="PopupOut" @receviceFromChild="receviceFromOut"></popup-out>
	</div>
</template>

<script>
	import axios from '@/axios'
	import PopupDistribution from '@/components/PopupDistribution.vue'
	import PopupOut from '@/components/PopupOut.vue'
	import Export2Excel from '../../excel/Export2Excel.js'
	import TotalBlock    from '@/components/TotalBlock.vue'
	import {
		mapState
	} from 'vuex'
	export default {
		components : {
			PopupDistribution,
			PopupOut,
			TotalBlock
		},
		computed: {
			...mapState({
				serverName: state => state.app.serverName,
			})
		},
		data() {
			return {
				query: { //查询条件
					wareName: '',
					stackName: '',
					model: '',
					materialName: '',
					standard: '',
					customerName: '',
					plateNo: [],
					wareId:'',
					ordNo:[],
					contractNo:[],
					packNo:[],
					fkcustmerName:'',
					outFlag:'0',
					inRecordDate:[]
				},
				optionsWare: [],   //库房下拉框
				optionsCust: [],   //客户名称下拉框
				optionsOutFlag: [{ //物料状态下拉框
					value: '0',
					label: '在库'
				},{
					value: '1',
					label: '已出库'
				}],
				tableData: [],   //数据展示区域用到变量
				selectRows: [],  //数据展示区域选选中行数数据暂存
				multipleSelection: [],
				currentPage: 1,  //数据展示显示页数
				totalRows: 0,    //数据合计
				pageSizes: [50, 100, 200,1000],//单页中数据展示的行数下拉框
				pageSize: 1000,//初始单页中数据展示的默认值
				loading: false,//数据展示区中是否正在加载flag
				childParam:{   //数据统计区域用到的查询变量
					wareName: '',
					stackName: '',
					model: '',
					materialName: '',
					standard: '',
					customerName: '',
					plateNo: [],
					wareId:'',
					ordNo:[],
					contractNo:[],
					packNo:[],
					fkcustmerName:'',
					remark1:'',
					outFlag:'0',
					inRecordDate:[]
				},
				childUrl:'WareStore/queryTotal.do',// 数据统计区域调用的后台

				customerDialogVisible: false,	//“货权转移”的弹框Flag
				stackDialogVisible: false,		//“批量垛位”的弹框Flag
				changeCUSTDialogVisible: false,	//“批量修改信息”的弹框Flag
				storedialogVisible: false,		//“单只材料修改”的弹框Flag

				newCustomer: {//“货权转移”的弹框中“新客户”
					id: '',
					name: ''
				},
				newfkCustomer: {//“货权转移”的弹框中“新货主”
					id: '',
					name: ''
				},
				newAddress: '',//“货权转移”的弹框中“新地址”

				newWare:'', //“批量修改垛位”弹窗中“新库房”
				newStack:'',//“批量修改垛位”弹窗中“新垛位”
				
				store:{  //“单只材料信息修改”弹窗中对应数据信息
					id: '',
					material: {
						id: '',
						name: '',
						standard: ''
					},
					model: '',
					customer: {
						id: '',
						name: ''
					},
					fkCompony: {
						id: '',
						name: ''
					},
					count: '',
					weight: '',
					remark: '',
					plateNo: '',
					receiveAddress: '',
					receiveAddressFir: '',
					receiveAddressLast: '',
					wgtDcnMtcCd:'',
					edgeTy:'',
					productionPlace:'',
					ordNo:'',
					carNo:'',
					tallyPeople:'',
					fkComponyId:'',
					customerSName:''
				},

				newCustomername:'',		//“批量修改”弹窗中“新客户名称”
				newFKCustomername:'',	//“批量修改”弹窗中“新付款单位”
				newContractno:'',		//“批量修改”弹窗中“新合同号”
				newOrdno:'',			//“批量修改”弹窗中“新订单号”
				newReceiveaddress:'',	//“批量修改”弹窗中“新收货地址”
				newProductionplace:'',	//“批量修改”弹窗中“新产地”
				newPackno:'',			//“批量修改”弹窗中“新捆包号”
			}
		},
		mounted() {
			this.getWare()         //初始化-库房下拉框-数据载入
			this.getAllCustomer()  //初始化-客户下拉框-数据载入
		},
		methods: {
			//获取--库房下拉框--数据
			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
				});
			},
			// “捆包号”查询框进行批量查询时用到的函数
			getPackList(){
				const replaceResult = this.query.packNo.replace(/[；,，;\s\r\n]+/g, ",").split(",");
				this.query.packNo = 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;
			},
			// “合同号”查询框进行批量查询时用到的函数
			getContractList(){
				const replaceResult = this.query.contractNo.replace(/[；,，;\s\r\n]+/g, ",").split(",");
				this.query.contractNo = replaceResult;
			},
			//下拉按钮中对应按钮调用的独影的函数
			batchOperate(command) {
				switch (command) {
					case "handleInBack":
						this.handleInBack();
						break;
					case "handleChangeCustomer":
						this.handleChangeCustomer();
						break;
					case "handleChangeStack":
						this.handleChangeStack();
						break;
					case "handleLock":
						this.handleLock();
						break;
					case "handleUnLock":
						this.handleUnLock();
						break;
					case "handleOutbound":
						this.handleOutbound();
						break;
				}
			},
			// 数据展示框中调用的函数
			handleTableSelect(selection, row) {
				console.log(JSON.stringify(row))
				this.selectRows = selection
			},
			handleTableSelectionChange(val) {
				this.selectRows = val
			},
			selectAll(selection){
				this.selectRows = selection;
			},
			lockFormatter: function(row, column) {
				switch (row.lockFlag) {

					case "0":
						return "";
						break;
					default:
						return "已锁定";
						break;
				}
			},
			tableRowClassName({row}) {     //行数据进行变色处理的函数
				if (row.lockFlag === '1') {
					return 'warning-row'
				}
				return ''
			},

			// 查询相关的函数
			handleSearch() {         //查询按钮调用的函数
				this.currentPage = 1
				this.getTableData()
			},
			handleSizeChange(val) {  //数据展示区域中翻页调用的函数
				this.pageSize = val
				this.getTableData()
			},
			handleCurrentChange(val) { //数据展示区域中单页显示条数变更调用的函数
				this.currentPage = val
				this.getTableData()
			},
			getTableData() {   //调用后台的通用函数
				//增加判断条件，防止查询历史数据时间过长
				if(this.query.outFlag == '1' && (this.query.inRecordDate == null || this.query.inRecordDate == '')){
					this.$message({
						type: 'error',
						message: '查询历史数据请选择入库时间区间',
					});
					return
				}
				if(this.query.inRecordDate == null){
					this.query.inRecordDate = [false,false];
				}
				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(','),
					contractNo: this.query.contractNo == 0 ? '' : this.query.contractNo.join(','),
					packNo: this.query.packNo == 0 ? '' : this.query.packNo.join(','),
					remark1: this.query.remark1,
					outFlag: this.query.outFlag,
					fromDate:(!this.query.inRecordDate[0]) ? "1970-01-01 00:00:00" : this.query.inRecordDate[0].Format("yyyy-MM-dd HH:mm:ss"),		//date类型
					toDate  :(!this.query.inRecordDate[1]) ? new Date().Format("yyyy-MM-dd HH:mm:ss") :this.query.inRecordDate[1].Format("yyyy-MM-dd HH:mm:ss"),

				}
				this.childParam = param;
				axios.get(url, param).then(response => {
					if (response.data.code == 0) {
						this.tableData = response.data.data.list
						this.totalRows = response.data.data.total
						this.$refs.totalBlock.getTotalData();
					} else {
						this.$message({
							type: 'error',
							message: '操作失败；' + response.data.msg,
						});
					}
					this.loading = false
				});
			},

			//货权转移按钮对应的操作函数
			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.newCustomer.name = "",
					this.newCustomer.id = "",
					this.newfkCustomer.name="",
					this.newfkCustomer.id = "",
					this.customerDialogVisible = true
					
				} else {
					this.$message({
						type: 'error',
						message: '请选择同一客户！',
					});
				}
			},
			handleCustomerSave() {   //“货权转移”界面“保存”按钮对应的调用后台的函数
				this.newCustomer.id = this.newCustomer.name;
				this.newfkCustomer.id = this.newfkCustomer.name;
				var url = 'WareChange/changeCustomer.do'
				var param = {
					json: JSON.stringify(this.multipleSelection),
					customer: JSON.stringify(this.newCustomer),
					fkcustomer: JSON.stringify(this.newfkCustomer),
					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
			},

			//配货按钮对应的操作函数
			showDistribution() {
				if (this.selectRows.length < 1) {
					this.$message({
						type: 'warning',
						message: '至少选择一条数据！',
					});
				}
				this.$refs.PopupDistribution.show()
			},
			receviceFromDistreibution() { //弹窗返回的数据调用的函数
				this.handleSearch()
			},

			//出库按钮对应的操作函数
			showOut() {
				this.$refs.PopupOut.show()
			},
			receviceFromOut(customer) { //弹窗返回的数据调用的函数
				this.handleSearch()
			},

			//重置按钮对应的操作函数
			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 = ''
			},

			//导出记录按钮对应操作函数
			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(','),
					contractNo: this.query.contractNo == 0 ? '' : this.query.contractNo.join(','),
					packNo: this.query.packNo == 0 ? '' : this.query.packNo.join(','),
					remark1: this.query.remark1,
					outFlag: this.query.outFlag,
					fromDate:(!this.query.inRecordDate[0]) ? "1970-01-01 00:00:00" : this.query.inRecordDate[0].Format("yyyy-MM-dd HH:mm:ss"),		//date类型
					toDate  :(!this.query.inRecordDate[1]) ? new Date().Format("yyyy-MM-dd HH:mm:ss") :this.query.inRecordDate[1].Format("yyyy-MM-dd HH:mm:ss"),
				}
				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) {//处理数据并生成excel文件的代码
				const header = ["仓库名称",
								"垛位",
								"层数",
								"品名",
								"钢种",
								"产品编号",
								"订单号",
								"规格型号",
								"重量",
								"数量",
								"合约号",
								"入库车号",
								"入库时间",
								"货权单位",
								"客户名称",
								"收货地址",
								"产地",
								"捆包号",
								"备注",
								"锁定状态",
								"入库操作人",
								"吊装工",
								"计量方式",
								"月付方式",
								"是否出仓",
								"存储天数"

				] // 导出的表头名
				const filterVal = ["wareName",
									"stackName",
									"layer",
									"materialName",
									"materialStandard",
									"plateNo",
									"ordNo",
									"model",
									"weight",
									"count",
									"contractNo",
									"carNo",
									"addTime",
									"fkCustomerName",
									"customerName",
									"receiveAddress",
									"productionPlace",
									"packNo",
									"remark",
									"lockFlag",
									"addUserUserDesc",
									"tallyPeople",
									"wgtDcnMtcCd",
									"payWay",
									"outBound",
									"inwareDay"
				]
				for(var i=0;i<imptData.length;i++){
					imptData[i]["wareName"] 			= imptData[i].ware.name;
					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;
					imptData[i]["addUserUserDesc"]     	= imptData[i].addUser.userDesc;
					imptData[i]["lockFlag"]     		= imptData[i].lockFlag == 0 ? '': '已锁定';
				}
				const list = imptData
				const data = this.formatJson(filterVal, list)

				const filename = '库存信息' + (new Date()).toLocaleDateString();
				Export2Excel.export_json_to_excel({
					header,
					data,
					filename,
					rowStyle: (rowData, rowIndex) => {
						// 根据库存量设置颜色
						if (rowData.lockFlag === "已锁定") {
							return {
								fill: { fgColor: { rgb: "FF0000" } }, // 红色
								font: { color: { rgb: "FFFFFF" }, bold: true }
							};
						} 
						return {};
					}
				})
			},
			formatJson(filterVal, jsonData) { 
				return jsonData.map(v => filterVal.map(j => {
					return v[j]
				}))
			},

			//取消入库按钮对应的操作函数
			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(() => {});
				
			},

			//”批量修改“操作对应的操作函数
			handleChangeCustomer(){ //打开“批量修改”的弹窗
				this.newCustomername = '',
				this.newFKCustomername='',
				this.newContractno='',
				this.newOrdno='',
				this.newReceiveaddress='',
				this.newProductionplace='',
				this.newPackno='',
				this.changeCUSTDialogVisible= true
			},
			handleChangeCUSTSave(){ //“批量修改”弹窗中“保存”按钮对应的函数
				var url = 'WareStore/changeAll.do'
				var param = {
					json: JSON.stringify(this.multipleSelection),
					newCustomername: this.newCustomername,
					newFKCustomername: this.newFKCustomername,
					newContractno: this.newContractno,
					newOrdno: this.newOrdno,
					newReceiveaddress: this.newReceiveaddress,
					newProductionplace: this.newProductionplace,
					newPackno: this.newPackno,
					
				}
				axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						this.getTableData()
						this.changeCUSTDialogVisible = false
					} else {
						this.$message({
							type: 'error',
							message: '操作失败；' + response.data.msg,
						});
					}
				});
			},
			handleChangeCUSTCancelSave(){//“批量修改”弹窗中“取消”按钮对应的函数
				this.changeCUSTDialogVisible = false
			},

			//“批量修改垛位”操作对应的操作函数
			handleChangeStack(){ //打开“批量垛位修改”的弹窗
				this.stackDialogVisible = true;
				this.newStack='';
			},
			handleStackSave(){  //“批量垛位修改”弹窗中“保存”按钮对应的函数
				var url = 'WareStore/changeStack.do'
				var param = {

					json: JSON.stringify(this.multipleSelection),
					newWare: this.newWare,
					newStack: this.newStack,
					newRemark1: this.newRemark1,
					newRemark: this.newRemark
				}
				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
			},

			handleLock(){  //“封锁”按钮对应的函数
				this.$confirm("确认将选中的材料进行封锁吗?", "提示", {
					confirmButtonText:'确认',
					cancelButtonText:'取消',
					type: "warning"
				}).then(() => {
					if (this.selectRows.length < 1) {
						this.$message({
						type: 'error',
						message: '至少选择一条数据！',
						});
						return
					} else {
						var url = 'WareStore/lockAndUnlock.do'
						var param = {
							json: JSON.stringify(this.selectRows),
							lockFlag:'1'
						}
						axios.post(url, param).then(response => {
							if (response.data.code == 0) {
								this.getTableData()
							} else {
								this.$message({
									type: 'error',
									message: '操作失败；' + response.data.msg,
								});
							}
						});
					}
				}).catch(() => {});
			},

			handleUnLock(){//“取消封锁”的按钮对应的函数
				this.$confirm("确认将选中的材料取消封锁吗?", "提示", {
					confirmButtonText:'确认',
					cancelButtonText:'取消',
					type: "warning"
				}).then(() => {
					if (this.selectRows.length < 1) {
						this.$message({
						type: 'error',
						message: '至少选择一条数据！',
						});
						return
					} else {
						var url = 'WareStore/lockAndUnlock.do'
						var param = {
							json: JSON.stringify(this.selectRows),
							lockFlag:'0'
						}
						axios.post(url, param).then(response => {
							if (response.data.code == 0) {
								this.getTableData()
							} else {
								this.$message({
									type: 'error',
									message: '操作失败；' + response.data.msg,
								});
							}
						});
					}
				}).catch(() => {});
			},

			handleOutbound(){  //“入仓”按钮对应的函数
				this.$confirm("确认将选中的材料标记为入仓吗?", "提示", {
					confirmButtonText:'确认',
					cancelButtonText:'取消',
					type: "warning"
				}).then(() => {
					if (this.selectRows.length < 1) {
						this.$message({
						type: 'error',
						message: '至少选择一条数据！',
						});
						return
					} else {
						var url = 'WareStore/Outbound.do'
						var param = {
							json: JSON.stringify(this.selectRows),
							outbound: '已入仓'
						}
						axios.post(url, param).then(response => {
							if (response.data.code == 0) {
								this.getTableData()
							} else {
								this.$message({
									type: 'error',
									message: '操作失败；' + response.data.msg,
								});
							}
						});
					}
				}).catch(() => {});
			},

		}
	}
</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);
	}

	.el-select-dropdown .el-scrollbar .el-scrollbar__wrap { overflow: scroll!important; }

	.el-table .warning-row { background-color: #fde2e2; }

	.el-table .success-row { background-color: #f0f9eb; }
</style>
