import { defineComponent, openBlock, createBlock, unref, createElementBlock, normalizeClass, createElementVNode, createCommentVNode, toDisplayString, createVNode, render, ref, reactive, computed, watch, renderSlot, isRef, withCtx, withModifiers, nextTick } from "vue";
import WlSvg from "@wltech/svg";
import { Field, Popup, Picker } from "vant";
var employeeSelector = {
  employeeData: null,
  topFiveEmployeeData: null,
  organization: null,
  organization_count: null,
  count: 0,
  dept_list: [],
  company_list: [],
  company_list_count: 0,
  companyEmployeeList: [],
  totalCompanyEmployeeList: [],
  totalCompanyEmployeeObjList: []
};
const Store = {
  sid: "",
  app_id: "",
  user_id: "",
  user_name: "",
  corp_id: "",
  node_env: "",
  domain: "",
  token: "",
  card_resource: "",
  employeeSelector
};
var Store$1 = new Proxy(Store, {
  get(target, name, property) {
    return Reflect.get(target, name, property);
  },
  set(target, name, value, property) {
    return Reflect.set(target, name, value, property);
  }
});
const token_key = {
  dev_uat: "auth-token-mp-test",
  dev_stg: "auth-token-mp",
  dev_prd: "auth-token-mp",
  dev_uat_xsf: "auth-token-se-test",
  dev_stg_xsf: "auth-token-se",
  dev_gray_xsf: "auth-token-se",
  dev_prd_xsf: "auth-token-se",
  uat: "auth-token-mp-test",
  stg: "auth-token-mp",
  prd: "auth-token-mp",
  gray: "auth-token-mp",
  uat_xsf: "auth-token-se-test",
  stg_xsf: "auth-token-se",
  prd_xsf: "auth-token-se",
  gray_xsf: "auth-token-se"
};
const __default__$2 = {
  name: "WlSvgIcon"
};
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
  ...__default__$2,
  props: {
    type: { default: "" },
    color: { default: "var(--wl-text-color-title-1)" },
    width: { default: "16" },
    height: { default: "16" }
  },
  setup(__props) {
    const sub = location.origin;
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(WlSvg), {
        type: __props.type,
        width: __props.width,
        height: __props.height,
        color: __props.color,
        sub: unref(sub)
      }, null, 8, ["type", "width", "height", "color", "sub"]);
    };
  }
});
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1$1 = { class: "icon" };
const _hoisted_2$1 = { class: "text" };
const __default__$1 = {
  name: "WlNotice"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  props: {
    show_toast: { type: Boolean, default: true },
    message: { default: "" },
    type: { default: "success" },
    duration: { default: 1500 }
  },
  setup(__props) {
    return (_ctx, _cache) => {
      return __props.show_toast ? (openBlock(), createElementBlock("div", {
        key: 0,
        class: normalizeClass(`notice ${__props.type}`),
        "data-weiling-mobile-ui-wl-notice": ""
      }, [
        createElementVNode("div", _hoisted_1$1, [
          __props.type === "success" ? (openBlock(), createBlock(_sfc_main$2, {
            key: 0,
            type: "successFill",
            width: "24",
            height: "24",
            color: "#45ce03"
          })) : __props.type === "warning" ? (openBlock(), createBlock(_sfc_main$2, {
            key: 1,
            type: "warningFill",
            width: "24",
            height: "24",
            color: "#f3a401"
          })) : __props.type === "alert" ? (openBlock(), createBlock(_sfc_main$2, {
            key: 2,
            type: "tipsFill",
            width: "24",
            height: "24",
            color: "#1b9fff"
          })) : __props.type === "error" ? (openBlock(), createBlock(_sfc_main$2, {
            key: 3,
            type: "closeFill",
            width: "24",
            height: "24",
            color: "#ff2a2d"
          })) : createCommentVNode("", true)
        ]),
        createElementVNode("p", _hoisted_2$1, toDisplayString(__props.message), 1)
      ], 2)) : createCommentVNode("", true);
    };
  }
});
let mountNode = null;
var WlNotice = (options) => {
  const duration = options.duration | 2e3;
  if (mountNode) {
    document.body.removeChild(mountNode);
    mountNode = null;
  }
  const app = createVNode(_sfc_main$1, {
    ...options,
    duration,
    show_toast: true
  });
  const timer = setTimeout(() => {
    if (mountNode) {
      document.body.removeChild(mountNode);
      mountNode = null;
    }
    clearTimeout(timer);
  }, duration);
  mountNode = document.createElement("div");
  render(app, mountNode);
  document.body.appendChild(mountNode);
};
const getQueryVariable = (variable) => {
  const query = window.location.search.substring(1);
  const vars = query.split("&");
  for (let i = 0; i < vars.length; i++) {
    const pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return "";
};
const removeEmptyField = (obj) => {
  let newObj = {};
  if (typeof obj === "string") {
    obj = JSON.parse(obj);
  }
  if (obj instanceof Array) {
    newObj = [];
  }
  if (obj instanceof Object) {
    for (const attr in obj) {
      if (obj[attr] !== "" && obj[attr] !== null && obj[attr] !== void 0) {
        if (obj[attr] instanceof Object) {
          if (JSON.stringify(obj[attr]) === "{}" || JSON.stringify(obj[attr]) === "[]") {
            continue;
          }
          newObj[attr] = removeEmptyField(obj[attr]);
        } else if (typeof obj[attr] === "string" && (obj[attr].indexOf("{") > -1 && obj[attr].indexOf("}") > -1 || obj[attr].indexOf("[") > -1 && obj[attr].indexOf("]") > -1)) {
          try {
            const attrObj = JSON.parse(obj[attr]);
            if (attrObj instanceof Object) {
              newObj[attr] = removeEmptyField(attrObj);
            }
          } catch (e) {
            newObj[attr] = obj[attr];
          }
        } else {
          newObj[attr] = obj[attr];
        }
      }
    }
  }
  return newObj;
};
function obj2String(obj, arr = [], idx = 0) {
  for (const item in obj) {
    arr[idx++] = [item, obj[item]];
  }
  return new URLSearchParams(arr).toString();
}
function getOptions(options) {
  const { sid = "", corp_id = "", card_resource = "" } = Store$1 != null ? Store$1 : {};
  const params = {
    sid,
    corp_id,
    card_resource,
    ...options
  };
  return obj2String(params);
}
const onHandleUrl = (url) => {
  const { node_env } = Store$1;
  const isPersonMiniApp = node_env.includes("xsf");
  if (isPersonMiniApp) {
    return setPersonMiniAppUrl(url);
  }
  return url;
};
const setPersonMiniAppUrl = (url) => {
  let filterUrl = url;
  if (filterUrl.includes("/api/user/share/path")) {
    filterUrl = filterUrl.replace(
      "/api/user/share/path",
      "/apise/material/share/path"
    );
  } else if (filterUrl.includes("/interact/")) {
    filterUrl = filterUrl.replace("/interact/", "/apise/");
  } else if (filterUrl.includes("/api/")) {
    filterUrl = filterUrl.replace("/api/", "/apise/");
  } else if (filterUrl.includes("/wx/track")) {
    filterUrl = filterUrl.replace("/wx/track", "/apise/track/wx/track");
  }
  return filterUrl;
};
function request(url, options, method = "GET") {
  const staticOption = {
    sid: Store$1.sid,
    corp_id: Store$1.corp_id,
    tab_change: 0
  };
  const data = {
    ...staticOption,
    ...options
  };
  const searchStr = getOptions(removeEmptyField(data));
  const staticSearchStr = getOptions(removeEmptyField(staticOption));
  let initObj = {};
  let params = "";
  if (method === "GET") {
    initObj = {
      method,
      credentials: "include",
      headers: new Headers({
        "access-auth-token": getQueryVariable("msid"),
        [token_key[Store$1.node_env]]: Store$1.token
      })
    };
    params = searchStr;
  } else if (method === "FormPOST") {
    initObj = {
      method: "POST",
      credentials: "include",
      headers: new Headers({
        [token_key[Store$1.node_env]]: Store$1.token
      }),
      body: options
    };
    params = staticSearchStr;
  } else {
    initObj = {
      method,
      credentials: "include",
      headers: new Headers({
        "access-auth-token": getQueryVariable("msid"),
        Accept: "application/json, text/plain, */*",
        "Content-Type": "application/json",
        [token_key[Store$1.node_env]]: Store$1.token
      }),
      body: JSON.stringify(data)
    };
    params = staticSearchStr;
  }
  const filterUrl = onHandleUrl(url) + "?" + params;
  return fetch(filterUrl, initObj).then((res) => {
    const isArea = url.includes("region.json");
    return res.json().then((result) => {
      var _a;
      if (result.code === 200 || isArea) {
        return result;
      } else {
        WlNotice({
          message: (_a = result.msg) != null ? _a : "\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEF",
          type: "error",
          duration: 3e3
        });
        throw Error(result);
      }
    });
  }).then((res) => {
    return res;
  });
}
const GET = (url, options) => {
  return request(url, options, "GET");
};
var Api = {
  gePcaCodeJson() {
    let proxy_api = "";
    switch (Store$1.node_env) {
      case "dev":
      case "dev_uat":
        proxy_api = "/cos_api";
        break;
      case "uat":
        proxy_api = "https://demo-cos.weiling.cn";
        break;
      default:
        proxy_api = "https://wlmvp-cos.weiling.cn";
        break;
    }
    return GET(`${proxy_api}/resources/region.json`, {});
  }
};
var index_vue_vue_type_style_index_0_scoped_true_lang = "";
var _export_sfc = (sfc, props) => {
  const target = sfc.__vccOpts || sfc;
  for (const [key, val] of props) {
    target[key] = val;
  }
  return target;
};
const _hoisted_1 = { class: "wl-area" };
const _hoisted_2 = { class: "bottom-btn" };
const _hoisted_3 = ["onClick"];
const __default__ = {
  name: "WlArea"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    modelValue: { default: () => ({
      key: "000000",
      name: "\u8BF7\u9009\u62E9/\u8BF7\u9009\u62E9/\u8BF7\u9009\u62E9"
    }) },
    title: { default: "\u9009\u62E9\u5730\u5740" },
    fieldLabel: { default: "\u5730\u5740" },
    fieldPlaceholder: { default: "\u7701/\u5E02/\u533A" },
    isFieldLabel: { type: Boolean, default: true },
    env_data: { default: () => ({
      node_env: ""
    }) },
    only_Popup: { type: Boolean, default: false },
    popup_visible: { type: Boolean, default: false }
  },
  emits: ["confirm", "update:popup_visible"],
  setup(__props, { emit }) {
    const props = __props;
    const pickerRef = ref(null);
    const state = reactive({
      fieldValue: "",
      pickerValue: [],
      showPicker: false,
      columns: [],
      disableBtn: true
    });
    const customFieldName = {
      text: "name",
      value: "code",
      children: "children"
    };
    const show_visible = computed(() => state.showPicker || props.popup_visible);
    const click_overlay = () => {
      state.showPicker = false;
      emit("update:popup_visible", false);
    };
    const getRegionJson = async () => {
      var _a, _b;
      const data = await Api.gePcaCodeJson();
      if (!Array.isArray(data))
        return [];
      data == null ? void 0 : data.forEach((ep) => {
        var _a2, _b2;
        ep.children = ep.children || [];
        (_a2 = ep.children) == null ? void 0 : _a2.unshift({
          children: [],
          code: ep.code,
          name: "\u4E0D\u9650"
        });
        (_b2 = ep.children) == null ? void 0 : _b2.forEach((ec) => {
          var _a3;
          ec.children = ec.children || [];
          (_a3 = ec.children) == null ? void 0 : _a3.unshift({
            code: ec.code,
            name: "\u4E0D\u9650"
          });
        });
      });
      const secondColumns = (_a = data == null ? void 0 : data[0]) == null ? void 0 : _a.children;
      const thirdColumns = (_b = secondColumns == null ? void 0 : secondColumns[0]) == null ? void 0 : _b.children;
      const columnsPlaceholder = {
        name: "\u8BF7\u9009\u62E9",
        code: "000000"
      };
      data.unshift({
        ...columnsPlaceholder,
        children: [
          {
            ...columnsPlaceholder,
            children: [columnsPlaceholder, ...thirdColumns]
          },
          ...secondColumns
        ]
      });
      return data;
    };
    const setValue = async (name) => {
      var _a;
      if (!((_a = state.columns) == null ? void 0 : _a.length))
        state.columns = await getRegionJson();
      nextTick(() => {
        var _a2, _b, _c;
        if ((_a2 = state.columns) == null ? void 0 : _a2.length) {
          state.pickerValue = (_c = (_b = pickerRef.value) == null ? void 0 : _b.getSelectedOptions()) == null ? void 0 : _c.map((e) => ({
            code: e.code,
            name: e.name
          }));
          if (name)
            state.fieldValue = name;
        }
      });
    };
    const onChange = (e) => {
      const params = e.selectedOptions.reduce((pre, next) => {
        pre.push({
          code: next.code,
          name: next.name
        });
        return pre;
      }, []);
      state.pickerValue = params;
    };
    const setFieldValue = (arr) => {
      var _a, _b;
      return (_b = (_a = arr == null ? void 0 : arr.filter((e) => e.name && !e.name.includes("\u4E0D\u9650"))) == null ? void 0 : _a.map((e) => e.name)) == null ? void 0 : _b.join("/");
    };
    const onConfirm = () => {
      if (state.disableBtn)
        return;
      state.fieldValue = setFieldValue(state.pickerValue);
      emit("confirm", state.pickerValue);
      click_overlay();
    };
    const onClick = () => {
      state.showPicker = true;
    };
    watch(
      () => props.env_data,
      (val) => {
        Store$1.sid = val.sid;
        Store$1.corp_id = val.corp_id;
        Store$1.node_env = val.node_env;
        Store$1.token = val.token;
      },
      {
        immediate: true,
        deep: true
      }
    );
    const modelValue1 = ref([]);
    watch(
      () => props.modelValue,
      (val) => {
        var _a;
        setValue(val == null ? void 0 : val.name);
        if ((_a = val == null ? void 0 : val.key) != null ? _a : false) {
          const province = +val.key.toString().slice(0, 2);
          const city = +val.key.toString().slice(0, 4);
          const district = val.key;
          modelValue1.value = [province, city, district];
        }
      },
      { immediate: true, deep: true }
    );
    watch(
      () => state.pickerValue,
      (val) => {
        var _a;
        if (val) {
          if (!((_a = state.pickerValue) == null ? void 0 : _a.length))
            return;
          if (state.pickerValue.every((e) => e.code != "000000")) {
            state.disableBtn = false;
          } else {
            state.disableBtn = true;
          }
        }
      },
      { immediate: true, deep: true }
    );
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        !__props.only_Popup ? (openBlock(), createElementBlock("div", {
          key: 0,
          onClick
        }, [
          renderSlot(_ctx.$slots, "default", {}, () => [
            createVNode(unref(Field), {
              modelValue: state.fieldValue,
              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => state.fieldValue = $event),
              readonly: "",
              clickable: "",
              "is-link": "",
              label: __props.isFieldLabel ? __props.fieldLabel : "",
              placeholder: __props.fieldPlaceholder
            }, null, 8, ["modelValue", "label", "placeholder"])
          ], true)
        ])) : createCommentVNode("", true),
        createVNode(unref(Popup), {
          show: unref(show_visible),
          "onUpdate:show": _cache[2] || (_cache[2] = ($event) => isRef(show_visible) ? show_visible.value = $event : null),
          round: "",
          position: "bottom",
          "get-container": "body",
          "lazy-render": false,
          onClickOverlay: click_overlay,
          "close-on-click-overlay": true
        }, {
          default: withCtx(() => [
            createVNode(unref(Picker), {
              ref_key: "pickerRef",
              ref: pickerRef,
              title: __props.title,
              "value-key": "name",
              columns: state.columns,
              "columns-field-names": customFieldName,
              onChange,
              modelValue: modelValue1.value,
              "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => modelValue1.value = $event)
            }, {
              "columns-bottom": withCtx(() => [
                createElementVNode("div", _hoisted_2, [
                  createElementVNode("div", {
                    class: normalizeClass(["btn", { "btn--not": state.disableBtn }]),
                    onClick: withModifiers(onConfirm, ["stop"])
                  }, " \u786E\u8BA4\u9009\u62E9 ", 10, _hoisted_3)
                ])
              ]),
              _: 1
            }, 8, ["title", "columns", "modelValue"])
          ]),
          _: 1
        }, 8, ["show"])
      ]);
    };
  }
});
var Comp = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-77c0c9b4"]]);
var __uno = "";
Comp.install = (app) => {
  app.component(Comp.name, Comp);
};
export { Comp as default };
