<template>
	<div style="height:100%;">
		<div class="searchForm-header">
			<el-row>
				<el-form :model="query" label-width="100px" inline="">
					<el-row>
						<el-form-item label="库房名称">
							<el-select size="small" v-model="query.wareName" clearable style="width: 140px;" @change="changeWare">
								<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:100px;margin-left: -8px"></el-input>
						</el-form-item>
						<el-form-item label="物料名称" style="margin-left: -35px">
							<el-input v-model="query.materialName" size="small" style="width:130px;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:130px;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.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: -35px">
							<el-select v-model="query.fkComponyName" 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-input v-model="query.carNo" size="small" style="width:100px;margin-left: -8px"></el-input>
						</el-form-item>

						<el-form-item label="规格型号" style="margin-left: 0px;">
							<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: -35px;">
							<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.contractNo" size="small"  style="width:120px;margin-left: -8px" @input="getConList">
              </el-input>
            </el-form-item>
						<el-form-item label="出库时间" style="margin-left: -35px">
								<el-date-picker v-model="query.RecordDate" style="width:330px;margin-left: -8px" size="small" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
							    </el-date-picker>
						</el-form-item>
						<el-form-item label="理货人员" >
							<el-select v-model="query.tallyPeople" size="small" style="margin-left: 10px;margin-top: -15px" clearable placeholder="理货人员">
								<el-option v-for="item in tallyPeopleOption" :key="item.id" :label="item.dicName" :value="item.dicCode">
								</el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="订单号" style="margin-left: -25px">
							<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: -25px">
							<el-input v-model="query.remark1" size="small"  style="width:120px;margin-left: -8px"  @input="getOrdList">
							</el-input>
						</el-form-item>
            <el-form-item label="修改时间" style="margin-left: -35px">
              <el-date-picker size="small" v-model="ChangeOutDtm" type="datetime" placeholder="选择日期时间" style="width:200px;margin-left: -8px">
              </el-date-picker>
            </el-form-item>
						<el-form-item label=" " style="margin-left: -60px">
							<el-button @click="handleSearch" type="primary" size="small">查询</el-button>
							<el-button @click="handlePrintOut" type="primary" size="small" style="width:90px;text-align: left">打印出库单</el-button>
							<!-- <el-button @click="handleOutBack" type="danger" size="small" style="width:70px">取消出库</el-button> -->
							<el-button @click="handleVerifyAcc" type="primary" size="small" style="width:70px">对账</el-button>
							<el-button @click="handleModifyPrice" type="primary" size="small" >批量改价</el-button>
							<el-button type="primary" size="small"  @click="resetButton" :disabled="backAble">重置</el-button>
							<el-button @click="changeCarNoShow" type="primary" size="small" >修改车号</el-button>
						</el-form-item>
						<el-form-item label="" >
							<el-upload class="upload-demo" action=""
								 ref="upload" :limit="1" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
								 :auto-upload="false"  >
								 <el-button plain slot="trigger"  type="success" v-show="false" style= "margin-left: 5px" size="small">询单导入</el-button>
								<el-button   type="success" @click="handleExport" style="margin-left: 2px" size="small">导出记录</el-button>
							</el-upload>
						</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="handleOutBack" style="background-color: #f5f5f5;">取消出库</el-dropdown-item>
								<el-dropdown-item command="handleDeleteRecord" style="background-color: #f5f5f5;">删除记录</el-dropdown-item>
								<el-dropdown-item command="changeRecordOutDtm" style="background-color: #f5f5f5;">修改时间</el-dropdown-item>
							</el-dropdown-menu>
						</el-dropdown>

					</el-form-item>

					</el-row>
				</el-form>
			</el-row>
			<total-block style="margin-top: -15px" ref="totalBlock" v-bind:childParam="childParam" v-bind:childUrl = 'childUrl'></total-block>
		</div>
		<div class="tabledata-grid">
			<el-table v-loading="loading"  :data="tableData"  @selection-change="handleSelectionChange" @select="handleTableSelect" height="100%" stripe border style="width: 97%;font-size: 13px;margin-top: -50px;margin-left: 25px" :header-cell-style="{'text-align':'center'}">
				<el-table-column type="selection" width="40" header-align="center" align="center"></el-table-column>
				<el-table-column prop="id" label="编号" min-width="10%" v-if="false">
				</el-table-column>
				<el-table-column prop="distributionId" label="配车号" min-width="10%" v-if="false">
				</el-table-column>
				<el-table-column prop="wareName" label="仓库名称" width="150px" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="stackName" label="垛位" width="60px" show-overflow-tooltip header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="layer" label="层号" show-overflow-tooltip width="60px" header-align="center" align="center">
				</el-table-column>
				<el-table-column prop="materialName" label="品名" show-overflow-tooltip width="100px" header-align="center" align="center">
				</el-table-column>
        <el-table-column prop="contractNo" label="合约号" show-overflow-tooltip width="100px" header-align="center" align="center">
        </el-table-column>
				<el-table-column prop="ordNo" label="订单号" width="180px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="inUser" label="入库人" width="100px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="inCarNo" label="入库车号" width="120px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="inTime" label="入库时间" width="200px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="model" label="规格" show-overflow-tooltip width="180px" align="center">
				</el-table-column>
				<el-table-column prop="standard" label="钢种" show-overflow-tooltip width="80px" align="center">
				</el-table-column>
				<el-table-column prop="count" label="出库数量" width="100px" show-overflow-tooltip align="right">
				</el-table-column>
				<el-table-column prop="weight" label="出库重量" width="100px" show-overflow-tooltip align="right">
				</el-table-column>
				<el-table-column prop="invoicePrice" label="基价" width="100px" show-overflow-tooltip align="right">
				</el-table-column>
				<el-table-column prop="unitPrice" label="结算价格" width="100px" show-overflow-tooltip align="right">
				</el-table-column>
				<el-table-column prop="plateNo" label="钢板号" width="200px" show-overflow-tooltip align="center">
				</el-table-column>
				<el-table-column prop="customerName" label="订单客户" width="200px" show-overflow-tooltip align="center">
				</el-table-column>   <!-- 原客户名称 -->
				<el-table-column prop="fkComponyName" label="客户名称" width="200px" show-overflow-tooltip align="center">
				</el-table-column>   <!-- 新增 -->
				<el-table-column prop="receiveAddress" label="收货地址" width="300" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="wgtDcnMtcCd" label="计量方式" width="100" show-overflow-tooltip header-align="center">
				</el-table-column>
				<el-table-column prop="edgeTy" label="切边类型" width="100" 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="outCarNo" label="出库车号" width="100px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="tallyPeople" label="出库理货人员" width="180px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="addId" label="出库操作人" width="120px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="addTime" label="出库时间" width="200px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="remark" label="备注" width="100px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="remark1" label="垛位备注" width="100px" show-overflow-tooltip align="left">
				</el-table-column>
				<el-table-column prop="recordType" label="类型" width="100px" show-overflow-tooltip align="center" :formatter="typeFormatter">
				</el-table-column>
				<el-table-column prop="verifyAccountId" v-if="false" label="对账ID" width="100px" show-overflow-tooltip align="center" >
				</el-table-column>
				<el-table-column prop="backFlag" label="取消标记" show-overflow-tooltip width="100px" align="center">
				</el-table-column>
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
			 :page-sizes="pageSizes" style="margin-left: 25px" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalRows">
			</el-pagination>
		</div>
		<el-dialog title="对账信息" :visible.sync="popupVerifyAcc" width="780px">
			<el-form label-width="150px" inline="">
				<el-row>
					<el-col :span="10">
						<el-form-item label="对账日期：" style="">
							<el-date-picker
						      v-model="accData.accDate"
						      type="date"
						      placeholder="选择日期"
						      style="width: 150px;margin-left: -8px">
						    </el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="总吨位：" style="">
							<el-input v-model="accData.accWgt" :disabled="true" size="small" style="width:150px;margin-left: -8px"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="10">
						<el-form-item label="总金额：" style="">
							<el-input v-model="accData.accAmt" :disabled="true" size="small" style="width:150px;margin-left: -8px"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="扣零：" style="">
							<el-input v-model="accData.accReminder" size="small" style="width:150px;margin-left: -8px"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="10">
						<el-form-item label="结算金额：" style="">
							<el-input v-model="accData.invoiceAmt" :disabled="true" size="small" style="width:150px;margin-left: -8px"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" :offset="2" >
						<el-button size="small" type="primary" style="margin-left: 30px;" @click="handleSaveVerifyAcc">提交</el-button>
					</el-col>
				</el-row>
			</el-form>


		</el-dialog>
		<el-dialog title="批量改价" :visible.sync="popupModPrice" width="780px">
			<el-form label-width="150px" inline="">
				<el-row>
					<el-col :span="12">
						<el-form-item label="总吨位：" style="">
							<el-input v-model="modifyWgt" :disabled="true" size="small" style="width:150px;margin-left: -8px"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="价格：" style="">
							<el-input v-model="modifyPrice" size="small" style="width:150px;margin-left: -8px"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-col :span="24" :offset="10" >
						<el-button size="small" type="primary" style="margin-left: 30px;" @click="handleSavePriceMod">提交</el-button>
					</el-col>
				</el-row>
			</el-form>
		</el-dialog>

		<el-dialog title="更改出库车号" :visible.sync="popupCarno" width="780px">
			<el-form label-width="150px" inline="">
				<el-row>
					<el-form-item label="车号" style="">
							<el-input v-model="changeCarNo" size="small" style="width:150px;margin-left: -8px"></el-input>
						</el-form-item>
				</el-row>
				<el-row>
					<el-button size="small" type="primary" style="margin-left: 30px;" @click="handlechangeCarNo">提交</el-button>
				</el-row>

			</el-form>
		</el-dialog>
		<popup-stack-with-select-ware :selectVareName="optionsWare" ref="PopupStackWithSelectWare" @receviceFromChild="receviceFromWareStack"></popup-stack-with-select-ware>
		<popup-material ref="PopupMaterial" @receviceFromChild="receviceFromMaterial"></popup-material>
		<popup-customer ref="PopupCustomer" @receviceFromChild="receviceFromCustomer"></popup-customer>
		<popup-customer ref="PopupFkCompony" @receviceFromChild="receviceFromFkCompony"></popup-customer>

		<!-- 导出Loading遮罩层 -->
		<div v-if="exportLoading" class="export-loading-mask">
			<div class="export-loading-content">
				<i class="el-icon-loading"></i>
				<p>正在导出，请稍候...</p>
			</div>
		</div>
	</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 PopupStackWithSelectWare from '@/components/PopupStackWithSelectWare.vue'
	import TotalBlock    from '@/components/TotalBlock.vue'
	import Export2Excel from '../../excel/Export2Excel.js'
	import {
		mapState
	} from 'vuex'
	export default {
		computed: {
			...mapState({
				serverName: state => state.app.serverName
			})
		},
		components: {
			PopupStackWithSelectWare,
			PopupMaterial,
			PopupCustomer,
			TotalBlock
		},
		data() {
			return {
				query: {
					wareName: '',
					stackName: '',
					model: '',
					materialName: '',
					standard: '',
					customerName: '',
					plateNo: [],
					RecordDate:[],
					carNo:'',
					tallyPeople:'',
					ordNo:[],
					fkComponyName:'',
					remark1:'',
          contractNo:'',
				},
				accData:{
					accDate:'',
					accWgt:0,
					accAmt:0,
					accReminder:0,
					invoiceAmt:0
				},
				tableData: [],

				currentPage: 1,
				totalRows: 0,
				pageSizes: [50, 100, 200,500,1000],
				pageSize: 50,
				HideAndShow: 0,
				optionsWare: [],
				dialogVisible: false,
				selectRows: [],
				moveFromStack: null,
				childParam:{
					page: '',
					rows: '',
					wareName: '',
					stackName: '',
					model: '',
					materialName: '',
					standard: '',
					customerName: '',
					plateNo: '',
					remark1:'',
          contractNo:''
				},
				childUrl:'WareOutRecord/queryTotal.do',
				time:"",
				tallyPeopleOption:[],
				loading: false,
				popupVerifyAcc:false,
				popupModPrice:false,
				modifyWgt:0,
				modifyPrice:0,
				optionsCust:[],
			changeCarNo:"",
			popupCarno: false,
			ChangeOutDtm:'',
			exportLoading: false  // 导出Loading状态
		};
		},
		//页面加载完成渲染
		mounted() {
			this.getWare()
			// this.getTableData()
			this.getSearchItem();
			this.setSearchTime();
			this.getAllCustomer();
		},
		methods: {
			setSearchTime(){
				var now = new Date();
				this.query.RecordDate = [new Date(now.getFullYear(), now.getMonth(), now.getDate()),new Date(now.getFullYear(), now.getMonth(), now.getDate()+1)];
			},
			typeFormatter: function(row, column) {
				switch (row.recordType) {
					case "0":
						return "出库取消";
						break;
					default:
						return "出库";
						break;
				}
			},
			getAllCustomer() {
				var url = 'MaintCustomer/queryByUserId.do'
				var param = {}
				axios.get(url, param).then(response => {
					this.optionsCust = response.data.data
				});
			},
			batchOperate(command) {
				switch (command) {
					case "handleOutBack":
						this.handleOutBack();
						break;
					case "handleDeleteRecord":
						this.handleDeleteRecord();
						break;
					case "changeRecordOutDtm":
						this.changeRecordOutDtm();
						break;
				}
			},
			handleSavePriceMod(){
				var url = 'WareOutRecord/savePriceMod.do'
				var param = {
					json: JSON.stringify(this.selectRows),
					modPrice:this.modifyPrice,
				}
				axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						this.$message({
							type: 'success',
							message: '保存成功',
						});
						this.popupModPrice = false
						this.getTableData();
					} else {
						this.$message({
							type: 'error',
							message: '保存失败！' + response.data.msg,
						});
					}
				});
			},
			handleSaveVerifyAcc() {
				var url = 'WareOutRecord/saveVerifyAcc.do'
				var param = {
					json: JSON.stringify(this.selectRows),
					accWgt:this.accData.accWgt,
					accAmt:this.accData.accAmt,
					invoiceAmt:this.accData.invoiceAmt,
					accDate:this.accData.accDate.Format("yyyyMMdd"),
					accReminder:this.accData.accReminder,
				}
				axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						this.$message({
							type: 'success',
							message: '保存成功',
						});
						this.popupVerifyAcc = false
						this.getTableData();
					} else {
						this.$message({
							type: 'error',
							message: '保存失败！' + response.data.msg,
						});
					}
				});
			},
			handleModifyPrice(){
				if (this.selectRows.length < 1) {
					this.$message({
						type: 'warning',
						message: '至少选择一条数据！',
					});
					return;
				}
				var wgt = 0;
				for(var i = 0;i < this.selectRows.length;i++){
					wgt += parseFloat(this.selectRows[i]["weight"]);
				}
				this.modifyWgt = wgt;
				this.popupModPrice = true;
			},
			handleVerifyAcc(){
				if (this.selectRows.length < 1) {
					this.$message({
						type: 'warning',
						message: '至少选择一条数据！',
					});
					return;
				}
				// accData:{
				// 	accDate:'',
				// 	accWgt:'',
				// 	accAmt:'',
				// 	accReminder:0,
				// 	invoiceAmt:''
				// },
				var wgt = 0;
				var amt = 0;
				var invAmt = 0;
				var fkcpy = this.selectRows[0]["fkComponyName"];
				var flag = true;
				for(var i = 0;i < this.selectRows.length;i++){
					if(this.selectRows[i]["fkComponyName"] != fkcpy){
						flag = false;
					}
					wgt += parseFloat(this.selectRows[i]["weight"]);
					amt = this.numSub(amt,this.numMulti(this.selectRows[i]["invoicePrice"] , this.selectRows[i]["weight"]));
				}
				if(!flag){
					this.$message({
						type: 'warning',
						message: '付款单位不同，无法对账',
					});
					return;
				}
				this.accData.accWgt = wgt;
				this.accData.accAmt = amt;
				this.accData.invoiceAmt = amt;
				var now = new Date();
				this.accData.accDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
				this.popupVerifyAcc = true;
			},
			resetButton(){      //查询条件重置
					this.query.wareName= '',
					this.query.stackName= '',
					this.query.model= '',
					this.query.materialName= '',
					this.query.standard= '',
					this.query.customerName= '',
					this.query.plateNo= [],
					this.query.RecordDate=[],
					this.query.carNo='',
					this.query.tallyPeople='',
					this.query.ordNo=[],
					this.query.fkComponyName='',
					this.query.remark1='';
					this.setSearchTime()
			},
			handleDeleteRecord(){
				if (this.selectRows.length < 1) {
					this.$message({
						type: 'error',
						message: '至少选择一条数据！',
					});
					return
				}else{
					var url = 'WareOutRecord/deleterecord.do'
					var param = {
						json: JSON.stringify(this.selectRows),
					}
					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,
							});
						}
					});
				}
			},
			numSub(num1, num2) {
				var baseNum, baseNum1, baseNum2;
				var precision;// 精度
				try {
					baseNum1 = num1.toString().split(".")[1].length;
				} catch (e) {
					baseNum1 = 0;
				}
				try {
					baseNum2 = num2.toString().split(".")[1].length;
				} catch (e) {
					baseNum2 = 0;
				}
				baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
				precision = (baseNum1 >= baseNum2) ? baseNum1 : baseNum2;
				return ((num1 * baseNum + num2 * baseNum) / baseNum).toFixed(precision);
			},
			numMulti(arg1,arg2){
				var m=0,s1=arg1.toString(),s2=arg2.toString();
				try{m+=s1.split(".")[1].length}catch(e){}
				try{m+=s2.split(".")[1].length}catch(e){}
				return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
			},
			getSearchItem(){
				var url = 'Common/querySelector.do'
				var param = {
					type: 'TALLY_PEOPLE',
				}
				axios.get(url, param).then(response => {
					// alert(JSON.stringify(response))
					this.tallyPeopleOption = response.data.data;
				});

			},
			getWare() {
				var url = 'MaintWare/queryByUserId.do'
				var param = {}
				axios.get(url, param).then(response => {
					// console.log(response)
					this.optionsWare = response.data.data
					if (response.data.data.length == 1) {
						this.wareName = response.data.data[0].name
						//	this.getStack()
					}
				});
			},
			handleTableSelectionChange(val) {
				this.selectRows = val
			},

			// 修改每页行数
			handleSizeChange(val) {
				this.pageSize = val
				this.getTableData()
			},
			// 修改当前页事件
			handleCurrentChange(val) {
				this.currentPage = val
				this.getTableData()
			},
			//点击查询
			handleSearch() {
				this.currentPage = 1
				this.getTableData()
			},
			showMaterial() {
				this.$refs.PopupMaterial.show()
			},
			receviceFromMaterial(material) {
				this.query.materialName = material.name
				this.query.standard = material.standard
			},
			showCustomer() {
				this.$refs.PopupCustomer.show()
			},
			showFkCompony(){
				this.$refs.PopupFkCompony.show()
			},
			receviceFromCustomer(customer) {
				this.query.customerName = customer.name
			},
			receviceFromFkCompony(customer) {
				this.query.fkComponyName = customer.name
			},

			getTableData() {
				var url = 'WareOutRecord/query.do'
				if(this.query.RecordDate == null){
					this.query.RecordDate = [false,false];
				}
				this.loading = true
				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,
					plateNo: this.query.plateNo.length == 0 ? '' : this.query.plateNo.join(','),
					pFromDate:(!this.query.RecordDate[0]) ? "1970-01-01 00:00:00" : this.query.RecordDate[0].Format("yyyy-MM-dd HH:mm:ss"),		//date类型
					pToDate  :(!this.query.RecordDate[1]) ? new Date().Format("yyyy-MM-dd HH:mm:ss") :this.query.RecordDate[1].Format("yyyy-MM-dd HH:mm:ss"),
					carNo:this.query.carNo,
					tallyPeople:this.query.tallyPeople,
					ordNo: this.query.ordNo == 0 ? '' : this.query.ordNo.join(','),
					fkComponyName:this.query.fkComponyName,
					remark1 : this.query.remark1,
          contractNo:this.query.contractNo.length == 0 ? '' : this.query.contractNo.join(','),
				}
				this.childParam = param;
				console.log(param);
				console.log(this.childParam);

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

			},
			handleSelectionChange(val) {
				this.selectRows = val
			},
			handleOutBack() {
				// if (this.selectRows.length != 1) {
				// 	this.$message({
				// 		type: 'error',
				// 		message: '只能选择一条数据取消出库！',
				// 	});
				// 	return
				// }

				if (this.selectRows[0].recordType == '0') {
					this.$message({
						type: 'error',
						message: '取消记录不能再次取消出库！',
					});
					return
				}

				if (this.selectRows[0].backFlag == '1') {
					this.$message({
						type: 'error',
						message: '该记录不能再次取消出库！',
					});
					return
				}
				// alert("1")
				this.$refs.PopupStackWithSelectWare.show()

			},
			receviceFromWareStack(stack) {
				var url = 'WareOut/back.do'
				var param = {
					json: JSON.stringify(this.selectRows),
					to: JSON.stringify(stack),
				}
				axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						this.getTableData()
					} else {
						this.$message({
							type: 'error',
							message: '操作失败；' + response.data.msg,
						});
					}
				});

			},
			changeWare(){
				//this.getTableData()
			},
			getPltList(){
				const replaceResult = this.query.plateNo.replace(/[；,，;\s\r\n]+/g, ",").split(",");
				this.query.plateNo = replaceResult;
			},
      getConList(){
        const replaceResult = this.query.contractNo.replace(/[；,，;\s\r\n]+/g, ",").split(",");
        console.log( this.query.contractNo,replaceResult)
        this.query.contractNo = replaceResult;
      },
			getOrdList(){
				const replaceResult = this.query.ordNo.replace(/[；,，;\s\r\n]+/g, ",").split(",");
				this.query.ordNo = replaceResult;
			},
			handlePrintOut(){
				if(this.selectRows.length > 1){
					this.$message({
						type: 'warning',
						message: '操作失败,请选择一条数据进行操作' ,
					});
					return;
				}
				// console.log(JSON.stringify(this.selectRows[0]))
				var distId = this.selectRows[0].distributionId;
				if( typeof(distId) == "undefined"||!distId){
					this.$message({
						type: 'warning',
						message: '操作失败,请选择正确的出库记录' ,
					});
					return;
				}
				window.open(this.serverName + 'ureport/preview?_u=file:out.ureport.xml&id=' + distId +
					'&time=' + this.time)

			},
			changeCarNoShow(){
				this.popupCarno = true,
				this.changeCarNo = ""
			},
			handlechangeCarNo(){
				if(this.selectRows.length > 1){
					this.$message({
						type: 'warning',
						message: '操作失败,请选择一条数据进行操作' ,
					});
					return;
				}
				// console.log(JSON.stringify(this.selectRows[0]))
				var distId = this.selectRows[0].distributionId;
				var url = 'WareOut/changeCarNo.do'
				var param = {
					distId: distId,
					carNo: this.changeCarNo
				}
				axios.post(url, param).then(response => {
					if (response.data.code == 0) {
						this.popupCarno = false,
						this.getTableData()
					} else {
						this.$message({
							type: 'error',
							message: '操作失败；' + response.data.msg,
						});
					}
				});

			},
			getTime() {
				var date = new Date();
				var year = date.getFullYear();
				var month = date.getMonth();
				var day = date.getDate();
				var hour = date.getHours();
				var minute = date.getMinutes();
				var second = date.getSeconds();
				month = Number(month) < 10 ? '0' + month : month
				day = Number(day) < 10 ? '0' + day : day
				hour = Number(hour) < 10 ? '0' + hour : hour
				minute = Number(minute) < 10 ? '0' + minute : minute
				second = Number(second) < 10 ? '0' + second : second
				this.time = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second

			},
			handleExport() {
        // 显示Loading遮罩，禁止用户操作
        this.exportLoading = true;

        var baseUrl = this.$store.state.app.serverName;
				var url = baseUrl + 'WareStore/outExportStoreExcel.do';
        let userId = localStorage.getItem("userId");
        let belongId = localStorage.getItem("belongId");
        let token = localStorage.getItem("token");
				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,
					plateNo: this.query.plateNo.length == 0 ? '' : this.query.plateNo.join(','),
					pFromDate:(!this.query.RecordDate[0]) ? "1970-01-01 00:00:00" : this.query.RecordDate[0].Format("yyyy-MM-dd HH:mm:ss"),		//date类型
					pToDate  :(!this.query.RecordDate[1]) ? new Date().Format("yyyy-MM-dd HH:mm:ss") :this.query.RecordDate[1].Format("yyyy-MM-dd HH:mm:ss"),
					carNo:this.query.carNo,
					tallyPeople:this.query.tallyPeople,
					ordNo: this.query.ordNo == 0 ? '' : this.query.ordNo.join(','),
					fkComponyName:this.query.fkComponyName,
					remark1:this.query.remark1,
          contractNo:this.query.contractNo.length == 0 ? '' : this.query.contractNo.join(','),
          userId: userId,
          belongId: belongId
				}

        var params = [];
        for (var key in param) {
          params.push(key + '=' + encodeURIComponent(param[key]));
        }
        var fullUrl = url + (params.length > 0 ? '?' + params.join('&') : '');

        // 使用 fetch + blob 方式，下载完成后关闭 loading
        fetch(fullUrl)
        .then(response => {
          if (!response.ok) {
            throw new Error('网络请求失败');
          }
          return response.blob();
        })
        .then(blob => {
          // 创建下载链接
          const url = window.URL.createObjectURL(blob);
          const link = document.createElement('a');
          link.href = url;
          link.download = '出库记录_' + new Date().toISOString().slice(0, 10) + '.xlsx';
          document.body.appendChild(link);
          link.click();
          // 浏览器开始下载后立即关闭 loading
          this.exportLoading = false;
          // 清理
          setTimeout(() => {
            document.body.removeChild(link);
            window.URL.revokeObjectURL(url);
          }, 100);
        })
        .catch(error => {
          console.error('导出失败:', error);
          this.$message.error('导出失败：' + error.message);
          this.exportLoading = false;
        });

		},
			exportExcel(imptData) {
				 console.log(JSON.stringify(imptData))
				const header = ["仓库名称"
								,"垛位"
								,"层号"
								,"品名"
								,"订单号"
								,"入库人"
								,"入库车号"
								,"入库时间"
								,"规格"
								,"钢种"
								,"出库数量"
								,"出库重量"
								,"钢板号"
								,"订单客户"
								,"客户单位"
								,"收货地址"
								,"计量方式"
								,"切边类型"
								,"产地"
								,"出库车号"
								,"出库理货人员"
								,"出库操作人"
								,"出库时间"
								,"备注"
								,"垛位备注"
								,"类型"
                ,"合约号"

				] // 导出的表头名
				const filterVal = [
						"wareName"
						,"stackName"
						,"layer"
						,"materialName"
						,"ordNo"
						,"inUser"
						,"inCarNo"
						,"inTime"
						,"model"
						,"standard"
						,"count"
						,"weight"
						,"plateNo"
						,"customerName"
						,"fkComponyName"
						,"receiveAddress"
						,"wgtDcnMtcCd"
						,"edgeTy"
						,"productionPlace"
						,"outCarNo"
						,"tallyPeople"
						,"addId"
						,"addTime"
						,"remark"
						,"remark1"
						,"recordType"
          ,"contractNo"
				]

				for(var i=0;i<imptData.length;i++){
					/*imptData[i]["addUserUserDesc"] = imptData[i].addUser.userDesc;
					imptData[i]["distributionTruckNo"] = imptData[i].distribution.truckNo;*/
					imptData[i]["recordType"]      = imptData[i]["recordType"] == 0 ? "出库取消" : "出库";
				}
				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]
				}))
			},

			changeRecordOutDtm(){
				if (this.selectRows.length < 1) {
					this.$message({
						type: 'error',
						message: '至少选择一条数据！',
					});
					return
				}else{
					var url = 'WareOutRecord/changeRecordOutDtm.do'
					var param = {
						json: JSON.stringify(this.selectRows),
						ChangeOutDtm: this.ChangeOutDtm.Format("yyyy-MM-dd HH:mm:ss")
					}
					axios.post(url, param).then(response => {
						if (response.data.code == 0) {
							this.getTableData()
						} else {
							this.$message({
								type: 'error',
								message: '操作失败；' + response.data.msg,
							});
						}
					});
				}
			}
		},
	}
</script>

<style>
.searchForm-header{
		/*background-color: red;*/
		height: auto;
		/*;*/
		margin-left: 10px;
	}
	.tabledata-grid{
		/*margin-left: 100px;*/
		font-size: 20px;
		height: calc(100% - 230px);
		/*background-color: #000;*/
	}

	/* 导出Loading遮罩层样式 */
	.export-loading-mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 9999;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.export-loading-content {
		background-color: #fff;
		padding: 40px 60px;
		border-radius: 8px;
		text-align: center;
		box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
	}

	.export-loading-content .el-icon-loading {
		font-size: 48px;
		color: #409EFF;
	}

	.export-loading-content p {
		margin-top: 20px;
		font-size: 16px;
		color: #333;
	}
</style>
