service.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <view class="service-main">
  3. <map @markertap='markertapFn' class="my_app" id="myMap" :longitude="myLocation.longitude"
  4. :latitude="myLocation.latitude" :scale="18" show-location enable-3D show-compass enable-overlooking
  5. :enable-satellite="false" :markers="markers" :polyline="polylines" :enable-traffic="false"
  6. style="width: 100%; height: calc(50vh - 0rpx)">
  7. <block v-for="(item, index) in nearCabinetList" :key="index">
  8. <cover-view v-if="selectType === 'cabinet'" slot="callout" :marker-id="item.id" class="mark blue_bg">
  9. {{ item.available_cnt }}
  10. </cover-view>
  11. </block>
  12. </map>
  13. <!-- 地图控件 -->
  14. <cover-view :class="[
  15. 'control-icon-view',
  16. 'flex-row',
  17. isSearch ? 'flex-between' : 'flex-end',
  18. ]">
  19. <cover-view v-if="isSearch" class="seach-return-view flex-row"><cover-image class="seach-return-img"
  20. src="https://qiniu.bms16.com/Fjpnr3cH9ZqTQrGlw3Ywp3qbJGIG"></cover-image></cover-view>
  21. <!-- <cover-view @tap="moveToLocation" class="current-location-view flex-row"><cover-image
  22. class="current-location-icon"
  23. src="https://qiniu.bms16.com/FgLe8FKDOzgt3wxi2lZt-yQGmbP3"></cover-image></cover-view> -->
  24. </cover-view>
  25. <view class="store-cabinet-block">
  26. <view class="block-p"></view>
  27. <view v-if="isSearch" class="search-view flex-row">
  28. <view class="search-input-view">
  29. <img class="search-icon" src="https://qiniu.bms16.com/FgvJrOE8Lps7tyNL86SOZKbLT1uH" alt="" />
  30. <input v-model="inputSearchValue" type="text" class="search-input" placeholder="请输入搜索内容"
  31. placeholder-class="input-placeholder" :focus="isFocused" @focus="handleFocus"
  32. @blur="handleBlur" />
  33. <img v-if="isFocused" @tap="clearSearch" class="search-close-icon"
  34. src="https://qiniu.bms16.com/FhKzwftEPo70kloqIVxKH7g0pD6I" alt="清空" />
  35. </view>
  36. <view v-if="isFocused" @tap="tapSearch" :class="['search-btn', isFocused ? 'search-btn-i' : '']">搜索
  37. </view>
  38. </view>
  39. <view class="flex-row flex-between" style="margin-bottom: 40rpx">
  40. <view class="check-type flex-row">
  41. <view @tap="tapSelectType" data-type="store" :class="[
  42. 'store-type',
  43. selectType === 'store' ? 'store-type-i' : 'store-type-s',
  44. ]">门店</view>
  45. <view @tap="tapSelectType" data-type="cabinet" :class="[
  46. 'cabinet-type',
  47. selectType === 'cabinet' ? 'cabinet-type-i' : 'cabinet-type-s',
  48. ]">换电柜</view>
  49. </view>
  50. <view class="config-view flex-row">
  51. <view class="seach-img" @tap="openSearch"><img
  52. src="https://qiniu.bms16.com/FiWnFuZm5vWQ_Si3CEYLGJnVhSal" alt="搜索" /></view>
  53. <view @tap="openSelectType" class="screen-img"><img
  54. :src="'https://qiniu.bms16.com/'+(shop_type!=''?'FikPWd13ENc2SWnC3q1n5F22uUDs':'FpElQHM5NbxHDjz1LrwaHYN668LR')"
  55. alt="筛选" /></view>
  56. </view>
  57. </view>
  58. <CarRentalList v-if="selectType === 'store'" :near_store_list="nearCabinetList" />
  59. <CabinetList v-if="selectType === 'cabinet'" :near_cabinet_list="nearCabinetList" />
  60. </view>
  61. <leaseType :showLeaseType="showLeaseType" :selectType="selectType" :modelTypeList="modelTypeList"
  62. @closeSelectType="closeSelectType" @checkCabinetType="checkCabinetType" />
  63. <CustomTabbar curt-tab="service" />
  64. </view>
  65. </template>
  66. <script>
  67. var app = getApp();
  68. var config = require("@/common/config.js");
  69. var config_gyq = require("@/common/config_gyq.js");
  70. var common = require("@/common/common.js");
  71. var http = require("@/common/http.js");
  72. var http_gyq = require("@/common/request.js");
  73. var storage = require("@/common/storage.js");
  74. import LeaseType from "./components/leaseType/leaseType";
  75. import CarRentalList from "./components/carRentalList/carRentalList";
  76. import CabinetList from "./components/cabinetList/cabinetList";
  77. import CustomTabbar from "@/component/customTabbar/index";
  78. import {
  79. LEASE_TYPE_ARR
  80. } from '@/common/constant.js'
  81. const SHOPSELECTIMG = `https://qiniu.bms16.com/FkS7hjd6tl6ydLIi9-SQI0vGboMW`
  82. const CABINET_ICON_URL =
  83. "https://zxappfile.bms16.com/zx_client/shop_mark.png";
  84. const CABINET_ICON_URLS =
  85. "https://qiniu.bms16.com/FmYKRICv7sPvsFuFB3wo9MIkpd0-";
  86. export default {
  87. data() {
  88. return {
  89. activeMarkersId: 0,
  90. myLocation: {
  91. latitude: 23.099994,
  92. longitude: 113.324004,
  93. },
  94. selectType: "store",
  95. nearStoreList: [],
  96. nearCabinetList: [],
  97. markers: [],
  98. polylines: [],
  99. mapContext: null, // map上下文
  100. isSearch: false, //是否处于搜索状态
  101. inputSearchValue: "123",
  102. isFocused: false,
  103. showLeaseType: false,
  104. modelTypeList: [],
  105. shop_type: ''
  106. };
  107. },
  108. components: {
  109. LeaseType,
  110. CarRentalList,
  111. CabinetList,
  112. CustomTabbar,
  113. },
  114. /**
  115. * 生命周期函数--监听页面加载
  116. */
  117. onLoad: function(options) {
  118. this.loadModelType();
  119. this.locationFn()
  120. // this.nearStoreOrCabinetList = [
  121. // {
  122. // id:1,
  123. // latitude:'',
  124. // longitude:'',
  125. // iconPath:"",
  126. // width:"",
  127. // height:"",
  128. // label:{
  129. // content:"",
  130. // color:"#333",
  131. // bgColor:"#fff",
  132. // borderRadius:10,
  133. // padding:10
  134. // }
  135. // }
  136. // ]
  137. },
  138. methods: {
  139. markertapFn(e) {
  140. let markerId = e.markerId
  141. if (markerId == 5000) return
  142. if (this.selectType == 'store') {
  143. this.markers.map(item => {
  144. if (markerId == item.id) {
  145. item.iconPath = SHOPSELECTIMG
  146. let distance = common.getFlatternDistance(this.myLocation.longitude, this.myLocation
  147. .latitude, item.longitude, item.latitude)
  148. let time = Math.ceil(Number(((distance - 0) / 1000).toFixed(2)) * 25 / 10)
  149. let content = `${common.formatDistance(Number(distance))} 骑行${time}分钟`
  150. item.label = {
  151. content,
  152. color: "#0074FF",
  153. fontSize: 10,
  154. bgColor: "#fff",
  155. borderRadius: 10,
  156. padding: 5,
  157. anchorX: -45,
  158. anchorY: -6
  159. }
  160. this.activeMarkersId = item.id
  161. } else {
  162. item.iconPath = CABINET_ICON_URL
  163. item.label = {}
  164. }
  165. })
  166. }else if(this.selectType == 'cabinet'){
  167. }
  168. },
  169. async locationFn() {
  170. let res = await uni.getLocation()
  171. if (res[1]) {
  172. this.myLocation = {
  173. latitude: res[1].latitude,
  174. longitude: res[1].longitude,
  175. }
  176. this.loadCarRentalList();
  177. }
  178. },
  179. tapSelectType(e) {
  180. const {
  181. type
  182. } = e.currentTarget.dataset;
  183. this.nearCabinetList = []
  184. this.setData({
  185. selectType: type,
  186. });
  187. if (type === "store") {
  188. this.loadCarRentalList();
  189. } else {
  190. this.loadNearCabinetList();
  191. }
  192. },
  193. //附近门店列表
  194. loadCarRentalList(name = '', shop_type = '') {
  195. const pData = {
  196. limit: 50,
  197. longitude: this.myLocation.longitude,
  198. latitude: this.myLocation.latitude,
  199. name,
  200. shop_type
  201. };
  202. const me = this;
  203. var nearCabinetList = [];
  204. console.log(99999)
  205. http.postApi(config.API_NEAR_SHOP_LIST, pData, (resp) => {
  206. if (resp.data.code == 200) {
  207. me.markers = []
  208. nearCabinetList = resp.data.data.list || [];
  209. // if (nearCabinetList.length != 0) {
  210. // nearCabinetList.forEach((store, index) => {
  211. // store.width = 50;
  212. // store.height = 52;
  213. // store.available_cnt = 2;
  214. // store.id = 100000 + (store.id - 0);
  215. // store.type = "SHOP";
  216. // store.iconPath = CABINET_ICON_URL;
  217. // });
  218. // }
  219. this.markers = nearCabinetList.map(item => {
  220. return {
  221. width: 50,
  222. height: 52,
  223. id: Number(item.id),
  224. longitude: item.longitude,
  225. latitude: item.latitude,
  226. iconPath: CABINET_ICON_URL,
  227. // label:{
  228. // content:"21",
  229. // color:"#0074FF",
  230. // fontSize:10,
  231. // bgColor:"#fff",
  232. // borderRadius:1000,
  233. // padding:3,
  234. // anchorX:0,
  235. // anchorY:-50
  236. // }
  237. }
  238. })
  239. this.getLocationPostion(this.myLocation, nearCabinetList);
  240. console.log(nearCabinetList, "nearCabinetList");
  241. me.setData({
  242. nearCabinetList: nearCabinetList,
  243. });
  244. } else {
  245. common.simpleToast(resp.data.msg);
  246. }
  247. });
  248. },
  249. //附近机柜列表
  250. async loadNearCabinetList(name = '') {
  251. const pData = {
  252. limit: 50,
  253. longitude: this.myLocation.longitude,
  254. latitude: this.myLocation.latitude,
  255. name
  256. };
  257. const me = this;
  258. var nearCabinetList = [];
  259. let {data} = await http_gyq.postApi(config_gyq.API_FLK_CABINET_NEAR_LIST,pData)
  260. if (data.code === 200) {
  261. nearCabinetList = data.data.cabinetList || [];
  262. this.markers = nearCabinetList.map(item=>{
  263. return {
  264. width: 50,
  265. height: 52,
  266. id: Number(item.id),
  267. longitude: item.longitude,
  268. latitude: item.latitude,
  269. iconPath: CABINET_ICON_URLS,
  270. label:{
  271. content:"21",
  272. color:"#0074FF",
  273. fontSize:10,
  274. bgColor:"#fff",
  275. borderRadius:1000,
  276. padding:3,
  277. anchorX:0,
  278. anchorY:-50
  279. }
  280. }
  281. })
  282. this.getLocationPostion(this.myLocation, nearCabinetList);
  283. me.setData({
  284. nearCabinetList: nearCabinetList,
  285. });
  286. } else {
  287. common.simpleToast(data.msg);
  288. }
  289. },
  290. getLocationPostion(centerLocation, nearCabinetList) {
  291. const locationData = {
  292. longitude: centerLocation.longitude,
  293. latitude: centerLocation.latitude,
  294. width: 22,
  295. height: 40,
  296. id: 50000,
  297. iconPath: "https://zxappfile.bms16.com/zx_client/location_n.png",
  298. model_list: [],
  299. };
  300. this.markers.push(locationData);
  301. },
  302. moveToLocation() {
  303. // 将marker移动至中心点
  304. const mapContext = uni.createMapContext("myMap", this);
  305. this.mapContext = mapContext;
  306. this.mapContext.moveToLocation({
  307. longitude: this.myLocation.longitude,
  308. latitude: this.myLocation.latitude,
  309. success: (res) => {
  310. console.log("marker已移动至中心点");
  311. },
  312. });
  313. },
  314. handleFocus() {
  315. this.isFocused = true;
  316. },
  317. handleBlur() {
  318. this.isFocused = false;
  319. },
  320. clearSearch() {
  321. this.setData({
  322. inputSearchValue: "",
  323. });
  324. },
  325. openSearch() {
  326. this.isSearch = true;
  327. this.isFocused = true;
  328. },
  329. openSelectType() {
  330. this.setData({
  331. showLeaseType: true,
  332. });
  333. },
  334. closeSelectType() {
  335. this.setData({
  336. showLeaseType: false,
  337. });
  338. },
  339. tapSearch() {
  340. if (this.selectType === 'store') {
  341. this.loadCarRentalList(this.inputSearchValue)
  342. } else {
  343. this.loadNearCabinetList(this.inputSearchValue)
  344. }
  345. },
  346. checkCabinetType(e) {
  347. console.log(e, "e");
  348. const obj = LEASE_TYPE_ARR.find(v => v.value == e)
  349. const shop_type = (e == 100) ? '' : obj.type
  350. this.setData({
  351. showLeaseType: false,
  352. shop_type
  353. });
  354. this.loadCarRentalList('', shop_type)
  355. },
  356. loadModelType() {
  357. const me = this
  358. http.postApi(config.API_NEAR_BATTERY_TYPE_LIST, {}, (resp) => {
  359. if (resp.data.code === 200) {
  360. me.setData({
  361. modelTypeList: resp.data.data.list
  362. })
  363. } else {
  364. common.simpleToast(resp.data.msg);
  365. }
  366. });
  367. },
  368. },
  369. };
  370. </script>
  371. <style>
  372. @import "./service.css";
  373. </style>