小程序农机手端

index.jsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import Taro from "@tarojs/taro"
  2. import { useState, useEffect } from "react"
  3. import { View, Map, Image } from "@tarojs/components"
  4. import withLayout from '@/layouts'
  5. import { getMachineryList } from '@/services/machinery'
  6. import { useModel } from "@/store"
  7. import CustomNav from "@/components/CustomNav"
  8. import m1 from '@/assets/machinery/greenMachinery.png'
  9. import m2 from '@/assets/machinery/orangeMachinery.png'
  10. import picon from '@/assets/comm/position.png'
  11. import './style.less'
  12. export default withLayout((props) => {
  13. const [show, setShow] = useState(false)
  14. const { location } = useModel('location')
  15. const [machineryList, setMachineryList] = useState([])
  16. const [markerList, setMarkerList] = useState([])
  17. const [current, setCurrent] = useState()
  18. const locList = [
  19. {
  20. longitude: 112.106514,
  21. latitude: 32.685927
  22. },
  23. {
  24. longitude: 112.100406,
  25. latitude: 32.673406
  26. },
  27. {
  28. longitude: 112.06397,
  29. latitude: 32.670488
  30. },
  31. {
  32. longitude: 112.05434,
  33. latitude: 32.685684
  34. },
  35. {
  36. longitude: 112.058724,
  37. latitude: 32.701302
  38. },
  39. {
  40. longitude: 112.015102,
  41. latitude: 32.665504
  42. },
  43. {
  44. longitude: 112.010503,
  45. latitude: 32.685502
  46. },
  47. {
  48. longitude: 112.097747,
  49. latitude: 32.651764
  50. },
  51. {
  52. longitude: 112.149705,
  53. latitude: 32.664957
  54. },
  55. {
  56. longitude: 112.16185,
  57. latitude: 32.701241
  58. },
  59. ]
  60. const handleClick = (e) => {
  61. setCurrent(machineryList[e.markerId])
  62. setShow(true)
  63. }
  64. const goDetail = (val) => {
  65. Taro.navigateTo({ url: `/pages/machineryDetail/index?id=${val}` });
  66. }
  67. const goList = () => {
  68. Taro.navigateTo({ url: '/pages/machineryList/index' });
  69. }
  70. useEffect(() => {
  71. getMachineryList({ location: location }).then((res) => {
  72. setMachineryList(res.records)
  73. setMarkerList(res.records.map((item, index) => {
  74. return {
  75. id: index,
  76. longitude: locList[index % 10].longitude,
  77. latitude: locList[index % 10].latitude,
  78. iconPath: item.jobStatus?m1:m2,
  79. width: 50,
  80. height: 50
  81. }
  82. }))
  83. })
  84. }, [])
  85. return (
  86. <View className='page-index'>
  87. <View className='index-navbar'>
  88. <CustomNav title='我的农机' />
  89. </View>
  90. <View className='index-container machineryMap'>
  91. <Map
  92. longitude={112.092716}
  93. latitude={32.681642}
  94. markers={markerList}
  95. className='map'
  96. onMarkerTap={handleClick}
  97. onRegionChange={() => setShow(false)}
  98. />
  99. {
  100. show &&
  101. <View className='showModel'>
  102. <View className='goList' onClick={goList}>{'<'}{'<'} 农机列表</View>
  103. <View className='title'>
  104. <View className='name'>{current.name}</View>
  105. <View className='action' onClick={() => goDetail(current.machineryId)}>详情 {">"}{">"}</View>
  106. </View>
  107. <View className='position'>
  108. <Image src={picon} className='picon' />
  109. 当前位置:&nbsp;&nbsp;邓州市陈楼
  110. </View>
  111. </View>
  112. }
  113. </View>
  114. </View>
  115. )
  116. })