service.vue 14 KB

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