import fetch from 'isomorphic-fetch';
import {getTaskList} from "./common";
import {saveProductInfo} from './barcodeCommon'
const domain = ENV.domain;
let myHeaders = new Headers({
    // 'Access-Control-Allow-Origin': '*',
    // 'Content-Type': 'text/plain;charset=UTF-8',
    // 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Content-Type': 'application/json; charset=UTF-8',
});

const finishBoxRecovery = (info)=>{
    //已放入回收箱
    let {userInfo,taskInfo,storeInfo,taskList} = info;
    let bodyData = Object.assign({},{
        storeId : storeInfo.id,
        taskId : taskInfo.taskId,
        userId : userInfo.id,
        id : taskList.workListId,
        taskType : taskInfo.currentTaskType,
        area : taskInfo.area
    })
    let url=`${domain}machine_pad/update_machine_recovery_sku.action`
    return (dispatch)=>{
        fetch(url,{
            credentials : 'include',
            method : 'POST',
            mode : 'cors',
            headers: myHeaders,
            body:JSON.stringify(bodyData)
        }).then(response=>response.json())
            .then((json)=>{
                dispatch(saveProductInfo({}));
                dispatch(getTaskList(info));
            })
    }
};

export {finishBoxRecovery}
