Commit 704abb56 by zhangzhi

选门店拉任务

parent 59f0f122
import fetch from 'isomorphic-fetch'; import fetch from 'isomorphic-fetch';
import actionType from '../actiontype/common' import actionType from '../actiontype/common'
import {addErrorInfo} from './uploadError' import {addErrorInfo} from './uploadError'
import {emit} from "../util/event";
let domain = ENV.domain; let domain = ENV.domain;
let myHeaders = new Headers({ let myHeaders = new Headers({
...@@ -45,6 +46,63 @@ const getStoreInfo = (storeId)=>{ ...@@ -45,6 +46,63 @@ const getStoreInfo = (storeId)=>{
} }
}; };
//获取门店信息以及当前用户信息以及任务信息
const fetchStoreInfo = (storeId)=>{
return async (dispatch)=>{
let bodyData = {storeId};
UTILPATH.myLogger.info("getMachineData request ",bodyData);
let success = (json)=>{
UTILPATH.myLogger.info("getMachineData response ",json);
let storeInfo = Object.assign({},{id:storeId});
let taskInfo = {}
let userinfo = {}
if(json.meta.success){
if(!json.data.employeeInfo){
dispatch(addErrorInfo('这个门店没有开门用户'))
return;
}
if(!json.data.taskInfo){
dispatch(addErrorInfo('这个门店没有任务'))
return;
}
if(json.data.warehouse){
storeInfo = Object.assign({},storeInfo,json.data.warehouse)
}
if(json.data.taskInfo){
taskInfo = Object.assign({},taskInfo,json.data.taskInfo)
}
if(json.data.employeeInfo){
userinfo = Object.assign({},userinfo,json.data.employeeInfo)
}
dispatch(saveCommonInfo(Object.assign({},{storeInfo})));
dispatch(saveCommonInfo(Object.assign({},{taskInfo})));
dispatch(saveCommonInfo(Object.assign({},{userinfo})));
emit(CONFIG.customEvent.STOREINFOREADY,{});
}
};
let fail = (e)=>{
UTILPATH.myLogger.error(`getMachineData error ${e}`);
dispatch(getStoreInfo(storeId));
};
try{
let res = await fetch(domain + 'pad_warehouse/getMachineData.action',{
credentials : 'include',
method : 'POST',
mode : 'cors',
headers:myHeaders,
body: JSON.stringify(bodyData)
}).then((response)=>response.json());
return success(res);
}catch (e) {
return fail(e)
}
}
};
//获取用户信息 //获取用户信息
const getUserinfo = (employeeId,storeId)=>{ const getUserinfo = (employeeId,storeId)=>{
...@@ -161,4 +219,4 @@ const getTaskName = (currentTaskType,childTaskNum=0)=>{ ...@@ -161,4 +219,4 @@ const getTaskName = (currentTaskType,childTaskNum=0)=>{
} }
} }
export {getStoreInfo,saveCommonInfo,getUserinfo,logout,getTaskList,getTaskName,emptyStoreInfo} export {getStoreInfo,saveCommonInfo,getUserinfo,logout,getTaskList,getTaskName,emptyStoreInfo,fetchStoreInfo}
import fetch from 'isomorphic-fetch'; import fetch from 'isomorphic-fetch';
import actionTypes from '../actiontype/store' import actionTypes from '../actiontype/store'
import {saveHeaderInfo} from './initHeader' import {saveHeaderInfo} from './initHeader'
import {emit} from "../util/event";
const domain = ENV.domain; const domain = ENV.domain;
const saveStoreInfo = (data)=>{ const saveStoreInfo = (data)=>{
...@@ -41,7 +42,30 @@ const getStoreInfo = (data)=>{ ...@@ -41,7 +42,30 @@ const getStoreInfo = (data)=>{
} }
}; };
const listStores = ()=>{
return (dispatch)=>{
fetch(domain + 'machine_pad/power_cut_find_store',{
credentials : 'include',
method : 'POST',
mode : 'cors',
headers: { 'Content-Type': 'application/json' },
body:JSON.stringify({})
}).then((response)=>response.json())
.then(json=>{
UTILPATH.myLogger.info("power_cut_find_store ",json);
if(json.meta.success){
let storeList = json.data;
dispatch(saveStoreList(storeList))
emit(CONFIG.customEvent.STORELISTREADY,{});
}else{
//没有店铺信息
}
}).catch(e=>{
UTILPATH.myLogger.error(`power_cut_find_store ${e}`);
dispatch(listStores());
});
}
}
const getStoreList = ()=>{ const getStoreList = ()=>{
return (dispatch)=>{ return (dispatch)=>{
fetch(domain + 'machine_pad/power_cut_find_store',{ fetch(domain + 'machine_pad/power_cut_find_store',{
...@@ -73,5 +97,5 @@ const saveStoreList = (data)=>{ ...@@ -73,5 +97,5 @@ const saveStoreList = (data)=>{
} }
}; };
export {getStoreInfo,getStoreList} export {getStoreInfo,getStoreList,listStores}
const customEvent = {
STORELISTREADY: 'STORELISTREADY',
STOREINFOREADY: 'STOREINFOREADY',
}
module.exports = customEvent;
\ No newline at end of file
...@@ -3,5 +3,6 @@ import showPage from './showPage' ...@@ -3,5 +3,6 @@ import showPage from './showPage'
import socketType from './socketType' import socketType from './socketType'
import taskErrorType from './taskErrorType' import taskErrorType from './taskErrorType'
import config from './config' import config from './config'
import customEvent from './customEvent'
module.exports = {swiperContainers,...showPage,socketType,taskErrorType , config } module.exports = {swiperContainers,...showPage,socketType,taskErrorType,customEvent , config }
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,7 @@ const socketType = { ...@@ -4,7 +4,7 @@ const socketType = {
GETSOCKETMSG:'GETSOCKETMSG', GETSOCKETMSG:'GETSOCKETMSG',
SOCKETERROR : 'SOCKETERROR', SOCKETERROR : 'SOCKETERROR',
STARTSTOPSERVER : 'STARTSTOPSERVER', //开启断电断网流程 STARTSTOPSERVER : 'STARTSTOPSERVER', //开启断电断网流程
STOPSTOPSERVER : 'STOPSTOPSERVER' //关闭断电断网流程 STOPSTOPSERVER : 'STOPSTOPSERVER', //关闭断电断网流程,
} }
module.exports = socketType; module.exports = socketType;
\ No newline at end of file
...@@ -210,15 +210,21 @@ export default class HomePageContainer extends React.Component{ ...@@ -210,15 +210,21 @@ export default class HomePageContainer extends React.Component{
) )
} }
start(){ start(){
//改成先选门店
let props = this.props; let props = this.props;
let {getTaskList} = props; let {showStoreSelect} = props;
if(getTaskList){ if(showStoreSelect){
getTaskList(); showStoreSelect()
} }
// getStoreList();
// let props = this.props;
// let {getTaskList} = props;
// if(getTaskList){
// getTaskList();
// }
} }
} }
11
HomePageContainer.propTypes = { HomePageContainer.propTypes = {
}; };
......
...@@ -33,10 +33,10 @@ import {getBarCodeProductInfo,saveProductInfo} from '../../actions/barcodeCommon ...@@ -33,10 +33,10 @@ import {getBarCodeProductInfo,saveProductInfo} from '../../actions/barcodeCommon
import {getTaskList, askForNextTask, emptyStoreInfo} from '../../actions/common' import {getTaskList, askForNextTask, emptyStoreInfo} from '../../actions/common'
import {submitBreakageProduct,hasNoSku} from '../../actions/breakaegContainer' import {submitBreakageProduct,hasNoSku} from '../../actions/breakaegContainer'
import {checkProductQuantity} from '../../actions/TokeStokeContainer' import {checkProductQuantity} from '../../actions/TokeStokeContainer'
import {getStoreInfo,saveCommonInfo,getUserinfo,logout,getTaskName} from "../../actions/common"; import {getStoreInfo,saveCommonInfo,getUserinfo,logout,getTaskName,fetchStoreInfo} from "../../actions/common";
import {finishBoxRecovery} from "../../actions/recovery"; import {finishBoxRecovery} from "../../actions/recovery";
import replenishAction from "../../actions/replenish"; import replenishAction from "../../actions/replenish";
import {getStoreList} from "../../actions/getStore"; import {getStoreList,listStores} from "../../actions/getStore";
import {pollingGetUserinfo} from "../../actions/userinfo"; import {pollingGetUserinfo} from "../../actions/userinfo";
import AllClassify from '../AllClassifyContainer/AllClassifyContainer' import AllClassify from '../AllClassifyContainer/AllClassifyContainer'
import {willCloseDoor,closeDoorSuccess} from '../../actions/chooseTaskContainer' import {willCloseDoor,closeDoorSuccess} from '../../actions/chooseTaskContainer'
...@@ -90,6 +90,7 @@ class PageContainer extends React.Component { ...@@ -90,6 +90,7 @@ class PageContainer extends React.Component {
storeValue : "", // 断网情况下的 门店id storeValue : "", // 断网情况下的 门店id
startWork : false, //断网情况下 开始工作标识(暂未用到) startWork : false, //断网情况下 开始工作标识(暂未用到)
startCountback : false, // 开始超时倒计时标识 startCountback : false, // 开始超时倒计时标识
showSelectStore: false, //显示选择门店
}; };
this.getPages = this.getPages.bind(this); //获取当前页面 this.getPages = this.getPages.bind(this); //获取当前页面
this.showPopup = this.showPopup.bind(this); //显示弹窗 this.showPopup = this.showPopup.bind(this); //显示弹窗
...@@ -120,6 +121,7 @@ class PageContainer extends React.Component { ...@@ -120,6 +121,7 @@ class PageContainer extends React.Component {
this.showStoreListPop = this.showStoreListPop.bind(this); //展示门店列表窗口 this.showStoreListPop = this.showStoreListPop.bind(this); //展示门店列表窗口
this.handleStoreChange = this.handleStoreChange.bind(this); //监听门店切换 this.handleStoreChange = this.handleStoreChange.bind(this); //监听门店切换
this.handleChooseStore = this.handleChooseStore.bind(this); //监听门店切换 this.handleChooseStore = this.handleChooseStore.bind(this); //监听门店切换
this.handleSelectStore = this.handleSelectStore.bind(this); //选择新的门店
this.showQrcodePop = this.showQrcodePop.bind(this); //展示扫码开门二维码弹窗 this.showQrcodePop = this.showQrcodePop.bind(this); //展示扫码开门二维码弹窗
this.startWork = this.startWork.bind(this); //展示扫码开门二维码弹窗 this.startWork = this.startWork.bind(this); //展示扫码开门二维码弹窗
/*以下是二期方法 end*/ /*以下是二期方法 end*/
...@@ -241,6 +243,20 @@ class PageContainer extends React.Component { ...@@ -241,6 +243,20 @@ class PageContainer extends React.Component {
}) })
} }
}); });
on(CONFIG.customEvent.STORELISTREADY, this, ()=>{
const that = this;
if(!this.state.showSelectStore){
this.setState({
showSelectStore : true
},()=>{
that.showStoreSelectPop();
})
}
})
on(CONFIG.customEvent.STOREINFOREADY, this, ()=>{
const that = this;
that.startWork();
})
on(CONFIG.socketType.STOPSTOPSERVER,this,()=>{ on(CONFIG.socketType.STOPSTOPSERVER,this,()=>{
// 接收到终止断网指令(即联网成功) // 接收到终止断网指令(即联网成功)
UTILPATH.myLogger.info("componentWillMount " ,CONFIG.socketType.STOPSTOPSERVER); UTILPATH.myLogger.info("componentWillMount " ,CONFIG.socketType.STOPSTOPSERVER);
...@@ -471,7 +487,23 @@ class PageContainer extends React.Component { ...@@ -471,7 +487,23 @@ class PageContainer extends React.Component {
} }
componentWillUnmount(){ componentWillUnmount(){
} }
showStoreSelect(){
console.log('in show store select')
let {dispatch} = this.props;
dispatch(listStores())
// let {dispatch} = this.props;
// console.log('kkkkkkkkk')
// dispatch(listStores()).then(()=>{
// console.log('vvvvvvvvv');
// })
// let storeList = this.state.storeInfo && this.state.storeInfo.storeList ? this.state.storeInfo.storeList : [];
//
// this.setState({
// showSelectStore: true},()=>{
// this.showStoreListPop(storeList);
// }
// )
}
showError(errMsg){ showError(errMsg){
let className = errMsg.length > 24 ? 'popupExtClass' : ''; let className = errMsg.length > 24 ? 'popupExtClass' : '';
let style = {'width':UTILPATH.getRemByPx(260)} let style = {'width':UTILPATH.getRemByPx(260)}
...@@ -661,7 +693,8 @@ class PageContainer extends React.Component { ...@@ -661,7 +693,8 @@ class PageContainer extends React.Component {
hidePopup(){ hidePopup(){
if(this.state.popupInfo.showPopup){ if(this.state.popupInfo.showPopup){
this.setState({ this.setState({
popupInfo : defaultPopupInfo popupInfo : defaultPopupInfo,
showSelectStore: false,
}) })
} }
...@@ -728,10 +761,59 @@ class PageContainer extends React.Component { ...@@ -728,10 +761,59 @@ class PageContainer extends React.Component {
} }
// 断网模式,监听选择门店,获取门店信息 // 断网模式,监听选择门店,获取门店信息
handleChooseStore(){ handleChooseStore(){
const {dispatch} = this.props; const {dispatch, state} = this.props;
let storeId = this.state.storeValue; let storeId = this.state.storeValue;
if(!storeId){
storeId = state.storeInfo.storeList[0].id
}
dispatch(getStoreInfo(storeId)); dispatch(getStoreInfo(storeId));
} }
// 门店选择后获取门店信息及开门用户信息
handleSelectStore(){
const {dispatch, state} = this.props;
let storeId = this.state.storeValue;
if(!storeId){
storeId = state.storeInfo.storeList[0].id
}
dispatch(fetchStoreInfo(storeId));
}
// 选择门店拉取任务
showStoreSelectPop(){
let {state} = this.props;
let storeList = state.storeInfo && state.storeInfo.storeList ? state.storeInfo.storeList : [];
if(storeList && storeList.length > 0){
let storeDom = storeList.map((store,index)=>{
return <option key={"storeListPop"+index} value = {store.id}>{store.name}</option>
});
let btnWidth = UTILPATH.getRemByPx(240);
let btnMiddle = UTILPATH.getRemByPx(40)
let btnMarginLeft = UTILPATH.getRemByPx(30);
let btnBorderRadius = UTILPATH.getRemByPx(10);
let border = "2px solid #e5e5e5"
let btnDom = <Button key={"showStoreListBtn"} style={{'width':btnWidth,'border':border,'marginRight':btnMiddle,'marginTop':'12%','display':'inline-block'}} text={"确定"} option={this.handleSelectStore}/>
let cancelBtnDom = <Button key={"cancelStoreListBtn"} style={{'width':btnWidth,'border':border,'marginTop':'12%','display':'inline-block'}} text={"取消"} option={this.hidePopup}/>
let dom = <PopModel popupTitle={"门店任务拉取"} classContainer={"recoveryPopInfo"}>
<div className={"font36"} style={{'marginTop':'12%'}}>
<span className={"font"}>选择当前门店 </span>
<select
defaultValue=""
onChange={this.handleStoreChange}
>
{storeDom}
</select>
</div>
{btnDom}{cancelBtnDom}
</PopModel>;
this.setState({
popupInfo : defaultPopupInfo
},()=>{
this.showPopup({
popupChild : dom
});
});
}
}
// 断网模式,显示门店列表弹窗 // 断网模式,显示门店列表弹窗
showStoreListPop(storeList){ showStoreListPop(storeList){
if(storeList && storeList.length > 0){ if(storeList && storeList.length > 0){
...@@ -962,6 +1044,8 @@ class PageContainer extends React.Component { ...@@ -962,6 +1044,8 @@ class PageContainer extends React.Component {
changePages={(data)=>this.changePages(data)} changePages={(data)=>this.changePages(data)}
showPopup={(info)=>this.showPopup(info)} showPopup={(info)=>this.showPopup(info)}
hidePopup={()=>this.hidePopup()} hidePopup={()=>this.hidePopup()}
dispatch={dispatch}
showStoreSelect={()=>this.showStoreSelect()}
/>; />;
break; break;
case showPage[131]: case showPage[131]:
......
...@@ -20,14 +20,14 @@ let startStopServer = false; ...@@ -20,14 +20,14 @@ let startStopServer = false;
let beginConnectSocket = ()=>{ let beginConnectSocket = ()=>{
console.log("===socket===beginConnectSocket===getIpING=== ",getIpING); // console.log("===socket===beginConnectSocket===getIpING=== ",getIpING);
if(!getIpING){ // if(!getIpING){
currentIpIndex = 255; // currentIpIndex = 255;
totalCount = 0; // totalCount = 0;
storeId = 0; // storeId = 0;
socket.getIp1(); // socket.getIp1();
socket.stopServer(); // socket.stopServer();
} // }
}; };
socket.stopServer = ()=>{ socket.stopServer = ()=>{
...@@ -124,57 +124,57 @@ const getClose = ()=>{ ...@@ -124,57 +124,57 @@ const getClose = ()=>{
const init = (ip,storeid,from = false)=>{ const init = (ip,storeid,from = false)=>{
let theIp = exactDomainIp || `${domainIp}${ip}`; let theIp = exactDomainIp || `${domainIp}${ip}`;
let wsUrl = `ws://${theIp}:${domainPort}/notify?from=plant&storeId=${storeid}`; let wsUrl = `ws://${theIp}:${domainPort}/notify?from=plant&storeId=${storeid}`;
if("WebSocket" in window && !ws && storeid && // if("WebSocket" in window && !ws && storeid &&
(exactDomainIp || (ip && storeid && (currentIpIndex === 255 || from))) ){ // (exactDomainIp || (ip && storeid && (currentIpIndex === 255 || from))) ){
ws = new WebSocket(wsUrl); // ws = new WebSocket(wsUrl);
//
ws.onopen = function() // ws.onopen = function()
{ // {
// Web Socket 已连接上,使用 send() 方法发送数据 // // Web Socket 已连接上,使用 send() 方法发送数据
// ws.send("发送数据"); // // ws.send("发送数据");
currentIpIndex = ip; // // currentIpIndex = ip;
storeId = storeid; // // storeId = storeid;
getIpING = false; // // getIpING = false;
myLogger.saveDomain(exactDomainIp || (domainIp + ip)); // // myLogger.saveDomain(exactDomainIp || (domainIp + ip));
if(stopTimer){ // // if(stopTimer){
//重连成功后,终止倒计时 // // //重连成功后,终止倒计时
clearTimeout(stopTimer); // // clearTimeout(stopTimer);
stopTimer = null; // // stopTimer = null;
startStopServer = false; // // startStopServer = false;
myLogger.info("连接成功,停止stopTimer倒计时"); // // myLogger.info("连接成功,停止stopTimer倒计时");
} // // }
emit(CONFIG.socketType.GETSTOREINFO,{ip:(exactDomainIp || (domainIp + ip)),storeId:storeid}) // // emit(CONFIG.socketType.GETSTOREINFO,{ip:(exactDomainIp || (domainIp + ip)),storeId:storeid})
}; // };
//
ws.onmessage = function (evt) // ws.onmessage = function (evt)
{ // {
if(evt.data === "ping"){ // // if(evt.data === "ping"){
let o = { // // let o = {
type : 'PONG' // // type : 'PONG'
}; // // };
ws.send(JSON.stringify(o)); // // ws.send(JSON.stringify(o));
}else{ // // }else{
let received_msg = JSON.parse(evt.data); //String // // let received_msg = JSON.parse(evt.data); //String
emit(CONFIG.socketType.GETSOCKETMSG,received_msg); // // emit(CONFIG.socketType.GETSOCKETMSG,received_msg);
} // // }
//
}; // };
//
ws.onclose = function(err) // ws.onclose = function(err)
{ // {
// 关闭 websocket // // 关闭 websocket
myLogger.error("socket close & getIpING",err,getIpING); // myLogger.error("socket close & getIpING",err,getIpING);
emit(CONFIG.socketType.SOCKETERROR,""); // // emit(CONFIG.socketType.SOCKETERROR,"");
getClose(); // // getClose();
}; // };
ws.onerror = function (err) { // ws.onerror = function (err) {
myLogger.error("socket error & getIpING",err,getIpING); // myLogger.error("socket error & getIpING",err,getIpING);
emit(CONFIG.socketType.SOCKETERROR,""); // // emit(CONFIG.socketType.SOCKETERROR,"");
getError(); // // getError();
} // }
//
//
} // }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment