liujq temp20230202 2 年之前
父节点
当前提交
5274b321a3
共有 4 个文件被更改,包括 183 次插入53 次删除
  1. 5 0
      package-lock.json
  2. 1 0
      package.json
  3. 161 53
      src/pagesMore/center/uploadRoom2.jsx
  4. 16 0
      src/pagesMore/center/uploadRoom2.scss

+ 5 - 0
package-lock.json

@@ -17289,6 +17289,11 @@
         "xtend": "^4.0.0"
       }
     },
+    "taro-cropper": {
+      "version": "1.2.4",
+      "resolved": "https://registry.npmjs.org/taro-cropper/-/taro-cropper-1.2.4.tgz",
+      "integrity": "sha512-Jdf6+AquRLCj6pqlafSl6+LQV5EAaDNVRmzyb7F71EKXNSeJojJtStWCGMRfi9WTCQ4esnSmZI7si7qqfn+04A=="
+    },
     "taro-css-to-react-native": {
       "version": "2.2.16",
       "resolved": "https://registry.npmjs.org/taro-css-to-react-native/-/taro-css-to-react-native-2.2.16.tgz",

+ 1 - 0
package.json

@@ -51,6 +51,7 @@
     "redux-logger": "^3.0.6",
     "redux-thunk": "^2.3.0",
     "regenerator-runtime": "0.11.1",
+    "taro-cropper": "^1.2.4",
     "taro-ui": "^2.3.4"
   },
   "devDependencies": {

+ 161 - 53
src/pagesMore/center/uploadRoom2.jsx

@@ -6,6 +6,9 @@ const HLKEY = '654mca0l38b489d9'
 const CJ = require('crypto-js')
 import './uploadRoom2.scss'
 
+
+import { TaroCropper } from 'taro-cropper'
+
 class Index extends Component {
 
   onShareAppMessage() {
@@ -26,11 +29,15 @@ class Index extends Component {
       addr1: '',
       addr2: '',
       addr3: '',
+      hType1: '',
+      hType2: '',
+      hType3: '',
       formObj: {
-        house_type: '1室1厅1卫',
         hide_status: '1',
       },
-      imgArr: []
+      imgArr: [],
+      cutImgTempUrl: '',
+      cutImgShow: false,
     }
   }
   config = {
@@ -48,13 +55,13 @@ class Index extends Component {
         let cObj = res || {}
         // console.log(cObj)
         const addr = cObj.house_no.split('-')
+        const hType = cObj.house_type.split('-')
         Taro.setNavigationBarTitle({
           title: cObj.sale_user.sale_name + '-编辑房源'
         })
         this.setState({
           formObj: {
             id: cObj.id,
-            house_type: cObj.house_type || '1室1厅1卫',
             hide_status: cObj.hide_status || '1',
             estate_id: cObj.estate_id || '',
             estate_name: cObj.estate_name || '',
@@ -79,6 +86,9 @@ class Index extends Component {
           addr1: addr[0],
           addr2: addr[1],
           addr3: addr[2],
+          hType1: hType[0],
+          hType2: hType[1],
+          hType3: hType[2],
         })
       })
     }
@@ -87,7 +97,7 @@ class Index extends Component {
 
 
   saveHandle () {
-    const { formObj, imgArr, addr1, addr2, addr3 } = this.state
+    const { formObj, imgArr, addr1, addr2, addr3, hType1, hType2, hType3 } = this.state
     let house_no = ''
     if (addr1 && addr2 && addr3) {
       house_no = `${addr1}-${addr2}-${addr3}`
@@ -95,6 +105,10 @@ class Index extends Component {
       Taro.$msg('请输入楼栋单号房间号')
       return
     }
+    let house_type = ''
+    if (hType1 && hType2 && hType3) {
+      house_type = `${hType1}-${hType2}-${hType3}`
+    }
     // console.log(formObj.estate_id, formObj.title, formObj.pri_image)
     let apiStr = 'apieshouseadd'
     let params = {
@@ -102,7 +116,7 @@ class Index extends Component {
       title: formObj.title,
       house_no,
       delivery_at: formObj.delivery_at,
-      house_type: formObj.house_type,
+      house_type,
       price: formObj.price,
       area: formObj.area,
       full_year: formObj.full_year,
@@ -125,18 +139,6 @@ class Index extends Component {
     }
     if (formObj.estate_id && formObj.title && formObj.pri_image) {
       Taro.api.room[apiStr](params).then(res => {
-        if (!formObj.id) {
-          this.setState({
-            formObj: {
-              house_type: '1室1厅1卫',
-              hide_status: '1',
-            },
-            imgArr: [],
-            addr1: '',
-            addr2: '',
-            addr3: '',
-          })
-        }
         Taro.$msgConfirm('操作成功', () => {
           Taro.navigateBack({
             delta: 1
@@ -148,7 +150,9 @@ class Index extends Component {
         })
       })
     } else {
-      Taro.$msg('楼盘、标题、封面图必填')
+      if (!formObj.estate_id) Taro.$msg('楼盘必填')
+      if (!formObj.title) Taro.$msg('标题必填')
+      if (!formObj.pri_image) Taro.$msg('封面图必填')
     }
   }
 
@@ -171,46 +175,61 @@ class Index extends Component {
   }
 
   addImg () {
-    this.uploadComImg((curImg) => {
+    this.uploadComImg((arr) => {
       let { imgArr } = this.state
-      imgArr.push(curImg)
+      imgArr = [...imgArr, ...arr]
       this.setState({
         imgArr
       })
-    })
+    }, 2)
   }
-  uploadComImg (bc) {
-    let token = Taro.getStorageSync('APP_token')
+  uploadComImg (bc, count) {
     const that = this
     Taro.chooseImage({
-      count: 1, // 默认9
+      count: count ? count : 1, // 默认9
       sizeType: ['compressed'],  // original
       sourceType: ['album', 'camera'],
       success: function (res) {
         const tempFilePaths = res.tempFilePaths
-        Taro.uploadFile({
-          url: `https://api.honglouplus.com/api/upload/cloudpir`,
-          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
+        if (tempFilePaths.length > 0) {
+          let imgBcArr = []
+          tempFilePaths.forEach((p, i) => {
+            that.diyUploadFile(p).then(url => {
+              imgBcArr.push(url)
+              if (bc && imgBcArr.length === tempFilePaths.length) {
+                bc(imgBcArr)
+              }
             })
-            const originalText = bytes.toString(CJ.enc.Utf8)
-            const cData = JSON.parse(originalText)
-            const curImg = cData.data.url || ''
-            if (bc) bc(curImg)
-          }
-        })
+          })
+        }
       }
     })
   }
+  diyUploadFile (filePath) {
+    return new Promise((resolve, reject) => {
+      let token = Taro.getStorageSync('APP_token')
+      Taro.uploadFile({
+        url: `https://api.honglouplus.com/api/upload/cloudpir`,
+        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)
@@ -245,6 +264,19 @@ class Index extends Component {
       </View>
     )
   }
+  renderHouseType () {
+    const { hType1, hType2, hType3 } = this.state
+    return (
+      <View className="scoped-addr-box">
+        <Input type="number" value={hType1} onInput={this.changeAddrInput.bind(this, 'hType1')}  className="i" placeholder="__" />
+        <View className='t'>室</View>
+        <Input type="number" value={hType2} onInput={this.changeAddrInput.bind(this, 'hType2')}  className="i" placeholder="__" />
+        <View className='t'>厅</View>
+        <Input type="number" value={hType3} onInput={this.changeAddrInput.bind(this, 'hType3')}  className="i" placeholder="__" />
+        <View className='t'>卫</View>
+      </View>
+    )
+  }
   changeAddrInput (str, e) {
     this.setState({
       [str]: e.detail.value
@@ -273,6 +305,70 @@ class Index extends Component {
 
 
 
+
+
+
+
+
+
+
+  renderCutImg () {
+    const { cutImgTempUrl } = this.state
+    const { cutImgShow } = this.state
+    return (
+      <View className={cutImgShow ? 'scoped-ci-popup show' : 'scoped-ci-popup'}>
+        <TaroCropper
+          src={cutImgTempUrl}
+          cropperWidth={375}
+          cropperHeight={250}
+          fullScreen
+          onCut={this.cutHandle.bind(this)}
+        />
+      </View>
+    )
+  }
+  cutHandle (filePath) {
+    let { formObj } = this.state
+    let token = Taro.getStorageSync('APP_token')
+    const that = this
+    Taro.uploadFile({
+      url: `https://api.honglouplus.com/api/upload/cloudpir`,
+      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)
+        formObj.pri_image = cData.data.url || ''
+        that.setState({
+          cutImgShow: false,
+          formObj,
+        })
+      }
+    })
+  }
+  openCutImg () {
+    Taro.chooseImage({
+      count: 1,
+      sizeType: ['compressed'],
+      sourceType: ['album', 'camera'],
+    }).then(res => {
+      this.setState({
+        cutImgTempUrl: res.tempFilePaths[0],
+        cutImgShow: true,
+      })
+    })
+  }
+
+
   render () {
     const { formObj, imgArr } = this.state
     const dictData = Taro.getStorageSync('dictData')
@@ -296,13 +392,15 @@ class Index extends Component {
       opVal: 'id',
       skey: 'estate_name',
     }
+    
     return (
       <View className="l-box">
+        {/* {this.renderCutImg()} */}
         <View className="l-floor-pos2">
           {
             formObj.estate_name
             ?
-            <View className='scoped-estate-name'>{formObj.estate_name}[只读]</View>
+            <Navigator url={`/pagesHouse/indexDtl?id=${formObj.estate_id}`} className='scoped-estate-name'>{formObj.estate_name}[只读]</Navigator>
             : ''
           }
           <LFormGroup
@@ -334,20 +432,19 @@ class Index extends Component {
         </View>
         <View className="l-floor-pos2">
           <LFormGroup
-            val={formObj.floor}
-            valStr="floor"
-            keyStr="楼层"
+            val={formObj.house_type}
+            valStr="house_type"
+            keyStr="户型"
           />
-          {this.renderFloorHeight()}
+          {this.renderHouseType()}
         </View>
         <View className="l-floor-pos2">
           <LFormGroup
-            val={formObj.house_type}
-            valStr="house_type"
-            keyStr="户型"
-            keyStr2="请输入"
-            bc={this.baseFormChange.bind(this)}
+            val={formObj.floor}
+            valStr="floor"
+            keyStr="楼层"
           />
+          {this.renderFloorHeight()}
         </View>
         <View className="l-floor-pos2">
           <LFormGroup
@@ -459,6 +556,17 @@ class Index extends Component {
                   <Image src={addIcon} className="img"/>
                 </View>
               }
+              {/* {
+                formObj.pri_image
+                ?
+                <View className="si-op" onClick={this.openCutImg.bind(this)}>
+                  <Image src={formObj.pri_image + '_plus'} className="img"/>
+                </View>
+                :
+                <View className="si-op" onClick={this.openCutImg.bind(this)}>
+                  <Image src={addIcon} className="img"/>
+                </View>
+              } */}
             </View>
           </View>
           <View className="scoped-box shr-r">

+ 16 - 0
src/pagesMore/center/uploadRoom2.scss

@@ -126,4 +126,20 @@
     right: 20px;
     top: 0;
   }
+}
+
+.scoped-ci-popup {
+  position: fixed;
+  z-index: 99999;
+  top: 0;
+  right: 0;
+  bottom: 0;
+  left: 0;
+  height: 0;
+  width: 100%;
+  overflow: hidden;
+  background: #000;
+  &.show {
+    height: 100%;
+  }
 }