service.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view class="service-main">
  3. <map
  4. class="my_app"
  5. id="myMap"
  6. :longitude="myLocation.longitude"
  7. :latitude="myLocation.latitude"
  8. :scale="14"
  9. show-location
  10. enable-3D
  11. show-compass
  12. enable-overlooking
  13. :enable-satellite="false"
  14. :markers="nearStoreOrCabinetList"
  15. :polyline="polylines"
  16. :enable-traffic="false"
  17. style="width: 100%; height: calc(50vh - 0rpx)"
  18. >
  19. <block v-for="(item, index) in nearStoreOrCabinetList" :key="index">
  20. <cover-view
  21. v-if="selectType === 'cabinet'"
  22. slot="callout"
  23. :marker-id="item.id"
  24. class="mark blue_bg"
  25. >
  26. {{ item.available_cnt }}
  27. </cover-view>
  28. </block>
  29. </map>
  30. <!-- 地图控件 -->
  31. <cover-view
  32. :class="[
  33. 'control-icon-view',
  34. 'flex-row',
  35. isSearch ? 'flex-between' : 'flex-end',
  36. ]"
  37. >
  38. <cover-view v-if="isSearch" class="seach-return-view flex-row"
  39. ><cover-image
  40. class="seach-return-img"
  41. src="https://qiniu.bms16.com/Fjpnr3cH9ZqTQrGlw3Ywp3qbJGIG"
  42. ></cover-image
  43. ></cover-view>
  44. <cover-view @tap="moveToLocation" class="current-location-view flex-row"
  45. ><cover-image
  46. class="current-location-icon"
  47. src="https://qiniu.bms16.com/FgLe8FKDOzgt3wxi2lZt-yQGmbP3"
  48. ></cover-image
  49. ></cover-view>
  50. </cover-view>
  51. <view class="store-cabinet-block">
  52. <view class="block-p"></view>
  53. <view v-if="isSearch" class="search-view flex-row">
  54. <view class="search-input-view">
  55. <img
  56. class="search-icon"
  57. src="https://qiniu.bms16.com/FgvJrOE8Lps7tyNL86SOZKbLT1uH"
  58. alt=""
  59. />
  60. <input
  61. v-model="inputSearchValue"
  62. type="text"
  63. class="search-input"
  64. placeholder="请输入搜索内容"
  65. placeholder-class="input-placeholder"
  66. :focus="isFocused"
  67. @focus="handleFocus"
  68. @blur="handleBlur"
  69. />
  70. <img
  71. v-if="isFocused"
  72. @tap="clearSearch"
  73. class="search-close-icon"
  74. src="https://qiniu.bms16.com/FhKzwftEPo70kloqIVxKH7g0pD6I"
  75. alt="清空"
  76. />
  77. </view>
  78. <view
  79. v-if="isFocused"
  80. @tap="tapSearch"
  81. :class="['search-btn', isFocused ? 'search-btn-i' : '']"
  82. >搜索</view
  83. >
  84. </view>
  85. <view class="flex-row flex-between" style="margin-bottom: 40rpx">
  86. <view class="check-type flex-row">
  87. <view
  88. @tap="tapSelectType"
  89. data-type="store"
  90. :class="[
  91. 'store-type',
  92. selectType === 'store' ? 'store-type-i' : 'store-type-s',
  93. ]"
  94. >门店</view
  95. >
  96. <view
  97. @tap="tapSelectType"
  98. data-type="cabinet"
  99. :class="[
  100. 'cabinet-type',
  101. selectType === 'cabinet' ? 'cabinet-type-i' : 'cabinet-type-s',
  102. ]"
  103. >换电柜</view
  104. >
  105. </view>
  106. <view class="config-view flex-row">
  107. <view class="seach-img" @tap="openSearch"
  108. ><img
  109. src="https://qiniu.bms16.com/FiWnFuZm5vWQ_Si3CEYLGJnVhSal"
  110. alt="搜索"
  111. /></view>
  112. <view @tap="openSelectType" class="screen-img"
  113. ><img
  114. :src="'https://qiniu.bms16.com/'+(shop_type!=''?'FikPWd13ENc2SWnC3q1n5F22uUDs':'FpElQHM5NbxHDjz1LrwaHYN668LR')"
  115. alt="筛选"
  116. /></view>
  117. </view>
  118. </view>
  119. <CarRentalList
  120. v-if="selectType === 'store'"
  121. :near_store_list="nearStoreList"
  122. />
  123. <CabinetList
  124. v-if="selectType === 'cabinet'"
  125. :near_cabinet_list="nearCabinetList"
  126. />
  127. </view>
  128. <leaseType
  129. :showLeaseType="showLeaseType"
  130. :selectType="selectType"
  131. :modelTypeList="modelTypeList"
  132. @closeSelectType="closeSelectType"
  133. @checkCabinetType="checkCabinetType"
  134. />
  135. <CustomTabbar curt-tab="service" />
  136. </view>
  137. </template>
  138. <script>
  139. var app = getApp();
  140. var config = require("@/common/config.js");
  141. var common = require("@/common/common.js");
  142. var http = require("@/common/http.js");
  143. var storage = require("@/common/storage.js");
  144. import LeaseType from "./components/leaseType/leaseType";
  145. import CarRentalList from "./components/carRentalList/carRentalList";
  146. import CabinetList from "./components/cabinetList/cabinetList";
  147. import CustomTabbar from "@/component/customTabbar/index";
  148. import {LEASE_TYPE_ARR} from '@/common/constant.js'
  149. export default {
  150. data() {
  151. return {
  152. myLocation: {
  153. latitude: 23.099994,
  154. longitude: 113.324004,
  155. },
  156. selectType: "store",
  157. nearStoreList: [],
  158. nearCabinetList: [],
  159. polylines: [],
  160. mapContext: null, // map上下文
  161. isSearch: false, //是否处于搜索状态
  162. inputSearchValue: "123",
  163. isFocused: false,
  164. showLeaseType: false,
  165. modelTypeList:[],
  166. shop_type:''
  167. };
  168. },
  169. components: {
  170. LeaseType,
  171. CarRentalList,
  172. CabinetList,
  173. CustomTabbar,
  174. },
  175. /**
  176. * 生命周期函数--监听页面加载
  177. */
  178. onLoad: function (options) {
  179. this.loadCarRentalList();
  180. this.loadModelType();
  181. },
  182. methods: {
  183. tapSelectType(e) {
  184. const { type } = e.currentTarget.dataset;
  185. this.setData({
  186. selectType: type,
  187. });
  188. if (type === "store") {
  189. this.loadCarRentalList();
  190. } else {
  191. this.loadNearCabinetList();
  192. }
  193. },
  194. //附近门店列表
  195. loadCarRentalList(name='',shop_type='') {
  196. const pData = {
  197. limit: 10,
  198. longitude: this.myLocation.longitude,
  199. latitude: this.myLocation.latitude,
  200. name,
  201. shop_type
  202. };
  203. const me = this;
  204. var nearCabinetList = [];
  205. const CABINET_ICON_URL =
  206. "https://zxappfile.bms16.com/zx_client/shop_mark.png";
  207. http.postApi(config.API_NEAR_SHOP_LIST, pData, (resp) => {
  208. if (resp.data.code === 200) {
  209. nearCabinetList = resp.data.data.list || [];
  210. if (nearCabinetList.length != 0) {
  211. nearCabinetList.forEach((store, index) => {
  212. store.width = 50;
  213. store.height = 52;
  214. store.available_cnt = 2;
  215. store.id = 100000 + (store.id - 0);
  216. store.type = "SHOP";
  217. store.iconPath = CABINET_ICON_URL;
  218. });
  219. }
  220. this.getLocationPostion(this.myLocation, nearCabinetList);
  221. console.log(nearCabinetList, "nearCabinetList");
  222. me.setData({
  223. nearStoreList: nearCabinetList,
  224. });
  225. } else {
  226. common.simpleToast(resp.data.msg);
  227. }
  228. });
  229. },
  230. //附近机柜列表
  231. loadNearCabinetList(name='') {
  232. const pData = {
  233. limit: 10,
  234. longitude: this.myLocation.longitude,
  235. latitude: this.myLocation.latitude,
  236. name
  237. };
  238. const CABINET_ICON_URL =
  239. "https://qiniu.bms16.com/FktjmQ4rGZqYVj6taEtjown-_k5x";
  240. const me = this;
  241. var nearCabinetList = [];
  242. http.postApi(config.API_NEAR_CABINET_LIST, pData, (resp) => {
  243. if (resp.data.code === 200) {
  244. nearCabinetList = resp.data.data.cabinetList || [];
  245. if (nearCabinetList.length !== 0) {
  246. nearCabinetList.forEach((cabinet, index) => {
  247. cabinet.width = 50;
  248. cabinet.height = 52;
  249. cabinet.available_cnt = 2;
  250. cabinet.id = 100000 + (cabinet.cabinet_id - 0);
  251. cabinet.type = "SHOP";
  252. cabinet.iconPath = CABINET_ICON_URL;
  253. });
  254. }
  255. this.getLocationPostion(this.myLocation, nearCabinetList);
  256. me.setData({
  257. nearCabinetList: nearCabinetList,
  258. });
  259. } else {
  260. common.simpleToast(resp.data.msg);
  261. }
  262. });
  263. },
  264. getLocationPostion(centerLocation, nearCabinetList) {
  265. const locationData = {
  266. longitude: centerLocation.longitude,
  267. latitude: centerLocation.latitude,
  268. width: 22,
  269. height: 40,
  270. id: 50000,
  271. iconPath: "https://zxappfile.bms16.com/zx_client/location_n.png",
  272. model_list: [],
  273. };
  274. nearCabinetList.push(locationData);
  275. },
  276. moveToLocation() {
  277. // 将marker移动至中心点
  278. const mapContext = uni.createMapContext("myMap", this);
  279. this.mapContext = mapContext;
  280. this.mapContext.moveToLocation({
  281. longitude: this.myLocation.longitude,
  282. latitude: this.myLocation.latitude,
  283. success: (res) => {
  284. console.log("marker已移动至中心点");
  285. },
  286. });
  287. },
  288. handleFocus() {
  289. this.isFocused = true;
  290. },
  291. handleBlur() {
  292. this.isFocused = false;
  293. },
  294. clearSearch() {
  295. this.setData({
  296. inputSearchValue: "",
  297. });
  298. },
  299. openSearch() {
  300. this.isSearch = true;
  301. this.isFocused = true;
  302. },
  303. openSelectType() {
  304. this.setData({
  305. showLeaseType: true,
  306. });
  307. },
  308. closeSelectType() {
  309. this.setData({
  310. showLeaseType: false,
  311. });
  312. },
  313. tapSearch(){
  314. if(this.selectType==='store'){
  315. this.loadCarRentalList(this.inputSearchValue)
  316. }else{
  317. this.loadNearCabinetList(this.inputSearchValue)
  318. }
  319. },
  320. checkCabinetType(e) {
  321. console.log(e, "e");
  322. const obj = LEASE_TYPE_ARR.find(v => v.value == e)
  323. const shop_type= (e==100) ? '' : obj.type
  324. this.setData({
  325. showLeaseType: false,
  326. shop_type
  327. });
  328. this.loadCarRentalList('',shop_type)
  329. },
  330. loadModelType() {
  331. const me=this
  332. http.postApi(config.API_NEAR_BATTERY_TYPE_LIST, {}, (resp) => {
  333. if (resp.data.code === 200) {
  334. me.setData({
  335. modelTypeList:resp.data.data.list
  336. })
  337. } else {
  338. common.simpleToast(resp.data.msg);
  339. }
  340. });
  341. },
  342. },
  343. };
  344. </script>
  345. <style>
  346. @import "./service.css";
  347. </style>