张延森 4 år sedan
förälder
incheckning
a8eb081fc9

+ 2
- 1
src/pages/WuYe/ShengHuoGuanJia/components/Card.jsx Visa fil

@@ -1,6 +1,7 @@
1 1
 import React, { useEffect, useState } from 'react'
2 2
 import LR from './LR'
3 3
 import Btn from './Btn'
4
+import Stars from './Stars'
4 5
 import './style.less'
5 6
 
6 7
 export default props => {
@@ -29,7 +30,7 @@ export default props => {
29 30
           <LR title="管家姓名">{data.userName || ''}</LR>
30 31
           <LR title="联系方式">{data.phone || ''}</LR>
31 32
           <LR title="管家说明">{data.description || ''}</LR>
32
-          <LR title="综合评价"></LR>
33
+          <LR title="综合评价"><Stars value={4} editable /></LR>
33 34
         </view>
34 35
       </view>
35 36
       <view className="gj-card-footer">

+ 16
- 0
src/pages/WuYe/ShengHuoGuanJia/components/Star.jsx Visa fil

@@ -0,0 +1,16 @@
1
+import React, { useEffect, useRef, useState } from 'react'
2
+
3
+export default props => {
4
+  const clsName = [
5
+    props.className,
6
+    props.active ? props.activeClass : false
7
+  ].filter(Boolean).join(' ')
8
+
9
+  const handleClick = e => {
10
+    if (props.onClick) {
11
+      props.onClick(e)
12
+    }
13
+  }
14
+
15
+  return <text className={clsName} style={props.style} onClick={handleClick}>&#9733;</text>
16
+}

+ 37
- 0
src/pages/WuYe/ShengHuoGuanJia/components/Stars.jsx Visa fil

@@ -0,0 +1,37 @@
1
+import React, { useEffect, useRef, useState } from 'react'
2
+import Star from './Star'
3
+
4
+const total = new Array(5).fill(0).map((_, inx) => inx + 1)
5
+
6
+// 小数得分会被转为整数
7
+export default props => {
8
+  const [score, setScore] = useState(0)
9
+  const inited = useRef(false)
10
+
11
+  // 暂时只写了默认以及 size=large 的样式
12
+  const sizeClass = props.size ? `${gj-star}-${props.size}` : ''
13
+
14
+  const handleClick = i => {
15
+    if (props.editable) {
16
+      setScore(i)
17
+      if (props.onChange) {
18
+        props.onChange(i)
19
+      }
20
+    }
21
+  }
22
+
23
+  useEffect(() => {
24
+    if (props.value !== null && props.value !== undefined && !inited.current) {
25
+      setScore(Math.floor(props.value))
26
+      inited.current = true
27
+    }
28
+  }, [props.value])
29
+
30
+  return (
31
+    <view className="gj-stars">
32
+      {
33
+        total.map(i => <Star className={`gj-start ${sizeClass}`} activeClass="gj-star-active" key={i} active={score >= i} onClick={() => handleClick(i)} />)
34
+      }
35
+    </view>
36
+  )
37
+}

+ 25
- 0
src/pages/WuYe/ShengHuoGuanJia/components/style.less Visa fil

@@ -75,3 +75,28 @@
75 75
   border: 1px solid #F35844;
76 76
   border-radius: 30px;
77 77
 }
78
+
79
+.gj-stars {
80
+  font-size: 36rpx;
81
+
82
+  .gj-star-large {
83
+    font-size: 64rpx;
84
+  
85
+    & + .gj-star-large {
86
+      margin-left: 16rpx;
87
+    }
88
+  }
89
+}
90
+
91
+.gj-star {
92
+  color: #333;
93
+  display: inline-block;
94
+
95
+  &.gj-star-active {
96
+    color: #F35844;
97
+  }
98
+
99
+  & + .gj-star {
100
+    margin-left: 8rpx;
101
+  }
102
+}