const options = {
  url: '/arcgisApi/4.7/init.js',
};

import _default, * as esriLoader from 'esri-loader';
import { getMyBiaoJi } from '../../../api/zhxxAPI.js';
import { _getLngLat } from './mercatorToLngLat';
export function getBiaoJiList(_self, tableData) {
  esriLoader
    .loadModules(
      [
        'esri/Graphic',
        'esri/geometry/Point',
        'esri/geometry/SpatialReference',
        'dojo/domReady!',
      ],
      options,
    )
    .then(([Graphic, Point, SpatialReference]) => {
      var bjGraphicLayer = _self.mapObject.findLayerById('bjGraphicLayer');
      bjGraphicLayer.removeAll();
      bjGraphicLayer.visible = true;
      var symbol = {
        //
        type: 'picture-marker',
        url: '/src/views/zongHeXinXiNew/assets/bjR.png',
        width: '16px',
        height: '34px',
      };
      var gra, pt, symbol;
      tableData.forEach((item) => {
        if (item.lgtd && item.lttd) {
          pt = new Point(item.lgtd, item.lttd, new SpatialReference(102100));
          gra = new Graphic({
            geometry: pt,
            symbol: symbol,
            attributes: item,
          });
          bjGraphicLayer.add(gra);
        }
      });
      // getMyBiaoJi(_self.userId,'','','',1,10000).then((res)=>{
      //     if(res.data.list){
      //         res.data.list.forEach((item)=>{
      //             if(item.lgtd && item.lttd){
      //                 pt = new Point(item.lgtd,item.lttd,new SpatialReference(102100));
      //                 gra = new Graphic({
      //                     geometry:pt,
      //                     symbol:symbol,
      //                     attributes:item
      //                 })
      //                 bjGraphicLayer.add(gra);
      //             }
      //         });
      //     }
      // })
    })
    .catch((err) => {
      console.error(err);
    });
}

export function biaojiHandler(_self, mapPoint) {
  esriLoader
    .loadModules(
      [
        'esri/Graphic',
        'esri/geometry/Point',
        'esri/geometry/SpatialReference',
        'dojo/domReady!',
      ],
      options,
    )
    .then(([Graphic, Point, SpatialReference]) => {
      var symbol = {
        //
        type: 'picture-marker',
        url: '/src/views/zongHeXinXiNew/assets/bjR.png',
        width: '16px',
        height: '34px',
      };
      var gra = new Graphic({
        geometry: mapPoint,
        symbol: symbol,
        attributes: '',
      });
      _self.viewObject.graphics.removeAll();
      _self.viewObject.graphics.add(gra);
      var longLat = _getLngLat({
        x: mapPoint.x,
        y: mapPoint.y,
      });
      var str =
        '<div>' +
        '<div>' +
        "<div style='display: flex;padding: 2px;'>" +
        "<p style='font-size: 14px;padding: 5px;'>名称:</p>" +
        "<input type='text' id='nameId' style='height: 33px;width: 222px;'>" +
        '</div>' +
        "<div style='display: flex;padding: 2px;'>" +
        "<p style='font-size: 14px;padding: 5px;padding-top: 8px;'>经度:</p>" +
        "<input type='text' id='longId' style='height: 33px;width: 90px;'value='" +
        longLat.lng.toFixed(6) +
        "'>" +
        "<p style='font-size: 14px;padding: 5px;padding-top: 8px;'>纬度:</p>" +
        "<input type='text' id='latId' style='height: 33px;width: 90px;' value='" +
        longLat.lat.toFixed(6) +
        "'>" +
        '</div>' +
        "<div style='display: flex;padding: 2px;'>" +
        "<p style='font-size: 14px;padding: 5px;'>备注:</p>" +
        "<textarea id='noteId' rows='6' cols='28' style='width: 222px;'>" +
        '</textarea>' +
        '</div>' +
        '</div>' +
        "<div style='margin-top:10px;float: right;'>" +
        "<button type='button' style='margin-right: 20px;width: 50px;' @click='cancelHandler()'>取消</button>" +
        "<button type='button' style='width: 50px;' @click='submitHandler(" +
        longLat.lng +
        ',' +
        longLat.lat +
        ")'>保存</button>" +
        '</div>' +
        '</div>';
      _self.viewObject.popup.open({
        title: '新建标记',
        content: _self.initHtml(str),
        location: mapPoint,
      });
    })
    .catch((err) => {
      console.error(err);
    });
}
