import { genSelfWarehouseLocator,genWarehouseLocatorSearchModal } from "../../../../../SearchModal";

const resultMap = {
    '0': '合格',
    '1': '不合格',
    '2': '隔离'
};

let warehouseId = null;
let cargoOwnerId = null;
let itemId = null;
let itemCategoryCode = null;
let itemHealthCategory = null;
let enterpriseId = null;
let paramData = {};
let clickIndex = -1;
export const extendFormItems = function (_this) {

    var getUrl = {}
    if (_this.L_type) {
        if (_this.L_type === '1') {
            getUrl = {
                ...genSelfWarehouseLocator(2, true, false, function (res, p) {
                    p.params.cargoOwnerId = paramData.mtlOwnerId;
                    p.params.itemId = paramData.itemId;
                    p.params.warehouseId = paramData.warehouseId;
                    p.params.itemHealthCategory = paramData.categoryId;//对应当前行商品大类
                    // itemIsPieceOrCase:(新)商品整散分离标识(0整散合一/1整散分开)"
                    //locatorTypeForInStock  货位入库上架拆分属性(0:整;1:散;2:整散合一)
                    // 整件的话：ZJK，散件：LHK，
                    let aa = paramData.itemIsPieceOrCase;
                    if (aa == 0) {
                        p.params.warehouseAreaCategory = 'HYK'//整散合一：HYK，
                    } else if (aa == 1) {
                        if (paramData.oddCaseQty == 0) {
                            p.params.warehouseAreaCategory = 'LHK'
                        } else if (paramData.oddPieceQty == 0) {
                            p.params.warehouseAreaCategory = 'ZJK'
                        }
                    }
                    // 验收结果为 不合格 带条件
                    if (paramData.result == '1') {
                        p.params.warehouseAreaCategory = 'THK';//不合格：THK
                    }
                    return p;
                }, function (modalRowData, index) {
                    if (modalRowData) {
                        let ref = _this.queryRefFromName('list')
                        let oldItem = ref.data[index];
                        let newItem = {
                            ...oldItem,
                            whAreaCode: modalRowData[0].warehouseAreaCode,
                            whRoom: modalRowData[0].warehouseRoomName,
                            whAreaCategoryId: modalRowData[0].warehouseAreaCategory,
                            whAreaCategoryCode: modalRowData[0].warehouseAreaCategoryCode,
                            realWhLocatorId: modalRowData[0].warehouseLocatorId,
                            realWhLocatorName: modalRowData[0].warehouseLocatorName,
                            realWhLocatorCode: modalRowData[0].warehouseLocatorCode,
                        }
                        ref.data.splice(index, 1, newItem)
                    } else {
                        warehouseId = null;
                        cargoOwnerId = null;
                        itemId = null;
                        itemCategoryCode = null;
                    }
                }, null, {
                    search(p1, p2, p3, p4, p5) {
                        paramData = p5;
                        clickIndex = p4;
                    },
                }),
                title: '实际货位',
                width: 140,
                dataIndex: "warehouseLocatorName",
                key: "warehouseLocatorName"
            }
        } else if (_this.L_type === '0') {
            getUrl = {
                ...genWarehouseLocatorSearchModal(2, true, false, function (res, p) {
                    p.params.warehouseId = warehouseId;
                    p.params.cargoOwnerId = cargoOwnerId;
                    p.params.itemId = itemId;
                    p.params.itemCategoryCode = itemCategoryCode;
                    // p.params.warehouseLocatorType = paramData.itemIsPieceOrCase;
                    p.params.warehouseId = paramData.warehouseId;
                    p.params.isEnable = '1';
                    // itemIsPieceOrCase:(新)商品整散分离标识(0整散合一/1整散分开)"
                    //locatorTypeForInStock  货位入库上架拆分属性(0:整;1:散;2:整散合一)
                    let aa = paramData.itemIsPieceOrCase;
                    if (aa == 0) {
                        p.params.locatorTypeForInStock = '2'
                    } else if (aa == 1) {
                        if (paramData.oddCaseQty == 0) {
                            p.params.locatorTypeForInStock = '1'
                        } else if (paramData.oddPieceQty == 0) {
                            p.params.locatorTypeForInStock = '0'
                        }
                    }
                    // 验收结果为 不合格 带条件
                    let result = _this.queryRefFromName('list').data[clickIndex].result;
                    if (result == '1') {
                        p.params.warehouseAreaCategory = 'THK';
                        // 验收结果为 合格 带条件
                    } else if (result == '0') {
                        p.params.excludeWarehouseAreaCategory = 'THK';
                    }
                    return p;
                }, function (modalRowData, index) {
                    if (modalRowData) {
                        let ref = _this.queryRefFromName('list')
                        let oldItem = ref.data[index];
                        let newItem = {
                            ...oldItem,
                            whAreaCode: modalRowData[0].warehouseAreaCode,
                            whRoom: modalRowData[0].warehouseRoomName,
                            whAreaCategoryId: modalRowData[0].warehouseAreaCategory,
                            whAreaCategoryCode: modalRowData[0].warehouseAreaCategoryCode,
                            realWhLocatorId: modalRowData[0].warehouseLocatorId,
                            realWhLocatorName: modalRowData[0].warehouseLocatorName,
                            realWhLocatorCode: modalRowData[0].warehouseLocatorCode,
                        }
                        ref.data.splice(index, 1, newItem)
                    } else {
                        warehouseId = null;
                        cargoOwnerId = null;
                        itemId = null;
                        itemCategoryCode = null;
                    }
                }, null, {
                    search(p1, p2, p3, p4, p5) {
                        paramData = p5;
                        clickIndex = p4;
                    },
                }),
                title: '实际货位',
                width: 140,
                dataIndex: "warehouseLocatorName",
                key: "warehouseLocatorName"
            }
        } else {
            return []
        }


    }else{
        return []
    }


    return [
        { hidden: true, title: "taskId", dataIndex: "taskId", key: "taskId" },
        { hidden: true, title: "warehouseId", dataIndex: "warehouseId", key: "warehouseId" },
        { hidden: true, title: "warehouseLocatorId", dataIndex: "warehouseLocatorId", key: "warehouseLocatorId" },
        { hidden: true, title: "lineNum", dataIndex: "lineNum", key: "lineNum" },
        { hidden: true, title: "itemId", dataIndex: "itemId", key: "itemId" },
        { hidden: true, title: "inBoundLineId", dataIndex: "rcvLineId", key: "inBoundLineId" },
        { hidden: true, title: "batchNum", dataIndex: "batchNum", key: "batchNum" },
        { hidden: true, title: "batchId", dataIndex: "batchId", key: "batchId" },
        { hidden: true, title: "rcvHeaderId", dataIndex: "rcvHeaderId", key: "rcvHeaderId" },
        { hidden: true, title: "货主ID", dataIndex: "mtlOwnerId", key: "mtlOwnerId" },

        // { hidden: true, type: 'txt', title: "库区编号", dataIndex: "whAreaCode", key: "whAreaCode" },
        { hidden: true, type: 'txt', title: "区域编号", dataIndex: "whAreaCategoryId", key: "whAreaCategoryId" },
        { hidden: true, type: 'txt', title: "库别编码", dataIndex: "whAreaCategoryCode", key: "whAreaCategoryCode" },
        { hidden: true, type: 'txt', title: "实际货位id", dataIndex: "realWhLocatorId", key: "realWhLocatorId" },
        { hidden: true, type: 'txt', title: "货位编号", dataIndex: "realWhLocatorName", key: "realWhLocatorName" },
        { hidden: true, type: 'txt', title: "货位编号", dataIndex: "realWhLocatorCode", key: "realWhLocatorCode" },
        { hidden: true, type: 'txt', title: "whLocatorId", dataIndex: "whLocatorId", key: "whLocatorId" },
        { hidden: true, type: 'txt', title: "warehouseLocatorType", dataIndex: "warehouseLocatorType", key: "warehouseLocatorType" },
        { hidden: true, type: 'txt', title: "itemIsPieceOrCase", dataIndex: "itemIsPieceOrCase", key: "itemIsPieceOrCase" },
        { hidden: true, type: 'txt', title: "受托生产企业id(供应商id)", dataIndex: "delegationPartyId", key: "delegationPartyId" },

        { type: 'txt', title: "原单据编号", dataIndex: "asnHeaderId", key: "asnHeaderId", width: 120 },
        { type: 'txt', title: "商品编码", dataIndex: "itemNum", key: "itemNum", width: 120 },
        { type: 'txt', title: "商品名称", dataIndex: "itemName", key: "itemName", width: 160 },
        { type: 'txt', title: "商品规格", dataIndex: "specification", key: "specification", width: 120 },
        { type: 'txt', title: "商品分类", dataIndex: "categoryName", key: "categoryName", width: 120 },
        { type: 'txt', title: "生产厂家", dataIndex: "manufacturerName", key: "manufacturerName", width: 120 },
        { title: "包装单位", dataIndex: "uom", width: 100, value: '' },
        { type: 'txt', title: "包装含量", dataIndex: "conversionRate", key: "conversionRate", width: 90 },
        // {
        //     type: 'txt', title: "验收结果", dataIndex: "result", key: "result", width: 120,
        //     customRender(text) {
        //         return resultMap[text] || '';
        //     }
        // },
        // { type: 'txt', title: "拒收数量", dataIndex: "pieceQty", key: "pieceQty", width: 90 },
        { type: 'txt', title: "原订单数量", dataIndex: "poPieceQty", key: "poPieceQty", width: 90 },
        { type: 'txt', title: "收货数量", dataIndex: "pieceQty", key: "pieceQty", width: 90 },
        // { type: 'txt', title: "建筑物", dataIndex: "bldgName", key: "bldgName", width: 90 },
        // { type: 'txt', title: "库区编号", dataIndex: "whAreaCode", key: "whAreaCode", width: 120 },
        // { type: 'txt', title: "库房", dataIndex: "whRoom", key: "whRoom", width: 60 },
        // { type: 'txt', title: "货格编码", dataIndex: "goodsCaseCode", key: "goodsCaseCode", width: 60 },
        // { type: 'txt', title: "区域编号", dataIndex: "warehouseAreaCategorys", key: "warehouseAreaCategorys", width: 60 },
        // { type: 'txt', title: "容器号", dataIndex: "containerCode", key: "containerCode", width: 90 },
        { type: 'txt', title: "批号", dataIndex: "manufacturerLotNum", key: "manufacturerLotNum", width: 60 },
        {
            type: 'txt', title: "生产日期", dataIndex: "batchProductionDate", key: "batchProductionDate", width: 80,
            customRender(text, record) {
                return record.manufacturerLotNum === '*' ? '' :
                    (text ? text.substring(0, 10) : '');
            }
        },
        {
            type: 'txt', title: "有效期至", dataIndex: "batchExpiredDate", key: "batchExpiredDate", width: 80,
            customRender(text, record) {
                return record.manufacturerLotNum === '*' ? '' :
                    (text ? text.substring(0, 10) : '');
            }
        },
        { type: 'txt', title: "注册证号", dataIndex: "itemHealthRegisterNbr", key: "itemHealthRegisterNbr", width: 60 },
        // { ...getUrl },
        // getUrl,
        // { type: 'txt', title: "受托生产企业名称", dataIndex: "delegationPartyName", key: "delegationPartyName", width: 120 },
        // { type: 'txt', title: "推荐库位名称", dataIndex: "whLocatorName", key: "whLocatorName", width: 120 },
        // { type: 'txt', title: "托盘条码", dataIndex: "***", key: "***", width: 60 },
        // { type: 'txt', title: "上架件数", dataIndex: "oddCaseQty", key: "oddCaseQty", width: 120 },
        // { type: 'txt', title: "上架零散数", dataIndex: "oddPieceQty", key: "oddPieceQty", width: 150 },
        // { type: 'txt', title: "上架最小单位数量", dataIndex: "pieceQty", key: "pieceQty", width: 150 },
        // { type: 'txt', title: '含税单价', dataIndex: 'piecePriceTi', key: 'piecePriceTi', width: 80 },
        // { type: 'txt', title: "库别名称", dataIndex: "whAreaCategoryName", key: "whAreaCategoryName", width: 60 },
        // { type: 'txt', title: "拆分人", dataIndex: "spilterName", key: "spilterName", width: 90 },
        // {
        //     type: 'txt', title: "是否正在拆分", dataIndex: "isSpilt", key: "isSpilt", width: 80,
        //     customRender(text) {
        //         return text ? '是' : '否';
        //     }
        // },

        // { type: 'txt', title: "生产厂家", dataIndex: "", key: "", width: 120 },
        // { type: 'txt', title: "注册证号", dataIndex: "paperno", key: "paperno", width: 120 },
        // { type: 'txt', title: "%批准文号", dataIndex: "xxxxx24", key: "xxxxx24", width: 120 },
        // { type: 'txt', title: "%助记码", dataIndex: "xxxxx29", key: "xxxxx29", width: 90 },
        // { type: 'txt', title: "%不合格商品", dataIndex: "xxxxx30", key: "xxxxx30", width: 150 }
    ];
}

export const extendFormItems2 = function (_this) {

    return [
        { hidden: true, title: "taskId", dataIndex: "taskId", key: "taskId" },
        { hidden: true, title: "warehouseId", dataIndex: "warehouseId", key: "warehouseId" },
        { hidden: true, title: "warehouseLocatorId", dataIndex: "warehouseLocatorId", key: "warehouseLocatorId" },
        { hidden: true, title: "lineNum", dataIndex: "lineNum", key: "lineNum" },
        { hidden: true, title: "itemId", dataIndex: "itemId", key: "itemId" },
        { hidden: true, title: "inBoundLineId", dataIndex: "rcvLineId", key: "inBoundLineId" },
        { hidden: true, title: "batchNum", dataIndex: "batchNum", key: "batchNum" },
        { hidden: true, title: "batchId", dataIndex: "batchId", key: "batchId" },
        { hidden: true, title: "rcvHeaderId", dataIndex: "rcvHeaderId", key: "rcvHeaderId" },
        { hidden: true, title: "货主ID", dataIndex: "mtlOwnerId", key: "mtlOwnerId" },

        // { hidden: true, type: 'txt', title: "库区编号", dataIndex: "whAreaCode", key: "whAreaCode" },
        { hidden: true, type: 'txt', title: "区域编号", dataIndex: "whAreaCategoryId", key: "whAreaCategoryId" },
        { hidden: true, type: 'txt', title: "库别编码", dataIndex: "whAreaCategoryCode", key: "whAreaCategoryCode" },
        { hidden: true, type: 'txt', title: "实际货位id", dataIndex: "realWhLocatorId", key: "realWhLocatorId" },
        { hidden: true, type: 'txt', title: "货位编号", dataIndex: "realWhLocatorName", key: "realWhLocatorName" },
        { hidden: true, type: 'txt', title: "货位编号", dataIndex: "realWhLocatorCode", key: "realWhLocatorCode" },
        { hidden: true, type: 'txt', title: "whLocatorId", dataIndex: "whLocatorId", key: "whLocatorId" },
        { hidden: true, type: 'txt', title: "warehouseLocatorType", dataIndex: "warehouseLocatorType", key: "warehouseLocatorType" },
        { hidden: true, type: 'txt', title: "itemIsPieceOrCase", dataIndex: "itemIsPieceOrCase", key: "itemIsPieceOrCase" },
        { hidden: true, type: 'txt', title: "受托生产企业id(供应商id)", dataIndex: "delegationPartyId", key: "delegationPartyId" },

        { type: 'txt', title: "原单据编号", dataIndex: "asnHeaderId", key: "asnHeaderId", width: 120 },
        { type: 'txt', title: "商品编码", dataIndex: "itemNum", key: "itemNum", width: 120 },
        { type: 'txt', title: "商品名称", dataIndex: "itemName", key: "itemName", width: 160 },
        { type: 'txt', title: "上架数量", dataIndex: "pieceQty", key: "pieceQty", width: 160 },
        { type: 'txt', title: "商品规格", dataIndex: "specification", key: "specification", width: 120 },
        { type: 'txt', title: "商品分类", dataIndex: "categoryName", key: "categoryName", width: 120 },
        { type: 'txt', title: "生产厂家", dataIndex: "manufacturerName", key: "manufacturerName", width: 120 },
    ]
}