import { remote } from './remote';
import store  from '@/store';
import { genWarehouseAuthSearchModal,
		genContainerSearchModal,
		genBldgSearchModal,
		genStageSearchModal,
		} from  '@/views/kzyWMS/SearchModal';

let warehouseId = store.getters.warehouse.warehouseId ||  null ;
let bldgId = null; //建筑物id

const items = [
  // 仓库
  	...genWarehouseAuthSearchModal(1, true, false,null, 
  			function (rowData, form) {
  				if (!rowData) {
  					warehouseId = '';
  					form.setFieldsValue({
  						warehouseId: '',
  						warehouseCode:'',
  						warehouseName:''
  					})
					} else {
  					warehouseId = rowData[0].warehouseId?rowData[0].warehouseId : rowData[0].companyId;
  					form.setFieldsValue({
  						warehouseId: rowData[0].warehouseId?rowData[0].warehouseId : rowData[0].companyId,
  						warehouseCode: rowData[0].warehouseCode,
  						warehouseName: rowData[0].warehouseName,
  					})
  				}
  				console.log('warehouseId:',warehouseId);
  				console.log('rowData:',rowData);
  			},
  			{ span: 8, labelCol: { span: 6 } }
  		),
		// 建筑物
		...genBldgSearchModal(1, false, false,
			function(vn,p){
				p.params.warehouseId = warehouseId;
				return p;
			}, 
		null,{ span: 8, labelCol: { span: 5 }},
		),
	  {
	  		type: 'input',
	  		name: 'billCode',
	  		label: '订单编码',
	  		value: '',
	  },
	  {
	  		type: 'input',
	  		name: 'waveId',
	  		label: '波次编码',
	  		value: '',
	  },
	 
   {
		span: 8,
		type: 'buttonGroup',
		style: { textAlign: 'center'},
		// labelCol: { span: 8 },	//标签布局 如：{span: 3, offset: 12}
		// wrapperCol: { span: 12 },  // 输入控件布局+标签布局=span
		options: [
		   {value: '查询',icon: 'search',btnType: 'primary',style: 'margin-right:16px',htmlType: 'submit'},
		   {value: '重置',name: 'ccz',icon: 'redo',
			on: {
			  click(event, form) {
				form.resetFields();
				 form.setFieldsValue({
				  		warehouseName: '',
						warehouseId:'',
						containerId:'',
						containerCode:''
				 });
					}
				}
			}
	 ]}
];

const items_modal = function(_this){
	return [
		// 建筑物
		...genBldgSearchModal(1, true, false,
			function(vn,p){
				p.params.warehouseId = warehouseId;
				console.log("当前仓库id：",warehouseId);
				return p;
			}, 
			function (rowData, form) {
				if (!rowData) {
					warehouseId = '';
					form.setFieldsValue({
						bldgId: '',
						bldgCode:'',
						bldgName:''
					})
				} else {
					bldgId = rowData[0].bldgId;
					form.setFieldsValue({
						bldgId: rowData[0].bldgId,
						bldgCode: rowData[0].bldgCode,
						bldgName: rowData[0].bldgName,
					})
				}
			},
		{ span: 24, labelCol: { span: 7 }},
		{label:'目标建筑物'}
		),
		// 集货区
		...genStageSearchModal(1, true, false,
			function(vn,p){
				p.params.bldgId = bldgId;
				console.log("当前建筑物id：",bldgId);
				return p;
			}, 
		null,
		{ span: 24, labelCol: { span: 7 }},
		{label:'目标集货区'}
		),
	]
}
 
const columns = [
	{ dataIndex:'id', title:'id',hidden:true },
	{ dataIndex:'srcCode', title:'订单编码' },
	// { dataIndex:'billCode', title:'订单编号' },
	{ dataIndex:'bldgCode', title:'建筑物编码' },
	{ dataIndex:'waveId', title:'波次编码' },
	{ dataIndex:'billGroupId', title:'合单编码' },
	{ dataIndex:'caseQty', title:'箱数' },
	{ dataIndex:'consignorname', title:'货主名称' },
	{ dataIndex:'stageCode', title:'暂存区编码' },
	{ dataIndex:'stageType', title:'暂存区类型' },
	{ dataIndex:'contactName', title:'联系人' },
	{ dataIndex:'contactTel', title:'联系方式' },
	{ dataIndex:'receiveAddress', title:'收货地址' },
];


 export { items, items_modal, columns }
