increase.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import Taro, { canIUse, Component } from '@tarojs/taro'
  2. import { View, Picker, ScrollView } from '@tarojs/components'
  3. import { connect } from '@tarojs/redux'
  4. import * as template from '@actions/template'
  5. import * as actions from '@actions/increase'
  6. import { getWindowHeight } from '@utils/style'
  7. import './increase.scss'
  8. const RECOMMEND_SIZE = 20
  9. @connect(state => state.home, { ...actions, ...template })
  10. class Increase extends Component {
  11. config = {
  12. navigationBarTitleText: '生成报告'
  13. }
  14. state = {
  15. selector: [],
  16. loaded: false,
  17. loading: false,
  18. lastItemId: 0,
  19. hasMore: true,
  20. selectorChecked: {},
  21. }
  22. componentDidMount() {
  23. this.getData()
  24. }
  25. getData() {
  26. let payload = {}
  27. this.props.getList(payload).then((data) => {
  28. let list = data.items
  29. list.push({
  30. id: null,
  31. name: "空白模板"
  32. })
  33. this.setState({
  34. loading: false,
  35. selector: list,
  36. })
  37. }).catch(() => {
  38. this.setState({ loading: false })
  39. })
  40. }
  41. onChange = e => {
  42. this.creatReports(this.state.selector[e.detail.value])
  43. }
  44. // 创建报告
  45. creatReports(obj) {
  46. const payload = {
  47. templateId: obj.id,
  48. }
  49. this.props.creatReport(payload).then((data) => {
  50. this.setState({
  51. loading: false,
  52. })
  53. Taro.navigateTo({
  54. url: "/pages/user/reportdetail?id=" + data
  55. })
  56. }).catch(() => {
  57. this.setState({ loading: false })
  58. })
  59. }
  60. render() {
  61. return (
  62. <View className='home'>
  63. <ScrollView
  64. scrollY
  65. className='home__wrap'
  66. onScrollToLower={this.loadRecommend}
  67. style={{ height: getWindowHeight() }}
  68. >
  69. <View className='increase'>
  70. <View className='increase__item'>
  71. <Picker
  72. mode='selector'
  73. rangeKey="name"
  74. range={this.state.selector}
  75. onChange={this.onChange}>
  76. <View className='increase__item-buttom'>
  77. + 新建报告
  78. </View>
  79. </Picker>
  80. </View>
  81. </View>
  82. </ScrollView>
  83. </View>
  84. )
  85. }
  86. }
  87. export default Increase