Browse Source

个人主页

许静 5 years ago
parent
commit
cdb1439425
1 changed files with 51 additions and 127 deletions
  1. 51
    127
      src/pages/card/index.js

+ 51
- 127
src/pages/card/index.js View File

6
 import ProjectItem from '../project/item'
6
 import ProjectItem from '../project/item'
7
 import BackHomeBtn from '@components/BackHomeBtn'
7
 import BackHomeBtn from '@components/BackHomeBtn'
8
 import getUserPhone from '@utils/getUserPhone'
8
 import getUserPhone from '@utils/getUserPhone'
9
-import AchievePhone from '@components/achievePhone'
10
 import ready from '@utils/ready'
9
 import ready from '@utils/ready'
11
-import { sceneInShare } from '@utils/tools'
12
 
10
 
13
 import { ROLE_CODE } from '@constants/user'
11
 import { ROLE_CODE } from '@constants/user'
14
 import { addCardUv, addCardShareNum, favorCard, cancelFavorCard } from '@services/card'
12
 import { addCardUv, addCardShareNum, favorCard, cancelFavorCard } from '@services/card'
27
 
25
 
28
 export default class Index extends Component {
26
 export default class Index extends Component {
29
   config = {
27
   config = {
30
-    navigationBarTitleText: '个人主页'
28
+    navigationBarTitleText: '个人主页' 
31
   }
29
   }
32
   state = {
30
   state = {
33
     cardId: null,
31
     cardId: null,
37
     actionSheetHide: true, // 控制分享弹窗modal
35
     actionSheetHide: true, // 控制分享弹窗modal
38
     recordId: null,
36
     recordId: null,
39
     isSave: false,
37
     isSave: false,
40
-    bound: false,
41
     modalStatus: false,
38
     modalStatus: false,
42
-    grantPhoneVisible: false, // 授权手机弹框
43
   }
39
   }
44
 
40
 
45
   componentWillMount() {
41
   componentWillMount() {
46
     ready.queue(() => {
42
     ready.queue(() => {
43
+      const router = Taro.getStorageSync('router')
44
+      const id = this.$router.params.id || router.query.id || '4604a792d575eb8187711625bd88832c'
47
 
45
 
48
-      // 分享场景需要先授权手机, 再授权头像
49
-      const options = wx.getLaunchOptionsSync()
50
-      if (sceneInShare(options.scene)) {
51
-        const { person = {} } = this.props.userInfo || {}
52
-        if ((person.tel || person.phone) && (person.avatarurl || '').indexOf('wx.qlogo.cn') === -1) {
53
-          Taro.reLaunch({ url: '/pages/auth/index' })
54
-          return
55
-        }
56
-
46
+      if(router.query.id){
57
         this.setState({
47
         this.setState({
58
-          grantPhoneVisible: true,
59
-        })
48
+          cardId: id,
49
+          modalStatus: true
50
+        }, this.loadCardDetail)
51
+      }else{
52
+        this.setState({
53
+          cardId: id,
54
+          modalStatus: false
55
+        }, this.loadCardDetail)
60
       }
56
       }
61
 
57
 
62
-      this.initPageData()
58
+      addCardUv(id)
63
     })
59
     })
64
   }
60
   }
65
 
61
 
66
-  initPageData() {
67
-    const router = Taro.getStorageSync('router')
68
-    const id = this.$router.params.id || router.query.id
69
-
70
-    if (router.query.id) {
71
-      this.setState({
72
-        cardId: id,
73
-        modalStatus: true
74
-      }, this.loadCardDetail)
75
-    } else {
76
-      this.setState({
77
-        cardId: id,
78
-        modalStatus: false
79
-      }, this.loadCardDetail)
80
-    }
81
-
82
-    addCardUv(id)
83
-  }
84
-
85
-  componentWillReceiveProps(nextProps) {
86
-    const { userInfo: { person: { phone, tel } } } = nextProps
87
-    this.handleModalConfirm(tel || phone)
88
-  }
89
-
90
   componentWillUnmount() {
62
   componentWillUnmount() {
91
     const { recordId } = this.state
63
     const { recordId } = this.state
92
     recordId && updatePoint(recordId)
64
     recordId && updatePoint(recordId)
102
         loaded: true,
74
         loaded: true,
103
         isSave: res.isSave
75
         isSave: res.isSave
104
       })
76
       })
105
-      let buildingId = (res.projects || [])[0]
77
+      let buildingId = res.projects[0]
106
       if (buildingId) {
78
       if (buildingId) {
107
         dispatchProjectDetail(buildingId)
79
         dispatchProjectDetail(buildingId)
108
       }
80
       }
291
         resolve(posterData)
263
         resolve(posterData)
292
         return
264
         return
293
       }
265
       }
294
-      const { userInfo: { person, miniApp }, projectDetail: { buildingId }, cardInfo } = this.props
266
+      const { userInfo: { person }, projectDetail: { buildingId }, cardInfo } = this.props
295
       const { id } = cardInfo
267
       const { id } = cardInfo
296
       const { personId } = person
268
       const { personId } = person
297
       const payload = {
269
       const payload = {
299
         "page": 'pages/card/index',
271
         "page": 'pages/card/index',
300
       }
272
       }
301
       getMiniQrcode(payload).then(qrcode => {
273
       getMiniQrcode(payload).then(qrcode => {
302
-        let data = Object.assign({ qrcode, miniAppName: miniApp.name }, cardInfo)
274
+        let data = Object.assign({ qrcode }, cardInfo)
303
         resolve(data)
275
         resolve(data)
304
       })
276
       })
305
     })
277
     })
349
     })
321
     })
350
   }
322
   }
351
 
323
 
352
-  handleModalConfirm(phoneNumber) {
324
+  handleModalConfirm() {
353
     const {
325
     const {
354
-      cardInfo: { id, projects = [] },
355
-      userInfo: { person: { phone, tel, personType, avatarurl } }
326
+      cardInfo: { id, projects },
327
+      userInfo: { person: { phone, tel } }
356
     } = this.props
328
     } = this.props
357
 
329
 
358
-    if (personType === ROLE_CODE['CONSULTANT']) {
359
-      return
360
-    }
361
-
362
     const buildingId = projects[0]
330
     const buildingId = projects[0]
363
-    const realPhone = phoneNumber || phone || tel
364
-
365
-    // TODO:
366
-    // 此处使用头像控制, 后期需要去掉这个条件
367
-    if (realPhone && id && buildingId && !this.state.bound && (avatarurl || '').indexOf('wx.qlogo.cn') > -1) {
368
-      const payload = {
369
-        realtyConsultant: id, //报备人 置业顾问
370
-        buildingId,
371
-        phone: realPhone
372
-      }
373
-
374
-      reportClient(payload).then(res => {
375
-        this.hideModal()
376
-        this.setState({ bound: true })
377
-
378
-        if (res !== 'bound') {
379
-          Taro.showToast({
380
-            title: '恭喜您绑定成功'
381
-          })
382
-        }
383
-      }).catch(err => {
384
-        console.error(err)
385
-        this.setState({ bound: true })
386
-
387
-        Taro.showToast({
388
-          title: err.message || err,
389
-          icon: 'none'
390
-        })
391
-      })
392
 
331
 
332
+    const payload = {
333
+      realtyConsultant: id, //报备人 置业顾问
334
+      buildingId,
335
+      phone: phone || tel
393
     }
336
     }
337
+    reportClient(payload).then(res => {
338
+      this.hideModal()
339
+      Taro.showToast({
340
+        title: '报备成功'
341
+      })
342
+    })
394
   }
343
   }
395
 
344
 
396
   // 卡片收藏
345
   // 卡片收藏
439
       modalStatus: false
388
       modalStatus: false
440
     })
389
     })
441
   }
390
   }
442
-  
443
-  handleAuthPhoneSuccess = (phone) => {
444
-    const { person = {} } = this.props.userInfo || {}
445
-    if ((person.avatarurl || '').indexOf('wx.qlogo.cn') === -1) {
446
-      Taro.reLaunch({ url: '/pages/auth/index' })
447
-      return
448
-    }
449
-
450
-    this.setState({ grantPhoneVisible: false })
451
-    this.initPageData()
452
-    // this.handleModalConfirm(phone)
453
-  }
454
-
455
-  handeAuthPhoneFail = () => {
456
-    Taro.showToast({ 
457
-      title: '未授权手机号无法成为报备客户',
458
-      icon: 'none'
459
-     })
460
-  }
461
-
462
   render() {
391
   render() {
463
-    const { makePosterStatus, posterData, modalStatus, grantPhoneVisible } = this.state
392
+    const { makePosterStatus, posterData, modalStatus } = this.state
464
     const { userInfo, cardInfo, projectDetail } = this.props
393
     const { userInfo, cardInfo, projectDetail } = this.props
465
     const { person: { personType, personId, phone, tel } } = userInfo
394
     const { person: { personType, personId, phone, tel } } = userInfo
466
     const { unReadNum, picture, visitors, id, isReport } = cardInfo
395
     const { unReadNum, picture, visitors, id, isReport } = cardInfo
467
-    const { buildingId,address } = projectDetail
396
+    const { buildingId } = projectDetail
468
 
397
 
469
-  const visitorList = visitors ? visitors.slice(0, 5) : []
398
+    const visitorList = visitors ? visitors.slice(0, 5) : []
470
     const isSelf = personId === id
399
     const isSelf = personId === id
471
 
400
 
472
     const isConsultant = personType === ROLE_CODE['CONSULTANT']
401
     const isConsultant = personType === ROLE_CODE['CONSULTANT']
473
-    const hadPhone = (phone || tel) ? true : false  // nb
402
+    const hadPhone = (phone || tel) ? true : false
474
     const visibleChatBtn = !isConsultant && !isSelf
403
     const visibleChatBtn = !isConsultant && !isSelf
475
     // const visibleConfirmModal = modalStatus && !isReport && !isSelf && (personType === ROLE_CODE['DRIFT'] || personType === ROLE_CODE['CUSTOMER'])
404
     // const visibleConfirmModal = modalStatus && !isReport && !isSelf && (personType === ROLE_CODE['DRIFT'] || personType === ROLE_CODE['CUSTOMER'])
476
     const visibleConfirmModal = modalStatus && !isReport && !isSelf
405
     const visibleConfirmModal = modalStatus && !isReport && !isSelf
477
-    const showAuthPhone = grantPhoneVisible && userInfo.person.personId && !userInfo.person.phone
478
-
479
     return (
406
     return (
480
       <Block>
407
       <Block>
481
         {/* 生成海报 */}
408
         {/* 生成海报 */}
482
         {makePosterStatus && (<Poster data={posterData} toggle={this.toggleVisiblePoster}></Poster>)}
409
         {makePosterStatus && (<Poster data={posterData} toggle={this.toggleVisiblePoster}></Poster>)}
410
+
483
         {
411
         {
484
-          showAuthPhone &&
485
-          <AchievePhone user={userInfo.person} onCancel={this.handeAuthPhoneFail} onSuccess={this.handleAuthPhoneSuccess}></AchievePhone>
486
-        }
487
-        {
488
-          // !showAuthPhone && visibleConfirmModal && (
489
-          //   <View className="modal">
490
-          //     <View className="modal-mask" onClick={this.hideModal}></View>
491
-          //     <View className="modal-body">
492
-          //       <View className="modal-body__con">请确认是否成为他的客户?</View>
493
-          //       {
494
-          //         hadPhone ? (
495
-          //           <Button onClick={this.handleModalConfirm} className='modal-body__btn'>确认</Button>
496
-          //         ) : (
497
-          //             <Button open-type="getPhoneNumber" onGetphonenumber={this.handleGetPhone} className='modal-body__btn'>确认</Button>
498
-          //           )
499
-          //       }
500
-          //     </View>
501
-          //   </View>
502
-          // )
412
+          visibleConfirmModal && (
413
+            <View className="modal">
414
+              <View className="modal-mask" onClick={this.hideModal}></View>
415
+              <View className="modal-body">
416
+                <View className="modal-body__con">请确认是否成为他的客户?</View>
417
+                {
418
+                  hadPhone ? (
419
+                    <Button onClick={this.handleModalConfirm} className='modal-body__btn'>确认</Button>
420
+                  ) : (
421
+                      <Button open-type="getPhoneNumber" onGetphonenumber={this.handleGetPhone} className='modal-body__btn'>确认</Button>
422
+                    )
423
+                }
424
+              </View>
425
+            </View>
426
+          )
503
         }
427
         }
504
 
428
 
505
         {this.state.loaded && (
429
         {this.state.loaded && (
511
                   <Image className='mycard__user__img' src={picture} mode="widthFix"></Image>
435
                   <Image className='mycard__user__img' src={picture} mode="widthFix"></Image>
512
                   <Image src={picture} mode="aspectFill" className='head__img'></Image>
436
                   <Image src={picture} mode="aspectFill" className='head__img'></Image>
513
                 </View>
437
                 </View>
514
-                <Image src={require('@assets/person/top.png')} className='top-img' mode="aspectFill"></Image>
438
+                <Image src={require('@assets/person/top.png')} className='top-img' mode="widthFix"></Image>
515
               </View>
439
               </View>
516
 
440
 
517
               <View className='mycard__user__information'>
441
               <View className='mycard__user__information'>
592
                   </View>
516
                   </View>
593
                   <View className='detailed__add' onClick={this.getLocation}>
517
                   <View className='detailed__add' onClick={this.getLocation}>
594
                     <View className='detailed__add__txt'>
518
                     <View className='detailed__add__txt'>
595
-                      <Text className='add__txt' space='emsp'>地址 </Text> {address}
519
+                      <Text className='add__txt' space='emsp'>地址 </Text> {cardInfo.address}
596
                     </View>
520
                     </View>
597
                     <Text className='iconfont icon-daohangdizhi add__img'></Text>
521
                     <Text className='iconfont icon-daohangdizhi add__img'></Text>
598
                   </View>
522
                   </View>