add.jsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View } from '@tarojs/components'
  3. import { AtTextarea } from 'taro-ui'
  4. import LFormGroup from '@/c/lform/formGroup'
  5. import './add.scss'
  6. class Index extends Component {
  7. constructor (props) {
  8. super(props)
  9. this.state = {
  10. question_cont: '',
  11. formObj: {},
  12. }
  13. }
  14. config = {
  15. navigationBarTitleText: '我要提问',
  16. }
  17. componentWillMount () {}
  18. commentChange (question_cont) {
  19. this.setState({
  20. question_cont
  21. })
  22. }
  23. saveHandle () {
  24. const { question_cont, formObj } = this.state
  25. if (question_cont && formObj.question_tag) {
  26. Taro.api.news.apiquestionadd({
  27. question_tag: formObj.question_tag.join(','),
  28. question_cont: question_cont,
  29. }).then(res => {
  30. Taro.$msgConfirm('提交成功~', () => {
  31. Taro.redirectTo({
  32. url: '/pagesMore/news/index?nav=1'
  33. })
  34. }, () => {
  35. Taro.redirectTo({
  36. url: '/pagesMore/news/index?nav=1'
  37. })
  38. })
  39. })
  40. } else {
  41. Taro.$msg('请输入提问的类型和内容')
  42. }
  43. }
  44. baseFormChange (key, val) {
  45. let { formObj } = this.state
  46. formObj[key] = val
  47. this.setState({
  48. formObj
  49. })
  50. }
  51. render () {
  52. const { question_cont, formObj } = this.state
  53. const dictData = Taro.getStorageSync('dictData')
  54. const questionTagMoreOptions = {arr: dictData.question_tag}
  55. return (
  56. <View className="l-box">
  57. <View className="l-floor-pos">
  58. <LFormGroup
  59. val={formObj.question_tag}
  60. moreRows={true}
  61. defineContentClassName="border2"
  62. valStr="question_tag"
  63. keyStr="问题类型"
  64. typeStr="multiSelect"
  65. moreOptions={questionTagMoreOptions}
  66. bc={this.baseFormChange.bind(this)}
  67. />
  68. </View>
  69. <View className="comment-box">
  70. <View className="cb-title">提问内容</View>
  71. <AtTextarea
  72. value={question_cont}
  73. onChange={this.commentChange.bind(this)}
  74. maxLength={300}
  75. height={300}
  76. placeholder='你想问的...'
  77. />
  78. </View>
  79. <Navigator openType="reLaunch" url={'/pagesMore/news/index?nav=1'} className="scoped-more">先看看其它人说些啥{'>>'}</Navigator>
  80. <View className="l-floor-footer t2">
  81. <View className="lff-flex">
  82. <View className="lff-btn full" onClick={this.saveHandle.bind(this)}>提交问题</View>
  83. </View>
  84. </View>
  85. </View>
  86. )
  87. }
  88. }
  89. export default Index