areaManage.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. var map,mouseTool;
  2. var cirCle,circleEdi = null,cirToo = false;
  3. var Poly,polyEdit = null,polToo = false;
  4. var poinLi = {
  5. "lon":[],
  6. "lat":[],
  7. "radius": 0
  8. };
  9. new Vue({
  10. el: '#app',
  11. data: function() {
  12. return {
  13. areaLi: [],
  14. treeLi: [],
  15. treeVis:false,
  16. treeForm:{
  17. group_name: "",
  18. pid: 0,
  19. type: 1,
  20. fence_type: 0,
  21. add_userid: 1
  22. },
  23. treeArea: [],
  24. logVis: false,
  25. treeAreaForm:{
  26. group_name: "",
  27. pid: 0,
  28. type: 0,
  29. fence_type: null,
  30. add_userid: 1
  31. },
  32. defaultProps: {
  33. children: 'children',
  34. label: 'group_name'
  35. },
  36. nowArea:{type: -1},
  37. centerVal: ""
  38. }
  39. },
  40. created() {
  41. _this = this;
  42. _this.getList();
  43. _this.getTreeLi();
  44. },
  45. mounted(){
  46. map = new AMap.Map("areaMap", {
  47. center: [116.433322, 39.900256],
  48. zoom: 14
  49. });
  50. },
  51. methods:{
  52. getList(){
  53. const loading = this.$loading({
  54. background: 'rgba(0, 0, 0, 0.4)'
  55. })
  56. let _opts = {
  57. url: baseUrl + "/SelGroupConfig?add_userid=1&type=2&_t="+new Date().getTime(),
  58. type:"GET"
  59. };
  60. let _data = {};
  61. getAxios(_opts,_data,{}).then((res) => {
  62. _this.areaLi = [{
  63. "group_name": "区域管理",
  64. "id": 0,
  65. "pid": -1,
  66. "show": true,
  67. "type": -1,
  68. "children": getTree(res.data,0)
  69. }];
  70. dkslfjk = _this.areaLi;
  71. loading.close();
  72. })
  73. },
  74. getTreeLi(){
  75. let _opts = {
  76. url: baseUrl + "/SelGroupConfig?add_userid=1&type=0&_t="+new Date().getTime(),
  77. type:"GET"
  78. };
  79. let _data = {};
  80. getAxios(_opts,_data,{}).then((res) => {
  81. _this.treeArea = [{
  82. "group_name": "区域管理",
  83. "id": 0,
  84. "pid": -1,
  85. "show": true,
  86. "type": -1,
  87. "children": getTree(res.data,0)
  88. }]
  89. _this.treeLi = getTree(res.data,0);
  90. })
  91. },
  92. // 显示圆形
  93. showCircle(_obj){
  94. cirCle = new AMap.Circle({
  95. center: [_obj.lng, _obj.lat],
  96. radius: _obj.radius,
  97. strokeColor: "#0081FF",
  98. strokeOpacity: 1,
  99. strokeWeight: 3,
  100. strokeOpacity: 0.8,
  101. fillColor: '#519efc',
  102. fillOpacity: 0.4,
  103. strokeStyle: 'solid',
  104. })
  105. cirCle.setMap(map);
  106. map.setFitView([ cirCle ]);
  107. // circleEdi.on('end', function(event) {
  108. // console.log(event)
  109. // })
  110. },
  111. // 显示多边形
  112. showPoly(_obj){
  113. Poly = new AMap.Polygon({
  114. path: _obj,
  115. strokeColor: "#0081FF",
  116. strokeOpacity: 1,
  117. strokeWeight: 3,
  118. strokeOpacity: 0.8,
  119. fillColor: '#519efc',
  120. fillOpacity: 0.4,
  121. strokeStyle: 'solid',
  122. });
  123. Poly.setMap(map);
  124. map.setFitView([ Poly ]);
  125. },
  126. // 根据区域ID获取经纬度
  127. getPoint(_data){
  128. let _opts = {
  129. url: baseUrl + "/SelFenceConfig?pid="+(_data.id)+"&_t="+new Date().getTime(),
  130. type:"GET"
  131. };
  132. let _ocn = {};
  133. getAxios(_opts,_ocn,{}).then((res) => {
  134. if(res.result == "ok"){
  135. let _ocj = JSON.parse(res.data[0].fence_gps);
  136. if(_data.fence_type == 0){
  137. _data["lng"] = _ocj.lon[0];
  138. _data["lat"] = _ocj.lat[0];
  139. _data["radius"] = _ocj.radius;
  140. _this.showCircle(_data);
  141. }else{
  142. let _arr = [],_saf = _ocj.lon,_xvj = _ocj.lat;
  143. for(let i=0;i<_saf.length;i++){
  144. _arr.push([_saf[i], _xvj[i]]);
  145. }
  146. _this.showPoly(_arr);
  147. }
  148. }
  149. })
  150. },
  151. // 编辑
  152. editArea(){
  153. if(_this.nowArea.id != undefined){
  154. if(_this.nowArea.type == 0){
  155. _this.logVis = true;
  156. _this.treeAreaForm = _this.nowArea;
  157. }else if(_this.nowArea.type == 1){
  158. if(_this.nowArea.fence_type == 0){
  159. circleEdi = new AMap.CircleEditor(map, cirCle);
  160. circleEdi.open();
  161. }else{
  162. polyEdit = new AMap.PolygonEditor(map, Poly);
  163. polyEdit.open();
  164. }
  165. }
  166. }
  167. },
  168. // 删除
  169. delArea(){
  170. if(_this.nowArea.id != undefined){
  171. _this.$confirm('你确定要删除['+(_this.nowArea.name)+']吗?', '温馨提示', {
  172. confirmButtonText: '确定',
  173. cancelButtonText: '取消',
  174. type: 'warning'
  175. }).then(() => {
  176. _this.$message({
  177. type: 'success',
  178. message: '删除成功!'
  179. });
  180. }).catch(() => {});
  181. }
  182. },
  183. //---------------------------- 分类 ----------------------------
  184. // 侧边树形
  185. nodeClick(data){
  186. if(data.type == 1){
  187. if(_this.nowArea.id != data.id){
  188. map.clearMap();
  189. _this.getPoint(data);
  190. }
  191. }else{
  192. map.clearMap();
  193. }
  194. _this.nowArea = data;
  195. },
  196. // 重置分类表单
  197. reSet(){
  198. _this.treeAreaForm = {
  199. group_name: "",
  200. pid: 0,
  201. type: 0,
  202. fence_type: null,
  203. add_userid: 1
  204. };
  205. _this.logVis = true;
  206. },
  207. hideM(){
  208. _this.getList();
  209. map.clearMap();
  210. _this.logVis = false;
  211. _this.treeVis = false;
  212. },
  213. // 分类树形
  214. treeAreaClick(data){
  215. _this.treeAreaForm.pid = data.id;
  216. },
  217. // 提交分类
  218. saveTreeArea(){
  219. if(_this.treeAreaForm.group_name == ""){
  220. _this.$message({
  221. type: 'warning',
  222. message: '请先填写分类名称!'
  223. });
  224. return;
  225. }
  226. let _opts = {
  227. url: baseUrl + "/AddGroupConfig?_t="+new Date().getTime(),
  228. type:"GET"
  229. };
  230. let _data = _this.treeAreaForm;
  231. getAxios(_opts,_data,{}).then((res) => {
  232. if(res.result == "ok"){
  233. _this.$message({
  234. type: 'success',
  235. message: '操作成功!'
  236. });
  237. _this.getList();
  238. _this.getTreeLi();
  239. _this.logVis = false;
  240. }else{
  241. _this.$message.error('操作失败');
  242. }
  243. })
  244. },
  245. //---------------------------- 分类 ----------------------------
  246. //---------------------------- 区域 ----------------------------
  247. // 区域树形
  248. treeClick(data){
  249. _this.treeForm.pid = data.id;
  250. },
  251. reTrSet(){
  252. _this.treeForm = {
  253. group_name: "",
  254. pid: (_this.treeLi.length?_this.treeLi[0].id:0),
  255. type: 1,
  256. fence_type: 0,
  257. add_userid: 1
  258. };
  259. poinLi = {
  260. "lon":[],
  261. "lat":[],
  262. "radius": 0
  263. };
  264. mouseTool = new AMap.MouseTool(map);
  265. _this.drawCircle();
  266. _this.treeVis = true;
  267. },
  268. // 提交区域
  269. saveTree(){
  270. if(circleEdi != null){
  271. circleEdi.close();
  272. }
  273. if(polyEdit != null){
  274. polyEdit.close();
  275. }
  276. if(!poinLi.lon.length){
  277. _this.$message({
  278. type: 'warning',
  279. message: '请先绘制区域!'
  280. });
  281. return;
  282. }
  283. if(_this.treeForm.group_name == ""){
  284. _this.$message({
  285. type: 'warning',
  286. message: '请先填写分类名称!'
  287. });
  288. return;
  289. }
  290. let _opts = {
  291. url: baseUrl + "/AddGroupConfig?_t="+new Date().getTime(),
  292. type:"GET"
  293. };
  294. let _data = _this.treeForm;
  295. getAxios(_opts,_data,{}).then((res) => {
  296. if(res.result == "ok"){
  297. let _xv = {
  298. url: baseUrl + "/AddFenceConfig?_t="+new Date().getTime()
  299. };
  300. let _fdh = {
  301. fence_gps: JSON.stringify(poinLi),
  302. pid: res.msg
  303. };
  304. getAxios(_xv,_fdh,{}).then((res) => {
  305. _this.$message({
  306. type: 'success',
  307. message: '操作成功!'
  308. });
  309. _this.getList();
  310. map.clearMap();
  311. _this.treeVis = false;
  312. })
  313. }else{
  314. _this.$message.error('操作失败');
  315. }
  316. })
  317. },
  318. // 画圆形
  319. drawCircle(){
  320. mouseTool.circle({
  321. strokeColor: "#0081FF",
  322. strokeOpacity: 1,
  323. strokeWeight: 3,
  324. strokeOpacity: 0.8,
  325. fillColor: '#519efc',
  326. fillOpacity: 0.4,
  327. strokeStyle: 'solid',
  328. })
  329. cirToo = true;
  330. mouseTool.on('draw', function(e) {
  331. var _ocj = e.obj["De"];
  332. mouseTool.close(true);
  333. if(_this.treeForm.fence_type == 0){
  334. cirCle = new AMap.Circle({
  335. center: [_ocj.center.lng, _ocj.center.lat],
  336. radius: _ocj.radius,
  337. strokeColor: "#0081FF",
  338. strokeOpacity: 1,
  339. strokeWeight: 3,
  340. strokeOpacity: 0.8,
  341. fillColor: '#519efc',
  342. fillOpacity: 0.4,
  343. strokeStyle: 'solid',
  344. })
  345. cirCle.setMap(map);
  346. map.setFitView([ cirCle ]);
  347. circleEdi = new AMap.CircleEditor(map, cirCle);
  348. circleEdi.open();
  349. circleEdi.on('end', function(e) {
  350. var _zxv = e.target["De"];
  351. poinLi = {
  352. "lon":[_ocj.center.lng],
  353. "lat":[_ocj.center.lat],
  354. "radius": _ocj.radius
  355. };
  356. })
  357. }else{
  358. let _xcv = _this.getEN(_ocj.path);
  359. Poly = new AMap.Polygon({
  360. path: _xcv,
  361. strokeColor: "#0081FF",
  362. strokeOpacity: 1,
  363. strokeWeight: 3,
  364. strokeOpacity: 0.8,
  365. fillColor: '#519efc',
  366. fillOpacity: 0.4,
  367. strokeStyle: 'solid',
  368. });
  369. Poly.setMap(map);
  370. map.setFitView([ Poly ]);
  371. polyEdit = new AMap.PolyEditor(map, Poly);
  372. polyEdit.open();
  373. polyEdit.on('end', function(e) {
  374. var _zxv = e.target["De"];
  375. _this.getEN(_zxv.path);
  376. })
  377. }
  378. })
  379. },
  380. // 提取多边形经纬度
  381. getEN(xcv){
  382. let _anv = [],_ikg = [], _zli = [];
  383. if(xcv.length){
  384. for(let i=0;i<xcv.length;i++){
  385. _anv.push([xcv[i].lng, xcv[i].lat]);
  386. _ikg.push(xcv[i].lng);
  387. _zli.push(xcv[i].lat);
  388. }
  389. }
  390. poinLi = {
  391. "lon": _ikg,
  392. "lat": _zli,
  393. "radius": 0
  394. };
  395. return _anv;
  396. },
  397. // 画多边形
  398. drawPoly(){
  399. mouseTool.polyline({
  400. strokeColor: "#0081FF",
  401. strokeOpacity: 1,
  402. strokeWeight: 3,
  403. strokeOpacity: 0.8,
  404. fillColor: '#519efc',
  405. fillOpacity: 0.4,
  406. strokeStyle: 'solid',
  407. })
  408. polToo = true;
  409. },
  410. // 单选框事件
  411. changFence(e){
  412. _this.treeForm.fence_type = e;
  413. map.clearMap();
  414. poinLi = {
  415. "lon":[],
  416. "lat":[],
  417. "radius": 0
  418. };
  419. if(e == 0){
  420. if(circleEdi != null){
  421. circleEdi.close();
  422. }
  423. _this.drawCircle();
  424. }else{
  425. if(polyEdit != null){
  426. polyEdit.close();
  427. }
  428. _this.drawPoly();
  429. }
  430. },
  431. setCenter(){
  432. if(_this.centerVal != ""){
  433. let _obj = _this.centerVal;
  434. let _cbv = [];
  435. if(_obj.indexOf(",") != -1){
  436. _cbv = _obj.split(",");
  437. }else if(_obj.indexOf(",") != -1){
  438. _cbv = _obj.split(",")
  439. }
  440. var marker = new AMap.Marker({
  441. icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png",
  442. position: [parseFloat(_cbv[0]), parseFloat(_cbv[1])]
  443. });
  444. map.add(marker);
  445. map.setFitView();
  446. }
  447. }
  448. //---------------------------- 区域 ----------------------------
  449. }
  450. })