service.vue 11 KB

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