瀏覽代碼

feats: add formid

张延森 5 年之前
父節點
當前提交
494840767f

+ 20
- 43
src/components/formIdCollector/index.js 查看文件

@@ -15,6 +15,10 @@ import { postFormId } from '@services/card'
15 15
  * ```
16 16
  */
17 17
 export default class Index extends Component {
18
+  static options = {
19
+    addGlobalClass: true,
20
+  };
21
+  
18 22
   static defaultProps = {
19 23
     count: 7,
20 24
     disabled: false,
@@ -26,55 +30,28 @@ export default class Index extends Component {
26 30
   }
27 31
 
28 32
   handleCollect = e => {
29
-    let { formIds } = this.state
30
-    const { onCollect, count } = this.props
31
-    formIds.push(e.detail.formId)
32
-    if (formIds.length === count) {
33
-      onCollect(formIds.slice())
34
-
35
-      // 发送到服务器
36
-      postFormId({ formids: formIds })
37
-      formIds = []
38
-    }
39
-    this.setState({
40
-      formIds
41
-    })
33
+    // 发送到服务器
34
+    postFormId({ formids: [e.detail.formId] })
42 35
   }
43 36
 
44 37
   render() {
45
-    const { count, disabled } = this.props
46
-    const finalCount = Math.min(count, 7)
38
+    const { disabled } = this.props
47 39
 
48
-    return (disabled || finalCount === 0) ? this.props.children : (
40
+    return disabled ? this.props.children : (
49 41
       <Block>
50
-        <Label for='button_6'>
51
-          <Label for='button_5'>
52
-            <Label for='button_4'>
53
-              <Label for='button_3'>
54
-                <Label for='button_2'>
55
-                  <Label for='button_1'>
56
-                    <Label for='button_0'>
57
-                      {this.props.children}
58
-                    </Label>
59
-                  </Label>
60
-                </Label>
61
-              </Label>
62
-            </Label>
63
-          </Label>
42
+        <Label for='button_0'>
43
+          {this.props.children}
64 44
         </Label>
65
-        {[1,2,3,4].map(i => (
66
-          <Form
67
-            key={i}
68
-            className='m-form-id-collector_form'
69
-            reportSubmit={true}
70
-            onSubmit={this.handleCollect}>
71
-            <Button
72
-              id={`button_${i}`}
73
-              formType='submit'
74
-            />
75
-          </Form>
76
-        ))}
45
+        <Form
46
+          className='m-form-id-collector_form'
47
+          reportSubmit={true}
48
+          onSubmit={this.handleCollect}>
49
+          <Button
50
+            id={`button_0`}
51
+            formType='submit'
52
+          />
53
+        </Form>
77 54
       </Block>
78 55
     )
79 56
   }
80
-}
57
+}

+ 3
- 2
src/pages/activity/activity.js 查看文件

@@ -1,5 +1,6 @@
1 1
 import Taro, { Component } from '@tarojs/taro';
2 2
 import Authorize from '@components/authorize'
3
+import FormIdCollector from '@components/formIdCollector'
3 4
 import './index.scss'
4 5
 import { AtTabs, AtTabsPane } from 'taro-ui'
5 6
 import "taro-ui/dist/style/components/tabs.scss"
@@ -61,9 +62,9 @@ export default class active extends Component {
61 62
       <View style="height:100vh">
62 63
         <AtTabs className="tab-box" scroll current={this.state.current} tabList={[{ title: '热门活动' }, { title: '最新资讯' }]} onClick={this.handleClick.bind(this)}>
63 64
           <AtTabsPane current={this.state.current} index={0} >
64
-            <View >
65
+            <FormIdCollector>
65 66
               <Activity ></Activity >
66
-            </View>
67
+            </FormIdCollector>
67 68
           </AtTabsPane>
68 69
           <AtTabsPane current={this.state.current} index={1}>
69 70
             <View >

+ 14
- 5
src/pages/activity/detail/assemble.js 查看文件

@@ -4,6 +4,7 @@ import Notice from '@components/Notice'
4 4
 import BackHomeBtn from '@components/BackHomeBtn'
5 5
 import AchievePhone from '@components/achievePhone'
6 6
 import Poster from '@components/Poster'
7
+import FormIdCollector from '@components/formIdCollector'
7 8
 import dayjs from 'dayjs'
8 9
 // import WxParse from '@components/wxParse/wxParse'
9 10
 // import getUserPhone from '@utils/getUserPhone'
@@ -617,16 +618,20 @@ export default class Detail extends Component {
617 618
                 <View className="btn-fixed">
618 619
                   {
619 620
                     actState === ActBeforeStart &&
620
-                    (<Button className="nostart-btn" style="margin: auto">未开始</Button>)
621
+                    (<View className="nostart-btn"><FormIdCollector><Button className="nostart-btn" style="margin: auto">未开始</Button></FormIdCollector></View>)
621 622
                   }
622 623
                   {
623 624
                     isStarter && actState === ActInProcess && groupState === GroupInProcess &&
624
-                    (<Button className="assistance-btn" style="margin: auto" onClick={this.groupBuyInvite}>邀请好友拼团</Button>)
625
+                    (<View className="assistance-btn"><FormIdCollector><Button className="assistance-btn" style="margin: auto" onClick={this.groupBuyInvite}>邀请好友拼团</Button></FormIdCollector></View>)
625 626
                   }
626 627
                   {
627 628
                     !isStarter && actState === ActInProcess && groupState != GroupInProcess &&
628 629
 
629
-                    <Button className={groupState === GroupInProcess ? "set-btn" : "assistance-btn"} onClick={this.startMine}>发起我的拼团</Button>
630
+                    <View className={groupState === GroupInProcess ? "set-btn" : "assistance-btn"}>
631
+                      <FormIdCollector>
632
+                        <Button className={groupState === GroupInProcess ? "set-btn" : "assistance-btn"} onClick={this.startMine}>发起我的拼团</Button>
633
+                      </FormIdCollector>
634
+                    </View>
630 635
                   }
631 636
                   {
632 637
                     !isStarter && actState === ActInProcess && groupState === GroupInProcess &&
@@ -634,9 +639,13 @@ export default class Detail extends Component {
634 639
                     <View className="btn-box" style="margin: auto; padding: 0;">
635 640
                       {
636 641
                         (groupState === GroupInProcess && !isJoin) &&
637
-                        (<Button className="assistance-btn" onClick={this.joinGroup}>立即参团</Button>)
642
+                        (<View className="assistance-btn"><FormIdCollector><Button className="assistance-btn" onClick={this.joinGroup}>立即参团</Button></FormIdCollector></View>)
638 643
                       }                      
639
-                      <Button className={groupState === GroupInProcess && !isJoin ? "set-btn" : "assistance-btn"} onClick={this.startMine}>发起我的拼团</Button>
644
+                      <View className={groupState === GroupInProcess && !isJoin ? "set-btn" : "assistance-btn"}>
645
+                        <FormIdCollector>
646
+                          <Button className={groupState === GroupInProcess && !isJoin ? "set-btn" : "assistance-btn"} onClick={this.startMine}>发起我的拼团</Button>
647
+                        </FormIdCollector>
648
+                      </View>
640 649
                     </View>
641 650
 
642 651
                   }

+ 9
- 4
src/pages/activity/detail/assistance.js 查看文件

@@ -4,6 +4,7 @@ import Notice from '@components/Notice'
4 4
 import BackHomeBtn from '@components/BackHomeBtn'
5 5
 import AchievePhone from '@components/achievePhone'
6 6
 import Poster from '@components/Poster'
7
+import FormIdCollector from '@components/formIdCollector'
7 8
 import dayjs from 'dayjs'
8 9
 // import WxParse from '@components/wxParse/wxParse'
9 10
 // import getUserPhone from '@utils/getUserPhone'
@@ -589,11 +590,11 @@ export default class Detail extends Component {
589 590
                 <View style="display:flex;justify-content: space-between;padding:0 15px">
590 591
                   {
591 592
                     actState === ActBeforeStart &&
592
-                    (<Button className="nostart-btn">未开始</Button>)
593
+                    (<View className="nostart-btn"><FormIdCollector><Button className="nostart-btn">未开始</Button></FormIdCollector></View>)
593 594
                   }
594 595
                   {
595 596
                     isStarter && actState === ActInProcess && helpState === HelpInProcess &&
596
-                    (<Button className="assistance-btn" onClick={this.askForHelp}>邀请好友助力</Button>)
597
+                    (<View className="assistance-btn"><FormIdCollector><Button className="assistance-btn" onClick={this.askForHelp}>邀请好友助力</Button></FormIdCollector></View>)
597 598
                   }
598 599
                   {
599 600
                     !isStarter && actState === ActInProcess &&
@@ -603,9 +604,13 @@ export default class Detail extends Component {
603 604
 
604 605
                         {
605 606
                           (helpState === HelpInProcess && !isJoin) &&
606
-                          (<Button className="assistance-btn" onClick={this.handleHelp}>立即助力好友</Button>)
607
+                          (<View className="assistance-btn"><FormIdCollector><Button className="assistance-btn" onClick={this.handleHelp}>立即助力好友</Button></FormIdCollector></View>)
607 608
                         }
608
-                        <Button className={(helpState === HelpInProcess && !isJoin) ? "set-btn" : "assistance-btn"} onClick={this.startMine}>发起我的助力</Button>
609
+                        <View className={(helpState === HelpInProcess && !isJoin) ? "set-btn" : "assistance-btn"}>
610
+                          <FormIdCollector>
611
+                            <Button className={(helpState === HelpInProcess && !isJoin) ? "set-btn" : "assistance-btn"} onClick={this.startMine}>发起我的助力</Button>
612
+                          </FormIdCollector>
613
+                        </View>
609 614
                       </View>
610 615
                     )
611 616
                   }