service.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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. <!-- {{ $t('地图控件') }} -->
  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="$t('请输入搜索内容')"
  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" />
  41. </view>
  42. <view v-if="isFocused" @tap="tapSearch" :class="['search-btn', isFocused ? 'search-btn-i' : '']">{{ $t('搜索') }}
  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. ]">{{ $t('门店') }}</view>
  51. <view @tap="tapSelectType" data-type="cabinet" :class="[
  52. 'cabinet-type',
  53. selectType === 'cabinet' ? 'cabinet-type-i' : 'cabinet-type-s',
  54. ]">{{ $t('换电柜') }}</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 ? '+' + $t('购买') : ''}}</text>
  59. <text v-if="selectType === 'cabinet'" class="text">{{cabinetType ? cabinetType : $t('全部')}}</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" /></view>
  65. <!-- <view @tap="openSelectType" class="screen-img"><img
  66. :src="'https://qiniu.bms16.com/'+(shop_type!=''?'FikPWd13ENc2SWnC3q1n5F22uUDs':'FpElQHM5NbxHDjz1LrwaHYN668LR')"
  67. alt="{{ $t('筛选') }}" /></view> -->
  68. </view>
  69. </view>
  70. <CarRentalList :isBuy='isBuy' :shopType='shopType' :activeMarkersId='activeMarkersId' v-if="selectType === 'store'" :near_store_list="nearCabinetList" />
  71. <CabinetList :activeMarkersId='activeMarkersId' 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(this.type == 1){
  154. if (item.id == e.id) {
  155. index = i
  156. break
  157. }
  158. }
  159. if(this.type == 2){
  160. if (item.dev_id == e.id) {
  161. index = i
  162. break
  163. }
  164. }
  165. }
  166. this.nearCabinetList.unshift(this.nearCabinetList.splice(index, 1)[0])
  167. this.$forceUpdate()
  168. },
  169. locationFn() {
  170. let _this = this
  171. if (this.selectType === "store") {
  172. this.loadCarRentalList();
  173. } else {
  174. this.loadNearCabinetList();
  175. }
  176. },
  177. tapSelectType(e) {
  178. const {
  179. type
  180. } = e.currentTarget.dataset;
  181. this.nearCabinetList = []
  182. this.setData({
  183. selectType: type,
  184. });
  185. this.type = type == 'store' ? 1 : 2
  186. if (type === "store") {
  187. this.loadCarRentalList();
  188. } else {
  189. this.loadNearCabinetList();
  190. }
  191. },
  192. //附近门店列表
  193. loadCarRentalList(name = '') {
  194. const pData = {
  195. limit: 50,
  196. longitude: this.myLocation.longitude,
  197. latitude: this.myLocation.latitude,
  198. name,
  199. shop_type:'',
  200. duration_unit:this.shopType
  201. };
  202. const me = this;
  203. let nearCabinetList = [];
  204. http.postApi(config.API_NEAR_SHOP_LIST, pData, (resp) => {
  205. if (resp.data.code == 200) {
  206. me.markers = {}
  207. let markers = {
  208. markers: []
  209. }
  210. for (let index = 0; index < resp.data.data.list.length; index++) {
  211. let element = resp.data.data.list[index];
  212. element.distance = common.formatDistance(common.getFlatternDistance(this.myLocation
  213. .longitude, this
  214. .myLocation.latitude, element.longitude, element.latitude))
  215. let model_list = []
  216. for (let y = 0; y < element.model_list.length; y++) {
  217. let item = element.model_list[y];
  218. item.model_images = item.model_images.split(',')[0] || ''
  219. let price_setting = []
  220. for (let i = 0; i < item.price_setting.length; i++) {
  221. let items1 = item.price_setting[i];
  222. if(items1.hire_duration_unit == this.shopType){
  223. item.hire_price = items1.hire_price
  224. model_list.push(item)
  225. }
  226. }
  227. }
  228. nearCabinetList.push({
  229. ...element,
  230. model_list
  231. })
  232. }
  233. markers.markers = nearCabinetList.map(item => {
  234. return {
  235. width: 50,
  236. height: 52,
  237. id: Number(item.id),
  238. longitude: item.longitude,
  239. latitude: item.latitude,
  240. iconPath: CABINET_ICON_URL,
  241. iconPathActive: SHOPSELECTIMG,
  242. content: '233'
  243. }
  244. })
  245. this.getLocationPostion(this.myLocation, markers);
  246. this.nearCabinetList = nearCabinetList
  247. } else {
  248. common.simpleToast(resp.data.msg);
  249. }
  250. });
  251. },
  252. //附近机柜列表
  253. async loadNearCabinetList(cabinet_name = '') {
  254. const pData = {
  255. limit: 50,
  256. longitude: this.myLocation.longitude,
  257. latitude: this.myLocation.latitude,
  258. cabinet_name
  259. };
  260. const me = this;
  261. let nearCabinetList = [];
  262. let {
  263. data
  264. } = await http_gyq.postApi(config_gyq.API_FLK_CABINET_NEAR_LIST, pData)
  265. if (data.code === 200) {
  266. this.markers = {}
  267. // nearCabinetList = data.data.cabinetList || [];
  268. for (let i = 0; i < data.data.cabinetList.length; i++) {
  269. let item = data.data.cabinetList[i];
  270. item.distance = common.formatDistance(common.getFlatternDistance(this.myLocation
  271. .longitude, this
  272. .myLocation.latitude, item.longitude, item.latitude))
  273. if(this.cabinetType){
  274. for (let i = 0; i < item.tag_code.length; i++) {
  275. let items = item.tag_code[i];
  276. if(items.main_tag_name == this.cabinetType || items.child_tag_name == this.cabinetType){
  277. nearCabinetList.push(item)
  278. }
  279. }
  280. }else{
  281. nearCabinetList.push(item)
  282. }
  283. }
  284. let markers = {}
  285. markers.markers = nearCabinetList.map(item => {
  286. return {
  287. width: 56,
  288. height: 56,
  289. id: Number(item.dev_id),
  290. longitude: item.longitude,
  291. latitude: item.latitude,
  292. iconPath: CABINET_ICON_URLS,
  293. iconPathActive: CABINET_ICON_URLS,
  294. content: '233'
  295. }
  296. })
  297. this.getLocationPostion(this.myLocation, markers);
  298. me.setData({
  299. nearCabinetList: nearCabinetList,
  300. });
  301. } else {
  302. common.simpleToast(data.msg);
  303. }
  304. },
  305. getLocationPostion(centerLocation, markers) {
  306. const locationData = {
  307. longitude: centerLocation.longitude,
  308. latitude: centerLocation.latitude,
  309. width: 22,
  310. height: 40,
  311. id: 50000,
  312. iconPath: "https://zxappfile.bms16.com/zx_client/location_n.png",
  313. model_list: [],
  314. };
  315. markers.markers.push(locationData);
  316. markers.type = this.type
  317. this.markers = markers
  318. console.log(this.markers)
  319. },
  320. moveToLocation() {
  321. // 将marker移动至中心点
  322. const mapContext = uni.createMapContext("myMap", this);
  323. this.mapContext = mapContext;
  324. this.mapContext.moveToLocation({
  325. longitude: this.myLocation.longitude,
  326. latitude: this.myLocation.latitude,
  327. success: (res) => {
  328. console.log("marker已移动至中心点");
  329. },
  330. });
  331. },
  332. handleFocus() {
  333. this.isFocused = true;
  334. },
  335. handleBlur() {
  336. // this.isFocused = false;
  337. },
  338. clearSearch() {
  339. this.setData({
  340. inputSearchValue: "",
  341. });
  342. },
  343. openSearch() {
  344. this.isSearch = !this.isSearch;
  345. if(this.isSearch == false){
  346. this.inputSearchValue = ''
  347. }
  348. this.isFocused = true;
  349. },
  350. openSelectType() {
  351. this.setData({
  352. showLeaseType: true,
  353. });
  354. },
  355. closeSelectType() {
  356. this.setData({
  357. showLeaseType: false,
  358. });
  359. },
  360. tapSearch() {
  361. if (this.selectType === 'store') {
  362. this.loadCarRentalList(this.inputSearchValue)
  363. } else {
  364. this.loadNearCabinetList(this.inputSearchValue)
  365. }
  366. },
  367. checkCabinetType(e) {
  368. if(e.selectType == "store"){
  369. this.isBuy = e.isBuy
  370. this.shopType = e.leaseType
  371. this.showLeaseType = false
  372. this.loadCarRentalList()
  373. }else{
  374. this.cabinetType = e.leaseType
  375. this.showLeaseType = false
  376. this.loadNearCabinetList()
  377. }
  378. // console.log(e, "e");
  379. // const obj = LEASE_TYPE_ARR.find(v => v.value == e)
  380. // const shop_type = (e == 100) ? '' : obj.type
  381. // this.setData({
  382. // showLeaseType: false,
  383. // shop_type
  384. // });
  385. // this.loadCarRentalList('', shop_type)
  386. },
  387. shopList(list){
  388. let nearCabinetList = []
  389. for (let i = 0; i < list.length; i++) {
  390. let item = list[i];
  391. for (var index = 0; index < item.model_list.length; index++) {
  392. var items = item.model_list[index];
  393. for (var s = 0; s < items.price_setting.length; s++) {
  394. var element = items.price_setting[s];
  395. if(element.hire_duration_unit == this.shopType){
  396. items.hire_price = element.hire_price
  397. }
  398. }
  399. }
  400. nearCabinetList.push(item)
  401. }
  402. this.nearCabinetList = nearCabinetList
  403. },
  404. loadModelType() {
  405. const me = this
  406. http.postApi(config.API_NEAR_BATTERY_TYPE_LIST, {}, (resp) => {
  407. if (resp.data.code === 200) {
  408. me.setData({
  409. modelTypeList: resp.data.data.list
  410. })
  411. } else {
  412. common.simpleToast(resp.data.msg);
  413. }
  414. });
  415. },
  416. },
  417. };
  418. </script>
  419. <style>
  420. @import "./service.css";
  421. .selectFlex{
  422. align-items: center;
  423. margin-right: 20rpx;
  424. }
  425. .selectFlex .text{
  426. font-family: PingFangSC, PingFang SC;
  427. font-weight: 500;
  428. font-size: 32rpx;
  429. color: #060809;
  430. margin-right: 10rpx;
  431. }
  432. </style>