service.vue 14 KB

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