service.vue 14 KB

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