feedback.jsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. const HLKEY = '654mca0l38b489d9'
  6. const CJ = require('crypto-js')
  7. import './feedback.scss'
  8. class Index extends Component {
  9. constructor (props) {
  10. super(props)
  11. this.state = {
  12. feedback_count: '',
  13. formObj: {},
  14. imgArr: [],
  15. }
  16. }
  17. config = {
  18. navigationBarTitleText: '反馈',
  19. }
  20. componentWillMount () {
  21. const { eName } = this.$router.params
  22. if (eName) {
  23. Taro.setNavigationBarTitle({
  24. title: '纠错补图-' + eName
  25. })
  26. }
  27. Taro.$AHU(this)
  28. }
  29. commentChange (feedback_count) {
  30. this.setState({
  31. feedback_count
  32. })
  33. }
  34. saveHandle () {
  35. const { feedback_count, formObj, imgArr } = this.state
  36. const { eId } = this.$router.params
  37. if (feedback_count && formObj.feedback_type) {
  38. Taro.api.base.apifeedbackadd({
  39. feedback_type: formObj.feedback_type,
  40. contact: formObj.contact,
  41. feedback_count: feedback_count,
  42. images: imgArr.join(','),
  43. estate_id: eId || '',
  44. }).then(res => {
  45. Taro.$msgConfirm('反馈成功~感谢您的宝贵建议', () => {
  46. Taro.navigateBack({
  47. delta: 1
  48. })
  49. }, () => {
  50. Taro.navigateBack({
  51. delta: 1
  52. })
  53. })
  54. })
  55. } else {
  56. Taro.$msg('请输入提问的类型和内容')
  57. }
  58. }
  59. baseFormChange (key, val) {
  60. let { formObj } = this.state
  61. formObj[key] = val
  62. this.setState({
  63. formObj
  64. })
  65. }
  66. addImg () {
  67. let token = Taro.getStorageSync('APP_token')
  68. let { imgArr } = this.state
  69. const that = this
  70. Taro.chooseImage({
  71. count: 1, // 默认9
  72. sizeType: ['original', 'compressed'],
  73. sourceType: ['album', 'camera'],
  74. success: function (res) {
  75. const tempFilePaths = res.tempFilePaths
  76. Taro.uploadFile({
  77. url: `https://api.honglouplus.com/api/upload/cloud`,
  78. filePath: tempFilePaths[0],
  79. name: 'upload',
  80. formData: {
  81. 'token': token
  82. },
  83. success (res){
  84. const msg = res.data || ''
  85. const key = CJ.enc.Utf8.parse(HLKEY)
  86. const bytes = CJ.AES.decrypt(msg, key, {
  87. mode: CJ.mode.ECB,
  88. padding: CJ.pad.Pkcs7
  89. })
  90. const originalText = bytes.toString(CJ.enc.Utf8)
  91. const cData = JSON.parse(originalText)
  92. const curImg = cData.data.url || ''
  93. imgArr.push(curImg)
  94. that.setState({
  95. imgArr
  96. })
  97. }
  98. })
  99. }
  100. })
  101. }
  102. delImg (index) {
  103. let { imgArr } = this.state
  104. imgArr.splice(index, 1)
  105. this.setState({
  106. imgArr
  107. })
  108. }
  109. previewImageHandle (current, arr) {
  110. const { imgArr } = this.state
  111. Taro.previewImage({
  112. current,
  113. urls: imgArr
  114. })
  115. }
  116. render () {
  117. const { feedback_count, formObj, imgArr } = this.state
  118. const dictData = Taro.getStorageSync('dictData')
  119. const ftMoreOptions = {arr: dictData.feedback_type}
  120. const addIcon = require('@img/icon_upload_img.png')
  121. const closeIcon = require('@img/icon_g_close.png')
  122. const imgItems = imgArr.map((src, index) => {
  123. return (
  124. <View className="si-op" key={index}>
  125. <Image src={src} className="img" onClick={this.previewImageHandle.bind(this, src)} />
  126. <Image src={closeIcon} className="i" onClick={this.delImg.bind(this, index)}/>
  127. </View>
  128. )
  129. })
  130. return (
  131. <View className="l-box">
  132. <View className="l-floor-pos2">
  133. <LFormGroup
  134. val={formObj.feedback_type}
  135. valStr="feedback_type"
  136. keyStr="*反馈类型"
  137. keyStr2="请选择反馈类型"
  138. typeStr="select"
  139. moreOptions={ftMoreOptions}
  140. bc={this.baseFormChange.bind(this)}
  141. />
  142. </View>
  143. <View className="l-floor-pos2">
  144. <LFormGroup
  145. val={formObj.contact}
  146. valStr="contact"
  147. keyStr="手机号"
  148. keyStr2="请输入联系方式"
  149. bc={this.baseFormChange.bind(this)}
  150. />
  151. </View>
  152. <View className="scoped-box">
  153. <View className="sb-title">*描述</View>
  154. <AtTextarea
  155. value={feedback_count}
  156. onChange={this.commentChange.bind(this)}
  157. maxLength={300}
  158. height={300}
  159. placeholder='请描述你的问题(300字以内)'
  160. />
  161. </View>
  162. <View className="scoped-box">
  163. <View className="sb-title">相关图片
  164. <View className="s">(最多9张)</View>
  165. </View>
  166. <View className="scoped-img">
  167. {imgItems}
  168. {
  169. imgArr.length < 9
  170. &&
  171. <View className="si-op" onClick={this.addImg.bind(this)}>
  172. <Image src={addIcon} className="img"/>
  173. </View>
  174. }
  175. </View>
  176. </View>
  177. <View className="l-floor-footer t2">
  178. <View className="lff-flex">
  179. <View className="lff-btn full" onClick={this.saveHandle.bind(this)}>提交</View>
  180. </View>
  181. </View>
  182. </View>
  183. )
  184. }
  185. }
  186. export default Index