import fetch from 'isomorphic-fetch'
import tokeActionType from '../actiontype/TokeStokeContainer'
import {getTaskList} from './common'
let domain = ENV.domain;
//点击提交后台核对商品数量
const checkProductQuantity = (data)=>{
      let {commonInfo,tokeProductInfo}=data;
      let storeId=commonInfo.storeInfo.id;
      let {taskId,area,currentTaskType}=commonInfo.taskInfo;
      let employeeId=commonInfo.userInfo.employeeId;
      let {quantity,skuPassId,workListId}=tokeProductInfo;
      let bodyData={storeId,taskId,area,quantity,skuPassId,workListId,employeeId,currentTaskType}
      let url=domain+`machine_pad/work/ck`;
      return (dispatch)=>{
                fetch(url,{
                    credentials : 'include',
                    method : 'POST',
                    mode : 'cors',
                    headers: {
                        'content-type':'application/json;charset=UTF-8',
                    },
                    body:JSON.stringify(bodyData)
                }).then(response=>response.json())
                .then((json)=>{
                    if(json.data===1){
                        console.log("执行了 json.data===1 的拉取工单的操作")
                        dispatch(getTaskList(commonInfo))
                    }
                    dispatch(checkQuantity({type:json.data}))
                }).catch(e=>{console.log('err'+e)})

      }
}
const checkQuantity = (data)=>{
      return{
          type:tokeActionType.SUBMIT_NUM,
          data
      }
  }

  export {checkProductQuantity}