
import store from '@/store';
import { genWarehouseAuthSearchModal, genCargoownerAuthSearchModal } from '@/views/kzyWMS/SearchModal';

let grid = {
	labelCol: { span: 6 }, span: 8,
};
export function setFormItems(self) {
	return [
		{ type: 'input', name: 'cargoOwnerId', label: '货主ID', ...grid, value: '', hidden: true },
		{ type: 'input', name: 'cargoOwnerCode', label: '货主code', ...grid, value: '', hidden: true },
		// 仓库
		...genWarehouseAuthSearchModal(1, true, false, null, null, grid),
		{ type: 'input', name: 'cargoOwnerName', label: '货主名称', ...grid, value: '', disabled: true, },
		// ...genCargoownerAuthSearchModal(1, true, false, null, null, grid),
		{ type: 'date', name: 'billdate', label: '单据日期', value: '', format: 'YYYY-MM-DD', disabled: true, ...grid },
		{ type: 'input', name: 'autoBillNum', label: '单据编号', ...grid, disabled: true, },
		{ type: 'input', 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: 'enterpriseName', label: '企业', value: store.getters.userInfo.enterpriseName, disabled: true, ...grid },
		{ type: 'input', name: 'departmentName', label: '部门', value: store.getters.userInfo.organizations ? store.getters.userInfo.organizations[0] ? store.getters.userInfo.organizations[0].name : '' : '', disabled: true, ...grid },
		{ type: 'input', name: 'departmentId', label: '部门ID', hidden: true, value: store.getters.userInfo.organizations ? store.getters.userInfo.organizations[0] ? store.getters.userInfo.organizations[0].id : '' : '', disabled: true, ...grid },
		// { type: 'input', name: 'comments', label: '备注', ...grid },
	]
}

const tableColumns = function (_this) {
	return [
		// { hidden: true, dataIndex: "key",customRender:(text,rows,index)=>index.toString() },

		{ hidden: true, dataIndex: 'lineId', key: 'lineId', title: 'lineId', },
		{ hidden: true, dataIndex: 'adjustHeaderId', key: 'adjustHeaderId', title: 'adjustHeaderId', },
		{ hidden: true, dataIndex: 'batchId', key: 'batchId', title: '批次ID', },
		{ hidden: true, dataIndex: 'batchNum', key: 'batchNum', title: 'batchNum', },
		{ hidden: true, dataIndex: 'cargoOwnerId', key: 'cargoOwnerId', title: '货主id', },
		{ hidden: true, dataIndex: 'warehouseId', key: 'warehouseId', title: '仓库ID', },
		{ hidden: true, dataIndex: 'cargoOwnerCode', key: 'cargoOwnerCode', title: '货主编号', },
		{ hidden: true, dataIndex: 'itemId', key: 'itemId', title: '商品ID', },
		{ hidden: true, dataIndex: 'whLocatorId', key: 'whLocatorId', title: '货位ID', },
		{ hidden: true, dataIndex: 'pieceQty', key: 'pieceQty', title: 'pieceQty', },

		{ dataIndex: 'cargoOwnerName', key: 'cargoOwnerName', title: '货主名称', width: 100 },
		{ dataIndex: 'itemCode', key: 'itemCode', title: '商品编码', width: 100 },
		{ dataIndex: 'itemName', key: 'itemName', title: '商品名称', width: 100 },
		{ dataIndex: 'prePieceQuantity', key: 'prePieceQuantity', title: '计划损溢数量', width: 100 },
		{
			dataIndex: 'adjustBillType', key: 'adjustBillType', title: '单据类型', width: 120,
			customRender: (text, rows, index) => {
				switch (text) {
					case '1':
						return '报损单';
						break;
					case '2':
						return '报溢单';
						break;
				}
			}
		},
		{
			hidden: true, title: '库位', dataIndex: 'whLocatorName', key: 'whLocatorName', width: 120,
			// on: {
			// 	click(p1) {// hostData
			// 		let dataSource = _this.dataSource;
			// 		var a = p1.target.dataset.rowIndex;
			// 		_this.selectLocation(dataSource[a])
			// 	}
			// }
		},
		{ title: '实际数量', dataIndex: 'pieceQuantity', key: 'pieceQuantity', width: 100, value: 0 },
		{ title: '批号', dataIndex: 'manufacturerLotNum', key: 'manufacturerLotNum', width: 80 },
		{
			title: "生产日期", dataIndex: "productionDate", key: "productionDate", width: 100,
			customRender(text, record) {
				return record.manufacturerLotNum === '*' ? '' :
					(text ? text.substring(0, 10) : '');
			}
		},
		{
			title: "有效期至", dataIndex: "batchExpiredDate", key: "batchExpiredDate", width: 80,
			customRender(text, record) {
				return record.manufacturerLotNum === '*' ? '' :
					(text ? text.substring(0, 10) : '');
			}
		},
		{ dataIndex: 'showProductionDate', title: '显示生产日期', key: "showProductionDate", width: 120 },//attrStr2
		{ dataIndex: 'showExpiredDate', title: '显示有效期至', key: "showExpiredDate", width: 120 },//attrStr3
		{ dataIndex: 'remark', title: '备注', key: "remark", },
		{ title: '操作', key: 'operate', align: 'center', width: '150px', scopedSlots: { customRender: 'action' } }
	]

}

export const extractColumns = [
	{ dataIndex: 'billid', title: '订单id', hidden: true },
	{ dataIndex: 'branchcode', title: '仓库id', hidden: true },
	{ dataIndex: 'cargoOwnerId', title: '货主id', hidden: true },
	{ dataIndex: 'branchname', title: '仓库名称' },
	{ dataIndex: 'consignorname', title: '货主名称' },
	{ dataIndex: 'billno', title: '订单编码', },
	{
		dataIndex: 'datasource', title: '订单来源',
		customRender: (text, rows, index) => {
			switch (text) {
				// case '0':
				// 	return '计划盘点';
				// 	break;
				// case '1':
				// 	return '无计划盘点';
				// 	break;
				case '1':
					return 'WMS调整';
					break;
				case '2':
					return 'ERP调整';
					break;
			}
		}
	},
	{ dataIndex: 'type', title: '订单类型',customRender: (text, rows, index) => {
		switch (text) {
			case '1':
				return '报损单';
				break;
			case '2':
				return '报溢单';
				break;
		}
	} },
	{ dataIndex: 'totalQuantity', title: '商品数量' },
]

export function detailFormItems(_this, object) {
	return [
		{ type: 'input', name: 'batchIdNew', label: '供应商批次号', hidden: true, value: '', },
		{ type: 'input', name: 'lineNum', label: '行号', hidden: true, value: '', },
		{ type: 'input', name: 'vendorBatchNumNew', label: '供应商批次号', hidden: true, value: '', },
		{ type: 'input', name: 'manufacturerLotNumNew', label: '生产商批号', hidden: true, value: '', },
		{ type: 'input', name: 'nodeType', label: '错误发现节点（收货/验收/质检/上架）', hidden: true, value: '', },
		{ type: 'input', name: 'conversionRate', label: '包装含量', hidden: true, value: '', },
		{ type: 'input', name: 'shelfLifeUnit', label: '保质期单位', hidden: true, value: '', },
		{ type: 'input', name: 'shelfLifeDays', label: '保质期天数', hidden: true, value: '', },
	]
}

//报损库位
export const locationColumns = [
	{ dataIndex: 'id', title: 'id', hidden: true },
	{ type: 'txt', dataIndex: 'rowId', title: 'rowId', hidden: true },

	{ type: 'txt', dataIndex: 'billid', title: '订单id', hidden: true },
	{ type: 'txt', dataIndex: 'whLocatorId', title: '库位id', hidden: true },
	{ type: 'txt', dataIndex: 'itemName', title: '商品名称' },
	{ type: 'txt', dataIndex: 'whLocatorName', title: '库位名称', },
	{ type: 'txt', dataIndex: 'batchId', title: '批次号' },
	{ type: 'txt', dataIndex: 'availableQuantity', title: '商品可用数量', },
]


//报溢库位
export const overflowColumns = [
	{ type:'txt', dataIndex: 'id', title: 'id', hidden: true },
	{ type:'txt', dataIndex: 'whLogicId', title: '订单id', hidden: true },
	{ type:'txt', dataIndex: 'whLocatorId', title: '库位id', hidden: true },
	{ type:'txt', dataIndex: 'whLocatorName', title: '库位名称', },
	{ type:'txt', dataIndex: 'itemquantity', title: '库位商品数量' },
	{ type:'txt', dataIndex: 'whAreaCode', title: '库区' },
	{ type:'txt', dataIndex: 'whAreaCategoryCode', title: '库别', },
	{ type:'txt', dataIndex: 'storeTemperature', title: '商品属性', },
]


//详情
const detailColumns = function (_this) {
	return [
		{ hidden: true, type: 'txt', dataIndex: 'id', key: 'id', title: 'lineId', },
		{ hidden: true, type: 'txt', dataIndex: 'lineId', key: 'lineId', title: 'lineId', },
		{ hidden: true, type: 'txt', dataIndex: 'adjustHeaderId', key: 'adjustHeaderId', title: 'adjustHeaderId', },
		{ hidden: true, type: 'txt', dataIndex: 'batchId', key: 'batchId', title: '批次ID', },
		{ hidden: true, type: 'txt', dataIndex: 'batchNum', key: 'batchNum', title: 'batchNum', },
		{ hidden: true, type: 'txt', dataIndex: 'cargoOwnerId', key: 'cargoOwnerId', title: '货主id', },
		{ hidden: true, type: 'txt', dataIndex: 'warehouseId', key: 'warehouseId', title: '仓库ID', },
		{ hidden: true, type: 'txt', dataIndex: 'cargoOwnerCode', key: 'cargoOwnerCode', title: '货主编号', },
		{ hidden: true, type: 'txt', dataIndex: 'itemId', key: 'itemId', title: '商品ID', },
		{ hidden: true, type: 'txt', dataIndex: 'whLocatorId', key: 'whLocatorId', title: '货位ID', },
		{ hidden: true, type: 'txt', dataIndex: 'adjustBillType', key: 'adjustBillType', title: '类型', },

		{ type: 'txt', dataIndex: 'itemCode', key: 'itemCode', title: '商品编码', width: 100 },
		{ type: 'txt', dataIndex: 'itemName', key: 'itemName', title: '商品名称', width: 100 },

		{ type: 'txt', dataIndex: 'categoryName', key: 'categoryName', title: '商品大类', width: 100 },
		{ type: 'txt', dataIndex: 'manufacturerLotNum', key: 'manufacturerLotNum', title: '批号', width: 100 }, {
			title: "生产日期", type: 'txt', dataIndex: "productionDate", key: "productionDate", width: 100,
			customRender(txt, record) {
				return record.manufacturerLotNum === '*' ? '' :
					(txt ? txt.substring(0, 10) : '');
			}
		},
		{
			title: "有效期至", type: 'txt', dataIndex: "batchExpiredDate", key: "batchExpiredDate", width: 80,
			customRender(txt, record) {
				return record.manufacturerLotNum === '*' ? '' :
					(txt ? txt.substring(0, 10) : '');
			}
		},
		{ type: 'txt', dataIndex: 'conversionRate', key: 'conversionRate', title: '包装含量', width: 100 },
		{ type: 'txt', dataIndex: 'uom', key: 'uom', title: '包装单位', width: 100 },
		{ type: 'txt', dataIndex: 'whLocatorName', key: 'whLocatorName', title: '库位', width: 100 },
		{ type: 'txt', dataIndex: 'whAreaCategory', key: 'whAreaCategory', title: '库别', width: 100 },
		{ type: 'txt', dataIndex: 'pieceQty', key: 'pieceQty', title: '库位库存数量', width: 100 },
		{
			type: 'number', dataIndex: 'pieceQuantity', key: 'pieceQuantity', title: '实际损溢数量', width: 100, min: 0,
			on: {
				// change({ record, value }) {
				// 	_this.qtyChange(record, value)
				// }
				blur(e, from) {
					console.log(e, from,'blurblurblur');	
					_this.qtyChange(from.record, from.value)
				  },
			}
		},
		// {  type:'txt',dataIndex: 'itemName', key: 'itemName', title: '损溢件数', width: 100 },
		// {  type:'txt',dataIndex: 'itemCode', key: 'itemCode', title: '损溢零散数', width: 100 },
		{ type: 'txt', dataIndex: 'storeTemperature', key: 'storeTemperature', title: '存储条件', width: 100 },
		{ type: 'txt', dataIndex: 'manufacturerName', key: 'manufacturerName', title: '生产厂家', width: 100 },
		{ type: 'txt', dataIndex: 'productionPlace', key: 'productionPlace', title: '产地', width: 100 },
		{ type: 'txt', dataIndex: 'specification', key: 'specification', title: '商品规格', width: 100 },
		{ title: '操作', align: 'center', width: '150px', scopedSlots: { customRender: 'operate' } }
	]

}

export { tableColumns, detailColumns }
