|
@@ -0,0 +1,226 @@
|
|
|
+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 './newsEdit.scss'
|
|
|
+
|
|
|
+class Index extends Component {
|
|
|
+ constructor (props) {
|
|
|
+ super(props)
|
|
|
+ this.state = {
|
|
|
+ trends_cont: '',
|
|
|
+ formObj: {},
|
|
|
+ imgArr: [],
|
|
|
+ }
|
|
|
+ }
|
|
|
+ config = {
|
|
|
+ navigationBarTitleText: '动态更新',
|
|
|
+ }
|
|
|
+
|
|
|
+ componentDidMount () {
|
|
|
+ const { name } = this.$router.params
|
|
|
+ Taro.setNavigationBarTitle({
|
|
|
+ title: name + '-动态更新' || '动态更新'
|
|
|
+ })
|
|
|
+ // Taro.api.base.apisaleuserdetail().then(res => {
|
|
|
+ // this.setState({
|
|
|
+ // formObj: {
|
|
|
+ // title: res.title,
|
|
|
+ // sale_phone: res.sale_phone,
|
|
|
+ // custom_tag: res.custom_tag,
|
|
|
+ // },
|
|
|
+ // trends_cont: res.trends_cont,
|
|
|
+ // imgArr: res.sale_avatar ? [res.sale_avatar] : []
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ Taro.$AHU(this)
|
|
|
+ }
|
|
|
+
|
|
|
+ commentChange (trends_cont) {
|
|
|
+ this.setState({
|
|
|
+ trends_cont
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ saveHandle () {
|
|
|
+ const { formObj, imgArr, trends_cont } = this.state
|
|
|
+ const {id: estate_id} = this.$router.params
|
|
|
+ if (formObj.title) {
|
|
|
+ Taro.api.house.apiestatenewsadd({
|
|
|
+ estate_id,
|
|
|
+ title: formObj.title,
|
|
|
+ trends_cont: trends_cont,
|
|
|
+ // trends_cont: 'app',
|
|
|
+ images: imgArr.join(','),
|
|
|
+ }).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 () {
|
|
|
+ this.uploadComImg((arr) => {
|
|
|
+ let { imgArr } = this.state
|
|
|
+ imgArr = imgArr.length > 0 ? [...imgArr, ...arr] : [...arr]
|
|
|
+ console.log(imgArr)
|
|
|
+ this.setState({
|
|
|
+ imgArr
|
|
|
+ })
|
|
|
+ }, 9)
|
|
|
+ }
|
|
|
+ uploadComImg (bc, count, moreStr) {
|
|
|
+ const that = this
|
|
|
+ Taro.chooseMedia({
|
|
|
+ count: count ? count : 1, // 默认9
|
|
|
+ mediaType: ['image'],
|
|
|
+ sizeType: ['compressed'], // original
|
|
|
+ sourceType: ['album', 'camera'],
|
|
|
+ success: function (res) {
|
|
|
+ const tempFiles = res.tempFiles
|
|
|
+ if (tempFiles.length > 0) {
|
|
|
+ let imgBcArr = []
|
|
|
+ tempFiles.forEach((p, i) => {
|
|
|
+ that.diyUploadFile(p.tempFilePath, moreStr).then(url => {
|
|
|
+ imgBcArr.push(url)
|
|
|
+ if (bc && imgBcArr.length === tempFiles.length) {
|
|
|
+ bc(imgBcArr)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ diyUploadFile (filePath, moreStr) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let token = Taro.getStorageSync('APP_token')
|
|
|
+ let url = `https://api.honglouplus.com/api/upload/cloudpir`
|
|
|
+ if (moreStr === 'noSign') url = `https://api.honglouplus.com/api/upload/cloud`
|
|
|
+ Taro.uploadFile({
|
|
|
+ url,
|
|
|
+ filePath,
|
|
|
+ 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 || ''
|
|
|
+ resolve(curImg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ delImg (index) {
|
|
|
+ let { imgArr } = this.state
|
|
|
+ imgArr.splice(index, 1)
|
|
|
+ this.setState({
|
|
|
+ imgArr
|
|
|
+ })
|
|
|
+ }
|
|
|
+ previewImageHandle (current, arr) {
|
|
|
+ const { imgArr } = this.state
|
|
|
+ let nArr = imgArr.map(item => {
|
|
|
+ return item + '_plus'
|
|
|
+ })
|
|
|
+ Taro.previewImage({
|
|
|
+ current,
|
|
|
+ urls: nArr
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ render () {
|
|
|
+ let { formObj, trends_cont } = this.state
|
|
|
+ const dictData = Taro.getStorageSync('dictData')
|
|
|
+ const addIcon = require('@img/icon_upload_img.png')
|
|
|
+ const closeIcon = require('@img/icon_g_close.png')
|
|
|
+ const imgItems = imgArr.map((src, index) => {
|
|
|
+ return (
|
|
|
+ <View className="si-op" key={index}>
|
|
|
+ <Image src={src + '_plus'} className="img" onClick={this.previewImageHandle.bind(this, src)} />
|
|
|
+ <Image src={closeIcon} className="i" onClick={this.delImg.bind(this, index)}/>
|
|
|
+ </View>
|
|
|
+ )
|
|
|
+ })
|
|
|
+ return (
|
|
|
+ <View className="l-box">
|
|
|
+ <View className="l-floor-pos2">
|
|
|
+ <LFormGroup
|
|
|
+ val={formObj.title}
|
|
|
+ valStr="title"
|
|
|
+ keyStr="标题"
|
|
|
+ bc={this.baseFormChange.bind(this)}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ <View className="scoped-box">
|
|
|
+ <View className="sb-title">动态内容</View>
|
|
|
+ <AtTextarea
|
|
|
+ value={trends_cont}
|
|
|
+ onChange={this.commentChange.bind(this)}
|
|
|
+ maxLength={300}
|
|
|
+ height={140}
|
|
|
+ placeholder='请输入动态内容(300字以内)'
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ <View className="scoped-box">
|
|
|
+ <View className="sb-title">动态图片
|
|
|
+ <View className="s">(最多9张)</View>
|
|
|
+ </View>
|
|
|
+ <View className="scoped-img">
|
|
|
+ {imgItems}
|
|
|
+ {
|
|
|
+ imgArr.length < 9
|
|
|
+ &&
|
|
|
+ <View className="si-op" onClick={this.addImg.bind(this)}>
|
|
|
+ <Image src={addIcon} className="img"/>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <View className="l-floor-footer t2">
|
|
|
+ <View className="lff-flex">
|
|
|
+ <View className="lff-btn full" onClick={this.saveHandle.bind(this)}>提交</View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export default Index
|