import Taro, { Component } from '@tarojs/taro' import { View } from '@tarojs/components' import { AtTextarea } from 'taro-ui' import LFormGroup from '@/c/lform/formGroup' const HLKEY = '654mca0l38b489d9' const CJ = require('crypto-js') import './feedback.scss' class Index extends Component { constructor (props) { super(props) this.state = { feedback_count: '', formObj: {}, imgArr: [], } } config = { navigationBarTitleText: '反馈', } componentWillMount () { const { eName } = this.$router.params if (eName) { Taro.setNavigationBarTitle({ title: '纠错补图-' + eName }) } Taro.$AHU(this) } commentChange (feedback_count) { this.setState({ feedback_count }) } saveHandle () { const { feedback_count, formObj, imgArr } = this.state const { eId } = this.$router.params if (feedback_count && formObj.feedback_type) { Taro.api.base.apifeedbackadd({ feedback_type: formObj.feedback_type, contact: formObj.contact, feedback_count: feedback_count, images: imgArr.join(','), estate_id: eId || '', }).then(res => { Taro.$msgConfirm('反馈成功~感谢您的宝贵建议', () => { Taro.navigateBack({ delta: 1 }) }, () => { Taro.navigateBack({ delta: 1 }) }) }) } else { Taro.$msg('请输入提问的类型和内容') } } baseFormChange (key, val) { let { formObj } = this.state formObj[key] = val this.setState({ formObj }) } addImg () { let token = Taro.getStorageSync('APP_token') let { imgArr } = this.state const that = this Taro.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success: function (res) { const tempFilePaths = res.tempFilePaths Taro.uploadFile({ url: `https://api.honglouplus.com/api/upload/cloud`, filePath: tempFilePaths[0], name: 'upload', formData: { 'token': token }, success (res){ const msg = res.data || '' const key = CJ.enc.Utf8.parse(HLKEY) const bytes = CJ.AES.decrypt(msg, key, { mode: CJ.mode.ECB, padding: CJ.pad.Pkcs7 }) const originalText = bytes.toString(CJ.enc.Utf8) const cData = JSON.parse(originalText) const curImg = cData.data.url || '' imgArr.push(curImg) that.setState({ imgArr }) } }) } }) } delImg (index) { let { imgArr } = this.state imgArr.splice(index, 1) this.setState({ imgArr }) } previewImageHandle (current, arr) { const { imgArr } = this.state Taro.previewImage({ current, urls: imgArr }) } render () { const { feedback_count, formObj, imgArr } = this.state const dictData = Taro.getStorageSync('dictData') const ftMoreOptions = {arr: dictData.feedback_type} const addIcon = require('@img/icon_upload_img.png') const closeIcon = require('@img/icon_g_close.png') const imgItems = imgArr.map((src, index) => { return ( ) }) return ( *描述 相关图片 (最多9张) {imgItems} { imgArr.length < 9 && } 提交 ) } } export default Index