小程序农机手端

index.jsx 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import Taro from "@tarojs/taro";
  2. import { useState, useEffect } from "react";
  3. import { View, Image } from "@tarojs/components"
  4. import indexImg from "@/assets/comm/index.png";
  5. import indexActive from "@/assets/comm/indexActive.png";
  6. import job from "@/assets/comm/job.png";
  7. import jobActive from "@/assets/comm/jobActive.png";
  8. import user from "@/assets/comm/user.png";
  9. import userActive from "@/assets/comm/userActive.png";
  10. import CustomNav from "@/components/CustomNav";
  11. import {setAmap} from '@/services/amap'
  12. import withLayout from '@/layouts'
  13. import { useModel } from "@/store";
  14. import Order from './components/Order'
  15. import Job from './components/Job'
  16. import User from "./components/User";
  17. import "./index.less";
  18. export default withLayout((props) => {
  19. const { router } = props
  20. let { tab } = router.params
  21. const { location,setLocation } = useModel('location')
  22. const [currentTab, setCurrentTab] = useState(0);
  23. const handleClick = (val) => {
  24. setCurrentTab(val);
  25. };
  26. useEffect(() => {
  27. if(!location){
  28. Taro.getLocation({
  29. type:'gcj02',
  30. success:function(res){
  31. setLocation(res.longitude+','+res.latitude)
  32. setAmap({params:'location='+res.longitude+','+res.latitude,path: '/v3/geocode/regeo'})
  33. }})
  34. } else {
  35. setAmap({params:'location='+location,path: '/v3/geocode/regeo'})
  36. }
  37. if (tab) {
  38. setCurrentTab(tab - 0)
  39. }
  40. }, [tab])
  41. return (
  42. <View className='page-index'>
  43. <View className='index-navbar'>
  44. <CustomNav home title={currentTab === 0 ? '首页' : currentTab === 1 ? '作业管理' : '我的'} />
  45. </View>
  46. <View className='index-container'>
  47. {currentTab === 0 && <Order />}
  48. {currentTab === 1 && <Job />}
  49. {currentTab === 2 && <User />}
  50. </View>
  51. <View className='index-tabbar'>
  52. <View
  53. className={['tabberItem', currentTab === 0 ? "activeTabber" : '']}
  54. onClick={() => handleClick(0)}
  55. >
  56. <Image className='tabberImg' src={currentTab === 0 ? indexActive : indexImg}></Image>
  57. <View className='text'>首页</View>
  58. </View>
  59. <View
  60. className={['tabberItem', currentTab === 1 ? "activeTabber" : '']}
  61. onClick={() => handleClick(1)}
  62. >
  63. <Image className='tabberImg' src={currentTab === 1 ? jobActive : job}></Image>
  64. <View className='text'>作业管理</View>
  65. </View>
  66. <View
  67. className={['tabberItem', currentTab === 2 ? "activeTabber" : '']}
  68. onClick={() => handleClick(2)}
  69. >
  70. <Image className='tabberImg' src={currentTab === 2 ? userActive : user}></Image>
  71. <View className='text'>个人中心</View>
  72. </View>
  73. </View>
  74. </View>
  75. );
  76. });