import { defineStore } from "pinia";

const commonStore = defineStore("common", {
  state: () => ({
    mapBool: 1, //1.高德 2.测绘院
    streetTownList: [
      { value: "", label: "全区" },
      { value: "华漕镇", label: "华漕镇" },
      { value: "虹桥镇", label: "虹桥镇" },
      { value: "梅陇镇", label: "梅陇镇" },
      { value: "七宝镇", label: "七宝镇" },
      { value: "颛桥镇", label: "颛桥镇" },
      { value: "马桥镇", label: "马桥镇" },
      { value: "吴泾镇", label: "吴泾镇" },
      { value: "浦江镇", label: "浦江镇" },
      { value: "新虹街道", label: "新虹街道" },
      { value: "古美路街道", label: "古美路街道" },
      { value: "江川路街道", label: "江川路街道" },
      { value: "浦锦街道", label: "浦锦街道" },
      { value: "莘庄镇", label: "莘庄镇" },
    ],
    timeList: [
      new Date().getFullYear() +
      "-" +
      (new Date().getMonth() + 1 < 10 ? "0" + (new Date().getMonth() + 1) : "" + (new Date().getMonth() + 1)) +
      "-" +
      (new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate()) +
      " 00:00:00",
      new Date().getFullYear() +
      "-" +
      (new Date().getMonth() + 1 < 10 ? "0" + (new Date().getMonth() + 1) : "" + (new Date().getMonth() + 1)) +
      "-" +
      (new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate()) +
      " 23:59:59",
    ],

    mhjz: [
      { streetTown: "全区", id: 12, x: 121.4175597, y: 31.119248 },
      { streetTown: "江川路街道", id: 1201, x: 121.399126538181, y: 31.0099719391863 },
      { streetTown: "新虹街道", id: 1217, x: 121.319329296294, y: 31.1983901916889 },
      { streetTown: "古美路街道", id: 1206, x: 121.388451866936, y: 31.1478233480159 },
      { streetTown: "浦锦街道", id: 1218, x: 121.483929120352, y: 31.089967318558 },
      { streetTown: "浦江镇", id: 1215, x: 121.524058543447, y: 31.0540039472667 },
      { streetTown: "吴泾镇", id: 1213, x: 121.454076463728, y: 31.04860402113 },
      { streetTown: "马桥镇", id: 1214, x: 121.352680027718, y: 31.0213512298508 },
      { streetTown: "颛桥镇", id: 1209, x: 121.40607138504, y: 31.0612972443508 },
      { streetTown: "莘庄镇", id: 1207, x: 121.37064864047, y: 31.1154549548722 },
      { streetTown: "梅陇镇", id: 1212, x: 121.421346814491, y: 31.1069718313722 },
      { streetTown: "七宝镇", id: 1208, x: 121.350366186317, y: 31.1553292680362 },
      { streetTown: "虹桥镇", id: 1211, x: 121.37956256207, y: 31.1806219953212 },
      { streetTown: "华漕镇", id: 1210, x: 121.277541517147, y: 31.2289121171624 },
      { streetTown: "莘庄工业区", id: 1216, x: 121.376508452784, y: 31.0678185611843 },
    ],

    deviceDetailsArray: {}, //设备详情页面-数据存储

    facilitiesGatherType: "", //设施采集类型-数据存储
    facilitiesGatherArray: {
      department: "", //所属部门
      facilityType: "", //设施类型
      facilityTypeName: "", //设施类型名称
      facilityName: "", //设施名称
      status: "0", //设施状态
      address: "", //设施地址
      longitude: "", //经度
      latitude: "", //纬度
      province: "", //省
      city: "", //市
      area: "", //区（县）
      facilityAddress: "", //详细地址
      streetTown: null, //所属街镇
      gpsAreas: [], //经纬度集合
      contact: "", //联系人
      contactPhone: "", //联系方式
      imagesUrl: "", //图⽚地址URL
      facilityDesc: "", //备注
      extendData: [], //扩展属性
      recordPictureList: [],
      typeGuise: "", //点线面类型
    }, //设施采集页面-数据存储
  }),
  actions: {
    /**
     * @计算当前坐标和G点坐标的偏差值
     * @returns
     */
    caculateLL(lat1, lng1, lat2, lng2) {
      var radLat1 = (lat1 * Math.PI) / 180.0;
      var radLat2 = (lat2 * Math.PI) / 180.0;
      var a = radLat1 - radLat2;
      var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
      var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
      s = s * 6378.137;
      s = Math.round(s * 10000) / 10;
      console.log(s);
      return s;
    },
    /**
     * @公共添加服务器列表
     */
    setServeList(linkUrl, content) {
      let serveList = uni.getStorageSync("serveList");
      if (serveList.length <= 0) {
        uni.setStorageSync("serveList", [
          {
            radiolist: [
              {
                id: 1,
                linkUrl: linkUrl,
                content: content,
              },
            ],
            radiovalue: 1,
          },
        ]);
      } else {
        serveList[0].radiolist.push({
          id: serveList[0].radiolist[serveList[0].radiolist.length - 1].id + 1,
          linkUrl: linkUrl,
          content: content,
        });

        uni.setStorageSync("serveList", serveList);
      }
    },
  },
});

export default commonStore;
