import moment from 'moment'
let grid = {
    labelCol: { span: 6 }, span: 10,
};
import { genWarehouseAuthSearchModal, genCargoownerAuthSearchModal } from "../../../../../SearchModal";
import { api } from '../../api'



export const basicData = function (self) {
    return {
        searchItems: [
            ...genWarehouseAuthSearchModal(1, true, false, null, null, grid),
            ...genCargoownerAuthSearchModal(1, true, false, null, null, grid, { mapper: { cargoOwnerId: 'mtlOwnerId' } }),
            {
                name: 'rcvType',
                label: '订单类型',
                value: '',
                ...grid,
                type: "select",
                autoLoad: true,
                allowClear: false,
                remoteUrl: {
                    url: api.queryDictList + '?dicttypeCodes=oms_asn_bill_type',
                    method: 'post'
                },
                replaceFields: {
                    value: 'dictCode',
                    label: 'dictName'
                },
            },


            { type: 'input', name: 'asnNo', label: 'ASN单号', value: '', ...grid },
            { type: 'input', name: 'rcvNo', label: '收货单号', value: '', ...grid },
            { type: 'input', name: 'rqcNo', label: '质检单号', value: '', ...grid },

            {
                name: 'whAreaCategoryCode',
                label: '库别',
                value: '',
                ...grid,
                type: "select",
                // autoLoad: true,
                allowClear: false,
                remoteUrl: {
                    url: api.queryRoomInfo,
                    method: 'get'
                },
                replaceFields: {
                    value: 'warehouse_room_code',
                    label: 'warehouse_room_name'
                },
                remoteBefore(res, remoteParams) {
                    // console.log(remoteParams, "remoteParams")
                    let vals = self.$refs.detail.$refs.main[0].$refs.form.form.getFieldsValue()
                    if (remoteParams.params) {
                      remoteParams.params.warehouseId = vals.warehouseId
                    } else {
                      remoteParams.params = {warehouseId: vals.warehouseId}
                    }
                    return remoteParams
                },
            },
            {
                name: 'whAreaCode',
                label: '库区',
                value: '',
                ...grid,
                type: "select",
                // autoLoad: true,
                allowClear: false,
                remoteUrl: {
                    url: api.queryAreaInfo,
                    method: 'get'
                },
                replaceFields: {
                    value: 'warehouse_area_code',
                    label: 'warehouse_area_name'
                },
                remoteBefore(res, remoteParams) {
                    // console.log(remoteParams, "remoteParams")
                    let vals = self.$refs.detail.$refs.main[0].$refs.form.form.getFieldsValue()
                    if (remoteParams.params) {
                      remoteParams.params.warehouseId = vals.warehouseId
                    } else {
                      remoteParams.params = {warehouseId: vals.warehouseId}
                    }
                    return remoteParams
                },
            },
            { type: 'input', name: 'containerCode', label: '容器', value: '', ...grid },
            { type: 'input', name: 'shipperCondition', label: '单位', value: '', ...grid },
            { type: 'input', name: 'itemCondition', label: '商品', value: '', ...grid },
            {
                name: 'status',
                label: '状态',
                value: '',
                ...grid,
                type: "select",
                options: [
                    { label: "未上架", value: 0 },
                    { label: "已上架", value: 1 },
                  ],
                // autoLoad: true,
                // allowClear: false,
                // remoteUrl: {
                //     // url: api.queryDictList + '?dicttypeCodes=itemtype',
                //     method: 'post'
                // },
                // replaceFields: {
                //     value: 'dictCode',
                //     label: 'dictName'
                // },
            },
            { type: 'date', name: 'startTime', showTime: true, format: 'YYYY-MM-DD HH:mm:ss', label: '创建时间起', value: moment().subtract(1, 'week').format('YYYY-MM-DD HH:mm:ss'), ...grid, },
            { type: 'date', name: 'endTime', showTime: true, format: 'YYYY-MM-DD HH:mm:ss', label: '创建时间止', value: moment().format('YYYY-MM-DD HH:mm:ss'), ...grid, },

        ],
        columns: [
            { hidden: true, title: "rqcHeaderId", dataIndex: "rqcHeaderId" },
            { hidden: true, title: "rcvHeaderId", dataIndex: "rcvHeaderId" },
            { title: "ASN单号", dataIndex: "asnNo", width: 90 },
            { title: "收货单号", dataIndex: "rcvNo", width: 90 },
            { title: "质检单号", dataIndex: "rqcNo", width: 90 },
            { title: "订单类型", dataIndex: "rcvTypeName", width: 90 },
            { title: "单位名称", dataIndex: "shipperName", width: 120 },
            { title: "商品助记码", dataIndex: "itemZjm", width: 60 },
            { title: "商品编码", dataIndex: "itemNum", width: 90 },
            { title: "商品名称", dataIndex: "itemName", width: 90 },
            { title: "包装单位", dataIndex: "uom", width: 90 },
            { title: "包装数量", dataIndex: "conversionRate", width: 90 },
            {
                title: "库存状态", dataIndex: "stockStatus", width: 90,
                customRender(text) {
                    if (text == null ) {
                        return "";
                    }
                    let options = [
                        // 合格0/不合格1/待处理2/拒绝3 
                        { value: '0', label: '合格' },
                        { value: '1', label: '不合格' },
                        { value: '2', label: '待检' },
                        // { value: '3', label: '拒收' }
                    ]
                    return options.find(t => t.value == text).label;
                }
            },
            { title: "批号", dataIndex: "manufacturerLotNum", width: 90 },
            { title: "生产日期", dataIndex: "showProductionDate", width: 90 },
            { title: "有效期至", dataIndex: "showExpiredDate", width: 90 },
            { title: "件数", dataIndex: "oddCaseQty", width: 90 },
            { title: "零散数", dataIndex: "oddPieceQty", width: 90 },
            { title: "数量", dataIndex: "pieceQty", width: 90 },
            { title: "容器", dataIndex: "containerCode", width: 90 },
            { title: "库别", dataIndex: "whAreaCategoryName", width: 90 },
            { title: "库区", dataIndex: "whAreaName", width: 90 },
            { title: "推荐货位", dataIndex: "whLocatorCodeRecommend", width: 90 },
            { title: "实际货位", dataIndex: "whLocatorCode", width: 90 },
            { title: "上架人", dataIndex: "creatorName", width: 90 },
            { title: "上架时间", dataIndex: "gmtCreateTime", width: 90 },
            { title: "创建时间", dataIndex: "gmtCreate", width: 90 },
        ]

    }
}