import request from '@/utils/request'
import {upcloud_base_common} from "@/config/serviceSettings";



export let getDicsModual = {

    methods: {

        //处理原因
        getBilldRcvreason1() {
            let params = { dicttypeCodes: 'rcv_billd_rcvreason3' }
            getDicts(params).then(res => {
                if (!res.success) {
                    this.$exception(res)
                    return
                }
                let ref = this.queryRefFromName('list')
                ref.scopedSlotsExtendData = {
                    ...ref.scopedSlotsExtendData,
                    rcvReason1: res.data.map(t => t.dictName)
                }
            })
        },

        // 不足原因
        getDefReason() {
            let params = { dicttypeCodes: 'rcv_billd_rcvreason2' }
            getDicts(params).then(res => {
                if (!res.success) {
                    this.$exception(res)
                    return
                }
                let ref = this.queryRefFromName('list')
                ref.scopedSlotsExtendData = {
                    ...ref.scopedSlotsExtendData,
                    rcvReason2: res.data.map(t => t.dictName)
                }
            })
        },

        //处理措施
        getHandlingMeasure() {
            let params = { dicttypeCodes: 'rcv_handle_measure' }
            getDicts(params).then((res) => {
                if (!res.success) {
                    this.$exception(res)
                    return
                }
                let ref = this.queryRefFromName('list')
                ref.scopedSlotsExtendData = {
                    ...ref.scopedSlotsExtendData,
                    handlingMeasure: res.data.map((t) => t.dictName),
                }
            })
        },

        //退货类型
        getReturnType() {
            let params = { dicttypeCodes: 'rcv_return_type' }
            getDicts(params).then((res) => {
                if (!res.success) {
                    this.$exception(res)
                    return
                }
                let ref = this.queryRefFromName('list')
                ref.scopedSlotsExtendData = {
                    ...ref.scopedSlotsExtendData,
                    returnType: res.data.map((t) => t.dictName),
                }
            })
        },

    }

}


function getDicts(parameter) {
    return request({
        method: 'post',
        url: upcloud_base_common+'/dict/listbytype',
        params: parameter,
        replaceFields: {
            value: 'dictCode',
            label: 'dictName'
        }
    })
}