import fetch from 'isomorphic-fetch'
import {getTaskList} from "./common";
let 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  submitBreakageProduct = (data)=>{
    console.log(data,"执行了提交遗留上报")
    let {productDetail,commonInfo}=data;
    let userId=commonInfo.userInfo.id;
    let {taskId}=commonInfo.taskInfo;
    let machineId=commonInfo.storeInfo.id;
    let {skuPosition,skuId,skuStatus}=productDetail;
    let bodyData={skuPosition,skuId,skuStatus,machineId,taskId}
    let url=domain+`machine_pad/lr/${userId}`
    return ()=>{
        fetch(url,{
            // credentials : 'include',
            method : 'POST',
            mode : 'cors',
            headers:{
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json; charset=UTF-8'
            },
            body:JSON.stringify(bodyData)
        }).then((response)=>response.json())
          .then((json)=>{
              console.log(json)
          })
  }
}


//test 没有散落货品
const hasNoSku = (commonInfo)=>{
    let {storeInfo={},userInfo={},taskInfo={}} = commonInfo;
    console.log("执行了没有散落商品的接口")
    return (dispatch)=>{
        let url = `${domain}machine_pad/work/lr/status/${taskInfo.taskId}/${taskInfo.area}/${taskInfo.currentTaskType}`;
        fetch(url,{
            // credentials : 'include',
            method : 'PUT',
            mode : 'cors',
            headers: myHeaders
        }).then(response=>response.json())
            .then((json)=>{
                dispatch(getTaskList(commonInfo))
            })
    }
}

export {submitBreakageProduct,hasNoSku}