Commit a8bd452f by Denglingling

完善【设备信息】菜单相关功能

parent 7c5633e1
......@@ -8,29 +8,29 @@ import {
import { exitLoginStatus } from './LoginAction';
// 设备信息-修改状态
export function updateDeviceStatus(params) {
export function updateDeviceStatus({access_token, ...params}) {
return (dispatch, getState) => {
// dispatch(requestUpdate())
// let {global_domain_config} = getState().login
// GetRequest(global_domain_config, getUrlParams('/surgery/collect_order/search', params))
// .then(res => {
// if(res.error_code == 0) {
// let { data: { surgery_collect_headers } } = res
// dispatch(requestUpdateSuccess(surgery_collect_headers));
// } else if(res.error_code === 41006) {
// show('登录过期,请重新登录');
// dispatch(exitLoginStatus());
// } else {
// let error_msg = res.error_msg || res.message
// show(error_msg);
// dispatch(requestUpdateFail());
// }
// })
// .catch(err => {
// console.log('------err--====updateDeviceStatus----', Object.keys(err), err)
// show(err.error);
// dispatch(requestUpdateFail());
// })
dispatch(requestUpdate())
let {global_domain_config} = getState().login
PostRequest(global_domain_config, getUrlParams('/hardware_control/door_control', {access_token: access_token}), params)
.then(res => {
if(res.error_code == 0) {
show(`${params.data.message}`);
dispatch(requestUpdateSuccess());
} else if(res.error_code === 41006) {
show('登录过期,请重新登录');
dispatch(exitLoginStatus());
} else {
let error_msg = res.error_msg || res.message
show(error_msg);
dispatch(requestUpdateFail());
}
})
.catch(err => {
console.log('------err--====updateDeviceStatus----', Object.keys(err), err)
show(err.error);
dispatch(requestUpdateFail());
})
}
}
......@@ -40,10 +40,9 @@ function requestUpdate() {
}
}
function requestUpdateSuccess(data) {
function requestUpdateSuccess() {
return {
type: DEVICE_INFORMATION_UPDATE_SUCCESS,
rawData: data
type: DEVICE_INFORMATION_UPDATE_SUCCESS
}
}
......
import React, { Component } from 'react';
import { View, Text, StyleSheet, SafeAreaView, ScrollView, TouchableOpacity, Image } from 'react-native';
import {
home_background_color,
promary_color,
safe_view,
icon_style,
pxSize,
foundation_color,
font_family_regular
} from '../../base/BaseStyle';
import StatusBarView from '../common/StatusBarView';
import HeadBackItem from '../common/HeadBackItem';
import {
AsteriskTextStyle,
TitleTextStyle,
ContTextStyle,
ImageTextStyle,
CellTextStyle,
ContInputTextStyle
} from '../common/CellTextStyle';
import { connect } from 'react-redux';
import { show } from '../../utils/Utils';
import DialogModel from '../common/DialogModel';
import LodingModel from '../common/LodingModel';
import { updateDeviceStatus } from '../../action/DeviceAction';
import { exitLoginStatus } from '../../action/LoginAction';
import {
DEVICE_INFORMATION_UPDATE_DOING,
DEVICE_INFORMATION_UPDATE_SUCCESS,
DEVICE_INFORMATION_UPDATE_FAILURE,
LOGIN_NO
} from '../../base/ActionTypes';
class DeviceInfoPage extends Component {
constructor(props) {
super(props);
this.state = {
listOptionData: [
{
"id": "0",
title: '销售员',
name: '',
value: ''
},
{
"id": "1",
title: '库存',
name: '请选择',
value: ''
}
],
currentItem: {
name: '请选择',
value: ''
},
currentTitle: '', // 当前点击项
showTypePop: false, // 选择器弹窗
isSubLoding: false, // 加载中弹窗
lodingTitle: '加载中',
listCurrentOption: [], // 当前选择器数据
deviceBtnInfo: [
{
operation: 'normal_open',
btnName: '门常开',
icon: require('../../images/al_open.png'),
message: '自动门常开设置成功'
},
{
operation: 'cancel_normal_open',
btnName: '取消门常开',
icon: require('../../images/can_al_open.png'),
message: '取消自动门常开设置成功'
},
{
operation: 'open',
btnName: '临时开门',
icon: require('../../images/tem_open.png'),
message: '临时开门成功,5s后将自动关闭'
},
{
operation: 'normal_close',
btnName: '门常闭',
icon: require('../../images/nor_open.png'),
message: '自动门常闭设置成功'
},
{
operation: 'cancel_normal_close',
btnName: '取消门常闭',
icon: require('../../images/can_nor_open.png'),
message: '取消自动门常闭设置成功'
},
{
operation: '',
btnName: '',
icon: '',
message: ''
}
]
}
}
componentDidMount() {
this.getSellerName()
}
componentWillReceiveProps(nextProps) {
let { device_info_status, loginState, navigation } = this.props
let that = this
if (device_info_status != nextProps.device_info_status) {
console.log('nextProps.device_info_status-', nextProps.device_info_status)
switch (nextProps.device_info_status) {
case DEVICE_INFORMATION_UPDATE_DOING:
this.changeSubLoding(true)
break;
case DEVICE_INFORMATION_UPDATE_SUCCESS:
this.changeSubLoding(false)
break;
case DEVICE_INFORMATION_UPDATE_FAILURE:
this.changeSubLoding(false)
break;
default:
break;
}
}
if (loginState != nextProps.loginState) {
switch (nextProps.loginState) {
case LOGIN_NO:
navigation.navigate('LoginPage')
break;
default:
break;
}
}
}
// 赋值销售员 初始化数据
getSellerName() {
let { state, props } = this
let { listOptionData } = this.state
if (state.listOptionData[0].name !== props.userInfo.person_name) {
listOptionData[0].name = props.userInfo.person_name
listOptionData[0].value = props.userInfo.user_name
this.setState({
listOptionData
})
}
}
// 修改正在加载
changeSubLoding(loading, loadTit) {
this.setState({
isSubLoding: loading || false,
lodingTitle: loadTit || '提交中'
})
}
// 选择器弹窗回调函数
handleCallBack(item, itemTitle) {
let { listOptionData } = this.state
let that = this
this.setState({
currentItem: item,
})
this.setState({
listOptionData: listOptionData.map((chItem, index) => {
if (chItem.title === itemTitle) {
chItem.name = item.name
chItem.value = item.value
}
return chItem
})
})
}
// 关闭弹窗
handleCloseModal(show) {
this.setState({
showTypePop: show
})
}
handleStockCheck() {
let { listOptionData } = this.state
let { userInfo: { inventorys } } = this.props
let that = this
let stockOpt = []
if (inventorys && inventorys.length) {
inventorys.forEach(item => {
let obj = {}
obj.name = item.inv_name
obj.value = item.inv_code
stockOpt.push(obj)
})
} else {
show('当前无库存权限,请联系管理员配置')
return
}
that.setState({
currentTitle: '库存',
currentItem: {
name: listOptionData[1].name,
value: listOptionData[1].value
}
}, () => {
that.setState({
showTypePop: true,
listCurrentOption: [...stockOpt]
})
})
}
// 判断库存是否选择
stockWhetherSel() {
let stoFlag = false
let { listOptionData } = this.state
if (listOptionData[1].value) {
stoFlag = true
} else {
show('请先选择库存')
}
return stoFlag
}
handleUpdateDeviceInfo(item) {
if (!item || !item.btnName) {
return
}
let that = this
if (that.stockWhetherSel()) {
let { listOptionData } = that.state
let { updateDeviceStatus, token } = that.props
let params = {
access_token: token,
data: {
inv_code: listOptionData[1].value,
device_code: 'automatic_door_enter',
operation: item.operation,
message: item.message
}
}
updateDeviceStatus(params)
}
}
// 按钮以上的元素
renderListItem() {
let { listOptionData } = this.state
return (
<View style={styles.list_cont}>
<View style={styles.item_container}>
<TouchableOpacity activeOpacity={1}>
<CellTextStyle>
<AsteriskTextStyle>*</AsteriskTextStyle>
<TitleTextStyle>{'销售员'}</TitleTextStyle>
<ContInputTextStyle editable={false} defaultValue={listOptionData[0].name}></ContInputTextStyle>
</CellTextStyle>
</TouchableOpacity>
</View>
<View style={styles.item_container}>
<TouchableOpacity
activeOpacity={.8}
onPress={() => this.handleStockCheck()}
>
<CellTextStyle>
<AsteriskTextStyle>*</AsteriskTextStyle>
<TitleTextStyle>{'库存'}</TitleTextStyle>
<ContTextStyle>{listOptionData[1].name}</ContTextStyle>
{this.renderRightArrowItem()}
</CellTextStyle>
</TouchableOpacity>
</View>
{ this.renderPickerModel()}
</View>
)
}
// 返回右侧箭头
renderRightArrowItem() {
return (
<ImageTextStyle>
<Image source={require('../../images/arr_rig.png')} style={icon_style} />
</ImageTextStyle>
)
}
// 返回选择器弹窗
renderPickerModel() {
let { listCurrentOption, currentItem, currentTitle, showTypePop } = this.state
return (
<SafeAreaView style={styles.item_container}>
<DialogModel
entityList={listCurrentOption}
callback={(item, itemTitle) => this.handleCallBack(item, itemTitle)}
show={showTypePop}
itemValue={currentItem.value}
itemTitle={currentTitle}
closeModal={(show) => this.handleCloseModal(show)}
/>
</SafeAreaView>
)
}
// 按钮元素
renderBtnItem() {
let { deviceBtnInfo } = this.state
return (
<View style={styles.btn_box}>
{
deviceBtnInfo.map((item, index) => {
return <TouchableOpacity
key={item.btnName}
activeOpacity={.8}
style={[styles.btn_item_cont, index === deviceBtnInfo.length - 1 ? styles.btn_item_cont_hid : '']}
onPress={() => this.handleUpdateDeviceInfo(item)}
>
<View style={styles.btn_item_inner}>
<View style={styles.btn_item_icon}>
<Image style={icon_style} source={item.icon} />
</View>
<View style={styles.btn_item_txt_box}>
<Text style={styles.btn_item_txt}>{item.btnName}</Text>
</View>
</View>
</TouchableOpacity>
})
}
</View>
)
}
// 返回正在加载中
renderLodingItem() {
let { lodingTitle, isSubLoding } = this.state
return (
<LodingModel title={lodingTitle} show={isSubLoding} style_back={styles.loding_back} />
)
}
render() {
let { navigation } = this.props
let { title } = navigation.state.params
return (
<View style={styles.device_container}>
<StatusBarView
isReactStackNavigator={true}
backgroundColor={promary_color}
barStyle='light-content' />
<SafeAreaView style={safe_view}>
<HeadBackItem title={title} navigation={navigation} />
<ScrollView
style={styles.device_main}
showsVerticalScrollIndicator={false}
>
{this.renderListItem()}
{this.renderBtnItem()}
</ScrollView>
{this.renderLodingItem()}
</SafeAreaView>
</View>
);
}
}
const styles = StyleSheet.create({
device_container: {
flex: 1,
backgroundColor: home_background_color
},
device_main: {
padding: 14
},
list_cont: {
flex: 1
},
item_container: {
flex: 1
},
btn_box: {
flexDirection: 'row',
justifyContent: 'space-between',
flexWrap: 'wrap'
},
btn_item_cont: {
backgroundColor: foundation_color,
borderRadius: 8,
marginBottom: 12
},
btn_item_cont_hid: {
backgroundColor: 'transparent'
},
btn_item_inner: {
width: pxSize(120),
height: pxSize(120),
justifyContent: 'center',
alignItems: 'center'
},
btn_item_icon: {
width: pxSize(26),
height: pxSize(26)
},
btn_item_txt_box: {
marginTop: 4
},
btn_item_txt: {
fontSize: 12,
fontFamily: font_family_regular
}
})
const mapStateToProps = (state) => {
return {
userInfo: state.login.userInfo,
token: state.login.token,
loginState: state.login.loginState,
device_info_status: state.deviceInfo.device_info_status
}
}
const mapDispatchToProps = (dispatch) => {
return {
exitLoginStatus: () => {
dispatch(exitLoginStatus())
},
updateDeviceStatus: (data) => {
dispatch(updateDeviceStatus(data))
}
}
}
export default connect(mapStateToProps, mapDispatchToProps)(DeviceInfoPage);
\ No newline at end of file
......@@ -83,6 +83,11 @@ class HomePage extends Component {
title: '转单申请',
page: 'TransOrderPage'
},
deviceInfo: {
icon: require('../../images/device_info.png'),
title: '设备信息',
page: 'DeviceInfoPage'
},
// tabNames: ['业务模块', '历史订单'],
// tabIconNames: [require('../../images/tab_mod_def.png'), require('../../images/tab_his_def.png')],
......@@ -110,7 +115,7 @@ class HomePage extends Component {
let { modDefauIcon, modSeleIcon,
hisDefauIcon, hisSeleIcon,
borrowInfo, consumpInfo,
transInfo, backLoginInfo } = this.state
transInfo, deviceInfo, backLoginInfo } = this.state
functions = referenceArrSort(functions, 'child_list', 'function_order')
let tempTabNames = []
let tempTabCodes = []
......@@ -135,6 +140,9 @@ class HomePage extends Component {
} else if(chItem.function_code == 'MOBILE_TRANSFER_APPLICATION') {
transInfo.title = chItem.function_name
tempModuleList.push(transInfo)
} else if(chItem.function_code == 'MOBILE_DEVICE_INFORMATION') {
deviceInfo.title = chItem.function_name
tempModuleList.push(deviceInfo)
}
})
}
......
......@@ -7,8 +7,7 @@ import {
// 设备信息状态
const defaultState = {
device_info_status: DEVICE_INFORMATION_UPDATE_NO, // 获取设备信息状态
deviceInfoOption: [] // 设备信息数据
device_info_status: DEVICE_INFORMATION_UPDATE_NO // 获取设备信息状态
}
export default deviceInfo = (state = defaultState, action) => {
......@@ -19,13 +18,11 @@ export default deviceInfo = (state = defaultState, action) => {
});
case DEVICE_INFORMATION_UPDATE_SUCCESS:
return Object.assign({}, state, {
device_info_status: DEVICE_INFORMATION_UPDATE_SUCCESS,
deviceInfoOption: action.rawData
device_info_status: DEVICE_INFORMATION_UPDATE_SUCCESS
});
case DEVICE_INFORMATION_UPDATE_FAILURE:
return Object.assign({}, state, {
device_info_status: DEVICE_INFORMATION_UPDATE_FAILURE,
deviceInfoOption: []
device_info_status: DEVICE_INFORMATION_UPDATE_FAILURE
});
default:
return state;
......
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 sign in to comment