张延森 vor 5 Jahren
Ursprung
Commit
642c471c3c
1 geänderte Dateien mit 56 neuen und 47 gelöschten Zeilen
  1. 56
    47
      src/pages/activity/detail/assistance.js

+ 56
- 47
src/pages/activity/detail/assistance.js Datei anzeigen

@@ -477,55 +477,54 @@ export default class Detail extends Component {
477 477
 
478 478
   // 发起我的助力
479 479
   startMine = () => {
480
-    const { userInfo: { miniApp: { tpls } } } = this.props
481
-    const tplId = (tpls.filter(x => x.tplType == noticeType.TPL_HELP && x.isSubscribe == true))[0].tplId
482
-    const that = this
483
-    wx.requestSubscribeMessage({
484
-      tmplIds: [tplId],
485
-      success(res) {
486
-
487
-      },
488
-      fail(res) {
489
-
490
-      },
491
-      complete() {
492
-
493
-        // 必须授权头像
494
-        if (that.toggleGrantAvatar()) {
495
-          const detail = that.state.detail
496
-          const person = that.props.userInfo.person
497
-
498
-          return new Promise((resolve, reject) => {
499
-            createHelpActivity({
500
-              buildingId: detail.buildingId,
501
-              helpActivityId: detail.helpActivityId,
502
-              personId: person.personId,
503
-              name: person.name || person.nickname,
504
-              phone: person.tel || person.phone,
505
-              avatarurl: person.avatarurl,
506
-            }).then(res => {
507
-              that.setState({
508
-                initiateDetail: res.helpInitiateRecord,
509
-                initiateId: res.helpInitiateRecord.helpRecordInitiateId,
510
-                helpList: res.helpRecordList,
511
-                isStarter: true,
512
-                helpState: res.helpInitiateRecord.status === undefined ? HelpInProcess : res.helpInitiateRecord.status,
513
-              }, resolve)
514
-            }).catch(err => {
515
-              console.log('err:', err)
516
-              Taro.showToast({
517
-                title: '发起助力失败',
518
-                icon: 'none'
519
-              })
520
-              reject()
521
-            })
480
+    const makeHelp = (resolve, reject) => {
481
+      // 必须授权头像
482
+      if (this.toggleGrantAvatar()) {
483
+        const detail = this.state.detail
484
+        const person = this.props.userInfo.person
485
+  
486
+        createHelpActivity({
487
+          buildingId: detail.buildingId,
488
+          helpActivityId: detail.helpActivityId,
489
+          personId: person.personId,
490
+          name: person.name || person.nickname,
491
+          phone: person.tel || person.phone,
492
+          avatarurl: person.avatarurl,
493
+        }).then(res => {
494
+          this.setState({
495
+            initiateDetail: res.helpInitiateRecord,
496
+            initiateId: res.helpInitiateRecord.helpRecordInitiateId,
497
+            helpList: res.helpRecordList,
498
+            isStarter: true,
499
+            helpState: res.helpInitiateRecord.status === undefined ? HelpInProcess : res.helpInitiateRecord.status,
500
+          }, resolve)
501
+        }).catch(err => {
502
+          console.log('err:', err)
503
+          Taro.showToast({
504
+            title: '发起助力失败',
505
+            icon: 'none'
522 506
           })
523
-        }
524
-
507
+          reject()
508
+        }) 
525 509
       }
526
-    })
510
+  
511
+      reject()
512
+    }
513
+
514
+    return new Promise((resolve, reject) => {
515
+      const { userInfo: { miniApp: { tpls } } } = this.props
516
+      const tplId = (tpls.filter(x => x.tplType == noticeType.TPL_HELP && x.isSubscribe == true))[0].tplId
517
+      
518
+      wx.requestSubscribeMessage({
519
+        tmplIds: [tplId],
520
+        success(res) {},
521
+        fail(res) {},
522
+        complete() {
523
+          makeHelp(resolve, reject)  
524
+        }
525
+      })
526
+    });
527 527
 
528
-    return Promise.reject()
529 528
   }
530 529
 
531 530
   // 请求好友助力
@@ -539,7 +538,17 @@ export default class Detail extends Component {
539 538
           this.toggleActionVisible()
540 539
         })
541 540
       } else {
542
-        this.toggleActionVisible()
541
+        const { userInfo: { miniApp: { tpls } } } = this.props
542
+        const tplId = (tpls.filter(x => x.tplType == noticeType.TPL_HELP && x.isSubscribe == true))[0].tplId
543
+        const that = this
544
+        wx.requestSubscribeMessage({
545
+          tmplIds: [tplId],
546
+          success(res) {},
547
+          fail(res) {},
548
+          complete() {
549
+            that.toggleActionVisible()
550
+          }
551
+        })        
543 552
       }
544 553
     }
545 554
   }