import fetch from 'isomorphic-fetch'
import getTaskList from './common'
import barcodeActionType from '../actiontype/barcodeCommon'
import {wrongQrcode,emptyErrorInfo} from './replenish'
let domain = ENV.domain;
// const changeStatus = (data)=>{
      
//       let {taskId,currentTaskType}=data.taskInfo;
//       let url = `http://192.168.10.128:8080/web/flat/work/lr/status/${taskId}/${currentTaskType}`
//       return (dispatch)=>{
//             fetch(url,{
//                 credentials : 'include',
//                 method : 'PUT',
//                 mode : 'cors',
//                 body : {}
//             }).then((response)=>response.json())
//              .then((json)=>{
//                   if(json.data){
//                         getTaskList(data)
//                   }
//              })
//       }
// }


const changeTaskStatus = (data)=>{
      return {

      }
}

//test 输入条形码获取商品信息

const getBarCodeProductInfo = (data)=>{
      let {barcode='',commonInfo={}}=data;
      let {taskInfo={},storeInfo={}}=commonInfo;
      let storeId=storeInfo.id || 0;
      let currentTaskType = taskInfo.currentTaskType || '';
      let area = taskInfo.area || ''
      let taskId = taskInfo.taskId || 0
      console.log(barcode,commonInfo,'这是吴加宝打印的数据')
      let url=`${domain}flat/barcode/${storeId}/${taskId}/${area}/${currentTaskType}/${barcode}`
      return (dispatch)=>{
            fetch(url,{
                // credentials : 'include',
                method : 'GET',
                mode : 'cors'
            }).then((response)=>response.json())
            .then((json)=>{
                if(json.meta.success&&json.data){
                    dispatch(emptyErrorInfo());
                    dispatch(saveProductInfo(json.data))
                }else{
                    switch (taskInfo.currentTaskNum){
                        case 3 :
                            //回收任务
                            break;
                        case 4 :
                            //补货任务
                            dispatch(wrongQrcode(json));
                            break;
                    }
                }
            })

      }
}
const saveProductInfo = (data)=>{
      return{
          type : barcodeActionType.GETPRODUCTINFO,
          data
      }
  }

  export {getBarCodeProductInfo}