import request from 'src/utils/request'
import Cookies from "js-cookie";

// 获取token
export function token() {
    return request({
        url: '/auth/sub-sys/token',
        headers: {
            "Content-Type": "application/json",
        },
        method: 'post',
        data: {
            "authCode": "210225"
        }
    })
}


// 查询订单信息
export function cartonOrder(params) {
    return request({
        url: '/qrcode/cartonOrder/order/list',
        method: 'get',
        params: params
    })
}
// 查询纠错订单信息
export function cartonOrderError(params) {
    return request({
        url: '/qrcode/cartonOrder/order/listError',
        method: 'get',
        params: params
    })
}

// 查询订单信息
export function cartonOrderbyId(param) {
    return request({
        url: '/qrcode/cartonOrder/order/' + param,
        method: 'get',
        // params: params
    })
}

// 根据订单号查询条码
export function cartonOrderByCusOrderCode(params) {
    return request({
        url: '/qrcode/cartonOrder/order/selectByOrderList',
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
        data: params
    })
}

// 根据订单号和流水号查询条码
export function cartonOrderinfoBy(params) {
    return request({
        url: '/qrcode/cartonOrder/api/cartonOrder/data/info/cartonOrderInfo',
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
        data:params
    })
}
// 根据根据二维码查询信息
export function cartonOrderByQrCode(params) {
    return request({
        url: '/qrcode/cartonOrder/api/cartonOrder/data/info/cartonOrderByQrCode' ,
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
        data :params
    })
}

// 根据根据二维码查询信息
export function cartonQualitySusses(cartonOrderInsList) {
    return request({
        url: '/qrcode/cartonOrder/api/cartonOrder/data/info/cartonQualitySusses' ,
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
        data : {
            "cartonOrderInsList":cartonOrderInsList,
            "qrSubSysInfo" : JSON.parse(localStorage.getItem('qrCodeProductLine'))
        }
    })
}



/**
 * 操作记录 条零
 * row 订单信息，
 * errorId 操作记录表Id
 * qrCodeList 关联二维码数据
 * qrCode 关联二维码扫描正确数据
 * errorQrCode 异常数据
 */
export function cartonQualityResult(row,errorId,qrCodeList,qrCode,errorQrCode){
    return request({
        url: '/qrcode/cartonOrder/api/cartonOrder/data/info/qualityResult',
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
        data: {
            // 订单数据
            "row": row,
            // 订单关联二维码数据
            "qrCodeList":qrCodeList,
            // errorId 操作记录表Id
            "errorId":errorId,
            // 判断校验异常二维码
            "errorQrCode":errorQrCode,
            // 已检验二维码，
            "qrCode": qrCode,
            // 产线
            "qrCodeProductLine" : JSON.parse(localStorage.getItem('qrCodeProductLine'))
        }
    })
}


// 根据订单号查询条码
export function cartonOrderinfo(code) {
    return request({
        url: '/qrcode/cartonOrder/api/cartonOrder/data/info/' + code,
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
    })
}

// 获取全部订单信息
export function cartonOrderlist(pageNum, pageSize) {
    return request({
        url: '/qrcode/cartonOrder/api/order/data/listTable',
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'get',
        params: {
            "pageNum": pageNum,
            "pageSize": pageSize
        }
    })
}

// // 强制替换
// export function forceReplace(orderCode,batchCode,generateTime,sortLineCode,code) {
//     return request({
//         url: '/qrcode/cartonOrder/api/cartonOrder/data/getOrderByQrCode',
//         headers: {
//             "Content-Type": "application/json",
//             "Authorization": Cookies.get('token')
//         },
//         method: 'post',
//         data: {
//             "orderCode": orderCode,
//             "generateTime":generateTime,
//             "batchCode":batchCode,
//             "sortLineCode":sortLineCode,
//             "code":code,
//         }
//     })
// }

// 绑定关联
export function relation(code,batchCode,generateTime,sortLineCode,sortLineName,retailerName,retailerCode,cusQrcode,arr,lineId,count,qrBrandCodeMap,type,orderCodeList,qrCodeIns,originalArrayBrandCode,scanIn,scanOut,orderId) {
    return request({
        url: '/qrcode/cartonOrder/api/cartonOrder/info/relation',
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
        data: {
            "orderCode": code,
            "generateTime":generateTime,
            "batchCode":batchCode,
            "sortLineCode":sortLineCode,
            "sortLineName":sortLineName,
            "retailerName":retailerName,
            "retailerCode":retailerCode,
            "cartonList": arr,
            "cusOrderCode":cusQrcode,
            "lineId":lineId,
            "type" : type,
            "originalCode" : orderCodeList,
            "code" : qrCodeIns,
            "count" : count,
            "qrBrandCodeMap" : qrBrandCodeMap,
            "originalArrayBrandCode":originalArrayBrandCode,
            "scanIn":scanIn,
            "scanOut":scanOut,
            "id":orderId,
            "qrSubSysInfo" : JSON.parse(localStorage.getItem('qrCodeProductLine'))

        }
    })
}

// 解除关联
export function unbound(code,batchCode,generateTime,sortLineCode,sortLineName,retailerName,retailerCode,cusQrcode,arr,lineId,type,orderCodeList,qrcode) {
    return request({
        url: '/qrcode/cartonOrder/api/cartonOrder/info/unbound',
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
        data: {
            "orderCode": code,
            "generateTime":generateTime,
            "batchCode":batchCode,
            "sortLineCode":sortLineCode,
            "sortLineName":sortLineName,
            "retailerName":retailerName,
            "retailerCode":retailerCode,
            "cartonList": arr,
            "cusOrderCode":cusQrcode,
            "lineId":lineId,
            "type":type,
            "originalCode":orderCodeList,
            "code":qrcode,
            "qrSubSysInfo" : JSON.parse(localStorage.getItem('qrCodeProductLine'))
        }
    })
}

export function getSortLine() {
    return request({
        url: '/qrcode/device/sortline/list',
        method: 'get'
    })
}


export function getCartonOrderInsList(params) {
    return request({
        url: '/qrcode/cartonOrder/cartonOrderIns/list',
        method: 'get',
        params: params
    })
}

// 根据订二维码Code查询OrderId
export function getOrderByQrCode(params) {
    return request({
        url: '/qrcode/cartonOrder/api/cartonOrder/data/info/getOrderByQrCode',
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
        data: params
    })
}

// 计数纠错
export function countError(id,count) {
    return request({
        url: '/qrcode/cartonOrder/api/cartonOrder/info/countError',
        headers: {
            "Content-Type": "application/json",
            "Authorization": Cookies.get('token')
        },
        method: 'post',
        data: {
            "id": id,
            "count":count,
            "qrSubSysInfo" : JSON.parse(localStorage.getItem('qrCodeProductLine'))
        }
    })
}