service.vue 13 KB

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