import { api } from "../../../api/common/dictionaries-type";

export function packingColChange(data, list) {
    if (data.name === 'maxSu' && data.value) {
        list.forEach((tt, i) => {
            if (data.index != i) tt.maxSu = false;
        });
    }
    if (data.name === 'minSu' && data.value) {
        list.forEach((tt, i) => {
            if (data.index != i) tt.minSu = false;
        });
    }
    if (data.name === 'length' || data.name === 'width' || data.name === 'height') {
        if (data.record.length && data.record.width && data.record.height) {
            let item = list.find(t => t.itemUomId == data.record.itemUomId);
            item.volume = (data.record.length * data.record.width * data.record.height).toFixed(4);
        }
    }
}

export const packingColumns = [
    {
        type: 'txt', hidden: true, title: "id",
        dataIndex: "itemUomId", key: "itemUomId"
    },
    {
        type: 'select', width: 100, title: "包装级别", /*required: true,*/
        dataIndex: "uomLevel", key: "uomLevel",
        autoLoad: true,
        remoteUrl: { url: api.queryDictList + '?dicttypeCodes=pub_pharm_code_info_packlevel', method: 'post' },
        replaceFields: {
            value: 'dictCode',
            label: 'dictName'
        },
    },
    {
        type: 'select', width: 100, title: "包装单位", /*required: true,*/
        dataIndex: "uom", key: "uom",
        autoLoad: true,
        remoteUrl: { url: api.queryDictList + '?dicttypeCodes=pub_itempack_packcode', method: 'post' },
        replaceFields: {
            value: 'dictCode',
            label: 'dictName'
        },
    },
    {
        type: 'number', width: 100, title: "单位含量", /*required: true,*/ precision: 4,
        dataIndex: "conversionRate", key: "conversionRate",
    },
    {
        type: 'switch', width: 90, title: "最小统计单位",
        dataIndex: "minSu", key: "minSu",
        value: false,
        transValues: ['Y', 'N'],
    },
    {
        type: 'switch', width: 90, title: "最大统计单位",
        dataIndex: "maxSu", key: "maxSu",
        value: false,
        transValues: ['Y', 'N'],
    },
    {
        type: 'edit', width: 170, title: "旧条码", maxLength: 30,
        dataIndex: "barcodeOld", key: "barcodeOld",
    },
    {
        type: 'edit', width: 170, title: "条码", /*required: true,*/ maxLength: 30,
        dataIndex: "barcode", key: "barcode",
    },
    {
        hidden: true, type: 'edit', title: "体积单位",
        dataIndex: "volumeUom", key: "volumeUom",
    },
    {
        hidden: true, type: 'edit', title: "重量单位",
        dataIndex: "weightUom", key: "weightUom",
    },
    {
        type: 'number', width: 80, title: "重量", precision: 4,
        dataIndex: "weight", key: "weight",
    },
    {
        type: 'number', width: 80, title: "净重", precision: 4,
        dataIndex: "netWeight", key: "netWeight",
    },
    {
        type: 'number', width: 80, title: "长(cm)", precision: 4,
        dataIndex: "length", key: "length",
    },
    {
        type: 'number', width: 80, title: "宽(cm)", precision: 4,
        dataIndex: "width", key: "width",
    },
    {
        type: 'number', width: 80, title: "高(cm)", precision: 4,
        dataIndex: "height", key: "height",
    },
    {
        type: 'txt', width: 80, title: "体积",
        dataIndex: "volume", key: "volume",
    },
    {
        type: 'edit', title: "受托厂家名称", maxLength: 120,
        dataIndex: "entrustedManufacturerName", key: "entrustedManufacturerName",
    },
    {
        type: 'txt', title: "受托厂家ID", maxLength: 100,
        dataIndex: "entrustedManufacturerId", key: "entrustedManufacturerId",
    },
    {
        type: 'edit', title: "产地", maxLength: 100,
        dataIndex: "countryOrigin", key: "countryOrigin",
    },
    // { type: 'delRow' }
]