Commit 77b124ae by hank

更改修改设备逻辑

parent 4c966f9f
import api from '@/api/index' import api from '@/api/index'
import { ComponentClass } from 'react' import { ComponentClass } from 'react'
import { connect } from '@tarojs/redux'
import { showMyToast } from '@/common/utils' import { showMyToast } from '@/common/utils'
import DeviceItem from '@/conpoments/device_item' import DeviceItem from '@/conpoments/device_item'
import { getFilmList } from '@/actions/asyncCounter'
import Taro, { Component, Config } from '@tarojs/taro' import Taro, { Component, Config } from '@tarojs/taro'
import { View, Text, ScrollView, Button, Checkbox, Label, Input } from '@tarojs/components' import { View, Text, ScrollView, Button, Checkbox, Label, Input } from '@tarojs/components'
import { AtDrawer } from 'taro-ui' import { AtDrawer } from 'taro-ui'
...@@ -15,18 +13,18 @@ type PageStateProps = { ...@@ -15,18 +13,18 @@ type PageStateProps = {
count: number count: number
} }
type PageDispatchProps = { type PageDispatchProps = {}
getFilmListData: (page: number) => void
}
type PageOwnProps = {} type PageOwnProps = {}
type PageState = { type PageState = {
page: number page: number
filmId: string filmId: string
searchName: string
checked: Set<string> checked: Set<string>
showModal: boolean showModal: boolean
groupList: any[] groupList: any[]
list: any[]
activeIndex: number activeIndex: number
} }
...@@ -37,17 +35,6 @@ interface DeviceSelect { ...@@ -37,17 +35,6 @@ interface DeviceSelect {
state: PageState state: PageState
} }
@connect(
({ counter }) => {
const { list, count } = counter.filmData
return { list, count }
},
dispatch => ({
getFilmListData(page: number) {
dispatch(getFilmList(page))
}
})
)
class DeviceSelect extends Component { class DeviceSelect extends Component {
config: Config = { config: Config = {
navigationBarTitleText: '设备管理' navigationBarTitleText: '设备管理'
...@@ -61,12 +48,15 @@ class DeviceSelect extends Component { ...@@ -61,12 +48,15 @@ class DeviceSelect extends Component {
page: 1, page: 1,
checked: new Set(), checked: new Set(),
showModal: false, showModal: false,
groupList: [], groupList: [{ equipmentGroupName: '全部', equipmentGroupId: '', equipmentCount: 0 }],
activeIndex: 0 activeIndex: 0,
searchName: '',
list: []
} }
this.updateBind = this.updateBind.bind(this) this.updateBind = this.updateBind.bind(this)
this.changeAllCheck = this.changeAllCheck.bind(this) this.changeAllCheck = this.changeAllCheck.bind(this)
this.showModalView = this.showModalView.bind(this) this.showModalView = this.showModalView.bind(this)
this.onItemClick = this.onItemClick.bind(this)
this.setState({ this.setState({
checked: new Set(), checked: new Set(),
showTempalte: 'HORIZONTAL' showTempalte: 'HORIZONTAL'
...@@ -90,13 +80,39 @@ class DeviceSelect extends Component { ...@@ -90,13 +80,39 @@ class DeviceSelect extends Component {
componentWillMount() { componentWillMount() {
this.getData() this.getData()
this.getGroupList() this.getGroupList()
this.getCDetail()
} }
getData() { getData(name?: string | '') {
const { page } = this.state const groupId = this.state.groupList[this.state.activeIndex]['equipmentGroupId']
this.props.getFilmListData(page) api.common.getGroupDevice(groupId, name).then(res => {
this.setState({
list: res || []
})
})
} }
getCDetail() {
/**
* 获取日程详情
*/
const { cId } = this.$router.params
cId &&
api.common.getScheduleDetail(cId).then(res => {
console.log(res)
const { equipmentInfos } = res
let arr = equipmentInfos.map(item => {
return item.equipmentId
})
this.setState({
checked: new Set(arr)
})
})
}
getGroupList() { getGroupList() {
/**
* 获取分组列表
*/
api.common.getGroupList().then(res => { api.common.getGroupList().then(res => {
this.setState({ this.setState({
groupList: [{ equipmentGroupName: '全部', equipmentGroupId: '', equipmentCount: 0 }].concat( groupList: [{ equipmentGroupName: '全部', equipmentGroupId: '', equipmentCount: 0 }].concat(
...@@ -126,70 +142,127 @@ class DeviceSelect extends Component { ...@@ -126,70 +142,127 @@ class DeviceSelect extends Component {
}) })
} }
onItemClick(index) { onItemClick(index) {
console.log(index) /**
this.setState({ * 子项被点击
activeIndex: index */
}) this.setState(
{
activeIndex: index
},
() => {
this.getData(this.state.searchName)
}
)
} }
showModalView() { showModalView() {
this.setState({ this.setState({
showModal: true showModal: true
}) })
} }
searchName({ target }) {
console.log(target.value)
this.setState({
searchName: target.value
})
this.getData(target.value)
}
async updateBind() { async updateBind() {
const { checked } = this.state // 更新设备绑定
const { list } = this.props const { checked, list } = this.state
const { cId, fId } = this.$router.params
let checkedArr: any = [] let checkedArr: any = []
const equipmentsIds = []
const equipmentTopicList = []
list.map(item => { list.map(item => {
if (checked.has(item.equipmentId)) { if (checked.has(item.equipmentId)) {
checkedArr.push(item) checkedArr.push(item)
if (cId) {
equipmentsIds.push(item.equipmentId)
equipmentTopicList.push(item.mqttTopic)
}
} }
}) })
Taro.setStorage({ if (cId) {
key: 'schedule-add-device', let obj = {
data: JSON.stringify([...checkedArr]) calendarName: 'DEFAULstring',
}) filmInfos: [
Taro.navigateBack() {
filmId: fId,
time: '00:00'
}
],
equipmentsIds: equipmentsIds,
equipmentTopicList: equipmentTopicList,
calendarType: cId ? 'CUSTOME' : 'DEFAUL',
calendarId: ''
}
if (!cId) {
delete obj.calendarId
api.common.createdSchedule(obj).then(() => {
Taro.navigateBack()
})
} else {
obj.calendarId = cId
api.common.updateSchedule(obj).then(() => {
Taro.navigateBack()
})
}
} else {
Taro.setStorage({
key: 'schedule-add-device',
data: JSON.stringify([...checkedArr])
})
Taro.navigateBack()
}
} }
changeAllCheck() { changeAllCheck() {
const { list } = this.props let { checked, list } = this.state
const { checked } = this.state
if (list.length === 0) return if (list.length === 0) return
if (checked.size !== list.length) { let arr = []
// 没全选 let noArr = []
const checkedId = list.reduce((previous, { equipmentId }) => { list.map(item => {
previous.push(equipmentId) if (checked.has(item.equipmentId)) {
return previous arr.push(item.equipmentId)
}, []) } else {
noArr.push(item.equipmentId)
}
})
if (arr.length !== list.length) {
this.setState({ this.setState({
checked: new Set([...checkedId]) checked: new Set([...checked].concat(noArr))
}) })
} else { } else {
// 已全选 arr.map(item => {
this.setState({ checked.delete(item)
checked: new Set() this.setState({
checked: checked
})
}) })
} }
} }
render() { render() {
const { list } = this.props const { checked, showModal, groupList, list, activeIndex } = this.state
const { checked, showModal, groupList } = this.state
const { size } = checked const { size } = checked
let items = groupList.map(item => { let items = groupList.map(item => {
if (item.equipmentGroupName === '全部') {
return item.equipmentGroupName + ` (${list.length})`
}
return item.equipmentGroupName + ` (${item.equipmentCount})` return item.equipmentGroupName + ` (${item.equipmentCount})`
}) })
return ( return (
<View className="device-bind"> <View className="device-bind">
<View className="search-bar-container"> <View className="search-bar-container">
<View className="search-bar-container-left" onClick={this.showModalView}> <View className="search-bar-container-left" onClick={this.showModalView}>
<Text>全部( {1})</Text> <Text>{items[activeIndex]}</Text>
<Text className="triangle" /> <Text className="triangle" />
</View> </View>
<Input <Input
className="search-bar-container-input" className="search-bar-container-input"
placeholder="输入设备名称进行搜索" placeholder="输入设备名称进行搜索"
onInput={this.searchName}
type="text" type="text"
/> />
</View> </View>
......
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