<template>
<div class="modal_red">
	<p-modal title="冲红"
		width="90%"
		:visible="modal_visible"
		:enlargeable="true"
		:draggable="true"
		:confirm-loading="confirmLoading"
		@ok="handleOk"
		@cancel="handleCancel" >
		
		<p-table-edit-pro
		  ref="redTable"
		  auto-width
		  dragle
		  editor-row-table
		  rowKey="pickTaskDId"
		  :columns="modal_columns"
		  :data-source.sync="modal_data"
		  bordered
		  :hasRepairDataSource="true"
		  :row-select-type="0"
		  @colChange="colChange"
		  :loading = "loading"
		>
		<template slot="printStatus" slot-scope="text"> {{ text=='1' ? '已打印' : '未打印' }} </template>
		</p-table-edit-pro>
	</p-modal>
</div>
</template>

<script>
export default {
	props:{
		modal_visible:{type:Boolean,default:false},
		modal_columns:{type:Array,default:[]},
		modal_data:{type:Array,default:[]},
		modalType: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			loading: false,
			confirmLoading: false,
		}
	},	//data
	methods:{
		getData(params){
			params = {
				pageNum:this.pagination.current,
				pageSize:this.pagination.pageSize,
				...params
			};
			this.loading = true;
			/* page_picktask(params).then(res => {
			  if (res.success) {
			    this.data = res.data.list;
				this.pagination.total = Number(res.data.totalCount);
			    this.loading = false;
			  } else {
			    this.loading = false;
			    this.$exception(res);
			  }
			}) */
		},
		changePagination(pagination, filters, sorter) { // 分页变化
		  console.log(pagination, filters, sorter, '分页变化分页变化');
			this.pagination = pagination;
			// this.getData();  //分页查询所有列表
		},
		colChange({ name, value, index,label, record, modalRowData,config, vNode , options, moment, event}) {
		  console.log("改变单元格数据：",name, value, index,label, record, modalRowData);
		  
		  // this.modal_data[index].pickQty =record.pickQty;	//已拣数量
		  this.modal_data[index].redQty = parseInt(record.redQty) ;	//红冲数量
		  this.modal_data[index].redReason = record.redReason;
		  this.modal_data[index].messageType = record.messageType;
		  if(name=="redQty" && (/^[1-9]?[0-9]*\.[0-9]*[1-9]+$/.test(value) ) ){
		  			  this.$message.warning('冲红数量不能填小数！');
		  }
		  if(name=="redQty" &&  ((+record.redQty > +record.qty) || (+record.redQty > (+record.pickQty || +record.qty))) ){
			  record.redQty = 0;
			  this.$message.warning('冲红数量不能大于计划/已拣数量！');
		  } 
		  if(name=="redQty" && (record.redQty%record.conversionRate) != 0 && this.modalType == 'wholePicking'){
			//   record.redQty = 0;
			  this.$message.warning('冲红数量必须为整件数量！');
		  } 
		  console.log('行修改后：',this.modal_data[index]);
		},
		// 弹出框确认
		handleOk(e) {
			let _this = this ;
			this.$refs.redTable.validateFields(function (error, values, selectData) {
			if (!error) {
			// this.$nextTick(()=>{
				// _this.confirmLoading = true;
						console.log('弹出框OK: ', values,selectData);
						// _this.confirmLoading = false;
						//整件拣货判断
						let flag = _this.modal_data.every(item => {
						    return (item.redQty%item.conversionRate) == 0
						})
						if(!flag  && _this.modalType == 'wholePicking') {
							_this.$message.warning('冲红数量必须为整件数量！');
							return 
						}
						//整件拣货判断

						let orderPickingFalg = _this.modal_data.some(item => {
						    return item.pickTaskType == 0 && (item.redQty%item.conversionRate) != 0
						})
						if(orderPickingFalg  && _this.modalType == 'orderPicking') {
							_this.$message.warning('请将整件商品红冲数量改成为整件数量！');
							return 
						}
						_this.$emit('modal_confirm',_this.modal_data);
						_this.$emit('update:modal_visible',false);
				// });
				}
			})
			
		},
		handleCancel(e) {
				console.log('Clicked cancel button');
				//this.modal_visible = false;	//关闭确认弹窗
				this.$emit('update:modal_visible',false);
			},
	},	//methods
}
</script>

<style>
</style>
