index.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import React, { Component } from "react";
  2. import { View, Text, ScrollView } from '@tarojs/components'
  3. import Taro from '@tarojs/taro';
  4. import { AtNoticebar } from 'taro-ui'
  5. import './index.less';
  6. import { getPublicReleaseUnread } from '../../../utils/servers/servers';
  7. import "taro-ui/dist/style/components/icon.scss";
  8. import "taro-ui/dist/style/components/noticebar.scss";
  9. import "taro-ui/dist/style/components/modal.scss";
  10. import "taro-ui/dist/style/components/list.scss";
  11. import "taro-ui/dist/style/components/icon.scss";
  12. class MessageNoticebar extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. animationData: {},
  17. isOpend: false,
  18. isOpened: false,
  19. str: '',
  20. list: []
  21. }
  22. this.onClose = this.onClose.bind(this);
  23. this.getPublicReleaseUnread = this.getPublicReleaseUnread.bind(this);
  24. this.close = this.close.bind(this);
  25. this.onGotoMore = this.onGotoMore.bind(this);
  26. }
  27. componentWillMount() {
  28. let animation = Taro.createAnimation({
  29. duration: 1000,
  30. timingFunction: 'ease',
  31. })
  32. this.animation = animation
  33. this.setState({
  34. animation: animation.export()
  35. })
  36. Taro.eventCenter.on('GoPuncsshIn', (data) => {
  37. if (data.data === 'unread') {
  38. this.getPublicReleaseUnread();
  39. }
  40. })
  41. Taro.eventCenter.on('closeMessageNoticebar', () => {
  42. this.close();
  43. })
  44. Taro.eventCenter.on('getMessageNoticebar', (data) => {
  45. this.setState({
  46. str: data.str,
  47. list: data.list
  48. }, () => {
  49. this.animation.opacity(1).step()
  50. this.setState({
  51. animation: this.animation.export(),
  52. isOpend: true
  53. })
  54. })
  55. })
  56. }
  57. onClose() {
  58. Taro.eventCenter.trigger('closeMessageNoticebar');
  59. }
  60. close() {
  61. this.animation.opacity(0).step()
  62. this.setState({
  63. animation: this.animation.export(),
  64. isOpend: false,
  65. str: '',
  66. list: [],
  67. })
  68. }
  69. getPublicReleaseUnread() {
  70. getPublicReleaseUnread({}).then(v => {
  71. if (v.error.length === 0) {
  72. if (v.data.length === 0) { return; }
  73. let str = this.state.isOpend ? this.state.str : '';
  74. for (let i of v.data) {
  75. str += i.content + '\t\t\t\t\t'
  76. }
  77. Taro.eventCenter.trigger('getMessageNoticebar', {
  78. str,
  79. list: this.state.isOpend ? [...this.state.list, ...v.data] : v.data
  80. });
  81. } else {
  82. Taro.showToast({ title: v.error[0].message, icon: 'none' })
  83. }
  84. }).catch(() => {
  85. Taro.showToast({
  86. title: '系统错误,请稍后再试',
  87. icon: 'none'
  88. })
  89. })
  90. }
  91. onGotoMore() {
  92. this.setState({
  93. isOpened: true
  94. })
  95. }
  96. render() {
  97. return (
  98. <View className='messageNoticebar' animation={this.state.animation}>
  99. {this.state.isOpend ? <View className='content'>
  100. <View style={{ width: '100%' }}>
  101. <AtNoticebar
  102. close
  103. showMore
  104. moreText='查看全部'
  105. speed='50'
  106. single
  107. icon='volume-plus'
  108. onClose={this.onClose}
  109. onGotoMore={this.onGotoMore}
  110. >
  111. <Text decode>
  112. {this.state.str}
  113. </Text>
  114. </AtNoticebar>
  115. </View>
  116. {/*<View className='noticebar' onClick={this.onClose}>*/}
  117. {/* <AtIcon value='close' size='10'/>*/}
  118. {/*</View>*/}
  119. </View> : null}
  120. {this.state.isOpened ?
  121. <View className='messageNoticebarContent'>
  122. <View className='messageContent'>
  123. <View className='title'>未读消息</View>
  124. <ScrollView scrollY scrollWithAnimation scrollTop>
  125. <View className='list'>
  126. {
  127. this.state.list.map((v, k) => (
  128. <View key={k} className='item'>
  129. <View className='itemHead'>
  130. <View className='content'>
  131. <Text>{v.content}</Text>
  132. </View>
  133. </View>
  134. <View className='itemBottom'>
  135. <View className='noticeTypeName'>{v.noticeTypeName}</View>
  136. <View className='createTimeFormattedDate'>{v.createTimeFormattedDate}</View>
  137. </View>
  138. </View>
  139. ))
  140. }
  141. </View>
  142. </ScrollView>
  143. <View className='operation' onClick={() => {
  144. this.setState({
  145. isOpened: false,
  146. })
  147. }}>
  148. 确定
  149. </View>
  150. </View>
  151. </View> : null}
  152. </View>
  153. )
  154. }
  155. }
  156. export default MessageNoticebar;