import request from '@/utils/request'
import {upcloud_base_wh_inbound,upcloud_base_wh} from "@/config/serviceSettings";



export let receiveExtendInfoModule = {

    methods: {

        getBuildingList() {
            getBuildingList({
                warehouseId: this.mainlist[0].warehouseId,
                pageNum: 1,
                pageSize: 50,
            }).then((res) => {
                if (!res.success) {
                    return
                }
                this.buildingList = res.data.list
                let aColumns = this.queryRefFromName('list').aColumns
                aColumns.forEach((t) => {
                    // if (t.key == 'bldgId') t.options = res.data.list.map(tt => ({ value: tt.bldgId, label: tt.bldgName }));
                    if (t.key == 'bldgId') {
                        t.options.splice(0, t.options.length)
                        t.options.push(...res.data.list.map((tt) => ({ value: tt.bldgId, label: tt.bldgName })))
                    }
                })
            })
        },

        handleQueryItems(list, ref) {
            if (!list || list.lenght == 0) {
                return list
            }
            // let ref = this.$refs.detailModel;
            let rcvType = ref.getSelectedMainItem().rcvType
            ref.subLoading = true
            getRecommendArea(list.map((t) => ({ ...t, rcvType: rcvType }))).then((res) => {
                ref.subLoading = false
                if (!res.success) {
                    this.$exception(res)
                    return
                }
                ref.GoodsColumnsdata = list.map((t, i) => ({
                    ...t,
                    warehouseAreaCodes: res.data[i].warehouseAreaCodes,
                    warehouseAreaCategorys: res.data[i].warehouseAreaCategorys,
                    warehouseRoomCodes: res.data[i].warehouseRoomCodes,
                    categoryId: res.data[i].categoryId,
                }))
            })
            return list
        },

    }

};

function getBuildingList(parameter) {
    return request({
        method: 'get',
        url: upcloud_base_wh+'/wmsWhBldg/v1/page',
        params: parameter
    })
}

function getRecommendArea(parameter) {
    return request({
        method: 'post',
        url: upcloud_base_wh_inbound+'/rcvLines/v1.0/recommendArea',
        data: parameter
    })
}