deviceLocal.vue 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150
  1. <template>
  2. <view class="container">
  3. <map
  4. id="myMap"
  5. :longitude="longitude"
  6. :latitude="latitude"
  7. :scale="scale"
  8. :markers="marker"
  9. :polyline="polylines"
  10. :circles="circles"
  11. @markertap="bindMarkertap"
  12. show-location
  13. enable-3D
  14. show-compass
  15. enable-overlooking
  16. :enable-satellite="mapParams.enableSatellite"
  17. :enable-traffic="mapParams.enableTraffic"
  18. style="width: 100%; height: 100vh"
  19. @tap="bindTapMap"
  20. ></map>
  21. <map-control :mapParams="mapParams" @changeParams="mapChange"></map-control>
  22. <view v-if="showInfo" class="battery-group">
  23. <view class="battery-item">
  24. <view class="map-top">
  25. <view class="map-cross">
  26. <view class="map-top-box">
  27. <view class="map-top-text">GPS</view>
  28. <view :class="gps > 0 ? 'map-top-i' : 'map-top-n'" />
  29. <view :class="gps > 1 ? 'map-top-i' : 'map-top-n'" />
  30. <view :class="gps > 2 ? 'map-top-i' : 'map-top-n'" />
  31. <view :class="gps > 3 ? 'map-top-i' : 'map-top-n'" />
  32. <view :class="gps > 4 ? 'map-top-i' : 'map-top-n'" />
  33. </view>
  34. <view class="map-top-box gsm-view">
  35. <view class="map-top-text">GSM</view>
  36. <view :class="gsm > 0 ? 'map-top-i' : 'map-top-n'" />
  37. <view :class="gsm > 1 ? 'map-top-i' : 'map-top-n'" />
  38. <view :class="gsm > 2 ? 'map-top-i' : 'map-top-n'" />
  39. <view :class="gsm > 3 ? 'map-top-i' : 'map-top-n'" />
  40. <view :class="gsm > 4 ? 'map-top-i' : 'map-top-n'" />
  41. </view>
  42. </view>
  43. <view class="map-top-box-1">
  44. <view class="map-top-text-1">{{ deviceInfo.quantity }}%</view>
  45. <image src="https://qiniu.bms16.com/FikqU8xHYKBjolOPZ7uc9ZNJXfHU" class="bottom-img"></image>
  46. </view>
  47. <view v-if="deviceInfo.quantity >= 20" :style="'width: ' + batteryWidth + 'rpx;right:' + (71 + (37 - batteryWidth)) + 'rpx'" class="battery_num_view"></view>
  48. <view v-if="deviceInfo.quantity < 20" :style="'width: ' + batteryWidth + 'rpx;right:' + (71 + (37 - batteryWidth)) + 'rpx'" class="battery_num_view_red"></view>
  49. </view>
  50. <view class="batter-info-group">
  51. <view class="battery-desc flex-row flex-between">
  52. <view>{{ $t('名称') + ':' + deviceInfo.name }}</view>
  53. <view>{{ $t('状态') + ':' + status }}</view>
  54. </view>
  55. <view class="battery-desc flex-row flex-between">
  56. <view>{{ $t('编号') + ':' + macid }}</view>
  57. <view>{{ $t('设防状态') + ':' + deviceInfo.protectState ? (deviceInfo.protectState == 1 ? $t('设防') : $t('撤防')) : $t('未知') }}</view>
  58. </view>
  59. <view class="battery-desc flex-row flex-between">
  60. <view>{{ $t('控制') + ':' + deviceInfo.oilState == 1 ? $t('已通电') : $t('已断电') }}</view>
  61. <view>{{ $t('定位类型') + ':' + deviceInfo.signalType == 0 ? $t('北斗GPS') : deviceInfo.signalType == 1 ? 'WIFI' : deviceInfo.signalType == 16 ? 'LBS' : $t('未知') }}</view>
  62. </view>
  63. <view class="battery-desc flex-row flex-between">
  64. <view>{{ $t('当日里程') + ':' + deviceInfo.day_mil }}</view>
  65. <view>{{ $t('总里程') + ':' + deviceInfo.mil }}</view>
  66. </view>
  67. <view class="battery-desc flex-row flex-between">
  68. <view>
  69. {{ $t('电压') + ':' +
  70. (deviceInfo.voltage ? deviceInfo.voltage + 'V' : $t('未知')) +
  71. (deviceInfo.elecState ? (deviceInfo.elecState == 1 ? '('+ $t('主电接通')+')' : '('+ $t('主电断开')+')') : '')
  72. }}
  73. </view>
  74. <view v-if="deviceInfo && deviceInfo.temp && deviceInfo.temp != ''">{{ $t('温度') + ':' + deviceInfo.temp + '℃' }}</view>
  75. </view>
  76. <view class="battery-desc">{{ $t('通信') + ':' + deviceInfo.heart_time ? tools.formatTime(deviceInfo.heart_time) : $t('未知') }}</view>
  77. <view class="battery-desc">{{ $t('定位') + ':' + deviceInfo.gps_time ? tools.formatTime(deviceInfo.gps_time) : $t('未知') }}</view>
  78. <view v-if="address != ''" class="battery-desc">地址:{{ address }}</view>
  79. <!-- <view wx:if="{{ address != '' }}" class="battery-desc">GPS最近地址:{{ address }}</view> -->
  80. </view>
  81. </view>
  82. </view>
  83. <view class="bottom-view">
  84. <view class="bottom-center">
  85. <image :src="trace ? 'https://qiniu.bms16.com/FtYkQp4Nc2JD2SZ-_BjCI--DJWyi' : 'https://qiniu.bms16.com/FlRUmvzPd-BzkMAj04LwmX7UBrEP'" class="bottom-img"></image>
  86. </view>
  87. <view class="bottom-centent">
  88. <view class="bottom-item" @tap="bindTrackDialogOpen">
  89. <image :src="trackPoints.length == 0 ? 'https://qiniu.bms16.com/FqYJ3dMKvis19y8-onbNdRBEO5mT' : 'https://qiniu.bms16.com/FlH-IsasGFDH2QsRZixIFh7q7Tjv'" class="bottom-img"></image>
  90. <view class="bottom-text">{{$t('轨迹')}}</view>
  91. </view>
  92. <view class="bottom-item" @tap="bindAlarmPopupOpen">
  93. <image :src="alarmList.length == 0 ? 'https://qiniu.bms16.com/FkVJmibJNj0CvoIrQmtz_wKotWpO' : 'https://qiniu.bms16.com/Fu4mutL6ECkBLManyT_cvZ6C8iAT'" class="bottom-img"></image>
  94. <view class="bottom-text">{{$t('报警')}}</view>
  95. </view>
  96. <!--<view class="bottom-item" bindtap="bindTrace">
  97. <image class="bottom-img"></image>
  98. <view class="bottom-text">追踪</view>
  99. </view>-->
  100. <view class="bottom-item" @tap="bindNavigate">
  101. <image class="bottom-img"></image>
  102. <view class="bottom-text">{{$t('导航')}}</view>
  103. </view>
  104. <view class="bottom-item" @tap="bindSendCommand" data-cmd="CLOSERELAY">
  105. <image src="https://qiniu.bms16.com/Fr-g3_g0T5aZ_sLQB7Xs1qRpxGAS" class="bottom-img"></image>
  106. <view class="bottom-text">{{$t('断电')}}</view>
  107. </view>
  108. <view class="bottom-item" @tap="bindSendCommand" data-cmd="OPENRELAY">
  109. <image src="https://qiniu.bms16.com/Fv1eQozcTejKVdXbqkcea9syHOU3" class="bottom-img"></image>
  110. <view class="bottom-text">{{$t('通电')}}</view>
  111. </view>
  112. </view>
  113. <image v-if="trackPoints.length != 0" :src="inPlay ? 'https://qiniu.bms16.com/FrTpj-jPSkQIsRjPOFE25lzJ4H7Z' : 'https://qiniu.bms16.com/Fl6EjlB1RufKn7QeKdBJC7dXxC9M'" class="play-img" @tap="bindPlay"></image>
  114. <image v-if="trackPoints.length != 0" src="https://qiniu.bms16.com/FoMwbUuD37w4Ja13-NXtm3hhkUgZ" class="stop-img" @tap="bindStopPopupOpen"></image>
  115. <view v-if="trackStopList.length != 0" class="stop-img" @tap="bindStopPopupOpen">
  116. <view class="tip-top">{{ trackStopList.length }}</view>
  117. </view>
  118. <image v-if="trackPoints.length != 0" src="https://qiniu.bms16.com/FqZcllaWWt2WJ3QGDt3wfKJM3wgP" class="close-img" @tap="bindCloseTrack"></image>
  119. <view @tap="loadLastGpsInfo" class="gps_last">
  120. <view class="text_view">{{$t('最新')}}</view>
  121. <view class="text_view">GPS</view>
  122. </view>
  123. <image src="https://qiniu.bms16.com/Fg4wwTFjltC-0avrON1I0WLrIa82" class="fence-img" @tap="bindFencePopupOpen"></image>
  124. <view v-if="trace" class="trace-box">{{ $t('追踪时间') + ':' + tools.formatHourSeconds(traceTime) }}</view>
  125. <!--<van-grid>
  126. <van-grid-item text="轨迹" bind:click="bindTrackDialogOpen">
  127. <van-icon slot="icon" name="map-marked" color="#409EFF" />
  128. </van-grid-item>
  129. <van-grid-item text="报警" bind:click="bindAlarmPopupOpen">
  130. <van-icon slot="icon" name="bell" color="#F56C6C" info="{{ alarmList.length }}"/>
  131. </van-grid-item>
  132. <van-grid-item wx:if="{{trackPoints.length!=0}}" text="播放" bind:click="bindPlay">
  133. <van-icon wx:if="{{!inPlay}}" slot="icon" name="play" color="#67C23A" />
  134. <van-icon wx:if="{{inPlay}}" slot="icon" name="pause" color="#67C23A" />
  135. </van-grid-item>
  136. <van-grid-item wx:if="{{trackPoints.length!=0}}" text="停留" bind:click="bindStopPopupOpen">
  137. <van-icon slot="icon" name="location" color="#E6A23C" info="{{ trackStopList.length }}"/>
  138. </van-grid-item>
  139. </van-grid>-->
  140. </view>
  141. <view class="left-group">
  142. <view class="left-group-i">
  143. <image class="btn-ctr" src="https://qiniu.bms16.com/Fm-AhAqRdu14DZcE52vl85nw_vuD" @tap="moveToLocation"></image>
  144. </view>
  145. </view>
  146. <view v-if="trackPoints.length != 0" class="track_bottom">
  147. <view class="track_total_time">
  148. {{ $t('时间') + ':' + tools.formatTimeNoSecond(trackDialogFrom.startTime / 1000) + $t('至') + tools.formatTimeNoSecond(trackDialogFrom.endTime / 1000) + $t('共') + mileage_total + $t('公里')}}
  149. </view>
  150. <view class="track_slide flex-row flex-between">
  151. <slider @change="trackPlayChangeAdress" @changing="trackPlayChange" :value="nowPlayIndex" min="1" :max="totalTrackValue" style="width: 70%" />
  152. <view @tap="bindFastForward" class="flex-row fastForward">
  153. <image class="fastForward_img" src="https://qiniu.bms16.com/Fp6Kaid1eEQYqdGgwQD5TGZ1ir_7"></image>
  154. <text v-if="adjustSpeed == 0" class="fastForward_text">{{$t('慢')}}</text>
  155. <text v-if="adjustSpeed == 1" class="fastForward_text">{{$t('中')}}</text>
  156. <text v-if="adjustSpeed == 2" class="fastForward_text">{{$t('快')}}</text>
  157. </view>
  158. </view>
  159. </view>
  160. <!-- 下方点击轨迹弹窗 -->
  161. <view v-if="trackDialogShow" class="popup-black">
  162. <view class="popup-view">
  163. <view style="text-align: center;border-bottom: 4rpx solid #f7f7f7;margin-bottom: 20rpx;">{{$t('轨迹')}}</view>
  164. <view style="padding-left: 30rpx;padding-right: 30rpx;">
  165. <view class="flex-row" style="margin-bottom: 40rpx;">
  166. <view class="location_mark">{{$t('定位类型')}}:</view>
  167. <view @tap="bindLocationType" data-index="1" :class="isLocationType == 1 ? 'sel_location_view' : 'un_location_view'">GPS</view>
  168. <view @tap="bindLocationType" data-index="2" :class="isLocationType == 2 ? 'sel_location_view' : 'un_location_view'">LBS</view>
  169. <view @tap="bindLocationType" data-index="3" :class="isLocationType == 3 ? 'sel_location_view' : 'un_location_view'">GPS+LBS</view>
  170. </view>
  171. <view class="flex-row" style="margin-bottom: 50rpx;">
  172. <view class="flex-row" style="margin-right: 60rpx;">
  173. <img class="time-img" src="https://qiniu.bms16.com/Ful5wl2uV3-Ys8PdeFDGZRgBm6DX" />
  174. <text style="font-size: 28rpx;">{{$t('开始时间')}}</text>
  175. </view>
  176. <view style="height: 40rpx;">
  177. <time-picker :time="trackDialogFrom.formatStartTime" @confirmPickDate="confirmPickDate" />
  178. </view>
  179. </view>
  180. <view class="flex-row" style="margin-bottom: 70rpx;">
  181. <view class="flex-row" style="margin-right: 60rpx;">
  182. <img class="time-img" src="https://qiniu.bms16.com/Ful5wl2uV3-Ys8PdeFDGZRgBm6DX" />
  183. <text style="font-size: 28rpx;">{{$t('结束时间')}}</text>
  184. </view>
  185. <view style="height: 40rpx;">
  186. <time-picker :time="trackDialogFrom.formatEndTime" @confirmPickDate="confirmPickDate" />
  187. </view>
  188. </view>
  189. <view class="day-btn flex-row">
  190. <view @tap="bindTrackTimeSelectToday">{{$t('当天')}}</view>
  191. <view @tap="bindTrackTimeSelectYesterday">{{$t('昨天')}}</view>
  192. <view @tap="bindTrackTimeSelectLastday">{{$t('前天')}}</view>
  193. </view>
  194. </view>
  195. <view class="bottom-btn flex-row">
  196. <view @tap="bindTrackDialogClose" class="">{{$t('取消')}}</view>
  197. <view @tap="bindTrackDialogConfirm" class="">{{$t('查询')}}</view>
  198. </view>
  199. </view>
  200. </view>
  201. <!-- 下方点击报警弹窗 -->
  202. <view v-if="alarmPopupShow" class="popup-black">
  203. <scroll-view class="alarm-view" :scroll-y="true">
  204. <view class="alarm-top flex-row">
  205. <view>{{$t('报警')}}</view>
  206. <view @tap="bindAlarmPopupClose"><img src="https://qiniu.bms16.com/FjhcWGFGsI56rLZRu7_OnhGtpoUs" /></view>
  207. </view>
  208. <view class="alarm-content flex-row flex-between" @tap="MoveToAlarm($event, { p: item })" :data-p="item" v-for="(item, index) in alarmList" :key="index">
  209. <view>
  210. <view class="flex-row" style="margin-bottom: 10rpx;">
  211. <view class="danger-view">{{ item.alarm_desc }}</view>
  212. <view class="primary-view">{{ item.speed + $t('公里')+'/'+$t('小时')}}</view>
  213. </view>
  214. <view>{{ item.formatTime }}</view>
  215. </view>
  216. <view class="alarm-right">{{item.address}}</view>
  217. </view>
  218. </scroll-view>
  219. </view>
  220. <!-- 停留点 -->
  221. <view v-if="trackStopPopupShow" class="popup-black">
  222. <scroll-view class="stop-view flex-row">
  223. <view class="stop-top flex-row">
  224. <view>{{$t('停留点')}}</view>
  225. <view @tap="bindStopPopupClose"><img src="https://qiniu.bms16.com/FjhcWGFGsI56rLZRu7_OnhGtpoUs" /></view>
  226. </view>
  227. <view class="stop-content flex-row flex-between" @tap="MoveToStop($event, { p: item })" :data-p="item" v-for="(item, index) in trackStopList" :key="index">
  228. <view style="width: 50%;">
  229. <view class="flex-row" style="margin-bottom: 10rpx;">
  230. <view>{{ item.name }}</view>
  231. <view class="o-text">{{ item.format_stop_time }}</view>
  232. </view>
  233. <view style="white-space: break-spaces;">{{ item.time }} - {{ item.end_time }}</view>
  234. </view>
  235. <view class="stop-right">{{item.address}}</view>
  236. </view>
  237. </scroll-view>
  238. </view>
  239. <!-- 右下角围栏 -->
  240. <view v-if="fencePopupShow">
  241. <scroll-view class="fence-view" :scroll-y="true">
  242. <view class="fence-top flex-row flex-between">
  243. <view class="flex-row">
  244. <view style="margin-right: 20rpx;">{{$t('围栏')}}</view>
  245. <view class="fence-btn" @tap="addFence"><img src="https://qiniu.bms16.com/FkjjRjSiRHnbPJk_2PhaiAcfwY1f" />{{$t('添加')}}</view>
  246. </view>
  247. <view @tap="bindFencePopupClose"><img src="https://qiniu.bms16.com/FjhcWGFGsI56rLZRu7_OnhGtpoUs" /></view>
  248. </view>
  249. <view class="fence-content flex-row flex-between" @click="MoveToFence($event, { p: item })" :data-p="item" v-for="(item, index) in fenceList" :key="index">
  250. <view>
  251. <view class="van-cell-text">
  252. {{ item.name }}
  253. </view>
  254. <!-- <view class="van-cell-text"> {{ $t('报警类型') + ':' + item.type == 1 ? $t('进') : item.type == 2 ? $t('出') : item.type == 3 ? $t('双向') : $t('关闭') }}</view> -->
  255. <view class="van-cell-text"> {{ $t('报警类型') + ':' }}
  256. <text v-if="item.type == 2">{{$t('出')}}</text>
  257. <text v-if="item.type == 3">{{$t('双向')}}</text>
  258. <text v-if="item.type == 0">{{$t('关闭')}}</text>
  259. <text v-if="item.type == 1">{{$t('进')}}</text>
  260. </view>
  261. </view>
  262. <view class="">{{item.radius+$t('米')}}</view>
  263. </view>
  264. </scroll-view>
  265. </view>
  266. <!-- 围栏设置 -->
  267. <view v-if="selectFence != null">
  268. <scroll-view class="fence-view" :scroll-y="true">
  269. <view class="fence-top flex-row flex-between">
  270. <view style="margin-right: 20rpx;">{{$t('围栏设置')}}</view>
  271. <view @tap="bindFenceClose"><img src="https://qiniu.bms16.com/FjhcWGFGsI56rLZRu7_OnhGtpoUs" /></view>
  272. </view>
  273. <view class="">
  274. <view class="fence-config flex-row flex-between">
  275. <view>{{$t('围栏名称')}}</view>
  276. <input type="text" :placeholder="$t('请输入围栏名称')" @blur="onFenceNameChange" :value="selectFence.name" style="color: rgba(0, 0, 0, 1);text-align: right;" />
  277. </view>
  278. <view class="fence-config flex-row flex-between">
  279. <view>{{$t('报警类型')}}</view>
  280. <view class="flex-row">
  281. <radio-group class="radio-group" @change="onFenceTypeChange">
  282. <radio :checked="selectFence.type ==1" value="1" />{{$t('进')}}
  283. <radio :checked="selectFence.type ==2" value="2" />{{$t('出')}}
  284. <radio :checked="selectFence.type ==3" value="3" />{{$t('双向')}}
  285. <radio :checked="selectFence.type ==0" value="0" />{{$t('关闭')}}
  286. </radio-group>
  287. </view>
  288. </view>
  289. <view class="fence-config flex-row flex-between">
  290. <view>{{$t('围栏半径')}}</view>
  291. <view style="width: 75%;" class="flex-row flex-around">
  292. <image src="https://qiniu.bms16.com/Fgthw9jHOk5KP9wfiOEv_6iwCpt5" style="width: 40rpx; height: 40rpx" @tap="onFenceRadiusMinus"></image>
  293. <slider :value="selectFence.radius" @change="onFenceRadiusChange" @changing="onFenceRadiusChange" min="1" max="10000" show-value style="width: 75%" />
  294. <image src="https://qiniu.bms16.com/FnL1ghroP_oJRk1_0PpUXONI533U" style="width: 40rpx; height: 40rpx" @tap="onFenceRadiusPlus"></image>
  295. </view>
  296. </view>
  297. <view class="fence-config">
  298. <button class="save-btn" @tap="bindFenceSave">{{$t('保存')}}</button>
  299. </view>
  300. </view>
  301. </scroll-view>
  302. </view>
  303. </view>
  304. </template>
  305. <script module="tools" lang="wxs" src="@/pages/common/wxs/tools.wxs"></script>
  306. <script>
  307. import mapControl from '@/component/mapControl/mapControl';
  308. import timePicker from '@/component/time-pickers/time-pickers';
  309. // pages/deviceLocal/deviceLocal.js
  310. const config = require('../../common/config.js');
  311. const common = require('../../common/common.js');
  312. var http = require('../../common/http.js');
  313. var storage = require('../../common/storage.js');
  314. var QQMapWX = require('../../libs/qqmap-wx-jssdk.js');
  315. var qqmapsdk;
  316. export default {
  317. components: {
  318. mapControl,
  319. timePicker
  320. },
  321. data() {
  322. return {
  323. id: '',
  324. deviceInfo: {
  325. quantity: '',
  326. name: '',
  327. protectState: false,
  328. oilState: 0,
  329. signalType: 0,
  330. day_mil: '',
  331. mil: '',
  332. voltage: false,
  333. elecState: false,
  334. temp: '',
  335. heart_time: false,
  336. gps_time: false
  337. },
  338. marker: [],
  339. mileage_total: 0,
  340. deviceMarker: [],
  341. trackMarker: [],
  342. alarmMarker: [],
  343. playMarker: [],
  344. endSlide: 0,
  345. polylines: [],
  346. trackPoints: [],
  347. trackStopList: [],
  348. batteryWidth: 37,
  349. alarmList: [],
  350. adjustSpeed: 1,
  351. scale: 8,
  352. speedTime: 200,
  353. trackDialogFrom: {
  354. startTime: new Date().getTime(),
  355. endTime: new Date().getTime() + 3600,
  356. // startTime: new Date(new Date().getTime() - 3600000).getTime(),
  357. // endTime: new Date().getTime(),
  358. // formatStartTime: common.formatDateTime(new Date(new Date().getTime() - 3600000).getTime()),
  359. // formatEndTime: common.formatDateTime(new Date().getTime()),
  360. formatStartTime: common.formatDateTime(new Date().getTime()),
  361. formatEndTime: common.formatDateTime(new Date(new Date().getTime() + 3600000).getTime())
  362. },
  363. latitude_my: null,
  364. longitude_my: null,
  365. trackDialogShow: false,
  366. selectTime: new Date().getTime(),
  367. selectTimeType: '',
  368. alarmPopupShow: false,
  369. trackStopPopupShow: false,
  370. timeSelectShow: false,
  371. inPlay: false,
  372. playTimer: null,
  373. nowPlayIndex: 0,
  374. totalTrackValue: 0,
  375. currentTrackValue: 0,
  376. macid: '',
  377. gps: 0,
  378. gsm: 0,
  379. status: '',
  380. address: '',
  381. showInfo: true,
  382. iconList: [],
  383. locationTimer: null,
  384. longitude: null,
  385. latitude: null,
  386. trace: false,
  387. tracePoints: [],
  388. traceTime: 0,
  389. traceTimer: null,
  390. fencePopupShow: false,
  391. fenceList: [],
  392. isLocationType: 1,
  393. circles: [],
  394. selectFence: null,
  395. type: '1',
  396. mapParams: {
  397. enableSatellite: false,
  398. // 是否开启卫星图
  399. enableTraffic: false // 是否开启实时路况
  400. },
  401. isShowGPS: false,
  402. // locationInfo:{}
  403. locationType: '',
  404. locationAdress: '',
  405. locationGpsType: '',
  406. locationGpsAdress: '',
  407. gpsMarker: [],
  408. flase: '',
  409. };
  410. },
  411. /**
  412. * 生命周期函数--监听页面加载
  413. */
  414. onLoad: function (options) {
  415. this.loadIconList();
  416. this.readyDeviceInfo();
  417. this.loadAlarmList();
  418. this.loadFenceList();
  419. this.locationLoop(true);
  420. //this.loadLastGpsInfo()
  421. this.locationTimer = setInterval(this.locationLoop, 10000);
  422. //获取当前位置
  423. uni.getLocation({
  424. type: 'gcj02',
  425. success: (res) => {
  426. this.setData({
  427. latitude_my: res.latitude,
  428. longitude_my: res.longitude
  429. });
  430. }
  431. });
  432. const me=this
  433. setTimeout(function() {
  434. me.mapCtx = uni.createMapContext('myMap');
  435. }, 500);
  436. // this.mapCtx = uni.createMapContext('myMap');
  437. },
  438. onHide: function () {},
  439. onShow: function () {},
  440. onUnload: function () {
  441. clearInterval(this.locationTimer);
  442. clearInterval(this.traceTimer);
  443. clearInterval(this.playTimer);
  444. },
  445. methods: {
  446. loadIconList: function () {
  447. this.iconList = storage.getIconList();
  448. if (!this.iconList) {
  449. http.postApi(config.API_BATTERY_ICON_LIST, {}, (resp) => {
  450. if (resp.data.code === 200) {
  451. this.iconList = resp.data.data.list;
  452. storage.setIconList(resp.data.data.list);
  453. } else {
  454. common.simpleToast(this,resp.data.msg);
  455. }
  456. });
  457. }
  458. },
  459. onStartTimeChange(e) {
  460. console.log(1125);
  461. this.trackDialogFrom.startTime = e.detail.value;
  462. // 更新结束时间的最小值,确保结束时间不早于开始时间
  463. this.trackDialogFrom.endTime = Math.max(this.trackDialogFrom.endTime, this.trackDialogFrom.startTime);
  464. // trackDialogFrom.formatStartTime
  465. // trackDialogFrom.formatEndTime
  466. },
  467. onEndTimeChange(e) {
  468. this.trackDialogFrom.endTime = e.detail.value;
  469. },
  470. confirmPickDate(dataStr) {
  471. this.trackDialogFrom.formatStartTime = dataStr
  472. this.$emit("time", dateStr);
  473. },
  474. trackPlayChange(e) {
  475. var index = e.detail.value;
  476. this.setData({
  477. nowPlayIndex: index
  478. });
  479. this.playLoop();
  480. },
  481. bindLocationType(e) {
  482. const index = e.currentTarget.dataset.index;
  483. this.setData({
  484. isLocationType: index
  485. });
  486. },
  487. trackPlayChangeAdress(e) {
  488. var index = e.detail.value;
  489. this.setData({
  490. nowPlayIndex: index
  491. });
  492. const me = this;
  493. this.playLoop();
  494. if (me.playMarker.length > 0) {
  495. // qqmapsdk.reverseGeocoder({
  496. // location: {
  497. // latitude: me.data.playMarker[0].latitude,
  498. // longitude: me.data.playMarker[0].longitude
  499. // },
  500. // success: function (res) {
  501. // const formatted_addresses = res.result.formatted_addresses
  502. // const address = res.result.address
  503. // let ps = '';
  504. // let tmp_addr = '地址: ' + address
  505. // while (tmp_addr.length > 15) {
  506. // ps += tmp_addr.substring(0, 15) + "\n";
  507. // tmp_addr = tmp_addr.substring(15);
  508. // }
  509. // ps += tmp_addr
  510. // var playMark = me.data.playMarker
  511. // playMark[0].callout.content += ps
  512. // me.setData({
  513. // playMarker: playMark
  514. // })
  515. // me.setMarkers()
  516. // }
  517. // })
  518. const me = this;
  519. const pData = {
  520. lng: me.playMarker[0].longitude,
  521. lat: me.playMarker[0].latitude,
  522. pi: 'wx_deviceLocal'
  523. };
  524. http.postApi(config.API_MAP_REGEO, pData, function (resp) {
  525. if (resp.data.code === 200) {
  526. var jsonData = resp.data.data.data;
  527. if (jsonData.code === 0) {
  528. const address = jsonData.address;
  529. let ps = '';
  530. let tmp_addr = me.$t('地址')+':' + address;
  531. while (tmp_addr.length > 15) {
  532. ps += tmp_addr.substring(0, 15) + '\n';
  533. tmp_addr = tmp_addr.substring(15);
  534. }
  535. ps += tmp_addr;
  536. var playMark = me.playMarker;
  537. playMark[0].callout.content += ps;
  538. me.setData({
  539. playMarker: playMark
  540. });
  541. }
  542. }
  543. });
  544. }
  545. },
  546. bindFastForward() {
  547. if (this.adjustSpeed === 0) {
  548. this.setData({
  549. adjustSpeed: 1,
  550. speedTime: 400
  551. });
  552. clearInterval(this.playTimer);
  553. this.playTimer = setInterval(this.playLoop, this.speedTime);
  554. } else if (this.adjustSpeed === 1) {
  555. this.setData({
  556. adjustSpeed: 2,
  557. speedTime: 200
  558. });
  559. clearInterval(this.playTimer);
  560. this.playTimer = setInterval(this.playLoop, this.speedTime);
  561. } else if (this.adjustSpeed === 2) {
  562. this.setData({
  563. adjustSpeed: 0,
  564. speedTime: 600
  565. });
  566. clearInterval(this.playTimer);
  567. this.playTimer = setInterval(this.playLoop, this.speedTime);
  568. }
  569. },
  570. loadAlarmList() {
  571. common.loading(this);
  572. const me = this
  573. const deviceInfo = storage.getSelectedDeviceInfo();
  574. http.postApi(
  575. config.API_GPS_ALARM,
  576. {
  577. macid: deviceInfo.mac_id
  578. },
  579. (resp) => {
  580. uni.hideLoading();
  581. if (resp.data.code === 200) {
  582. var alarmList = resp.data.data.list;
  583. alarmList.forEach((p, i) => {
  584. alarmList[i].formatTime = common.formatDateTime(p.send_time * 1000);
  585. qqmapsdk.reverseGeocoder({
  586. location: {
  587. latitude: p.latitude,
  588. longitude: p.longitude
  589. },
  590. success: (res) => {
  591. const formatted_addresses = res.result.formatted_addresses;
  592. const address = res.result.address; //+ formatted_addresses.recommend
  593. let ps = '';
  594. let tmp_addr = me.$t('地址')+':' + address;
  595. while (tmp_addr.length > 15) {
  596. ps += tmp_addr.substring(0, 15) + '\n';
  597. tmp_addr = tmp_addr.substring(15);
  598. }
  599. ps += tmp_addr;
  600. alarmList[i].address = address;
  601. alarmList[i].ps = ps;
  602. this.setData({
  603. alarmList: alarmList
  604. });
  605. }
  606. });
  607. });
  608. this.setData({
  609. alarmList: alarmList
  610. });
  611. } else {
  612. common.simpleToast(this,resp.data.msg);
  613. }
  614. }
  615. );
  616. },
  617. readyDeviceInfo() {
  618. const me = this;
  619. // 实例化API核心类
  620. qqmapsdk = new QQMapWX({
  621. key: config.QQ_MAP_KEY
  622. });
  623. const deviceInfo = storage.getSelectedDeviceInfo();
  624. if (deviceInfo) {
  625. // this.batteryWidth = deviceInfo.quantity/100*37
  626. uni.setNavigationBarTitle({
  627. title: deviceInfo.mac_id
  628. });
  629. if (parseInt(deviceInfo.expire) === 1) {
  630. common.simpleToast(me,me.$t('设备到期'));
  631. setTimeout(function () {
  632. uni.navigateBack({
  633. delta: 1
  634. });
  635. }, 1500);
  636. }
  637. } else {
  638. clearInterval(this.locationTimer);
  639. setTimeout(function () {
  640. uni.navigateBack({
  641. delta: 1
  642. });
  643. }, 1500);
  644. }
  645. },
  646. setMarkers() {
  647. this.setData({
  648. marker: this.deviceMarker.concat(this.trackMarker, this.alarmMarker, this.playMarker, this.gpsMarker)
  649. });
  650. },
  651. setPolylines() {
  652. var polylines = [
  653. {
  654. points: this.trackPoints,
  655. color: '#1989FADD',
  656. width: 5,
  657. arrowLine: true
  658. }
  659. ]; /*, {
  660. points: this.data.trackPoints.slice(0,this.data.nowPlayIndex+1),
  661. color: '#F56C6CDD',
  662. width: 3,
  663. }]*/
  664. if (this.trace) {
  665. polylines.push({
  666. points: this.tracePoints,
  667. color: '#DD4C4CDD',
  668. width: 3,
  669. arrowLine: true
  670. });
  671. }
  672. this.setData({
  673. polylines: polylines
  674. });
  675. },
  676. bindTrackDialogOpen() {
  677. this.setData({
  678. trackDialogShow: true
  679. });
  680. },
  681. // 计算里程数
  682. calculateMileage(history) {
  683. let mileage = 0;
  684. for (let i = 0; i < history.length - 1; i++) {
  685. mileage += parseInt(common.getFlatternDistance(history[i].longitude, history[i].latitude, history[i + 1].longitude, history[i + 1].latitude));
  686. }
  687. var mileage_total = mileage == 0 ? 0 : (mileage / 1000).toFixed(2);
  688. this.setData({
  689. mileage_total: mileage_total
  690. });
  691. },
  692. getCurrentMil(mileage, i, history) {
  693. //var mileage = mileage_current
  694. mileage += parseInt(common.getFlatternDistance(history[i].longitude, history[i].latitude, history[i + 1].longitude, history[i + 1].latitude));
  695. return mileage;
  696. },
  697. loadTotalMil() {
  698. const deviceInfo = storage.getSelectedDeviceInfo();
  699. http.postApi(
  700. config.API_SHOW_MIL,
  701. {
  702. macid: deviceInfo.mac_id,
  703. location_type: this.isLocationType,
  704. from: parseInt(this.trackDialogFrom.startTime / 1000),
  705. to: parseInt(this.trackDialogFrom.endTime / 1000)
  706. },
  707. (resp) => {
  708. if (resp.data.code === 200) {
  709. this.setData({
  710. mileage_total: resp.data.data.distance
  711. });
  712. } else {
  713. common.simpleToast(this,this,resp.data.msg);
  714. }
  715. }
  716. );
  717. },
  718. bindTrackDialogConfirm() {
  719. this.bindTrackDialogClose();
  720. this.setData({
  721. inPlay: false
  722. });
  723. clearInterval(this.playTimer);
  724. common.loading(this);
  725. var me = this
  726. const deviceInfo = storage.getSelectedDeviceInfo();
  727. http.postApi(
  728. config.API_GPS_TRACK,
  729. {
  730. macid: deviceInfo.mac_id,
  731. location_type: this.isLocationType,
  732. from: parseInt(this.trackDialogFrom.startTime / 1000),
  733. to: parseInt(this.trackDialogFrom.endTime / 1000)
  734. },
  735. (resp) => {
  736. this.loadTotalMil();
  737. uni.hideLoading();
  738. if (resp.data.code === 200) {
  739. if (!resp.data.data.points || resp.data.data.points.length === 0) {
  740. common.simpleToast(me,me.$t('当前未有轨迹'));
  741. return;
  742. }
  743. // this.calculateMileage(resp.data.data.points)
  744. var points = [];
  745. var trackMarker = [];
  746. var trackStopList = [];
  747. var n = 1;
  748. this.setData({
  749. totalTrackValue: resp.data.data.points.length
  750. });
  751. var mileage = 0;
  752. resp.data.data.points.forEach((p, i) => {
  753. //移动坐标点
  754. if (resp.data.data.points.length - 1 > i) {
  755. mileage = this.getCurrentMil(mileage, i, resp.data.data.points);
  756. }
  757. points.push({
  758. latitude: parseFloat(p.latitude),
  759. longitude: parseFloat(p.longitude),
  760. time: p.time,
  761. speed: p.speed,
  762. voltage: p.voltage,
  763. time: p.time,
  764. mileage: (mileage / 1000).toFixed(2),
  765. stop_time: p.stop_time
  766. });
  767. //起点
  768. if (i === 0) {
  769. trackStopList.push({
  770. name: me.$t('起点'),
  771. latitude: parseFloat(p.latitude),
  772. longitude: parseFloat(p.longitude),
  773. time: p.time,
  774. end_time: common.formatDateTime(new Date(p.time).getTime() + p.stop_time * 1000),
  775. stop_time: p.stop_time,
  776. format_stop_time: common.formatSeconds(me,p.stop_time),
  777. address: ''
  778. });
  779. //mark弹出框坐标
  780. trackMarker.push({
  781. id: 0,
  782. latitude: p.latitude,
  783. longitude: p.longitude,
  784. name: '',
  785. iconPath: 'https://qiniu.bms16.com/FudnX-2lAHteUZHxpH6cAXFESNVs',
  786. width: 28,
  787. height: 35,
  788. zIndex: 2,
  789. callout: {
  790. content:
  791. '\u8D77\u70B9\n\u505C\u7559: ' +
  792. common.formatSeconds(me,p.stop_time) +
  793. '\n' +
  794. me.$t('开始')+':' +
  795. p.time +
  796. '\n' +
  797. me.$t('结束')+':' +
  798. common.formatDateTime(new Date(p.time).getTime() + p.stop_time * 1000) +
  799. '\n',
  800. padding: 10,
  801. borderRadius: 4,
  802. boxShadow: '4px 8px 16px 0 rgba(0,0,0,0.3)',
  803. display: 'BYCLICK'
  804. }
  805. });
  806. const pData = {
  807. lng: parseFloat(p.longitude),
  808. lat: parseFloat(p.latitude),
  809. pi: 'wx_deviceLocal'
  810. };
  811. http.postApi(config.API_MAP_REGEO, pData, function (resp) {
  812. if (resp.data.code === 200) {
  813. var jsonData = resp.data.data.data;
  814. if (jsonData.code === 0) {
  815. const address = jsonData.address;
  816. let ps = '';
  817. let tmp_addr = me.$t('地址')+':' + address;
  818. while (tmp_addr.length > 15) {
  819. ps += tmp_addr.substring(0, 15) + '\n';
  820. tmp_addr = tmp_addr.substring(15);
  821. }
  822. ps += tmp_addr;
  823. trackMarker[0].callout.content += ps;
  824. trackStopList[0].address = address;
  825. me.setData({
  826. trackMarker: trackMarker,
  827. trackStopList: trackStopList
  828. });
  829. me.setMarkers();
  830. }
  831. }
  832. });
  833. // qqmapsdk.reverseGeocoder({
  834. // location: {
  835. // latitude: parseFloat(p.latitude),
  836. // longitude: parseFloat(p.longitude)
  837. // },
  838. // success: (res) => {
  839. // const formatted_addresses = res.result.formatted_addresses
  840. // const address = res.result.address + formatted_addresses.recommend
  841. // let ps = '';
  842. // let tmp_addr = '地址: ' + address
  843. // while (tmp_addr.length > 15) {
  844. // ps += tmp_addr.substring(0, 15) + "\n";
  845. // tmp_addr = tmp_addr.substring(15);
  846. // }
  847. // ps += tmp_addr
  848. // trackMarker[0].callout.content += ps
  849. // trackStopList[0].address = address
  850. // this.setData({
  851. // trackMarker: trackMarker,
  852. // trackStopList: trackStopList,
  853. // })
  854. // this.setMarkers()
  855. // }
  856. // })
  857. } else if (p.stop_time > 300 && i !== resp.data.data.points.length - 1) {
  858. //地图设置mark停留点
  859. trackStopList.push({
  860. name: 'P' + n,
  861. latitude: parseFloat(p.latitude),
  862. longitude: parseFloat(p.longitude),
  863. time: p.time,
  864. end_time: common.formatDateTime(new Date(p.time).getTime() + p.stop_time * 1000),
  865. stop_time: p.stop_time,
  866. format_stop_time: common.formatSeconds(me,p.stop_time),
  867. address: ''
  868. });
  869. //mark弹出框
  870. trackMarker.push({
  871. id: i,
  872. latitude: parseFloat(p.latitude),
  873. longitude: parseFloat(p.longitude),
  874. name: '',
  875. iconPath: 'https://qiniu.bms16.com/FtYXEurXCr7Ul2A1J8Kgn4BqF8Z7',
  876. width: 28,
  877. height: 35,
  878. zIndex: 1,
  879. callout: {
  880. content:
  881. 'P' +
  882. n +
  883. '\n' +
  884. me.$t('停留')+': ' +
  885. common.formatSeconds(me,p.stop_time) +
  886. '\n' +
  887. me.$t('开始')+': ' +
  888. p.time +
  889. '\n' +
  890. me.$t('结束')+': ' +
  891. common.formatDateTime(new Date(p.time).getTime() + p.stop_time * 1000) +
  892. '\n',
  893. padding: 10,
  894. borderRadius: 4,
  895. boxShadow: '4px 8px 16px 0 rgba(0,0,0,0.3)',
  896. display: 'BYCLICK'
  897. }
  898. });
  899. var i = n;
  900. qqmapsdk.reverseGeocoder({
  901. location: {
  902. latitude: parseFloat(p.latitude),
  903. longitude: parseFloat(p.longitude)
  904. },
  905. success: (res) => {
  906. console.log(res);
  907. const formatted_addresses = res.result.formatted_addresses;
  908. const address = res.result.address + formatted_addresses.recommend;
  909. let ps = '';
  910. let tmp_addr = me.$t('地址')+': ' + address;
  911. while (tmp_addr.length > 15) {
  912. ps += tmp_addr.substring(0, 15) + '\n';
  913. tmp_addr = tmp_addr.substring(15);
  914. }
  915. ps += tmp_addr;
  916. trackMarker[i].callout.content += ps;
  917. trackStopList[i].address = address;
  918. this.setData({
  919. trackMarker: trackMarker,
  920. trackStopList: trackStopList
  921. });
  922. this.setMarkers();
  923. }
  924. });
  925. n++;
  926. }
  927. });
  928. //设置终点
  929. trackStopList.push({
  930. name: me.$t('终点'),
  931. latitude: parseFloat(points[points.length - 1].latitude),
  932. longitude: parseFloat(points[points.length - 1].longitude),
  933. time: points[points.length - 1].time,
  934. end_time: common.formatDateTime(new Date(points[points.length - 1].time).getTime() + points[points.length - 1].stop_time * 1000),
  935. stop_time: points[points.length - 1].stop_time,
  936. format_stop_time: common.formatSeconds(me,points[points.length - 1].stop_time),
  937. address: ''
  938. });
  939. trackMarker.push({
  940. id: points.length - 1,
  941. latitude: points[points.length - 1].latitude,
  942. longitude: points[points.length - 1].longitude,
  943. name: '',
  944. iconPath: '/static/resource/images/end_point.png',
  945. width: 28,
  946. height: 35,
  947. zIndex: 2,
  948. callout: {
  949. content:
  950. '\u7EC8\u70B9\n\u505C\u7559: ' +
  951. common.formatSeconds(me,points[points.length - 1].stop_time) +
  952. '\n' +
  953. me.$t('开始')+': ' +
  954. points[points.length - 1].time +
  955. '\n' +
  956. me.$t('结束')+': ' +
  957. common.formatDateTime(new Date(points[points.length - 1].time).getTime() + points[points.length - 1].stop_time * 1000) +
  958. '\n',
  959. padding: 10,
  960. borderRadius: 4,
  961. boxShadow: '4px 8px 16px 0 rgba(0,0,0,0.3)',
  962. display: 'BYCLICK'
  963. }
  964. });
  965. qqmapsdk.reverseGeocoder({
  966. location: {
  967. latitude: parseFloat(points[points.length - 1].latitude),
  968. longitude: parseFloat(points[points.length - 1].longitude)
  969. },
  970. success: (res) => {
  971. console.log(res);
  972. const formatted_addresses = res.result.formatted_addresses;
  973. const address = res.result.address + formatted_addresses.recommend;
  974. let ps = '';
  975. let tmp_addr = me.$t('地址')+': ' + address;
  976. while (tmp_addr.length > 15) {
  977. ps += tmp_addr.substring(0, 15) + '\n';
  978. tmp_addr = tmp_addr.substring(15);
  979. }
  980. ps += tmp_addr;
  981. trackMarker[n].callout.content += ps;
  982. trackStopList[n].address = address;
  983. this.setData({
  984. trackMarker: trackMarker,
  985. trackStopList: trackStopList
  986. });
  987. this.setMarkers();
  988. }
  989. });
  990. var deviceMarker = this.deviceMarker;
  991. //deviceMarker[0].callout.display = 'BYCLICK'
  992. this.setData({
  993. trackPoints: points,
  994. trackMarker: trackMarker,
  995. deviceMarker: deviceMarker,
  996. trackStopList: trackStopList,
  997. nowPlayIndex: 0,
  998. playMarker: []
  999. });
  1000. this.setMarkers();
  1001. this.setPolylines();
  1002. // this.mapCtx.scale = 8
  1003. var map = uni.createMapContext('myMap');
  1004. map.includePoints({
  1005. points: points,
  1006. padding: [10, 10, 10, 10]
  1007. });
  1008. this.setData({
  1009. scale: 13
  1010. });
  1011. } else {
  1012. common.simpleToast(this,resp.data.msg);
  1013. }
  1014. }
  1015. );
  1016. },
  1017. bindTrackDialogClose() {
  1018. this.setData({
  1019. trackDialogShow: false
  1020. });
  1021. },
  1022. bindTrackStartTimeSelect(e) {
  1023. this.setData({
  1024. selectTime: this.trackDialogFrom.formatStartTime,
  1025. selectTimeType: 'track_start'
  1026. });
  1027. // this.bindTimeSelectOpen();
  1028. },
  1029. bindTrackEndTimeSelect() {
  1030. this.setData({
  1031. selectTime: this.trackDialogFrom.formatEndTime,
  1032. selectTimeType: 'track_end'
  1033. });
  1034. // this.bindTimeSelectOpen();
  1035. },
  1036. bindTrackTimeSelectToday() {
  1037. this.setData({
  1038. trackDialogFrom: Object.assign(this.trackDialogFrom, {
  1039. startTime: new Date(new Date().toLocaleDateString()).getTime(),
  1040. formatStartTime: common.formatDateTime(new Date(new Date().toLocaleDateString()).getTime()),
  1041. endTime: new Date().getTime(),
  1042. formatEndTime: common.formatDateTime(new Date().getTime())
  1043. })
  1044. });
  1045. this.bindTrackDialogConfirm();
  1046. },
  1047. bindTrackTimeSelectYesterday() {
  1048. this.setData({
  1049. trackDialogFrom: Object.assign(this.trackDialogFrom, {
  1050. startTime: new Date(new Date().toLocaleDateString()).getTime() - 86400 * 1000,
  1051. formatStartTime: common.formatDateTime(new Date(new Date().toLocaleDateString()).getTime() - 86400 * 1000),
  1052. endTime: new Date(new Date().toLocaleDateString()).getTime() - 1,
  1053. formatEndTime: common.formatDateTime(new Date(new Date().toLocaleDateString()).getTime() - 1)
  1054. })
  1055. });
  1056. this.bindTrackDialogConfirm();
  1057. },
  1058. bindTrackTimeSelectLastday() {
  1059. this.setData({
  1060. trackDialogFrom: Object.assign(this.trackDialogFrom, {
  1061. startTime: new Date(new Date().toLocaleDateString()).getTime() - 2880 * 60 * 1000,
  1062. formatStartTime: common.formatDateTime(new Date(new Date().toLocaleDateString()).getTime() - 2880 * 60 * 1000),
  1063. endTime: new Date(new Date().toLocaleDateString()).getTime() - 86400 * 1000 - 1,
  1064. formatEndTime: common.formatDateTime(new Date(new Date().toLocaleDateString()).getTime() - 86400 * 1000 - 1)
  1065. })
  1066. });
  1067. this.bindTrackDialogConfirm();
  1068. },
  1069. bindTimeSelectConfirm(event) {
  1070. switch (this.selectTimeType) {
  1071. case 'track_start':
  1072. this.setData({
  1073. trackDialogFrom: Object.assign(this.trackDialogFrom, {
  1074. startTime: event.detail,
  1075. formatStartTime: common.formatDateTime(event.detail)
  1076. }),
  1077. selectTimeType: ''
  1078. });
  1079. break;
  1080. case 'track_end':
  1081. this.setData({
  1082. trackDialogFrom: Object.assign(this.trackDialogFrom, {
  1083. endTime: event.detail,
  1084. formatEndTime: common.formatDateTime(event.detail)
  1085. }),
  1086. selectTimeType: ''
  1087. });
  1088. break;
  1089. }
  1090. this.bindTimeSelectClose();
  1091. },
  1092. bindTimeSelectOpen() {
  1093. this.setData({
  1094. timeSelectShow: true
  1095. });
  1096. },
  1097. bindTimeSelectClose() {
  1098. this.setData({
  1099. timeSelectShow: false
  1100. });
  1101. },
  1102. bindStopPopupOpen() {
  1103. this.setData({
  1104. trackStopPopupShow: true
  1105. });
  1106. },
  1107. bindStopPopupClose() {
  1108. this.setData({
  1109. trackStopPopupShow: false
  1110. });
  1111. },
  1112. MoveToStop(event, _dataset) {
  1113. /* ---处理dataset begin--- */
  1114. this.handleDataset(event, _dataset);
  1115. /* ---处理dataset end--- */
  1116. var map = uni.createMapContext('myMap');
  1117. this.setData({
  1118. latitude: event.currentTarget.dataset.p.latitude,
  1119. longitude: event.currentTarget.dataset.p.longitude
  1120. });
  1121. /*map.moveToLocation({
  1122. latitude: event.currentTarget.dataset.p.latitude,
  1123. longitude: event.currentTarget.dataset.p.longitude
  1124. })*/
  1125. },
  1126. bindAlarmPopupOpen() {
  1127. this.setData({
  1128. alarmPopupShow: true
  1129. });
  1130. },
  1131. bindAlarmPopupClose() {
  1132. this.setData({
  1133. alarmPopupShow: false
  1134. });
  1135. this.setData({
  1136. alarmMarker: []
  1137. });
  1138. this.setMarkers();
  1139. },
  1140. MoveToAlarm(event, _dataset) {
  1141. /* ---处理dataset begin--- */
  1142. this.handleDataset(event, _dataset);
  1143. /* ---处理dataset end--- */
  1144. var map = uni.createMapContext('myMap');
  1145. var me = this
  1146. var alarmMarker = [
  1147. {
  1148. id: 0,
  1149. latitude: event.currentTarget.dataset.p.latitude,
  1150. longitude: event.currentTarget.dataset.p.longitude,
  1151. name: '',
  1152. iconPath: '/static/resource/images/alarm.png',
  1153. width: 28,
  1154. height: 35,
  1155. zIndex: 10,
  1156. callout: {
  1157. content:
  1158. event.currentTarget.dataset.p.alarm_desc +
  1159. '\n' +
  1160. me.$t('时间')+': ' +
  1161. event.currentTarget.dataset.p.formatTime +
  1162. '\n' +
  1163. me.$t('速度')+': ' +
  1164. event.currentTarget.dataset.p.speed +
  1165. me.$t('公里')+'/'+me.$t('小时')+'\n' +
  1166. event.currentTarget.dataset.p.ps +
  1167. '\n',
  1168. padding: 10,
  1169. borderRadius: 4,
  1170. boxShadow: '4px 8px 16px 0 rgba(0,0,0,0.3)',
  1171. display: 'ALWAYS'
  1172. }
  1173. }
  1174. ];
  1175. this.setData({
  1176. alarmMarker: alarmMarker,
  1177. latitude: event.currentTarget.dataset.p.latitude,
  1178. longitude: event.currentTarget.dataset.p.longitude
  1179. });
  1180. this.setMarkers();
  1181. },
  1182. playLoop() {
  1183. if (this.nowPlayIndex >= this.trackPoints.length - 1) {
  1184. this.setData({
  1185. inPlay: false
  1186. });
  1187. clearInterval(this.playTimer);
  1188. return;
  1189. }
  1190. this.setData({
  1191. showInfo: false
  1192. });
  1193. var map = uni.createMapContext('myMap');
  1194. var leng = Math.sqrt(
  1195. Math.pow(Math.abs(this.trackPoints[this.nowPlayIndex + 1].longitude - this.trackPoints[this.nowPlayIndex].longitude) * 111, 2) +
  1196. Math.pow(
  1197. Math.abs(this.trackPoints[this.nowPlayIndex + 1].latitude - this.trackPoints[this.nowPlayIndex].latitude) *
  1198. 111 *
  1199. Math.cos(((2 * Math.PI) / 360) * this.trackPoints[this.nowPlayIndex].latitude),
  1200. 2
  1201. )
  1202. );
  1203. while (leng < 0.1 && this.nowPlayIndex < this.trackPoints.length - 1) {
  1204. leng += Math.sqrt(
  1205. Math.pow(Math.abs(this.trackPoints[this.nowPlayIndex + 1].longitude - this.trackPoints[this.nowPlayIndex].longitude) * 111, 2) +
  1206. Math.pow(
  1207. Math.abs(this.trackPoints[this.nowPlayIndex + 1].latitude - this.trackPoints[this.nowPlayIndex].latitude) *
  1208. 111 *
  1209. Math.cos(((2 * Math.PI) / 360) * this.trackPoints[this.nowPlayIndex].latitude),
  1210. 2
  1211. )
  1212. );
  1213. this.nowPlayIndex = this.nowPlayIndex + 1;
  1214. }
  1215. var rotate =
  1216. (Math.atan(
  1217. (this.trackPoints[this.nowPlayIndex + 1].longitude - this.trackPoints[this.nowPlayIndex].longitude) /
  1218. (this.trackPoints[this.nowPlayIndex + 1].latitude - this.trackPoints[this.nowPlayIndex].latitude) /
  1219. Math.cos(((2 * Math.PI) / 360) * this.trackPoints[this.nowPlayIndex].latitude)
  1220. ) *
  1221. 180) /
  1222. Math.PI;
  1223. if (rotate === NaN) {
  1224. if (this.trackPoints[this.nowPlayIndex + 1].longitude - this.trackPoints[this.nowPlayIndex].longitude > 0) {
  1225. rotate = 90;
  1226. } else {
  1227. rotate = 270;
  1228. }
  1229. } else if (this.trackPoints[this.nowPlayIndex + 1].latitude - this.trackPoints[this.nowPlayIndex].latitude < 0) {
  1230. rotate = 180 + rotate;
  1231. } else if (this.trackPoints[this.nowPlayIndex + 1].longitude - this.trackPoints[this.nowPlayIndex].longitude < 0) {
  1232. rotate = 360 + rotate;
  1233. }
  1234. var playMarker = [
  1235. {
  1236. id: -1,
  1237. latitude: this.trackPoints[this.nowPlayIndex].latitude,
  1238. longitude: this.trackPoints[this.nowPlayIndex].longitude,
  1239. name: '',
  1240. iconPath: '/static/resource/images/1.gif',
  1241. width: 35,
  1242. height: 35,
  1243. zIndex: 20,
  1244. callout: {
  1245. content:
  1246. this.$t('电压')+': ' +
  1247. this.trackPoints[this.nowPlayIndex].voltage +
  1248. '\n' +
  1249. this.$t('速度')+': ' +
  1250. this.trackPoints[this.nowPlayIndex].speed +
  1251. 'km/'+this.$t('小时')+'\n' +
  1252. this.$t('时间')+': ' +
  1253. this.trackPoints[this.nowPlayIndex].time +
  1254. '\n' +
  1255. this.$t('里程')+': ' +
  1256. this.trackPoints[this.nowPlayIndex].mileage +
  1257. this.$t('公里')+'\n',
  1258. padding: 10,
  1259. borderRadius: 4,
  1260. boxShadow: '4px 8px 16px 0 rgba(0,0,0,0.3)',
  1261. display: 'ALWAYS'
  1262. }
  1263. }
  1264. ];
  1265. this.playMarker = playMarker;
  1266. this.setMarkers();
  1267. this.setData({
  1268. latitude: this.trackPoints[this.nowPlayIndex].latitude,
  1269. longitude: this.trackPoints[this.nowPlayIndex].longitude,
  1270. nowPlayIndex: this.nowPlayIndex + 1
  1271. });
  1272. },
  1273. bindPlay() {
  1274. if (this.inPlay) {
  1275. this.setData({
  1276. inPlay: false
  1277. });
  1278. const me = this;
  1279. clearInterval(this.playTimer);
  1280. if (me.playMarker.length > 0) {
  1281. const pData = {
  1282. lng: me.playMarker[0].longitude,
  1283. lat: me.playMarker[0].latitude,
  1284. pi: 'wx_deviceLocal'
  1285. };
  1286. const me = this;
  1287. http.postApi(config.API_MAP_REGEO, pData, function (resp) {
  1288. if (resp.data.code === 200) {
  1289. var jsonData = resp.data.data.data;
  1290. if (jsonData.code === 0) {
  1291. const address = jsonData.address;
  1292. var ps = '';
  1293. let tmp_addr = me.$t('地址')+': ' + address;
  1294. while (tmp_addr.length > 15) {
  1295. ps += tmp_addr.substring(0, 15) + '\n';
  1296. tmp_addr = tmp_addr.substring(15);
  1297. }
  1298. ps += tmp_addr;
  1299. var playMark = me.playMarker;
  1300. playMark[0].callout.content += ps;
  1301. me.setData({
  1302. playMarker: playMark
  1303. });
  1304. me.setMarkers();
  1305. }
  1306. }
  1307. });
  1308. // qqmapsdk.reverseGeocoder({
  1309. // location: {
  1310. // latitude: me.data.playMarker[0].latitude,
  1311. // longitude: me.data.playMarker[0].longitude
  1312. // },
  1313. // success: function (res) {
  1314. // const formatted_addresses = res.result.formatted_addresses
  1315. // const address = res.result.address
  1316. // let ps = '';
  1317. // let tmp_addr = '地址: ' + address
  1318. // while (tmp_addr.length > 15) {
  1319. // ps += tmp_addr.substring(0, 15) + "\n";
  1320. // tmp_addr = tmp_addr.substring(15);
  1321. // }
  1322. // ps += tmp_addr
  1323. // var playMark = me.data.playMarker
  1324. // playMark[0].callout.content += ps
  1325. // me.setData({
  1326. // playMarker: playMark
  1327. // })
  1328. // me.setMarkers()
  1329. // }
  1330. // })
  1331. }
  1332. } else {
  1333. if (this.nowPlayIndex >= this.trackPoints.length - 1) {
  1334. this.setData({
  1335. nowPlayIndex: 0
  1336. });
  1337. }
  1338. this.setData({
  1339. inPlay: true
  1340. });
  1341. this.playTimer = setInterval(this.playLoop, this.speedTime);
  1342. }
  1343. },
  1344. // bindGPSLocation(){
  1345. // this.setData({
  1346. // isShowGPS:true
  1347. // })
  1348. // this.locationLoop(true)
  1349. // },
  1350. locationLoop(init = false) {
  1351. const deviceInfo = storage.getSelectedDeviceInfo();
  1352. if (deviceInfo) {
  1353. //common.loading()
  1354. http.postApi(
  1355. config.API_GPS_INFO,
  1356. {
  1357. macid: deviceInfo.mac_id
  1358. },
  1359. (resp) => {
  1360. //wx.hideLoading()
  1361. if (resp.data.code === 200) {
  1362. let status;
  1363. let stat = '';
  1364. if (parseInt(resp.data.data.info.online) === 1) {
  1365. if (parseInt(resp.data.data.info.speed) === 0) {
  1366. status = this.$t('静止')+'(' + common.formatSeconds(this,resp.data.data.info.heart_time - resp.data.data.info.gps_time, false) + ')';
  1367. stat = 'static';
  1368. } else {
  1369. status = this.$t('行驶')+'(' + resp.data.data.info.speed + 'Km/h)';
  1370. stat = 'running';
  1371. }
  1372. } else {
  1373. status =
  1374. this.$t('离线')+'(' +
  1375. common.formatSeconds(
  1376. this,new Date().getTime() / 1000 -
  1377. (resp.data.data.info.heart_time === undefined ? resp.data.data.info.gps_time : resp.data.data.info.heart_time),
  1378. false
  1379. ) +
  1380. ')';
  1381. stat = 'offline';
  1382. }
  1383. if (init) {
  1384. this.setData({
  1385. longitude: resp.data.data.info.longitude,
  1386. latitude: resp.data.data.info.latitude
  1387. });
  1388. }
  1389. var device_info = resp.data.data.info;
  1390. this.setData({
  1391. locationType: device_info.signalType
  1392. });
  1393. this.setData({
  1394. macid: deviceInfo.mac_id,
  1395. deviceInfo: resp.data.data.info,
  1396. gps: resp.data.data.info.gpscount,
  1397. gsm: parseInt(resp.data.data.info.online) === 0 ? 0 : resp.data.data.info.gsmlevel <= 15 ? 3 : resp.data.data.info.gsmlevel > 18 ? 5 : 4,
  1398. status: status,
  1399. deviceMarker: [
  1400. {
  1401. id: 1,
  1402. latitude: resp.data.data.info.latitude,
  1403. longitude: resp.data.data.info.longitude,
  1404. name: '',
  1405. iconPath: this.iconList[resp.data.data.info.icon] ? this.iconList[resp.data.data.info.icon][stat] : '/static/resource/images/weizhi2.png',
  1406. width: 35,
  1407. height: 35,
  1408. zIndex: 10
  1409. }
  1410. ],
  1411. circles: [
  1412. {
  1413. latitude: resp.data.data.info.latitude,
  1414. longitude: resp.data.data.info.longitude,
  1415. color: '#6495ED1F',
  1416. fillColor: '#6495ED1F',
  1417. radius: 1000,
  1418. strokeWidth: 1
  1419. }
  1420. ]
  1421. });
  1422. this.setMarkers();
  1423. if (
  1424. this.trace &&
  1425. (this.tracePoints.length == 0 ||
  1426. this.tracePoints[this.tracePoints.length - 1].latitude != resp.data.data.info.latitude ||
  1427. this.tracePoints[this.tracePoints.length - 1].longitude != resp.data.data.info.longitude)
  1428. ) {
  1429. this.tracePoints.push({
  1430. latitude: resp.data.data.info.latitude,
  1431. longitude: resp.data.data.info.longitude
  1432. });
  1433. this.setPolylines();
  1434. this.setData({
  1435. latitude: resp.data.data.info.latitude,
  1436. longitude: resp.data.data.info.longitude
  1437. });
  1438. }
  1439. const pData = {
  1440. lng: resp.data.data.info.longitude,
  1441. lat: resp.data.data.info.latitude,
  1442. pi: 'wx_deviceLocal'
  1443. };
  1444. const me = this;
  1445. http.postApi(config.API_MAP_REGEO, pData, function (resp) {
  1446. if (resp.data.code === 200) {
  1447. var jsonData = resp.data.data.data;
  1448. if (jsonData.code === 0) {
  1449. me.setData({
  1450. address: jsonData.address,
  1451. locationAdress: jsonData.address
  1452. });
  1453. }
  1454. }
  1455. });
  1456. // qqmapsdk.reverseGeocoder({
  1457. // location: {
  1458. // latitude: resp.data.data.info.latitude,
  1459. // longitude: resp.data.data.info.longitude
  1460. // },
  1461. // success: function (res) {
  1462. // console.log(res)
  1463. // const formatted_addresses = res.result.formatted_addresses
  1464. // const address = res.result.address //+ formatted_addresses.recommend
  1465. // me.setData({
  1466. // address: address,
  1467. // locationAdress: address
  1468. // })
  1469. // }
  1470. // })
  1471. } else {
  1472. common.simpleToast(this,resp.data.msg);
  1473. clearInterval(this.locationTimer);
  1474. setTimeout(function () {
  1475. uni.navigateBack({
  1476. delta: 1
  1477. });
  1478. }, 1500);
  1479. }
  1480. }
  1481. );
  1482. }
  1483. },
  1484. isEmptyObject(obj) {
  1485. for (var key in obj) {
  1486. return false;
  1487. }
  1488. return true;
  1489. },
  1490. loadLastGpsInfo() {
  1491. var init = true;
  1492. const me = this;
  1493. const deviceInfo = storage.getSelectedDeviceInfo();
  1494. if (deviceInfo) {
  1495. http.postApi(
  1496. config.API_GPS_INFO,
  1497. {
  1498. macid: deviceInfo.mac_id
  1499. },
  1500. (resp) => {
  1501. if (resp.data.code === 200) {
  1502. if (this.isEmptyObject(resp.data.data.info.last_location)) {
  1503. common.simpleToast(me,me.$t('当前设备没有GPS坐标'));
  1504. return;
  1505. }
  1506. // var last_location = resp.data.data.info.last_location
  1507. // last_location.lng = 121.19023414159073
  1508. // last_location.lat = 31.390001627411883
  1509. // resp.data.data.info.last_location = last_location
  1510. let status;
  1511. let stat = '';
  1512. if (parseInt(resp.data.data.info.online) === 1) {
  1513. if (parseInt(resp.data.data.info.speed) === 0) {
  1514. status = me.$t('静止')+'(' + common.formatSeconds(me,resp.data.data.info.heart_time - resp.data.data.info.gps_time, false) + ')';
  1515. stat = 'static';
  1516. } else {
  1517. status = me.$t('行驶')+'(' + resp.data.data.info.speed + 'Km/h)';
  1518. stat = 'running';
  1519. }
  1520. } else {
  1521. status =
  1522. me.$t('离线')+'(' +
  1523. common.formatSeconds(
  1524. me,new Date().getTime() / 1000 -
  1525. (resp.data.data.info.heart_time === undefined ? resp.data.data.info.gps_time : resp.data.data.info.heart_time),
  1526. false
  1527. ) +
  1528. ')';
  1529. stat = 'offline';
  1530. }
  1531. if (init) {
  1532. this.setData({
  1533. longitude: resp.data.data.info.last_location.lng,
  1534. latitude: resp.data.data.info.last_location.lat
  1535. });
  1536. }
  1537. var device_info = resp.data.data.info;
  1538. device_info.signalType = '0';
  1539. this.setData({
  1540. locationGpsType: device_info.signalType
  1541. });
  1542. var device_marker = {
  1543. id: 2,
  1544. latitude: resp.data.data.info.last_location.lat,
  1545. longitude: resp.data.data.info.last_location.lng,
  1546. name: '',
  1547. iconPath: this.iconList[resp.data.data.info.icon] ? this.iconList[resp.data.data.info.icon][stat] : '/static/resource/images/weizhi2.png',
  1548. width: 35,
  1549. height: 35,
  1550. zIndex: 10
  1551. };
  1552. // this.setData({
  1553. // marker: this.data.marker.concat(device_marker)
  1554. // })
  1555. this.setData({
  1556. gpsMarker: [device_marker]
  1557. });
  1558. this.setData({
  1559. marker: this.gpsMarker.concat(this.trackMarker, this.alarmMarker, this.playMarker, this.deviceMarker)
  1560. });
  1561. // this.setData({
  1562. // marker: this.data.deviceMarker.concat(this.data.trackMarker, this.data.alarmMarker, this.data.playMarker)
  1563. // })
  1564. //this.data.deviceMarker.concat(this.data.trackMarker, this.data.alarmMarker, this.data.playMarker)
  1565. this.setData({
  1566. macid: deviceInfo.mac_id,
  1567. deviceInfo: device_info,
  1568. gps: resp.data.data.info.gpscount,
  1569. gsm: parseInt(resp.data.data.info.online) === 0 ? 0 : resp.data.data.info.gsmlevel <= 15 ? 3 : resp.data.data.info.gsmlevel > 18 ? 5 : 4,
  1570. status: status,
  1571. deviceMarker: [device_marker],
  1572. circles: [
  1573. {
  1574. latitude: resp.data.data.info.last_location.lat,
  1575. longitude: resp.data.data.info.last_location.lng,
  1576. color: '#6495ED1F',
  1577. fillColor: '#6495ED1F',
  1578. radius: 1000,
  1579. strokeWidth: 1
  1580. }
  1581. ]
  1582. });
  1583. //this.setMarkers()
  1584. // this.setData({
  1585. // marker: this.data.deviceMarker.concat(this.data.deviceMarker)
  1586. // })
  1587. this.setData({
  1588. batteryWidth: parseInt((this.deviceInfo.quantity / 100) * 37)
  1589. });
  1590. // const me = this;
  1591. const pData = {
  1592. lng: resp.data.data.info.last_location.lng,
  1593. lat: resp.data.data.info.last_location.lat,
  1594. pi: 'wx_deviceLocal'
  1595. };
  1596. http.postApi(config.API_MAP_REGEO, pData, function (resp) {
  1597. if (resp.data.code === 200) {
  1598. var jsonData = resp.data.data.data;
  1599. if (jsonData.code === 0) {
  1600. const address = jsonData.address;
  1601. me.setData({
  1602. address: address,
  1603. locationGpsAdress: address
  1604. });
  1605. }
  1606. }
  1607. });
  1608. // qqmapsdk.reverseGeocoder({
  1609. // location: {
  1610. // latitude: resp.data.data.info.last_location.latitude,
  1611. // longitude: resp.data.data.info.last_location.longitude
  1612. // },
  1613. // success: function (res) {
  1614. // console.log(res)
  1615. // const formatted_addresses = res.result.formatted_addresses
  1616. // const address = res.result.address //+ formatted_addresses.recommend
  1617. // me.setData({
  1618. // address: address,
  1619. // locationGpsAdress: address
  1620. // })
  1621. // }
  1622. // })
  1623. } else {
  1624. common.simpleToast(this,resp.data.msg);
  1625. clearInterval(this.locationTimer);
  1626. setTimeout(function () {
  1627. uni.navigateBack({
  1628. delta: 1
  1629. });
  1630. }, 1500);
  1631. }
  1632. }
  1633. );
  1634. }
  1635. },
  1636. bindMarkertap(e) {
  1637. if (e.markerId == 1 || e.markerId == 2) {
  1638. if (e.markerId == 1) {
  1639. var deviceInfo = this.deviceInfo;
  1640. deviceInfo.signalType = this.locationType;
  1641. this.setData({
  1642. deviceInfo: deviceInfo,
  1643. address: this.locationAdress
  1644. });
  1645. }
  1646. if (e.markerId == 2) {
  1647. var deviceInfo = this.deviceInfo;
  1648. deviceInfo.signalType = this.locationGpsType;
  1649. this.setData({
  1650. deviceInfo: deviceInfo,
  1651. address: this.locationGpsAdress
  1652. });
  1653. }
  1654. this.setData({
  1655. showInfo: !this.showInfo
  1656. });
  1657. }
  1658. },
  1659. bindTapMap(e) {
  1660. this.setData({
  1661. showInfo: false
  1662. });
  1663. if (this.selectFence != null) {
  1664. var fence = this.selectFence;
  1665. fence.latitude = e.detail.latitude;
  1666. fence.longitude = e.detail.longitude;
  1667. this.setData({
  1668. selectFence: fence,
  1669. circles: [
  1670. {
  1671. latitude: fence.latitude,
  1672. longitude: fence.longitude,
  1673. radius: parseInt(fence.radius),
  1674. color: '#6495ED1F',
  1675. fillColor: '#6495ED1F',
  1676. strokeWidth: 1
  1677. }
  1678. ]
  1679. });
  1680. }
  1681. },
  1682. bindSendCommand: function (e) {
  1683. this.sendCommand(e.currentTarget.dataset.cmd);
  1684. },
  1685. sendCommand: function (cmd) {
  1686. var me = this
  1687. uni.showModal({
  1688. content: me.$t('确定发送指令吗?'),
  1689. showCancel: true,
  1690. cancelText: me.$t('取消'),
  1691. confirmText: me.$t('确定'),
  1692. success: (res) => {
  1693. console.log(res);
  1694. if (res.confirm) {
  1695. common.loading(me);
  1696. http.postApi(
  1697. config.API_BATTERY_SEND_COMMAND,
  1698. {
  1699. macid: this.macid,
  1700. cmd: cmd
  1701. },
  1702. function (resp) {
  1703. if (resp.data.code === 200) {
  1704. uni.hideLoading();
  1705. common.simpleToast(me,me.$t('操作成功'));
  1706. } else {
  1707. common.simpleToast(me,resp.data.msg);
  1708. }
  1709. }
  1710. );
  1711. }
  1712. },
  1713. fail: function (res) {},
  1714. complete: function (res) {}
  1715. });
  1716. },
  1717. bindTrace() {
  1718. if (this.trace) {
  1719. this.setData({
  1720. trace: false,
  1721. tracePoints: []
  1722. });
  1723. this.setPolylines();
  1724. clearInterval(this.traceTimer);
  1725. } else {
  1726. this.setData({
  1727. trace: true
  1728. });
  1729. this.traceTimer = setInterval(() => {
  1730. this.setData({
  1731. traceTime: this.traceTime + 1
  1732. });
  1733. }, 1000);
  1734. }
  1735. },
  1736. bindNavigate() {
  1737. //使用微信内置地图查看标记点位置,并进行导航
  1738. const latitude = this.latitude;
  1739. const longitude = this.longitude;
  1740. const address = this.address;
  1741. const name = this.deviceInfo.name
  1742. uni.openLocation({
  1743. latitude,
  1744. //要去的纬度-地址
  1745. longitude,
  1746. //要去的经度-地址
  1747. address,
  1748. name,
  1749. scale: 11
  1750. });
  1751. },
  1752. bindCloseTrack() {
  1753. this.setData({
  1754. trackPoints: [],
  1755. trackMarker: [],
  1756. trackStopList: [],
  1757. nowPlayIndex: 0,
  1758. playMarker: []
  1759. });
  1760. this.setMarkers();
  1761. this.setPolylines();
  1762. },
  1763. bindFencePopupOpen() {
  1764. this.setData({
  1765. fencePopupShow: true
  1766. });
  1767. },
  1768. bindFencePopupClose() {
  1769. this.setData({
  1770. fencePopupShow: false
  1771. });
  1772. },
  1773. MoveToFence(event, _dataset) {
  1774. clearInterval(this.locationTimer);
  1775. /* ---处理dataset begin--- */
  1776. this.handleDataset(event, _dataset);
  1777. /* ---处理dataset end--- */
  1778. var map = uni.createMapContext('myMap');
  1779. const fence = Object.assign({}, event.currentTarget.dataset.p);
  1780. this.setData({
  1781. selectFence: fence,
  1782. circles: [
  1783. {
  1784. latitude: fence.latitude,
  1785. longitude: fence.longitude,
  1786. radius: parseInt(fence.radius),
  1787. color: '#6495ED1F',
  1788. fillColor: '#6495ED1F',
  1789. strokeWidth: 1
  1790. }
  1791. ],
  1792. fencePopupShow: false,
  1793. latitude: fence.latitude,
  1794. longitude: fence.longitude
  1795. });
  1796. console.log(this.selectFence,'this.selectFence');
  1797. /*map.moveToLocation({
  1798. latitude: event.currentTarget.dataset.p.latitude,
  1799. longitude: event.currentTarget.dataset.p.longitude
  1800. })*/
  1801. },
  1802. addFence() {
  1803. clearInterval(this.locationTimer);
  1804. var map = uni.createMapContext('myMap');
  1805. map.getCenterLocation({
  1806. success: (res) => {
  1807. const fence = {
  1808. name: '',
  1809. type: '0',
  1810. latitude: res.latitude,
  1811. longitude: res.longitude,
  1812. radius: 100
  1813. };
  1814. console.log(fence,'fence');
  1815. this.setData({
  1816. selectFence: fence,
  1817. circles: [
  1818. {
  1819. latitude: fence.latitude,
  1820. longitude: fence.longitude,
  1821. radius: parseInt(fence.radius),
  1822. color: '#6495ED1F',
  1823. fillColor: '#6495ED1F',
  1824. strokeWidth: 1
  1825. }
  1826. ],
  1827. fencePopupShow: false
  1828. });
  1829. }
  1830. });
  1831. },
  1832. loadFenceList() {
  1833. common.loading(this);
  1834. const deviceInfo = storage.getSelectedDeviceInfo();
  1835. http.postApi(
  1836. config.API_FENCE_LIST,
  1837. {
  1838. macid: deviceInfo.mac_id
  1839. },
  1840. (resp) => {
  1841. uni.hideLoading();
  1842. if (resp.data.code === 200) {
  1843. var fenceList = resp.data.data.list;
  1844. this.setData({
  1845. fenceList: fenceList
  1846. });
  1847. } else {
  1848. common.simpleToast(this,resp.data.msg);
  1849. }
  1850. }
  1851. );
  1852. },
  1853. bindFenceClose() {
  1854. this.locationTimer = setInterval(this.locationLoop, 10000);
  1855. this.setData({
  1856. selectFence: null,
  1857. circles: [],
  1858. fencePopupShow: true
  1859. });
  1860. },
  1861. onFenceNameChange(e) {
  1862. var fence = this.selectFence;
  1863. fence.name = e.detail.value;
  1864. this.setData({
  1865. selectFence: fence
  1866. });
  1867. },
  1868. onFenceTypeChange(e) {
  1869. var fence = this.selectFence;
  1870. fence.type = e.detail.value;
  1871. this.setData({
  1872. selectFence: fence
  1873. });
  1874. },
  1875. onFenceRadiusDrag(e) {
  1876. var fence = this.selectFence;
  1877. fence.radius = e.detail.value;
  1878. this.setData({
  1879. selectFence: fence
  1880. /*circles: [{
  1881. latitude: fence.latitude,
  1882. longitude: fence.longitude,
  1883. radius: parseInt(fence.radius),
  1884. color: '#6495EDBB',
  1885. fillColor: '#6495ED1F',
  1886. strokeWidth: 1
  1887. }],*/
  1888. });
  1889. },
  1890. onFenceRadiusChange(e) {
  1891. var fence = this.selectFence;
  1892. fence.radius = e.detail.value;
  1893. // this.setData({circles:[]})
  1894. var startSlide = new Date().getTime();
  1895. if (startSlide - this.endSlide > 100) {
  1896. this.setData({
  1897. endSlide: startSlide
  1898. });
  1899. this.setData({
  1900. selectFence: fence,
  1901. circles: [
  1902. {
  1903. latitude: fence.latitude,
  1904. longitude: fence.longitude,
  1905. radius: parseInt(fence.radius),
  1906. color: '#6495ED1F',
  1907. fillColor: '#6495ED1F',
  1908. strokeWidth: 1
  1909. }
  1910. ]
  1911. });
  1912. }
  1913. },
  1914. onFenceRadiusMinus() {
  1915. var fence = this.selectFence;
  1916. if (fence.radius > 1) {
  1917. fence.radius = parseInt(fence.radius) - 100;
  1918. this.setData({
  1919. selectFence: fence,
  1920. circles: [
  1921. {
  1922. latitude: fence.latitude,
  1923. longitude: fence.longitude,
  1924. radius: parseInt(fence.radius),
  1925. color: '#6495ED1F',
  1926. fillColor: '#6495ED1F',
  1927. strokeWidth: 1
  1928. }
  1929. ]
  1930. });
  1931. }
  1932. },
  1933. onFenceRadiusPlus() {
  1934. var fence = this.selectFence;
  1935. if (fence.radius < 10000) {
  1936. fence.radius = parseInt(fence.radius) + 100;
  1937. this.setData({
  1938. selectFence: fence,
  1939. circles: [
  1940. {
  1941. latitude: fence.latitude,
  1942. longitude: fence.longitude,
  1943. radius: parseInt(fence.radius),
  1944. color: '#6495ED1F',
  1945. fillColor: '#6495ED1F',
  1946. strokeWidth: 1
  1947. }
  1948. ]
  1949. });
  1950. }
  1951. },
  1952. bindFenceSave() {
  1953. var fence = this.selectFence;
  1954. console.log(fence,'fence');
  1955. if (!fence.name) {
  1956. common.simpleToast(this,this.$t('请输入围栏名称'));
  1957. return;
  1958. }
  1959. if (fence != null) {
  1960. common.loading(this);
  1961. const deviceInfo = storage.getSelectedDeviceInfo();
  1962. console.log(this.selectFence,'selectFence');
  1963. if (fence.id) {
  1964. http.postApi(
  1965. config.API_FENCE_EDIT,
  1966. Object.assign(
  1967. {
  1968. macid: deviceInfo.mac_id,
  1969. id: fence.id,
  1970. type: fence.type.value?fence.type.value-0:fence.type.value,
  1971. name: fence.name,
  1972. latitude: fence.latitude,
  1973. longitude: fence.longitude,
  1974. radius: fence.radius
  1975. },
  1976. // fence
  1977. ),
  1978. (resp) => {
  1979. uni.hideLoading();
  1980. if (resp.data.code === 200) {
  1981. this.loadFenceList();
  1982. } else {
  1983. common.simpleToast(this,resp.data.msg);
  1984. }
  1985. this.setData({
  1986. selectFence: null,
  1987. circles: [],
  1988. fencePopupShow: true
  1989. });
  1990. }
  1991. );
  1992. } else {
  1993. http.postApi(
  1994. config.API_FENCE_ADD,
  1995. Object.assign(
  1996. {
  1997. macid: deviceInfo.mac_id,
  1998. type: fence.type.value-0,
  1999. name: fence.name,
  2000. latitude: fence.latitude,
  2001. longitude: fence.longitude,
  2002. radius: fence.radius
  2003. },
  2004. // fence
  2005. ),
  2006. (resp) => {
  2007. uni.hideLoading();
  2008. if (resp.data.code === 200) {
  2009. this.loadFenceList();
  2010. } else {
  2011. common.simpleToast(this,resp.data.msg);
  2012. }
  2013. this.setData({
  2014. selectFence: null,
  2015. circles: [],
  2016. fencePopupShow: true
  2017. });
  2018. }
  2019. );
  2020. }
  2021. }
  2022. this.locationTimer = setInterval(this.locationLoop, 10000);
  2023. },
  2024. delFence() {
  2025. var fence = this.selectFence;
  2026. if (fence != null && fence.id) {
  2027. common.loading(this);
  2028. const deviceInfo = storage.getSelectedDeviceInfo();
  2029. http.postApi(
  2030. config.API_FENCE_DEL,
  2031. {
  2032. macid: deviceInfo.mac_id,
  2033. id: fence.id
  2034. },
  2035. (resp) => {
  2036. uni.hideLoading();
  2037. if (resp.data.code === 200) {
  2038. this.loadFenceList();
  2039. } else {
  2040. common.simpleToast(this,resp.data.msg);
  2041. }
  2042. this.setData({
  2043. selectFence: null,
  2044. circles: [],
  2045. fencePopupShow: true
  2046. });
  2047. }
  2048. );
  2049. }
  2050. },
  2051. moveToLocation: function () {
  2052. uni.createMapContext("myMap", this).moveToLocation({
  2053. latitude: this.latitude,
  2054. longitude: this.longitude
  2055. });
  2056. // this.mapCtx.moveToLocation();
  2057. //this.setData({ showShopInfo: false, scale: 14 })
  2058. },
  2059. mapChange: function (e) {
  2060. this.setData({
  2061. mapParams: e.detail.mapParams
  2062. });
  2063. }
  2064. }
  2065. };
  2066. </script>
  2067. <style>
  2068. @import './deviceLocal.css';
  2069. </style>