| | |
| | | "use strict"; |
| | | /* WEBPACK VAR INJECTION */(function(uni) { |
| | | |
| | | var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4); |
| | | Object.defineProperty(exports, "__esModule", { |
| | | value: true |
| | | }); |
| | | exports.default = void 0; |
| | | var _regenerator = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/regenerator */ 30)); |
| | | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/toConsumableArray */ 18)); |
| | | var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ 32)); |
| | | var _utils = __webpack_require__(/*! @/utils/utils.js */ 194); |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | | // |
| | |
| | | var _default = { |
| | | data: function data() { |
| | | return { |
| | | type: null, |
| | | show: false, |
| | | latitude: '', |
| | | longitude: '', |
| | | markers: [], |
| | | info: {}, |
| | | rice: '' |
| | | rice: '', |
| | | eleBusinessArea: [] |
| | | }; |
| | | }, |
| | | onLoad: function onLoad() { |
| | | onLoad: function onLoad(options) { |
| | | this.type = options.type; |
| | | this.getAddress(); |
| | | }, |
| | | methods: { |
| | |
| | | } |
| | | }); |
| | | }, |
| | | getEleBikeList: function getEleBikeList() { |
| | | var _this = this; |
| | | return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() { |
| | | var res; |
| | | return _regenerator.default.wrap(function _callee$(_context) { |
| | | while (1) { |
| | | switch (_context.prev = _context.next) { |
| | | case 0: |
| | | _context.next = 2; |
| | | return _this.$u.api.eleBikeList({}); |
| | | case 2: |
| | | res = _context.sent; |
| | | if (res.code === 200) { |
| | | res.data.forEach(function (item, index) { |
| | | var num = (0, _utils.distance)(_this.latitude, _this.longitude, item.latitude, item.longitude); |
| | | _this.markers.push({ |
| | | id: index, |
| | | width: 40, |
| | | height: 40, |
| | | distance: _this.latitude && _this.longitude ? num : '未知距离', |
| | | latitude: item.latitude, |
| | | longitude: item.longitude, |
| | | title: item.name, |
| | | iconPath: '/static/icon/ic_bike@2x.png', |
| | | customCallout: { |
| | | anchorY: 0, |
| | | anchorX: 0, |
| | | display: 'BYCLICK' |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | case 4: |
| | | case "end": |
| | | return _context.stop(); |
| | | } |
| | | } |
| | | }, _callee); |
| | | }))(); |
| | | }, |
| | | // 定位获取 |
| | | fnGetlocation: function fnGetlocation() { |
| | | var that = this; |
| | |
| | | success: function success(res) { |
| | | that.latitude = res.latitude; |
| | | that.longitude = res.longitude; |
| | | that.getSite(); |
| | | if (that.type == 1) { |
| | | console.log('自行车'); |
| | | that.getSite(); |
| | | } else { |
| | | console.log('电动车'); |
| | | that.getEleBikeList(); |
| | | that.getEleSiteList(); |
| | | } |
| | | }, |
| | | fail: function fail(err) { |
| | | if (err.errMsg === "getLocation:fail 频繁调用会增加电量损耗,可考虑使用 wx.onLocationChange 监听地理位置变化") { |
| | |
| | | } |
| | | }); |
| | | }, |
| | | // 获取范围 |
| | | getEleSiteList: function getEleSiteList() { |
| | | var _this2 = this; |
| | | return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() { |
| | | var array, quan, arrs, res; |
| | | return _regenerator.default.wrap(function _callee2$(_context2) { |
| | | while (1) { |
| | | switch (_context2.prev = _context2.next) { |
| | | case 0: |
| | | array = []; |
| | | _context2.next = 3; |
| | | return _this2.$u.api.getEleBusinessArea({}); |
| | | case 3: |
| | | quan = _context2.sent; |
| | | if (quan.code === 200) { |
| | | arrs = JSON.parse(quan.data); |
| | | array.push({ |
| | | points: arrs.map(function (item) { |
| | | return { |
| | | latitude: item.lat, |
| | | longitude: item.lng |
| | | }; |
| | | }), |
| | | fillColor: "#0077FF12", |
| | | strokeColor: "#0077FF", |
| | | strokeWidth: 3, |
| | | zIndex: 7 |
| | | }); |
| | | } |
| | | _context2.next = 7; |
| | | return _this2.$u.api.eleSiteList({}); |
| | | case 7: |
| | | res = _context2.sent; |
| | | if (res.code === 200) { |
| | | res.data.forEach(function (item) { |
| | | var arr = JSON.parse(item.electronicFence); |
| | | item.electronicFence = arr.map(function (data) { |
| | | return { |
| | | latitude: data.lat, |
| | | longitude: data.lng |
| | | }; |
| | | }); |
| | | }); |
| | | _this2.eleBusinessArea = res.data.map(function (item) { |
| | | return { |
| | | points: item.electronicFence, |
| | | title: item.name, |
| | | fillColor: "#0077FF4D", |
| | | strokeColor: "#0077FF", |
| | | strokeWidth: 3, |
| | | zIndex: 7 |
| | | }; |
| | | }); |
| | | _this2.eleBusinessArea.forEach(function (item) { |
| | | var _this2$calculatePolyg = _this2.calculatePolygonCenter(item.points), |
| | | latitude = _this2$calculatePolyg.latitude, |
| | | longitude = _this2$calculatePolyg.longitude; |
| | | var num = (0, _utils.distance)(_this2.latitude, _this2.longitude, latitude, longitude); |
| | | _this2.markers.push({ |
| | | id: Math.floor(Math.random() * 900) + 100, |
| | | width: 30, |
| | | height: 40, |
| | | isShow: false, |
| | | title: item.title, |
| | | distance: _this2.latitude && _this2.longitude ? num : '未知距离', |
| | | latitude: latitude, |
| | | longitude: longitude, |
| | | iconPath: '/static/icon/ic_park@2x.png', |
| | | customCallout: { |
| | | anchorY: 0, |
| | | anchorX: 0, |
| | | display: 'BYCLICK' |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | _this2.eleBusinessArea = [].concat(array, (0, _toConsumableArray2.default)(_this2.eleBusinessArea)); |
| | | case 10: |
| | | case "end": |
| | | return _context2.stop(); |
| | | } |
| | | } |
| | | }, _callee2); |
| | | }))(); |
| | | }, |
| | | // 计算多边形中心点 |
| | | calculatePolygonCenter: function calculatePolygonCenter(polygonPoints) { |
| | | var x = 0, |
| | | y = 0; |
| | | var numPoints = polygonPoints.length; |
| | | for (var i = 0; i < numPoints; i++) { |
| | | x += polygonPoints[i].latitude; |
| | | y += polygonPoints[i].longitude; |
| | | } |
| | | return { |
| | | latitude: x / numPoints, |
| | | longitude: y / numPoints |
| | | }; |
| | | }, |
| | | getSite: function getSite() { |
| | | var _this = this; |
| | | var _this3 = this; |
| | | this.$u.api.rentSiteList().then(function (res) { |
| | | if (res.code === 200) { |
| | | _this.markers = []; |
| | | _this3.markers = []; |
| | | res.data.forEach(function (item, index) { |
| | | var num = (0, _utils.distance)(_this.latitude, _this.longitude, item.latitude, item.longitude); |
| | | _this.markers.push({ |
| | | var num = (0, _utils.distance)(_this3.latitude, _this3.longitude, item.latitude, item.longitude); |
| | | _this3.markers.push({ |
| | | id: index, |
| | | width: 40, |
| | | height: 40, |
| | | distance: _this.latitude && _this.longitude ? num : '未知距离', |
| | | isShow: true, |
| | | distance: _this3.latitude && _this3.longitude ? num : '未知距离', |
| | | latitude: item.latitude, |
| | | longitude: item.longitude, |
| | | title: item.name, |
| | |
| | | }); |
| | | }, |
| | | markertap: function markertap(e) { |
| | | var _this2 = this; |
| | | var _this4 = this; |
| | | this.show = false; |
| | | this.markers.forEach(function (item) { |
| | | if (item.id === e.markerId) { |
| | | _this2.rice = item.distance; |
| | | _this4.rice = item.distance; |
| | | item.customCallout.display = 'ALWAYS'; |
| | | item.width = 50; |
| | | item.height = 50; |
| | | if (item.isShow) { |
| | | item.width = 50; |
| | | item.height = 50; |
| | | } else { |
| | | item.width = 40; |
| | | item.height = 50; |
| | | } |
| | | setTimeout(function () { |
| | | _this2.info = item; |
| | | _this2.show = true; |
| | | _this4.info = item; |
| | | _this4.show = true; |
| | | }, 300); |
| | | } else { |
| | | item.width = 40; |
| | | item.height = 40; |
| | | if (item.isShow) { |
| | | item.width = 40; |
| | | item.height = 40; |
| | | } else { |
| | | item.width = 30; |
| | | item.height = 40; |
| | | } |
| | | item.customCallout.display = 'BYCLICK'; |
| | | } |
| | | }); |