Commit c1292415 by hank

设备组功能开发

parent 3f344ec8
...@@ -231,46 +231,60 @@ class UsersApi extends ApiClient { ...@@ -231,46 +231,60 @@ class UsersApi extends ApiClient {
url: `/calendar/del/info/${id}` url: `/calendar/del/info/${id}`
}) })
} }
/** 添加设备组 */ /** 获取组列表 */
getGroupList(page: number = 1, limit: number = 1000000) { getGroupList(page: number = 1, limit: number = 100000000) {
return this.request({ return this.request({
method: 'post', method: 'get',
url: `/calendar/get/list?p=${page}&c=${limit}`, url: `/myequipmentgroup/get/list?p=${page}&c=${limit}`
data: {}
}) })
} }
/** 添加设备组 */ /** 添加设备组 */
addGroup(id) { addGroup(equipmentGroupName: string) {
return this.request({ return this.request({
method: 'post', method: 'post',
url: `/calendar/del/info/${id}` url: `/myequipmentgroup/add/info`,
data: {
equipmentGroupName
}
}) })
} }
/** 编辑设备组 */ /** 获取组下设备 */
getGroupDevice(id) { getGroupDevice(equipmentGroupId: string = '', equipmentGroupName: string = '') {
return this.request({ return this.request({
method: 'post', method: 'post',
url: `/calendar/del/info/${id}` url: `/myequipment/get/filter/list`,
data: {
equipmentGroupId,
equipmentGroupName
}
}) })
} }
editGroup(id) { editGroup(equipmentGroupId: string, equipmentGroupName: string) {
return this.request({ return this.request({
method: 'post', method: 'post',
url: `/calendar/del/info/${id}` url: `/myequipmentgroup/update/info`,
data: {
equipmentGroupId,
equipmentGroupName
}
}) })
} }
/** 删除设备组 */ /** 删除设备组 */
deleteGroup(id) { deleteGroup(id) {
return this.request({ return this.request({
method: 'post', method: 'GET',
url: `/calendar/del/info/${id}` url: `/myequipmentgroup/del/${id}`
}) })
} }
/** 删除设备组,摸个设备 */ /** 删除设备组,摸个设备 */
deleteGroupDevice(id) { deleteGroupDevice(equipmentGroupId: string, equipmentId: string) {
return this.request({ return this.request({
method: 'post', method: 'post',
url: `/calendar/del/info/${id}` url: `/myequipmentgroup/del/equipment`,
data: {
equipmentGroupId: equipmentGroupId,
equipmentId: equipmentId
}
}) })
} }
} }
......
import api from '@/api/index' import api from '@/api/index'
import { ComponentClass } from 'react' import { ComponentClass } from 'react'
import { AtSwipeAction } from 'taro-ui' import { AtSwipeAction } from 'taro-ui'
import { connect } from '@tarojs/redux'
import ListView from '@/conpoments/list_view' import ListView from '@/conpoments/list_view'
import Taro, { Component, Config } from '@tarojs/taro' import Taro, { Component, Config } from '@tarojs/taro'
import { View, Text } from '@tarojs/components' import { View, Text } from '@tarojs/components'
import DeviceItem from '@/conpoments/device_item' import DeviceItem from '@/conpoments/device_item'
import { getFilmList } from '@/actions/asyncCounter'
import { showMyToast } from '@/common/utils' import { showMyToast } from '@/common/utils'
import './index.scss' import './index.scss'
...@@ -36,10 +34,10 @@ type PageOwnProps = { ...@@ -36,10 +34,10 @@ type PageOwnProps = {
} }
type PageState = { type PageState = {
deviceCode: string
showModal: boolean showModal: boolean
deviceList: IDeviceItem[] deviceList: IDeviceItem[]
groupId: string | '' groupId: string | ''
list: any[]
} }
type IProps = PageStateProps & PageDispatchProps & PageOwnProps type IProps = PageStateProps & PageDispatchProps & PageOwnProps
...@@ -49,17 +47,6 @@ interface DeviceGroup { ...@@ -49,17 +47,6 @@ interface DeviceGroup {
state: PageState state: PageState
} }
@connect(
({ counter }) => {
const { list, count } = counter.filmData
return { list, count }
},
dispacth => ({
getFilmListData(page: number) {
dispacth(getFilmList(page))
}
})
)
class DeviceGroup extends Component { class DeviceGroup extends Component {
config: Config = { config: Config = {
navigationBarTitleText: '组详情' navigationBarTitleText: '组详情'
...@@ -69,10 +56,10 @@ class DeviceGroup extends Component { ...@@ -69,10 +56,10 @@ class DeviceGroup extends Component {
super(props) super(props)
const { id } = this.$router.params const { id } = this.$router.params
this.state = { this.state = {
deviceCode: '',
deviceList: [], deviceList: [],
showModal: false, showModal: false,
groupId: id groupId: id,
list: []
} }
this.selectAddDevice = this.selectAddDevice.bind(this) this.selectAddDevice = this.selectAddDevice.bind(this)
Taro.setNavigationBarTitle({ Taro.setNavigationBarTitle({
...@@ -89,7 +76,12 @@ class DeviceGroup extends Component { ...@@ -89,7 +76,12 @@ class DeviceGroup extends Component {
this.getDate() this.getDate()
} }
async getDate() { async getDate() {
this.props.getFilmListData(this.page) api.common.getGroupDevice(this.$router.params.id).then(res => {
const list = res
this.setState({
list: list || []
})
})
} }
selectAddDevice() { selectAddDevice() {
...@@ -100,16 +92,17 @@ class DeviceGroup extends Component { ...@@ -100,16 +92,17 @@ class DeviceGroup extends Component {
async handleItem(item: IDeviceItem, info) { async handleItem(item: IDeviceItem, info) {
const { text } = info const { text } = info
const { equipmentId } = item const { equipmentId } = item
const { id } = this.$router.params
if (text === '删除') { if (text === '删除') {
Taro.showModal({ content: '确定要删除?' }).then(async ({ confirm }) => { Taro.showModal({ content: '确定要删除?' }).then(async ({ confirm }) => {
if (confirm) { if (confirm) {
try { try {
await api.common.deleteGroupDevice(equipmentId) await api.common.deleteGroupDevice(id, equipmentId)
this.getDate() this.getDate()
showMyToast({ title: '删除成功~' }) showMyToast({ title: '删除成功~' })
} catch (error) { } catch (error) {
console.error(error) console.error(error)
showMyToast({ result: error, title: '失败成功~' }) showMyToast({ result: error, title: '失败~' })
} }
} }
}) })
...@@ -134,7 +127,8 @@ class DeviceGroup extends Component { ...@@ -134,7 +127,8 @@ class DeviceGroup extends Component {
Taro.navigateTo({ url: `/pages/home/device/device_detail/index?equipmentId=${equipmentId}` }) Taro.navigateTo({ url: `/pages/home/device/device_detail/index?equipmentId=${equipmentId}` })
} }
render() { render() {
const { list, count, height } = this.props const { count, height } = this.props
const { list } = this.state
return ( return (
<View className="device-list"> <View className="device-list">
<ListView <ListView
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
flex: 1; flex: 1;
&-view { &-view {
height: 100%; height: calc(100vh - 200px);
} }
} }
......
...@@ -25,6 +25,7 @@ type PageState = { ...@@ -25,6 +25,7 @@ type PageState = {
page: number page: number
filmId: string filmId: string
checked: Set<string> checked: Set<string>
searchValue: string | ''
} }
type IProps = PageStateProps & PageDispatchProps & PageOwnProps type IProps = PageStateProps & PageDispatchProps & PageOwnProps
...@@ -56,10 +57,12 @@ class DeviceSelect extends Component { ...@@ -56,10 +57,12 @@ class DeviceSelect extends Component {
this.state = { this.state = {
filmId, filmId,
page: 1, page: 1,
checked: new Set() checked: new Set(),
searchValue: ''
} }
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.searchChange = this.searchChange.bind(this)
} }
componentWillMount() { componentWillMount() {
...@@ -120,7 +123,12 @@ class DeviceSelect extends Component { ...@@ -120,7 +123,12 @@ class DeviceSelect extends Component {
} }
} }
searchChange() {} searchChange(target) {
console.log(target)
this.setState({
searchValue: target
})
}
shouldComponentUpdate(nextProps: IProps, nextState: PageState) { shouldComponentUpdate(nextProps: IProps, nextState: PageState) {
const { checked } = this.state const { checked } = this.state
...@@ -132,11 +140,11 @@ class DeviceSelect extends Component { ...@@ -132,11 +140,11 @@ class DeviceSelect extends Component {
render() { render() {
const { list } = this.props const { list } = this.props
const { checked } = this.state const { checked, searchValue } = this.state
const { size } = checked const { size } = checked
return ( return (
<View className="device-bind"> <View className="device-bind">
<AtSearchBar value={''} onChange={this.searchChange} /> <AtSearchBar showActionButton value={searchValue} onChange={this.searchChange} />
<View className="device-bind-scroll"> <View className="device-bind-scroll">
<ScrollView className="device-bind-scroll-view"> <ScrollView className="device-bind-scroll-view">
{list.map(item => ( {list.map(item => (
......
import api from '@/api/index' import api from '@/api/index'
import { ComponentClass } from 'react' import { ComponentClass } from 'react'
import { AtSwipeAction } from 'taro-ui' import { AtSwipeAction } from 'taro-ui'
import { connect } from '@tarojs/redux'
import ListView from '@/conpoments/list_view' import ListView from '@/conpoments/list_view'
import Taro, { Component } from '@tarojs/taro' import Taro, { Component } from '@tarojs/taro'
import { View, Text, Input } from '@tarojs/components' import { View, Text, Input } from '@tarojs/components'
import Modal from '@/conpoments/modal' import Modal from '@/conpoments/modal'
import { getFilmList } from '@/actions/asyncCounter'
import { showMyToast } from '@/common/utils' import { showMyToast } from '@/common/utils'
import Ble from '@/common/bluetooth'
import './index.scss' import './index.scss'
import template from '@/api/template'
export interface IDeviceItem { export interface IDeviceItem {
filmId: any filmId: any
filmName: any filmName: any
...@@ -29,19 +25,17 @@ type PageStateProps = { ...@@ -29,19 +25,17 @@ type PageStateProps = {
count: number count: number
} }
type PageDispatchProps = { type PageDispatchProps = {}
getFilmListData: (page: number) => void
}
type PageOwnProps = { type PageOwnProps = {
height: number height: number
} }
type PageState = { type PageState = {
deviceCode: string
showModal: boolean showModal: boolean
temp: any temp: any
deviceList: IDeviceItem[] deviceList: IDeviceItem[]
list: any[]
} }
type IProps = PageStateProps & PageDispatchProps & PageOwnProps type IProps = PageStateProps & PageDispatchProps & PageOwnProps
...@@ -51,27 +45,16 @@ interface DeviceGroup { ...@@ -51,27 +45,16 @@ interface DeviceGroup {
state: PageState state: PageState
} }
@connect(
({ counter }) => {
const { list, count } = counter.filmData
return { list, count }
},
dispacth => ({
getFilmListData(page: number) {
dispacth(getFilmList(page))
}
})
)
class DeviceGroup extends Component { class DeviceGroup extends Component {
protected page = 1 protected page = 1
constructor(props: any) { constructor(props: any) {
super(props) super(props)
this.state = { this.state = {
deviceCode: '',
deviceList: [], deviceList: [],
list: [],
showModal: false, showModal: false,
temp: { temp: {
name: '' equipmentGroupName: ''
} }
} }
this.cancelModal = this.cancelModal.bind(this) this.cancelModal = this.cancelModal.bind(this)
...@@ -89,14 +72,20 @@ class DeviceGroup extends Component { ...@@ -89,14 +72,20 @@ class DeviceGroup extends Component {
} }
async getDate() { async getDate() {
this.cancelModal() this.cancelModal()
this.props.getFilmListData(this.page) // this.props.getFilmListData(this.page)
api.common.getGroupList().then(res => {
const list = res.list
this.setState({
list: list
})
})
} }
AddGroup() { AddGroup() {
this.setState({ this.setState({
showModal: !this.state.showModal, showModal: !this.state.showModal,
temp: { temp: {
name: '' equipmentGroupName: ''
} }
}) })
} }
...@@ -112,18 +101,18 @@ class DeviceGroup extends Component { ...@@ -112,18 +101,18 @@ class DeviceGroup extends Component {
async handleItem(item, info) { async handleItem(item, info) {
const { text } = info const { text } = info
const { equipmentId } = item const { equipmentGroupId } = item
if (text === '编辑') { if (text === '编辑') {
// console.log('') // console.log('')
this.setState({ this.setState({
showModal: true, showModal: true,
temp: Object.assign({ name: '测试组名' }, item) temp: Object.assign({ equipmentGroupName: '测试组名' }, item)
}) })
} else if (text === '删除') { } else if (text === '删除') {
Taro.showModal({ content: '确定要删除?' }).then(async ({ confirm }) => { Taro.showModal({ content: '确定要删除?' }).then(async ({ confirm }) => {
if (confirm) { if (confirm) {
try { try {
await api.common.deleteGroup(equipmentId) await api.common.deleteGroup(equipmentGroupId)
this.getDate() this.getDate()
showMyToast({ title: '删除成功~' }) showMyToast({ title: '删除成功~' })
} catch (error) { } catch (error) {
...@@ -156,16 +145,18 @@ class DeviceGroup extends Component { ...@@ -156,16 +145,18 @@ class DeviceGroup extends Component {
inputConfirm() { inputConfirm() {
console.log() console.log()
const { temp } = this.state const { temp } = this.state
if (!temp.name) { if (!temp.equipmentGroupName) {
showMyToast({ title: '请输入设备组名称' }) showMyToast({ title: '请输入设备组名称' })
return return
} }
if (temp.equipmentId) { if (temp.equipmentGroupId) {
console.log('更新') console.log('更新')
api.common api.common
.editGroup(temp.name) .editGroup(temp.equipmentGroupId, temp.equipmentGroupName)
.then(() => { .then(() => {
showMyToast({ title: '更新成功' }) showMyToast({ title: '更新成功' })
this.cancelModal()
this.getDate()
}) })
.catch(() => { .catch(() => {
showMyToast({ title: '更新失败' }) showMyToast({ title: '更新失败' })
...@@ -173,13 +164,15 @@ class DeviceGroup extends Component { ...@@ -173,13 +164,15 @@ class DeviceGroup extends Component {
} else { } else {
console.log('创建') console.log('创建')
api.common api.common
.addGroup(temp.name) .addGroup(temp.equipmentGroupName)
.then(() => { .then(() => {
showMyToast({ title: '创建成功' }) showMyToast({ title: '创建成功' })
this.getDate()
}) })
.catch(() => { .catch(() => {
showMyToast({ title: '创建失败' }) showMyToast({ title: '创建失败' })
}) })
this.cancelModal()
} }
} }
...@@ -187,15 +180,15 @@ class DeviceGroup extends Component { ...@@ -187,15 +180,15 @@ class DeviceGroup extends Component {
let value = target.value let value = target.value
this.setState({ this.setState({
temp: Object.assign(this.state.temp, { temp: Object.assign(this.state.temp, {
name: value equipmentGroupName: value
}) })
}) })
} }
render() { render() {
const { list, count, height } = this.props const { count, height } = this.props
const { showModal, temp } = this.state const { showModal, temp, list } = this.state
let name = temp && temp.name ? '设备组信息' : '新建设备组' let name = temp && temp.equipmentGroupName ? '设备组信息' : '新建设备组'
return ( return (
<View className="device-list"> <View className="device-list">
<ListView <ListView
...@@ -225,8 +218,10 @@ class DeviceGroup extends Component { ...@@ -225,8 +218,10 @@ class DeviceGroup extends Component {
} }
]} ]}
> >
<View className="group-item" onClick={() => this.goDetail(item.equipmentId)}> <View className="group-item" onClick={() => this.goDetail(item.equipmentGroupId)}>
<View className="group-item-content">{item.equipmentName}</View> <View className="group-item-content">
{item.equipmentGroupName}({item.equipmentCount})
</View>
</View> </View>
</AtSwipeAction> </AtSwipeAction>
))} ))}
...@@ -250,7 +245,7 @@ class DeviceGroup extends Component { ...@@ -250,7 +245,7 @@ class DeviceGroup extends Component {
<Input <Input
placeholder="请输入设备组名称" placeholder="请输入设备组名称"
className="film-modal-input" className="film-modal-input"
value={temp.name} value={temp.equipmentGroupName}
onInput={this.changeName} onInput={this.changeName}
/> />
</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