index.jsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { Component } from 'react';
  2. import Taro from '@tarojs/taro';
  3. import {connect} from 'react-redux'
  4. import {View, Image} from '@tarojs/components'
  5. import {set} from '../../actions/counter'
  6. import { login,getUserOrderList,setDecryptData } from '../../utils/servers/servers'
  7. import NavBar from "../../components/NavBar";
  8. import ListBottomStart from "../../components/common/listBottomStart";
  9. import PhoneWarrantMore from "../../components/common/phoneWarrantMore";
  10. import './index.less'
  11. import userIcon from '../../custom-tab-bar/image/user.png';
  12. import background from "../../assets/images/background.png";
  13. @connect(({ counter }) => ({
  14. counter
  15. }), (dispatch) => ({
  16. set (value) {
  17. dispatch(set(value))
  18. }
  19. }))
  20. class Index extends Component {
  21. inst = Taro.getCurrentInstance()
  22. constructor(props) {
  23. super(props);
  24. this.state={
  25. list: [],
  26. pageNo: 0,
  27. listState: 'LOADING',
  28. userInfor:Taro.getStorageSync('userInfor') || '',
  29. token: Taro.getStorageSync('token') || '',
  30. visible: false,
  31. }
  32. }
  33. async componentDidShow() {
  34. this.props.set(2);
  35. this.setState({
  36. userInfor:Taro.getStorageSync('userInfor') || '',
  37. token: Taro.getStorageSync('token') || '',
  38. })
  39. }
  40. async componentDidMount() {
  41. await this.getUserOrderList();
  42. }
  43. onPullDownRefresh(){
  44. this.getUserOrderList();
  45. }
  46. onReachBottom(){
  47. this.getUserOrderList(this.state.pageNo+1);
  48. }
  49. login(){
  50. Taro.getUserProfile({
  51. desc: '用于用户登录',
  52. success: (userInfor)=> {
  53. login(userInfor).then((mobile)=>{
  54. if(!mobile){
  55. this.setState({
  56. visible: true
  57. })
  58. }
  59. this.setState({
  60. userInfor:Taro.getStorageSync('userInfor') || '',
  61. token: Taro.getStorageSync('token') || '',
  62. })
  63. this.getUserOrderList();
  64. })
  65. },
  66. fail: ()=>{
  67. Taro.showToast({title:'请同意授权获取用户信息',icon:'none'});
  68. }
  69. })
  70. }
  71. async getUserOrderList (pageNo = 1){
  72. this.setState({
  73. listState: 'LOADING'
  74. })
  75. let msg = await getUserOrderList({
  76. pageNo: pageNo,
  77. pageSize: 5,
  78. payStatus: 1,
  79. });
  80. if(msg.error.length === 0){
  81. if(msg.data.totalCount === 0){
  82. this.setState({
  83. listState: 'NO_DATA'
  84. })
  85. }else if(msg.data.totalCount === this.state.list.length && pageNo !== 1){
  86. Taro.showToast({title:'没有更多数据了',icon:'none'});
  87. this.setState({
  88. listState: 'NO_MORE_DATA'
  89. })
  90. }else{
  91. this.setState({
  92. list:pageNo === 1 ? msg.data.list : this.state.list.concat(msg.data.list),
  93. pageNo: msg.data.pageNo
  94. },()=>{
  95. if(msg.data.totalCount === this.state.list.length){
  96. this.setState({
  97. listState: 'NO_MORE_DATA'
  98. })
  99. }
  100. })
  101. }
  102. }else{
  103. Taro.showToast({title:msg.error[0].message,icon:'none'});
  104. if(msg.error[0].field === '403'){
  105. this.setState({
  106. token: ''
  107. })
  108. }
  109. this.setState({
  110. listState: msg.error[0].field === '403' ? 'NO_DATA' : 'RELOAD'
  111. })
  112. }
  113. Taro.stopPullDownRefresh();
  114. }
  115. async setDecryptData(data){
  116. let msg = await setDecryptData({
  117. encryptedData : data.encryptedData,
  118. iv : data.iv
  119. });
  120. if(msg.error && msg.error.length !== 0){
  121. if(msg.error[0].field === '403'){
  122. this.setState({
  123. token: ''
  124. })
  125. }
  126. Taro.showToast({title:msg.error[0].message,icon:'none'});
  127. return;
  128. }
  129. if(msg.phoneNumber){
  130. let userInfor = Taro.getStorageSync('userInfor');
  131. userInfor.mobile = msg.phoneNumber;
  132. Taro.setStorageSync('userInfor', userInfor);
  133. this.setState({
  134. userInfor: userInfor
  135. })
  136. Taro.showToast({
  137. title:'绑定成功',
  138. icon:'success'
  139. });
  140. }else{
  141. Taro.showToast({
  142. title:'绑定失败',
  143. icon:'error'
  144. });
  145. }
  146. }
  147. render () {
  148. return (
  149. <View className='userPage'>
  150. <NavBar
  151. extClass='NavBar'
  152. title='我的'
  153. background='#7ac7ff'
  154. onHome={()=>{}}
  155. />
  156. <Image src={background} className='background'/>
  157. <View className='userInfor' onClick={()=>{
  158. if(Taro.getStorageSync('token')){
  159. return;
  160. }
  161. this.login()
  162. }}>
  163. <View className='avatar'>
  164. {
  165. this.state.token ?
  166. <Image src={this.state.userInfor.avatarUrl} className='login'/> :
  167. <Image className='noLogin' src={userIcon}/>
  168. }
  169. </View>
  170. <View className='nickName'>
  171. {
  172. this.state.token ?
  173. this.state.userInfor.nickName :
  174. '点击登录'
  175. }
  176. </View>
  177. {this.state.token && this.state.userInfor && !this.state.userInfor.mobile ? <View className='bindPhone' onClick={(e)=>{
  178. e.stopPropagation();
  179. this.setState({
  180. visible:true
  181. })
  182. }}>绑定手机</View> : null}
  183. </View>
  184. <View className='list'>
  185. {this.state.list.map((v,k)=>(
  186. <View className='item' key={k} onClick={()=>{
  187. Taro.navigateTo({
  188. url:'/pages/details/index?id='+v.projectId
  189. })
  190. }}>
  191. <View className='block'>
  192. <View className='top'/>
  193. <View className='bottom'>
  194. <View className='left'/>
  195. <View className='right'/>
  196. </View>
  197. </View>
  198. <View className='infor'>
  199. <View className='title'>{v.projectName}</View>
  200. <View className='content'>{v.projectTypeName}</View>
  201. </View>
  202. <View className='moneyInfor'>
  203. <View className='money'>¥{parseFloat(v.projectAmount)}</View>
  204. <View className='time'>{v.createTimes}</View>
  205. </View>
  206. </View>
  207. ))}
  208. <ListBottomStart
  209. state={this.state.listState}
  210. reload={()=>{
  211. this.getUserOrderList(this.state.pageNo+1);
  212. }}/>
  213. </View>
  214. <PhoneWarrantMore
  215. visible={this.state.visible}
  216. onClose={()=>{
  217. this.setState({
  218. userInfor: Taro.getStorageSync('userInfor')
  219. })
  220. this.setState({
  221. visible:false
  222. })
  223. }}
  224. />
  225. </View>
  226. )
  227. }
  228. }
  229. export default Index