import moment  from 'moment';
import store  from '@/store';
import { genWarehouseAuthSearchModal,genCargoownerAuthSearchModal,genWarehouseLocatorSearchModal } from  '@/views/kzyWMS/SearchModal';
import { upcloud_base_strategy } from "@/config/serviceSettings";
const grid = { span: 8, labelCol: { span: 6 } };

let rows = null ;	// on search获取当前行数据
let warehouseId= store.getters.warehouse.warehouseId;	//仓库id;
let srcWarehouseCategory=null; //源库别
let warehouseAreaCategory=null;
let userId = store.getters.userInfo.userId;
const items = [
	// 仓库
	...genWarehouseAuthSearchModal(1, true, false,null, null,grid),
	// 货主(与账户权限关联)
	...genCargoownerAuthSearchModal(1, true, false,null, null,grid),
	// {type: 'input',name: 'enterpriseId',label: '企业ID',value: '',...grid},
	{type: 'input',name: 'code',label: '养护单号',value: '',...grid},
	{type: 'input',name: 'source',label: '数据来源',value: '',...grid},
	// {type: 'input',name: 'status',label: '状态',value: '',...grid },
	{type: 'input',name: 'creatorName',label: '创建人',value: '',...grid},
	{type: 'input',name: 'modifierName',label: '最后修改人',value: '',...grid},
	{type: 'input',name: 'gmtModified',label: '最后修改日期',value: '',...grid},
	{ name:'warehouseWorkerId',label:'操作员id',value:store.getters.userInfo.userId,hidden:true,...grid},
	{ type:'input',name:'warehouseWorkerName',label:'操作员',value:store.getters.userInfo.username,disabled:true,...grid},
	{type: 'input',name: 'comments',label: '备注',value: '',...grid},
	/* {
		span: 8, labelCol: { span: 6 },
		type: 'buttonGroup',
		style: { textAlign: 'center' },
		options: [
		   {value: '查询',icon: 'search',btnType: 'primary',style: 'margin-right:16px',htmlType: 'submit'},
		   {value: '重置',name: 'ccz',icon: 'redo',
			on: {
			  click(event, form) {
				form.resetFields();
					}
				}
			}
	 ]}*/
]; 

const columns2 = [
		{ dataIndex: 'warehouseId',title: '仓库ID',hidden:true },
		{ dataIndex: 'warehouseName',title: '仓库名称' },
		{ dataIndex: 'cargoOwnerName',title: '货主' },
		{ dataIndex: 'code',title: '养护单号'},
		/*{ dataIndex: 'source',title: '数据来源'},
		 { dataIndex: 'status',title: '状态',customRender:text=>{
									switch(text){
										case '10':return '初始';break;
										case '20':return '已审批 ';break;
										case '30':return '已驳回 ';break;
									}
								},
		}, */
		{ dataIndex: 'creatorName',title: '创建人'},
		{ dataIndex: 'modifierName',title: '最后修改人'},
		{ dataIndex: 'gmtModified',title: '最后修改日期'},
		{ dataIndex: 'comments',title: '备注'},
	];

const columns = [
	
	{type:'txt',dataIndex:'batchId',title:'批次ID',hidden:true},
	{type:'txt',dataIndex:'cargoOwnerId',title:'货主id',hidden:true},
	{type:'txt',dataIndex:'gspBillId',title:'ERP移库单ID',hidden:true},
	{type:'txt',dataIndex:'gspBillNo',title:'ERP移库单编号',hidden:true},
	{type:'txt',dataIndex:'gspLineId',title:'ERP明细ID',hidden:true},
	{type:'txt',dataIndex:'inContainerCode',title:'移入容器ID',hidden:true},
	{type:'txt',dataIndex:'inGoodsCaseCode',title:'移入货格',hidden:true},
	{type:'txt',dataIndex:'inStockStatus',title:'上架库存状态',hidden:true},
	{type:'txt',dataIndex:'outStockStatus',title:'下架库存状态',hidden:true},
	{ type:'txt',dataIndex:'warehouseId', title:'仓库id',hidden:true},
	{ type:'txt',dataIndex:'warehouseName', title:'仓库名称'},
	{ type:'txt',dataIndex:'bldgName', title:'建筑物名称'},
	{ type:'txt',dataIndex:'cargoOwnerName', title:'货主名称'},
	{ type:'txt',dataIndex:'itemCode', title:'商品编号'},
	{ type:'txt',dataIndex:'itemName', title:'商品名称'},
	{ type:'txt',dataIndex:'caseQuantity', title:'整件数'},
	{ type:'txt',dataIndex:'oddPieceQuantity', title:'零散数'},
	{ type:'txt',dataIndex:'upkeepQty', title:'养护数量' },
	{ type:'txt',dataIndex:'outContainerCode', title:'移出容器ID',hidden:true },
	{ type:'txt',dataIndex:'warehouseWorkerId', title:'库工ID',hidden:true },
	{ type:'txt',dataIndex:'outWhAreaCategoryName', title:'移出库别'},
	{ type:'txt',dataIndex:'outLocatorId', title:'移出库位ID',hidden:true },
	{ type:'txt',dataIndex:'outLocatorName', title:'移出库位名'},
	{ type:'txt',dataIndex:'outGoodsCaseCode', title:'移出货格号' },
	{
	  	title: "移入库别",
	  	type: "searchModal",
      width: 200,
	  	required: true,
	  	dataIndex: "inWhAreaCategoryName",
	  	targetClick: true,
	  	targetValueKey: "destWarehouseCategoryName",
	  	remoteUrl: { url: upcloud_base_strategy+'/rule/move/v1/list', method: 'get' },
	  	toolBar: {
	  	  items: [
	  		{type: "input",name: "srcWarehouseCategoryName",label: "源库别",value: "",},
	  		{type: "input",name: "destWarehouseCategoryName",label: "目标库别",value: "",},
	  	  ],
	  	},
	  	tableConfig: {
			rowKey:"moveRuleId",
	  	  // remoteParams:remoteParams,
	  	  remoteBefore:(vn,p)=>{
	  				p.params.warehouseId = warehouseId;
	  				p.params.srcWarehouseCategory = rows.outWhAreaCategory; //源库别编码
					return p;
	  			},
	  	  columns: [
	  		{dataIndex: "srcWarehouseCategoryName",title: "源库别"},
	  		{dataIndex: "destWarehouseCategoryName",title: "目标库别"},
	  		{dataIndex: "quantityMode",title: "包装属性",customRender:(text,rows,index)=>{
				switch(text){
					case 1:
						return '整件';
						break;
					case 2:
						return '零散';
						break;
					case 3:
						return '整散';
						break;
				}
			}},
	  		{dataIndex: "warehouseName",title: "仓库名称"},
	  	  ],
	  	},
	  	on: {
			search:(val1,val2,val3,val4,val5,val6,val7,val8,val9)=>{
				console.log(arguments,val1,val2,val3,val4,val5,val6,val7,val8,val9)
				rows = val5;	//当前行数据
			},
	  		change:({ event, name, value, modalRowData, record, index})=>{
	  				console.log("移入库别",event, name, value, modalRowData, record, index);
	  			    // record.quantityMode=modalRowData[0].quantityMode;  // 包装属性
	  			    warehouseAreaCategory =modalRowData[0].destWarehouseCategory; //目的库别编码
	  			    record.inWhAreaCategory =modalRowData[0].destWarehouseCategory; //目的库别编码
	  			    record.inWhAreaCategoryName =modalRowData[0].destWarehouseCategoryName; //目的库别编码
	  			  },
	  	},
	},
	// 根据上面的目标库区id查目的货位id
		{ 	title:'移入货位',
      dataIndex: 'inLocatorId',
      width: 200,
			targetClick: true,
			targetValueKey: "warehouseLocatorName",
			...genWarehouseLocatorSearchModal(2, true, false,
				function(vn,p){
					p.params.warehouseAreaCategory = warehouseAreaCategory ||  rows.inWhAreaCategory; //目的库别编码
				}, 
				null,
				null,
			),
			on:{
				search:(val1,val2,val3,val4,val5,val6,val7,val8,val9)=>{
					console.log(arguments,val1,val2,val3,val4,val5,val6,val7,val8,val9)
					rows = val5;	//当前行数据
				},
				change:({ event, value, modalRowData ,name,index, record})=> {
					console.log('移入货位2222：',modalRowData, index, value, record);
					record.inGoodsCaseCode=modalRowData[0].warehouseLocatorCode;  // 移入货位
					record.inLocatorId=modalRowData[0].warehouseLocatorId;  // 移入库位ID
				},
			}
		},
	{ type:'edit',dataIndex:'reason', title:'移动原因'},
	{ type:'txt',dataIndex:'lotNum', title:'批号'},
	{ type:'txt',dataIndex:'manufacturerName', title:'生产厂家'},
	{ type:'txt',dataIndex:'itemHealthListedLicensor', title:'市许可持有人'},
	{ type:'txt',dataIndex:'comments', title:'备注'},
	{ type:'txt',dataIndex:'productionDate', title:'生产日期',customRender: text=>(!text || moment(text).format("YYYY-MM-DD")) },
	{ type:'txt',dataIndex:'showProductionDate', title:'显示生产日期',customRender: text=>(!text || moment(text).format("YYYY-MM-DD")) },
	{ type:'txt',dataIndex:'expiredDate', title:'有效期至',customRender: text=>(!text || moment(text).format("YYYY-MM-DD")) },
	{ type:'txt',dataIndex:'showExpiredDate', title:'显示有效期至',customRender: text=>(!text || moment(text).format("YYYY-MM-DD")) },
	
	]
	
	
 export { items,columns,columns2 }

