|
@@ -0,0 +1,233 @@
|
|
|
|
+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 './uploadRoom.scss'
|
|
|
|
+
|
|
|
|
+class Index extends Component {
|
|
|
|
+
|
|
|
|
+ onShareAppMessage() {
|
|
|
|
+ return {
|
|
|
|
+ title: `自助上传房源`,
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ onShareTimeline () {
|
|
|
|
+ return {
|
|
|
|
+ title: `自助上传房源`,
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ constructor (props) {
|
|
|
|
+ super(props)
|
|
|
|
+ this.state = {
|
|
|
|
+ remark: '',
|
|
|
|
+ house_cert: '',
|
|
|
|
+ formObj: {},
|
|
|
|
+ imgArr: [],
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ config = {
|
|
|
|
+ navigationBarTitleText: '上传房源',
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ componentWillMount () {
|
|
|
|
+ Taro.$AHU(this)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ commentChange (remark) {
|
|
|
|
+ this.setState({
|
|
|
|
+ remark
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ saveHandle () {
|
|
|
|
+ const { remark, formObj, imgArr, house_cert } = this.state
|
|
|
|
+ if (formObj.price && formObj.phone && house_cert) {
|
|
|
|
+ Taro.api.base.apiuserhouseadd({
|
|
|
|
+ phone: formObj.phone,
|
|
|
|
+ price: formObj.price,
|
|
|
|
+ house_cert: house_cert,
|
|
|
|
+ remark: remark,
|
|
|
|
+ images: imgArr.join(','),
|
|
|
|
+ }).then(res => {
|
|
|
|
+ this.setState({
|
|
|
|
+ remark: '',
|
|
|
|
+ house_cert: '',
|
|
|
|
+ formObj: {},
|
|
|
|
+ imgArr: [],
|
|
|
|
+ })
|
|
|
|
+ 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
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ addHouseCertImg () {
|
|
|
|
+ this.uploadComImg((curImg) => {
|
|
|
|
+ this.setState({
|
|
|
|
+ house_cert: curImg,
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ addImg () {
|
|
|
|
+ this.uploadComImg((curImg) => {
|
|
|
|
+ let { imgArr } = this.state
|
|
|
|
+ imgArr.push(curImg)
|
|
|
|
+ this.setState({
|
|
|
|
+ imgArr
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ uploadComImg (bc) {
|
|
|
|
+ let token = Taro.getStorageSync('APP_token')
|
|
|
|
+ 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 || ''
|
|
|
|
+ if (bc) bc(curImg)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ 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, house_cert } = 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} 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.phone}
|
|
|
|
+ valStr="phone"
|
|
|
|
+ keyStr="手机号(必填)"
|
|
|
|
+ keyStr2="请输入联系方式"
|
|
|
|
+ bc={this.baseFormChange.bind(this)}
|
|
|
|
+ />
|
|
|
|
+ </View>
|
|
|
|
+ <View className="l-floor-pos2">
|
|
|
|
+ <LFormGroup
|
|
|
|
+ val={formObj.price}
|
|
|
|
+ valStr="price"
|
|
|
|
+ keyStr="价格(必填)"
|
|
|
|
+ keyStr2="请输入预期价格"
|
|
|
|
+ bc={this.baseFormChange.bind(this)}
|
|
|
|
+ />
|
|
|
|
+ </View>
|
|
|
|
+ <View className="scoped-box">
|
|
|
|
+ <View className="sb-title">房产证图片(必填)</View>
|
|
|
|
+ <View className="scoped-img">
|
|
|
|
+ {
|
|
|
|
+ house_cert
|
|
|
|
+ ?
|
|
|
|
+ <View className="si-op" onClick={this.addHouseCertImg.bind(this)}>
|
|
|
|
+ <Image src={house_cert} className="img"/>
|
|
|
|
+ </View>
|
|
|
|
+ :
|
|
|
|
+ <View className="si-op" onClick={this.addHouseCertImg.bind(this)}>
|
|
|
|
+ <Image src={addIcon} className="img"/>
|
|
|
|
+ </View>
|
|
|
|
+ }
|
|
|
|
+ </View>
|
|
|
|
+ </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="scoped-box">
|
|
|
|
+ <View className="sb-title">房源描述</View>
|
|
|
|
+ <AtTextarea
|
|
|
|
+ value={feedback_count}
|
|
|
|
+ onChange={this.commentChange.bind(this)}
|
|
|
|
+ maxLength={300}
|
|
|
|
+ height={200}
|
|
|
|
+ placeholder='请简单说说你的房子(300字以内)'
|
|
|
|
+ />
|
|
|
|
+ </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
|