1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from 'react';
  2. import { View, Image } from '@tarojs/components';
  3. import { ActionSheet, Cell } from '@antmjs/vantui';
  4. import { ROLES, ROLE_CITIZEN } from '@/utils/user';
  5. import logo from '@/assets/image/logo.png';
  6. import avatar from '@/assets/icons/avatar.png';
  7. import style from './head.module.less';
  8. export default (props) => {
  9. const { user = {}, duty, onDutyChange } = props;
  10. const { dutyList = [] } = user;
  11. const role = ROLES[duty || ROLE_CITIZEN];
  12. const [show, setShow] = React.useState(false);
  13. const actions = React.useMemo(() => {
  14. return dutyList.map(x => ({name: ROLES[x], value: x}));
  15. }, [dutyList]);
  16. const onClick = () => {
  17. if (dutyList.length < 1) return;
  18. setShow(true);
  19. }
  20. const onSelect = (e) => {
  21. onDutyChange(e.detail.value)
  22. }
  23. return (
  24. <View className={style.head}>
  25. <View className={style.profile}>
  26. <View style={{ letterSpacing: '2px' }}>Hi, {user.name}!</View>
  27. <View className={style.badge} onClick={onClick}>
  28. <View className={style.icon}>
  29. <Image src={avatar} />
  30. </View>
  31. <View>{role}</View>
  32. </View>
  33. <ActionSheet
  34. title="请选择身份"
  35. position="bottom"
  36. show={show}
  37. actions={actions}
  38. onClose={() => setShow(false)}
  39. onSelect={onSelect}
  40. />
  41. </View>
  42. <View className={style.avatar}>
  43. <Image src={user.avatar || logo}></Image>
  44. </View>
  45. </View>
  46. )
  47. }