瀏覽代碼

个人主页代码回滚

许静 5 年之前
父節點
當前提交
4b9b785bd6
共有 2 個檔案被更改,包括 125 行新增53 行删除
  1. 1
    1
      project.config.json
  2. 124
    52
      src/pages/card/index.js

+ 1
- 1
project.config.json 查看文件

2
 	"miniprogramRoot": "dist/",
2
 	"miniprogramRoot": "dist/",
3
 	"projectname": "mini-chengjiao",
3
 	"projectname": "mini-chengjiao",
4
 	"description": "知与行联调",
4
 	"description": "知与行联调",
5
-	"appid": "wxda1f84b79b3edeb3",
5
+	"appid": "wxd9ee3a9480a4e544",
6
 	"setting": {
6
 	"setting": {
7
 		"urlCheck": false,
7
 		"urlCheck": false,
8
 		"es6": false,
8
 		"es6": false,

+ 124
- 52
src/pages/card/index.js 查看文件

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